Update of /cvsroot/php-blog/serendipity
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17269
Modified Files:
serendipity_functions.inc.php
Log Message:
Pimp up that category selector:
* If one item is selected (or the selector is contracted) show the normal dropdown, otherwise show the multibox
* Hide no-category in multibox
* Make sure prefix works with this new behaviour
Should work like a charm, please test :)
Index: serendipity_functions.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_functions.inc.php,v
retrieving revision 1.282
retrieving revision 1.283
diff -u -d -r1.282 -r1.283
--- serendipity_functions.inc.php 7 Jun 2004 17:47:31 -0000 1.282
+++ serendipity_functions.inc.php 7 Jun 2004 18:56:30 -0000 1.283
@@ -2428,7 +2428,7 @@
}
$n = "\n";
- $cat_list = '<select id="categoryselector" name="serendipity[categories][]" multiple="multiple" style="vertical-align: middle;" size="3">' . $n;
+ $cat_list = '<select id="categoryselector" name="serendipity[categories][]" style="vertical-align: middle;" multiple="multple">' . $n;
$cat_list .= ' <option value="0">[' . NO_CATEGORY . ']</option>' . $n;
$selected = array();
if (is_array($entry['categories'])) {
@@ -2492,24 +2492,59 @@
<script type="text/javascript" language="JavaScript">
var selector_toggle = new Array();
var selector_store = new Array();
-
function showItem(id) {
+ var selected = 0;
if (document.getElementById) {
el = document.getElementById(id);
if (selector_toggle[id] && selector_toggle[id] == 'off') {
el.size = selector_store[id];
selector_toggle[id] = 'on';
+
+ /* Show a normal dropdown */
+ el.multiple = false;
+
+ /* Show the [No Category] item */
+ el.options.item(0).style.display = '';
+
+ /* Hack to make sure that when the single dropdown is shown, don't have multiple selections */
+ for (i=0; i< el.options.length; i++) {
+ if ( el.options[i].selected == true ) selected++;
+
+ if ( selected > 1 ) {
+ /* If there is more than one selected, we reset all those to false
+ This is because otherwise the label will say 'No Category', but the categories will still be selected */
+ for (i=0; i< el.options.length; i++) el.options[i].selected = false;
+
+ el.selectedIndex = 0
+ break;
+ }
+ }
+
+ if ( el.selectedIndex == -1 ) el.selectedIndex = 0;
+
document.getElementById('option_' + id).src = 'pixel/plus.png';
} else {
selector_store[id] = el.size;
- el.size = <?php echo count($cats)+1; ?>;
+ el.size = <?php echo count($cats)+1; ?>-1;
selector_toggle[id] = 'off';
+
+ /* Show multiple items */
+ el.multiple = true;
+
+ /* Hide the [No Category] item when we are in multi-mode */
+ el.options.item(0).style.display = 'none';
+
document.getElementById('option_' + id).src = 'pixel/minus.png';
}
}
}
</script>
- <a style="border:0; text-decoration: none" href="#" onclick="showItem('categoryselector'); return false" title="<?php echo TOGGLE_OPTION; ?>"><img src="pixel/plus.png" id="option_categoryselector" alt="+/-" border="0" /></a> <b><?php echo CATEGORY; ?>:</b> <?php echo $cat_list ; ?></td>
+ <a style="border:0; text-decoration: none" href="#" onclick="showItem('categoryselector'); return false" title="<?php echo TOGGLE_OPTION; ?>"><img src="pixel/plus.png" id="option_categoryselector" alt="+/-" border="0" /></a> <b><?php echo CATEGORY; ?>:</b> <?php echo $cat_list ; ?>
+<?php
+ echo '<script>selector_toggle[\'categoryselector\'] = \''. (sizeof($serendipity['POST']['categories']) > 1 ? 'on' : 'off') .'\'; showItem(\'categoryselector\'); </script>';
+?>
+
+</td>
</tr>
<tr>
<?php
|