diff options
| author | donncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36> | 2005-08-04 11:54:40 +0000 |
|---|---|---|
| committer | donncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36> | 2005-08-04 11:54:40 +0000 |
| commit | ddaa11d747bfdb2a8f16a868ad400e1880dd3d6f (patch) | |
| tree | 5171513705cc0141b87c1af96c19a167ae99bbd5 | |
| parent | 44322dc10630292a50aced9edaa19bce583b9bad (diff) | |
Move AJAX code into function so it can be used multiple times.
Add AJAX functionality to new category textbox on edit form and category page.
AJAX code from: http://grebowiec.net/?p=77 / http://grebowiec.net/wp-content/searchboxcode.txt
git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@124 7be80a69-a1ef-0310-a953-fb0f7c49ff36
| -rw-r--r-- | wp-inst/wp-admin/admin-functions.php | 72 | ||||
| -rw-r--r-- | wp-inst/wp-admin/categories.php | 4 | ||||
| -rw-r--r-- | wp-inst/wp-admin/edit-form-advanced.php | 2 | ||||
| -rw-r--r-- | wp-inst/wp-admin/wpmu-blogs.php | 66 | ||||
| -rw-r--r-- | wp-inst/wp-admin/wpmu-edit.php | 15 |
5 files changed, 92 insertions, 67 deletions
diff --git a/wp-inst/wp-admin/admin-functions.php b/wp-inst/wp-admin/admin-functions.php index 1be7991..ed85265 100644 --- a/wp-inst/wp-admin/admin-functions.php +++ b/wp-inst/wp-admin/admin-functions.php @@ -1380,4 +1380,76 @@ function documentation_link( $for ) { return; } +function AJAX_search_box( $get_url, $search_field = 'newvalue', $search_results_field = 'searchresults' ) { + ?> + <script language="JavaScript"> + + function update_AJAX_search_box( username ) + { + document.getElementById("<?php echo $search_field ?>").value=username; + document.getElementById("<?php echo $search_results_field ?>").innerHTML = "<?php _e( 'Search Results' ) ?>"; + document.getElementById("<?php echo $search_results_field ?>").style.display = 'none'; + return false; + } + + // from js_util.js by scottandrew.com/junkyard/js/ + function addEvent(elm, evType, fn, useCapture) + { + if (elm.addEventListener){ + elm.addEventListener(evType, fn, useCapture); + return true; + } else if (elm.attachEvent){ + var r = elm.attachEvent("on"+evType, fn); + return r; + } else { + alert("Handler could not be removed"); + } + } + // end from scottandrew.com/junkyard/js/ + + var valBox = document.getElementById("<?php echo $search_field ?>"); + var displayBox = document.getElementById("<?php echo $search_results_field ?>"); + addEvent(valBox, 'keyup', doTest, false); + var keyPressDelay = ''; + + var xmlhttp=false; + try { + xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); + } catch (e) { + try { + xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); + } catch (E) { + xmlhttp = false; + } + } + + if (!xmlhttp && typeof XMLHttpRequest!='undefined') { + xmlhttp = new XMLHttpRequest(); + } + + function doTest() { + if (keyPressDelay) { + window.clearTimeout(keyPressDelay); + } + + if(valBox.value != '') { + keyPressDelay = window.setTimeout('doSearch()',800); + } + } + + function doSearch() { + displayBox.style.display = ''; + displayBox.innerHTML = "Searching ..."; + xmlhttp.open("GET","<?php echo $get_url ?>"+valBox.value,true); + xmlhttp.onreadystatechange=function() { + if (xmlhttp.readyState==4) { + displayBox.innerHTML = xmlhttp.responseText; + } + } + xmlhttp.send(null); + } + </script> + <?php +} + ?> diff --git a/wp-inst/wp-admin/categories.php b/wp-inst/wp-admin/categories.php index 872adb6..efab600 100644 --- a/wp-inst/wp-admin/categories.php +++ b/wp-inst/wp-admin/categories.php @@ -146,7 +146,9 @@ cat_rows(); <form name="addcat" id="addcat" action="categories.php" method="post"> <p><?php _e('Name:') ?><br /> - <input type="text" name="cat_name" value="" /></p> + <input type="text" name="cat_name" id='cat_name' value="" /></p> + <div style='display:none; height: 60px; width: 100px; overflow: auto; border: 1px solid #ccc; background: #eee; margin: 5px; padding: 5px;' id="searchresults"><?php _e( 'Search Results' ) ?></div> + <?php AJAX_search_box( "wpmu-edit.php?action=searchcategories&search=", "cat_name", "searchresults" ); ?> <p><?php _e('Category parent:') ?><br /> <select name='category_parent' class='postform'> <option value='0'><?php _e('None') ?></option> diff --git a/wp-inst/wp-admin/edit-form-advanced.php b/wp-inst/wp-admin/edit-form-advanced.php index 0470587..e80bbb0 100644 --- a/wp-inst/wp-admin/edit-form-advanced.php +++ b/wp-inst/wp-admin/edit-form-advanced.php @@ -89,7 +89,9 @@ window.onload = focusit; <p id="ajaxcat"> <input type="text" name="cat_name" id="cat_name" size="16" /> <input type="submit" name="save" value="+"> + <div style='display:none; height: 60px; width: 100px; overflow: auto; border: 1px solid #ccc; background: #eee; margin: 5px; padding: 5px;' id="searchresults"><?php _e( 'Search Results' ) ?></div> </p> +<?php AJAX_search_box( "wpmu-edit.php?action=searchcategories&search=", "cat_name", "searchresults" ); ?> </div> </fieldset> diff --git a/wp-inst/wp-admin/wpmu-blogs.php b/wp-inst/wp-admin/wpmu-blogs.php index ed9469d..d5c784b 100644 --- a/wp-inst/wp-admin/wpmu-blogs.php +++ b/wp-inst/wp-admin/wpmu-blogs.php @@ -176,72 +176,8 @@ switch( $_GET[ 'action' ] ) { <p class="submit"> <input type="submit" name="Submit" value="<?php _e('Update Options') ?> »" /> </p> +<?php AJAX_search_box( "wpmu-edit.php?action=searchusers&search=", "newuser", "searchresults" ); ?> -<script language="JavaScript"> - -function updateUserBox( username ) -{ - document.form1.newuser.value=username; - document.getElementById("searchresults").innerHTML = "<?php _e( 'Search Results' ) ?>"; - return false; -} - -// from js_util.js by scottandrew.com/junkyard/js/ -function addEvent(elm, evType, fn, useCapture) -{ - if (elm.addEventListener){ - elm.addEventListener(evType, fn, useCapture); - return true; - } else if (elm.attachEvent){ - var r = elm.attachEvent("on"+evType, fn); - return r; - } else { - alert("Handler could not be removed"); - } -} -// end from scottandrew.com/junkyard/js/ - -var valBox = document.getElementById("newuser"); -var displayBox = document.getElementById("searchresults"); -addEvent(valBox, 'keyup', doTest, false); -var keyPressDelay = ''; - -var xmlhttp=false; - try { - xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); - } catch (e) { - try { - xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); - } catch (E) { - xmlhttp = false; - } - } - -if (!xmlhttp && typeof XMLHttpRequest!='undefined') { - xmlhttp = new XMLHttpRequest(); -} - -function doTest() { - if (keyPressDelay) { - window.clearTimeout(keyPressDelay); - } - - if(valBox.value != '') { - keyPressDelay = window.setTimeout('doSearch()',800); - } -} - -function doSearch() { - displayBox.innerHTML = "Searching ..."; - xmlhttp.open("GET","wpmu-edit.php?action=searchusers&search="+valBox.value,true); - xmlhttp.onreadystatechange=function() { - if (xmlhttp.readyState==4) { - displayBox.innerHTML = xmlhttp.responseText; - } - } - xmlhttp.send(null); -} -</script> </td> </table> <?php diff --git a/wp-inst/wp-admin/wpmu-edit.php b/wp-inst/wp-admin/wpmu-edit.php index 1b20ec9..fa8288c 100644 --- a/wp-inst/wp-admin/wpmu-edit.php +++ b/wp-inst/wp-admin/wpmu-edit.php @@ -5,6 +5,19 @@ do_action( "wpmuadminedit", "" ); $id = $wpdb->escape( $_POST[ 'id' ] ); switch( $_GET[ 'action' ] ) { + case "searchcategories": + $search = $wpdb->escape( $_GET[ 'search' ] ); + $id = $wpdb->escape( $_GET[ 'id' ] ); + $query = "SELECT cat_name FROM " . $wpdb->sitecategories . " WHERE cat_name LIKE '%" . $search . "%' limit 0,10"; + $cats = $wpdb->get_results( $query ); + if( is_array( $cats ) ) { + while( list( $key, $val ) = each( $cats ) ) + { + print '<span onclick="javascript:return update_AJAX_search_box(\'' . $val->cat_name . '\');"><a>' . $val->cat_name . '</a></span><br>'; + } + } + exit; + break; case "searchusers": $search = $wpdb->escape( $_GET[ 'search' ] ); $id = $wpdb->escape( $_GET[ 'id' ] ); @@ -14,7 +27,7 @@ switch( $_GET[ 'action' ] ) { if( is_array( $users ) ) { while( list( $key, $val ) = each( $users ) ) { - print '<span onclick="javascript:return updateUserBox(\'' . $val->user_login . '\');"><a>' . $val->user_login . '</a></span><br>'; + print '<span onclick="javascript:return update_AJAX_search_box(\'' . $val->user_login . '\');"><a>' . $val->user_login . '</a></span><br>'; } } else { print "No Users Found"; |
