| 1 |
// $Id: taxonomy_quick_find.js,v 1.3.2.3 2008/09/17 14:55:36 njt1982 Exp $
|
| 2 |
|
| 3 |
//Define the quick find function
|
| 4 |
Drupal.taxonomyQuickFind = function(delta, select) {
|
| 5 |
//Get the parent block which contains the drop down menu
|
| 6 |
var block = select.parentNode.parentNode.parentNode.parentNode;
|
| 7 |
|
| 8 |
//Disable the select box
|
| 9 |
select.disabled = true;
|
| 10 |
|
| 11 |
//Set the semaphore for this block so we know when its safe to run the AJAX...
|
| 12 |
block.blockActive = false;
|
| 13 |
|
| 14 |
|
| 15 |
//Get the Unordered Lists within the block and slide them up.
|
| 16 |
$('.item-list ul', block).animate(
|
| 17 |
{ height: 'hide', opacity: 'hide' },
|
| 18 |
'slow',
|
| 19 |
function() {
|
| 20 |
//Once we've finished hiding once of the blocks (they should all take roughly the same ammount of time...
|
| 21 |
// ... we can run the AJAX
|
| 22 |
|
| 23 |
if (!block.blockActive) {
|
| 24 |
//Set the block as 'active'
|
| 25 |
block.blockActive = true;
|
| 26 |
|
| 27 |
//Do an JSON callback using the AJAX handler
|
| 28 |
$.ajax({
|
| 29 |
type: "GET",
|
| 30 |
url: "/taxonomy_quick_find/" + delta + "/" + select.value,
|
| 31 |
dataType: "json",
|
| 32 |
success: function(msg){
|
| 33 |
//On sucess, loop over the JS Array...
|
| 34 |
for (x in msg) {
|
| 35 |
//Each 'x' is a node type section, eg 'blog' or 'page'
|
| 36 |
var linksForType = msg[x];
|
| 37 |
|
| 38 |
//Grab the List within the block
|
| 39 |
var ulList = $('.tqf_' + x, block);
|
| 40 |
|
| 41 |
//Empty it
|
| 42 |
$(ulList).empty();
|
| 43 |
|
| 44 |
//Each 'y' is a node. Build a list item with a hyperlink in it linking to the url provided in the JS Array
|
| 45 |
for (y in linksForType) {
|
| 46 |
if (typeof(linksForType[y].url) == 'undefined') {
|
| 47 |
$('<li>' + linksForType[y].title + '</li>').appendTo(ulList);
|
| 48 |
}
|
| 49 |
else {
|
| 50 |
$('<li><a href="' + linksForType[y].url + '">' + linksForType[y].title + '</a></li>').appendTo(ulList);
|
| 51 |
}
|
| 52 |
}
|
| 53 |
}
|
| 54 |
|
| 55 |
//Now the new content is set, we can make the content appear again.
|
| 56 |
if (block.blockActive) {
|
| 57 |
$('.item-list ul', block).animate(
|
| 58 |
{ height: 'show', opacity: 'show' },
|
| 59 |
'slow',
|
| 60 |
function() {
|
| 61 |
block.blockActive = false;
|
| 62 |
select.disabled = false;
|
| 63 |
}
|
| 64 |
);
|
| 65 |
}
|
| 66 |
}
|
| 67 |
});
|
| 68 |
}
|
| 69 |
}
|
| 70 |
);
|
| 71 |
}
|