Update of /cvsroot/php-blog/serendipity
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8547
Modified Files:
serendipity_functions.inc.php
Log Message:
Made funky category selector work better in IE.
In mozilla store the state of the box between toggling. Does not yet work in
IE, the friggin' piece of software needs a totally superfluous alert() to
get it done. Miracles of software technology.
Index: serendipity_functions.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_functions.inc.php,v
retrieving revision 1.283
retrieving revision 1.284
diff -u -d -r1.283 -r1.284
--- serendipity_functions.inc.php 7 Jun 2004 18:56:30 -0000 1.283
+++ serendipity_functions.inc.php 9 Jun 2004 11:52:19 -0000 1.284
@@ -2489,62 +2489,87 @@
<?php
}
?>
+ <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 ; ?>
<script type="text/javascript" language="JavaScript">
- var selector_toggle = new Array();
- var selector_store = new Array();
+ var selector_toggle = new Array();
+ var selector_store = new Array();
+ var selector_restore = 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_restore[id] = new Array();
+ if (selector_store[id] > 0) {
+ el.size = selector_store[id];
+ } else {
+ el.size = 1
+ }
+
selector_toggle[id] = 'on';
/* Show a normal dropdown */
- el.multiple = false;
-
- /* Show the [No Category] item */
- el.options.item(0).style.display = '';
+ if (el.multiple) {
+ el.multiple = false;
+ }
/* Hack to make sure that when the single dropdown is shown, don't have multiple selections */
+ last = 0;
for (i=0; i< el.options.length; i++) {
- if ( el.options[i].selected == true ) selected++;
+ if (el.options[i].selected == true) selected++;
- if ( selected > 1 ) {
+ 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;
+ for (j=0; j < el.options.length; j++) {
+ /* Save selection in array to later restore them */
+ if (el.options[j].selected == true) {
+ el.options[j].selected = false;
+ selector_restore[id][j] = 'on';
+ last = j;
+ } else {
+ selector_restore[id][j] = false;
+ }
+ }
- el.selectedIndex = 0
+ el.selectedIndex = last;
break;
}
}
- if ( el.selectedIndex == -1 ) el.selectedIndex = 0;
+ 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; ?>-1;
+ el.size = <?php echo count($cats)+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';
+ /* Restore previously selected items? */
+ for (i = 0; i < el.options.length; i++) {
+ if (selector_restore && selector_restore[id] && selector_restore[id][i] && selector_restore[id][i] == 'on') {
+ val = el.options[i].value;
+ if (el.options[i].selected != true) {
+ el.options[i].selected = true;
+ // [TODO] IE Bug: Don't ask me why, but this restoring only works in Internet Explorer if you put this:
+ // alert('it doesnt matter what, just the alert is important');
+ }
+ }
+ }
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 ; ?>
-<?php
- echo '<script>selector_toggle[\'categoryselector\'] = \''. (sizeof($serendipity['POST']['categories']) > 1 ? 'on' : 'off') .'\'; showItem(\'categoryselector\'); </script>';
-?>
-</td>
+ selector_toggle['categoryselector'] = '<?php echo ((isset($serendipity['POST']['categories']) && sizeof($serendipity['POST']['categories']) > 1) ? 'on' : 'off'); ?>';
+ showItem('categoryselector');
+ </script>
+ </td>
</tr>
<tr>
<?php
|