| 1 |
// $Id: navigate.js,v 1.5 2008/11/04 19:56:27 stompeers Exp $
|
| 2 |
|
| 3 |
var navigate_loader_count = 0;
|
| 4 |
|
| 5 |
$(document).ready(function(){
|
| 6 |
navigate_load();
|
| 7 |
});
|
| 8 |
|
| 9 |
/**
|
| 10 |
* This is run on document load ready and when any widget is added. Widget class is passed via 'item'
|
| 11 |
*/
|
| 12 |
function navigate_load_bind_widgets(item) {
|
| 13 |
|
| 14 |
// Set item if it's not set
|
| 15 |
item = navigate_item_default(item);
|
| 16 |
|
| 17 |
// Bind events to on/off buttons
|
| 18 |
navigate_bind_toggle_buttons(item);
|
| 19 |
|
| 20 |
// Bind events to callback buttons
|
| 21 |
navigate_bind_callback_buttons(item);
|
| 22 |
|
| 23 |
// Bind events to text inputs
|
| 24 |
navigate_bind_text_inputs(item);
|
| 25 |
|
| 26 |
// Bind events to close button
|
| 27 |
navigate_bind_widget_close();
|
| 28 |
|
| 29 |
// Bind events to textarea
|
| 30 |
navigate_bind_textareas();
|
| 31 |
|
| 32 |
// Bind event to widget settings button
|
| 33 |
$(item + ' .navigate-widget-settings-button').click(function() {
|
| 34 |
$(this).parent().find('.navigate-widget-settings-outer').slideToggle('slow', function() { navigate_cache_save();});
|
| 35 |
});
|
| 36 |
|
| 37 |
// Add select all on text inputs
|
| 38 |
$(item + " .navigate-select-all").focus(function () {
|
| 39 |
$(this).select();
|
| 40 |
});
|
| 41 |
|
| 42 |
// Bind doubleclick for title change
|
| 43 |
navigate_bind_title_change(item);
|
| 44 |
|
| 45 |
// Add tooltips
|
| 46 |
navigate_add_tooltips();
|
| 47 |
|
| 48 |
}
|
| 49 |
|
| 50 |
|
| 51 |
/**
|
| 52 |
* Bind doubleclick event to title to change and save it
|
| 53 |
*/
|
| 54 |
function navigate_bind_title_change(item) {
|
| 55 |
// Add double-click to widget title to change it
|
| 56 |
$(item + ".navigate-widget-title").dblclick(function() {
|
| 57 |
var parent = $(this).parent();
|
| 58 |
var wid = $(parent).attr('rel');
|
| 59 |
$(parent).html('<input type="text" class="navigate-title-input" value="' + $(this).text() + '" />');
|
| 60 |
$(parent).children().select();
|
| 61 |
$(parent).children().bind('keyup', function(e) {
|
| 62 |
// If pressing enter
|
| 63 |
if (e.which == 13 || e.keyCode == 13) {
|
| 64 |
if ($(parent).children().val() == '') {
|
| 65 |
alert('Please enter some value for the title');
|
| 66 |
} else {
|
| 67 |
navigate_variable_set('widget_title', $(parent).children().val(), wid);
|
| 68 |
$(parent).html('<div class="navigate-widget-title">' + $(parent).children().val() + '</div>');
|
| 69 |
var parent_id = $(parent).attr('id');
|
| 70 |
navigate_bind_title_change('#' + parent_id + ' ');
|
| 71 |
navigate_cache_save();
|
| 72 |
}
|
| 73 |
}
|
| 74 |
});
|
| 75 |
});
|
| 76 |
}
|
| 77 |
|
| 78 |
|
| 79 |
/**
|
| 80 |
* Set default item to bind events to
|
| 81 |
*
|
| 82 |
* If 'item' is not set, this will return .navigate, the class of the div containing the entire navigation
|
| 83 |
*/
|
| 84 |
function navigate_item_default(item) {
|
| 85 |
item = typeof(item) != 'undefined' ? item : '.navigate ';
|
| 86 |
return item + ' ';
|
| 87 |
}
|
| 88 |
|
| 89 |
|
| 90 |
/**
|
| 91 |
* Bind event for clicking a widgets close button
|
| 92 |
*/
|
| 93 |
function navigate_bind_widget_close() {
|
| 94 |
$('.navigate-widget-close').click(function() {
|
| 95 |
var wid = $(this).attr('rel');
|
| 96 |
navigate_queue_add();
|
| 97 |
$.ajax({
|
| 98 |
url: navigate_process_url(),
|
| 99 |
type: 'POST',
|
| 100 |
data: 'action=widget_delete&wid=' + wid,
|
| 101 |
error: function() {
|
| 102 |
},
|
| 103 |
success: function(msg) {
|
| 104 |
$('#navigate-widget-outer-' + wid).slideUp('slow', function() {
|
| 105 |
$('#navigate-widget-outer-' + wid).remove();
|
| 106 |
navigate_queue_subtract();
|
| 107 |
navigate_cache_save();
|
| 108 |
});
|
| 109 |
}
|
| 110 |
});
|
| 111 |
});
|
| 112 |
}
|
| 113 |
|
| 114 |
|
| 115 |
/**
|
| 116 |
* Binds events and various errata after page is loaded
|
| 117 |
*/
|
| 118 |
function navigate_load() {
|
| 119 |
|
| 120 |
// Bind click events to buttons and inputs to all widgets
|
| 121 |
navigate_load_bind_widgets();
|
| 122 |
|
| 123 |
// Bind click event to widget list (if visible)
|
| 124 |
navigate_bind_add_widget_list();
|
| 125 |
|
| 126 |
// Run pngFix for IE6
|
| 127 |
$('.navigate').pngFix();
|
| 128 |
|
| 129 |
// Make widgets sortable using their title as the handle
|
| 130 |
$(".navigate-all-widgets").sortable({
|
| 131 |
cursor: "move",
|
| 132 |
distance: 10,
|
| 133 |
handle: ".navigate-widget-title",
|
| 134 |
revert:true,
|
| 135 |
stop:function(e, ui) {
|
| 136 |
navigate_queue_add();
|
| 137 |
$.ajax({
|
| 138 |
url: navigate_process_url(),
|
| 139 |
type: 'POST',
|
| 140 |
data: 'action=widget_sort&' + $(".navigate-all-widgets").sortable('serialize'),
|
| 141 |
error: function() {
|
| 142 |
},
|
| 143 |
success: function(msg) {
|
| 144 |
navigate_queue_subtract();
|
| 145 |
navigate_cache_save();
|
| 146 |
}
|
| 147 |
});
|
| 148 |
}
|
| 149 |
});
|
| 150 |
|
| 151 |
// Bind click event to setting button to show close buttons and new widgets list
|
| 152 |
$('.navigate-launch-settings').click(function() {
|
| 153 |
navigate_queue_add();
|
| 154 |
$.ajax({
|
| 155 |
url: navigate_process_url(),
|
| 156 |
type: 'POST',
|
| 157 |
data: 'action=widget_list',
|
| 158 |
error: function() {
|
| 159 |
},
|
| 160 |
success: function(msg) {
|
| 161 |
navigate_queue_subtract();
|
| 162 |
$('.navigate-add-widgets').html(msg);
|
| 163 |
$('.navigate-add-widgets').pngFix();
|
| 164 |
$('.navigate-add-widgets').slideToggle('slow', function() {
|
| 165 |
$('.navigate-widget-close').toggle();
|
| 166 |
navigate_cache_save();
|
| 167 |
});
|
| 168 |
navigate_bind_add_widget_list();
|
| 169 |
}
|
| 170 |
});
|
| 171 |
});
|
| 172 |
|
| 173 |
// Add tooltips
|
| 174 |
navigate_add_tooltips()
|
| 175 |
|
| 176 |
// Bind event to text input to save the value of the input.
|
| 177 |
// Since the .val() and .attr() functions don't change the actual html of an input,
|
| 178 |
// we have to add a hidden input with the value of the text field, and then replace the text field with the value
|
| 179 |
// when the page is loaded.
|
| 180 |
$(".navigate-text-input").each(function(){
|
| 181 |
var rel = $(this).attr('id');
|
| 182 |
var outer = $(this);
|
| 183 |
if ($("input[rel='" + rel + "']").val() != 'undefined') {
|
| 184 |
$(this).val($("input[rel='" + rel + "']").val());
|
| 185 |
}
|
| 186 |
});
|
| 187 |
|
| 188 |
// Clear user cache when button is clicked
|
| 189 |
$('.navigate-clear-cache').click(function() {
|
| 190 |
$.ajax({
|
| 191 |
url: navigate_process_url(),
|
| 192 |
type: 'POST',
|
| 193 |
data: 'action=clear_user_cache',
|
| 194 |
error: function() {
|
| 195 |
},
|
| 196 |
success: function(msg) {
|
| 197 |
document.location = document.location;
|
| 198 |
}
|
| 199 |
});
|
| 200 |
});
|
| 201 |
|
| 202 |
|
| 203 |
// Run pngFix on switch button
|
| 204 |
$('#navigate-switch-outer').pngFix();
|
| 205 |
|
| 206 |
// Add select all on text inputs with select all specified
|
| 207 |
$(".navigate-select-all").focus(function () {
|
| 208 |
$(this).select();
|
| 209 |
});
|
| 210 |
|
| 211 |
// Bind events to switch button
|
| 212 |
$("#navigate-switch").click(function () {
|
| 213 |
// Close
|
| 214 |
if (navigate_on == 1) {
|
| 215 |
navigate_on = 0;
|
| 216 |
navigate_variable_set('on', '0');
|
| 217 |
$(".navigate").stop();
|
| 218 |
$("body").animate({ paddingLeft: "0px"}, "slow");
|
| 219 |
$(".navigate").animate({ marginLeft: "-550px"}, "slow");
|
| 220 |
$("#navigate-switch").animate({ marginLeft: "-230px", marginTop: "-30px"}, "slow");
|
| 221 |
$(".navigate-loading").animate({ marginLeft: "-550px"}, "slow");
|
| 222 |
} else {
|
| 223 |
// Open
|
| 224 |
navigate_on = 1;
|
| 225 |
navigate_variable_set('on', '1');
|
| 226 |
$("body").stop();
|
| 227 |
$("body").animate({ paddingLeft: "210px"}, "slow");
|
| 228 |
$(".navigate").animate({ marginLeft: "-195px"}, "slow");
|
| 229 |
$("#navigate-switch").animate({ marginLeft: "-195px", marginTop: "0px"}, "slow");
|
| 230 |
$(".navigate-loading").animate({ marginLeft: "-30px"}, "slow");
|
| 231 |
}
|
| 232 |
|
| 233 |
});
|
| 234 |
|
| 235 |
|
| 236 |
// Bind click event to acklowledgement link
|
| 237 |
$(".navigate-acknowledgement-switch").click(function () {
|
| 238 |
$('.navigate-acknowledgement').slideToggle('slow');
|
| 239 |
});
|
| 240 |
|
| 241 |
// Bind doubleclick event to title
|
| 242 |
$('.navigate-title').dblclick(function() {
|
| 243 |
$('.navigate-shorten').slideToggle('fast', function() {
|
| 244 |
navigate_cache_save();
|
| 245 |
});
|
| 246 |
});
|
| 247 |
}
|
| 248 |
|
| 249 |
|
| 250 |
/**
|
| 251 |
* Bind click actions to on/off buttons.
|
| 252 |
*/
|
| 253 |
function navigate_bind_toggle_buttons(item) {
|
| 254 |
item = navigate_item_default(item);
|
| 255 |
|
| 256 |
$(item + ' .navigate-button-outer').each(function() {
|
| 257 |
var wid = navigate_widget_id(this);
|
| 258 |
var widget = this;
|
| 259 |
$(this).children().click(function() {
|
| 260 |
|
| 261 |
// Grab all variables from hidden inputs
|
| 262 |
var on = $(widget).find('.on').val();
|
| 263 |
var off = $(widget).find('.off').val();
|
| 264 |
var name = $(widget).find('.name').val();
|
| 265 |
var required = $(widget).find('.required').val();
|
| 266 |
var callback = $(widget).find('.callback').val();
|
| 267 |
var val;
|
| 268 |
|
| 269 |
// If it's a group
|
| 270 |
if ($(widget).find('.group').length > 0) {
|
| 271 |
var group = $(widget).find('.group').val();
|
| 272 |
if ($(this).hasClass('navigate-button-on')) {
|
| 273 |
if (required == 1) {
|
| 274 |
return;
|
| 275 |
}
|
| 276 |
$(this).parents('.navigate-widget').find('.' + group).each(function(child) {
|
| 277 |
$(this).removeClass('navigate-button-on');
|
| 278 |
});
|
| 279 |
navigate_variable_set(name, '', wid);
|
| 280 |
navigate_cache_save();
|
| 281 |
return;
|
| 282 |
}
|
| 283 |
$(this).parents('.navigate-widget-outer').find('.' + group).each(function(child) {
|
| 284 |
$(this).removeClass('navigate-button-on');
|
| 285 |
});
|
| 286 |
val = on;
|
| 287 |
$(this).addClass('navigate-button-on');
|
| 288 |
|
| 289 |
// If not a group
|
| 290 |
} else {
|
| 291 |
// If it's just a callback
|
| 292 |
if (on != '') {
|
| 293 |
if ($(this).hasClass('navigate-button-on')) {
|
| 294 |
val = off;
|
| 295 |
$(this).removeClass('navigate-button-on');
|
| 296 |
} else {
|
| 297 |
val = on;
|
| 298 |
$(this).addClass('navigate-button-on');
|
| 299 |
}
|
| 300 |
}
|
| 301 |
}
|
| 302 |
if (callback != '' && callback != undefined) {
|
| 303 |
window[callback](wid);
|
| 304 |
}
|
| 305 |
navigate_variable_set(name, val, wid);
|
| 306 |
navigate_cache_save();
|
| 307 |
});
|
| 308 |
});
|
| 309 |
}
|
| 310 |
|
| 311 |
|
| 312 |
/**
|
| 313 |
* Bind callback click actions to buttons.
|
| 314 |
*/
|
| 315 |
function navigate_bind_callback_buttons(item) {
|
| 316 |
item = navigate_item_default(item);
|
| 317 |
$(item + ' .navigate-click-outer').each(function() {
|
| 318 |
var wid = navigate_widget_id(this);
|
| 319 |
var widget = this;
|
| 320 |
$(this).children().click(function() {
|
| 321 |
var callback = $(widget).children('.callback').val();
|
| 322 |
if (callback != '' && callback != undefined) {
|
| 323 |
window[callback](wid);
|
| 324 |
}
|
| 325 |
});
|
| 326 |
});
|
| 327 |
}
|
| 328 |
|
| 329 |
|
| 330 |
/**
|
| 331 |
* Bind text input events, including value saving and callback on pressing enter
|
| 332 |
*/
|
| 333 |
function navigate_bind_text_inputs(item) {
|
| 334 |
item = navigate_item_default(item);
|
| 335 |
var search_timeout = undefined;
|
| 336 |
$(item + ' .navigate-text-input-outer').each(function() {
|
| 337 |
|
| 338 |
var wid = navigate_widget_id(this);
|
| 339 |
var widget = this;
|
| 340 |
var callback = $(widget).children('.callback').val();
|
| 341 |
var name = $(widget).children('.name').val();
|
| 342 |
var text_input = this;
|
| 343 |
|
| 344 |
$(this).find('input').bind('keyup', function(e) {
|
| 345 |
var input_name = $(text_input).children('div').children('input').attr('name');
|
| 346 |
var id = $(text_input).children('div').children('input').attr('id');
|
| 347 |
var holder_id = name + wid + '_holder';
|
| 348 |
// If pressing enter
|
| 349 |
if (e.which == 13 || e.keyCode == 13) {
|
| 350 |
if (callback != '' && callback != undefined) {
|
| 351 |
window[callback](wid);
|
| 352 |
if ($(this).hasClass('navigate-clear')) {
|
| 353 |
var val = '';
|
| 354 |
$(this).val('');
|
| 355 |
$('.' + holder_id).remove();
|
| 356 |
var new_input = '<div class="' + holder_id + '"><input rel="' + id + '" type="hidden" name="' + input_name + '" value="' + val + '" /></div>';
|
| 357 |
$(text_input).parent().append(new_input);
|
| 358 |
//navigate_variable_set(name, '', wid);
|
| 359 |
}
|
| 360 |
}
|
| 361 |
} else {
|
| 362 |
if(search_timeout != undefined) {
|
| 363 |
clearTimeout(search_timeout);
|
| 364 |
}
|
| 365 |
var $this = this;
|
| 366 |
|
| 367 |
// Set timeout to save input text when typing is paused
|
| 368 |
search_timeout = setTimeout(function() {
|
| 369 |
search_timeout = undefined;
|
| 370 |
var val = $(text_input).children('div').children('input').val();
|
| 371 |
$('.' + holder_id).remove();
|
| 372 |
var new_input = '<div class="' + holder_id + '"><input rel="' + id + '" type="hidden" name="' + input_name + '" value="' + val + '" /></div>';
|
| 373 |
$(text_input).parent().append(new_input);
|
| 374 |
navigate_variable_set(name, val, wid);
|
| 375 |
navigate_cache_save();
|
| 376 |
}, 500);
|
| 377 |
}
|
| 378 |
});
|
| 379 |
|
| 380 |
});
|
| 381 |
}
|
| 382 |
|
| 383 |
|
| 384 |
/**
|
| 385 |
* Bind textarea save event, including value saving and callback on pressing enter
|
| 386 |
*/
|
| 387 |
function navigate_bind_textareas(item) {
|
| 388 |
item = navigate_item_default(item);
|
| 389 |
$(item + ' .navigate-textarea-outer').each(function() {
|
| 390 |
var wid = navigate_widget_id(this);
|
| 391 |
var widget = this;
|
| 392 |
var callback = $(widget).children('.callback').val();
|
| 393 |
var name = $(widget).children('.name').val();
|
| 394 |
var text_input = this;
|
| 395 |
$(this).find('.navigate-submit').click(function() {
|
| 396 |
var val = $(widget).find('.navigate-textarea').val();
|
| 397 |
navigate_variable_set(name, val, wid);
|
| 398 |
$(widget).find('.navigate-textarea').html(val);
|
| 399 |
if (callback != '' && callback != undefined) {
|
| 400 |
window[callback](wid);
|
| 401 |
}
|
| 402 |
});
|
| 403 |
|
| 404 |
});
|
| 405 |
}
|
| 406 |
|
| 407 |
|
| 408 |
/**
|
| 409 |
* Add tooltips
|
| 410 |
*/
|
| 411 |
function navigate_add_tooltips() {
|
| 412 |
// Add tooltips
|
| 413 |
$('.navigate-tip').tooltip({
|
| 414 |
bodyHandler: function() {
|
| 415 |
return $($(this).attr("rel")).html();
|
| 416 |
},
|
| 417 |
track: true,
|
| 418 |
fixPNG: true,
|
| 419 |
fade: 150,
|
| 420 |
delay:750
|
| 421 |
});
|
| 422 |
}
|
| 423 |
|
| 424 |
|
| 425 |
/**
|
| 426 |
* Set a variable
|
| 427 |
*/
|
| 428 |
function navigate_variable_set(name, val, wid) {
|
| 429 |
|
| 430 |
// Save the variable in a database
|
| 431 |
navigate_queue_add();
|
| 432 |
$.ajax({
|
| 433 |
url: $("#navigate_process_url").val(),
|
| 434 |
type: 'POST',
|
| 435 |
data: 'action=variable_save&name=' + name + '&wid=' + wid + '&value=' + encodeURIComponent(val),
|
| 436 |
error: function() {
|
| 437 |
},
|
| 438 |
success: function(msg) {
|
| 439 |
navigate_queue_subtract();
|
| 440 |
}
|
| 441 |
});
|
| 442 |
}
|
| 443 |
|
| 444 |
/**
|
| 445 |
* Add count to loader queue
|
| 446 |
*/
|
| 447 |
function navigate_queue_add() {
|
| 448 |
if (navigate_loader_count < 1) {
|
| 449 |
$(".navigate-loading").show();
|
| 450 |
}
|
| 451 |
navigate_loader_count++;
|
| 452 |
}
|
| 453 |
|
| 454 |
/**
|
| 455 |
* Remove count from loader
|
| 456 |
*/
|
| 457 |
function navigate_queue_subtract() {
|
| 458 |
navigate_loader_count--;
|
| 459 |
if (navigate_loader_count < 1) {
|
| 460 |
$(".navigate-loading").slideUp();
|
| 461 |
}
|
| 462 |
}
|
| 463 |
|
| 464 |
/**
|
| 465 |
* Save html to cache
|
| 466 |
*/
|
| 467 |
function navigate_cache_save() {
|
| 468 |
|
| 469 |
// Refresh tooltips, added here for convenience so widgets don't have to call it on laoding
|
| 470 |
navigate_add_tooltips();
|
| 471 |
|
| 472 |
navigate_queue_add();
|
| 473 |
$.ajax({
|
| 474 |
url: $("#navigate_process_url").val(),
|
| 475 |
type: 'POST',
|
| 476 |
data: 'action=cache_save&content=' + encodeURIComponent($('.navigate').html()),
|
| 477 |
error: function() {
|
| 478 |
},
|
| 479 |
success: function(msg) {
|
| 480 |
navigate_queue_subtract();
|
| 481 |
}
|
| 482 |
});
|
| 483 |
}
|
| 484 |
|
| 485 |
|
| 486 |
/**
|
| 487 |
* Grab the wid of a widget from inside the widget
|
| 488 |
*/
|
| 489 |
function navigate_widget_id(item) {
|
| 490 |
return $(item).parents('.navigate-widget-outer').children('.wid').val();
|
| 491 |
}
|
| 492 |
|
| 493 |
|
| 494 |
/**
|
| 495 |
* Get the location of the current URL
|
| 496 |
*/
|
| 497 |
function navigate_process_url() {
|
| 498 |
return $("#navigate_process_url").val();
|
| 499 |
}
|
| 500 |
|
| 501 |
|
| 502 |
/**
|
| 503 |
* Send request to navigate processing function
|
| 504 |
*
|
| 505 |
* This is used to run widget callbacks through, so we can sanitize query string data.
|
| 506 |
*/
|
| 507 |
function navigate_process(wid, query_array, callback) {
|
| 508 |
var query_string = '';
|
| 509 |
for(var i in query_array) {
|
| 510 |
if (i != '') {
|
| 511 |
query_string += i + '=';
|
| 512 |
}
|
| 513 |
query_string += query_array[i] + '&';
|
| 514 |
}
|
| 515 |
query_string += '&wid=' + wid + '&return=' + $('#navigate_q').val();
|
| 516 |
navigate_queue_add();
|
| 517 |
$.ajax({
|
| 518 |
url: navigate_process_url(),
|
| 519 |
type: 'POST',
|
| 520 |
data: query_string,
|
| 521 |
error: function() {
|
| 522 |
},
|
| 523 |
success: function(msg) {
|
| 524 |
navigate_queue_subtract();
|
| 525 |
if (callback != undefined) {
|
| 526 |
window[callback](msg, wid);
|
| 527 |
}
|
| 528 |
}
|
| 529 |
});
|
| 530 |
}
|
| 531 |
|
| 532 |
|
| 533 |
/**
|
| 534 |
* Binds click event to list of widgets
|
| 535 |
*/
|
| 536 |
function navigate_bind_add_widget_list() {
|
| 537 |
$('.navigate-widget-list-item').click(function() {
|
| 538 |
$list_item = $(this);
|
| 539 |
navigate_queue_add();
|
| 540 |
$.ajax({
|
| 541 |
url: navigate_process_url(),
|
| 542 |
type: 'POST',
|
| 543 |
dataType: 'html',
|
| 544 |
data: 'action=add_widget&module=' + $(this).attr('name') + '&type=' + $(this).attr('rel'),
|
| 545 |
error: function() {
|
| 546 |
},
|
| 547 |
success: function(msg) {
|
| 548 |
navigate_queue_subtract();
|
| 549 |
$('.navigate-all-widgets').append(msg);
|
| 550 |
var widget = '#' + $(msg).parent().children('.navigate-widget-outer').attr('id');
|
| 551 |
navigate_load_bind_widgets(widget);
|
| 552 |
funct = $list_item.find('.callback').val();
|
| 553 |
if (funct != '' && funct != undefined) {
|
| 554 |
window[funct](widget);
|
| 555 |
}
|
| 556 |
navigate_cache_save();
|
| 557 |
}
|
| 558 |
});
|
| 559 |
});
|
| 560 |
}
|