martes, 8 de noviembre de 2011

Create a JQuery AJAX call with Timer

This is a simple AJAX call I have created for autosaving an edition in a page. When the timer is triggered it performs an AJAX call for saving the page, disables the save button and shows a message that indicates that the autosave action was performed. Any user event on page enables the save button again.

autoSave: function() {
$.ajax({
"dataType": "JSON",
"type": "POST",
"url": "/autosave",
"success": function(result) {
var $messagePanel = $("#autoSaveMsg");
$messagePanel.show();
$messagePanel.css("top",$(window).scrollTop()+ 200 + "px");
setTimeout(function() {
$messagePanel.fadeOut("slow");
}, 2000);
}
});
},

userEvent: function() {
$("#post_job #btnSaveAccordion").removeAttr("disabled");
},

init: function(options){
$(document).bind("click dblclick mousedown mouseenter mouseleave", Behaviour.AutoSaveTimer.userEvent);
window.setInterval(Behaviour.AutoSaveTimer.autoSave, options.period);
}

martes, 13 de septiembre de 2011

Excellent JQuery Treeview plugin

Dynatree is a dynamic JavaScript tree view control with support for checkboxes, drag'n'drop, and lazy loading. I have used in a project and it is quite simple to use.
Main features:
  • Open source (MIT and GPL License)
  • Optimized for large dynamic trees (DOM elements are only created when really needed).
  • Programmable through a rich object oriented interface.
  • Support for lazy loading and Ajax.
  • Checkboxes and hierarchical selection.
  • Supports drag and drop.
  • Support for persistence.
  • Keyboard aware.
  • Initializes from HTML code, JSON, or JavaScript objects.
  • Implemented as a jQuery plugin.

Quick sample:
http://wwwendt.de/tech/dynatree/index.html