1 <?php
if (!defined('PmWiki')) exit();
6 Adds two sort buttons to edit form.
7 Lines in page can be sorted in ascending or descending order.
8 Duplicate and empty lines are removed.
11 Copyright 2011 Anomen (ludek_h@seznam.cz)
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published
14 by the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
18 $RecipeInfo['SortPageLines']['Version'] = '2013-01-24';
20 if ($action == 'edit') {
22 $HTMLHeaderFmt['sortpage'] = '
23 <script type="text/javascript">
27 function sortPage(order) {
29 var sortPage_fnc = function (a, b) {
32 return ((a < b) ? -1 : ((a > b) ? 1 : 0));
35 var textField = document.getElementById("text");
36 var value = textField.value;
38 var mySplitResult = value.split("\n");
39 mySplitResult.sort(sortPage_fnc);
41 mySplitResult.reverse();
45 for(i = 0; i < mySplitResult.length; i++) {
46 var curr = mySplitResult[i];
47 if ((lastval != curr) && (curr != "")) {
48 value = value + curr + "\n";
52 textField.value = value;
58 if (IsEnabled($EnableGUIButtons)) {
59 $GUIButtons['sortpageAsc'] = array(1250, '', '', '',
60 '<input type=\"button\" name=\"sortPageButtonAsc\" value=\"$[Sort lines ASC]\" onClick=\"sortPage(0);\" />');
61 $GUIButtons['sortpageDesc'] = array(1251, '', '', '',
62 '<input type=\"button\" name=\"sortPageButtonDesc\" value=\"$[Sort lines DESC]\" onClick=\"sortPage(1);\" />');
64 $MessagesFmt[] = "<input type='button' name='sortPageButtonAsc' value='$[Sort lines ASC]' onClick='sortPage(0);'/>";
65 $MessagesFmt[] = "<input type='button' name='sortPageButtonDesc' value='$[Sort lines DESC]' onClick='sortPage(1);'/>";