5. Saving the state
jQuery.data(element, key[, value])
Store any kind of information
on a DOM element
Circular references avoided
Low level function use
$().data() instead.
6. Saving possible?
jQuery.acceptData( element )
Low level function invoked by
$(elem).data()
Extend jQuery.noData to set
additional constraints
Does not raise an
error/exception
7. Removing the state
jQuery.removeData(element[, key])
Low level function use
$().removeData([key])
instead.
Removes all data if no key is
passed.
8. State example
var logo = $('#jq-siteLogo');
$(document).data('logo', logo);
$(logo).detach();
$('fieldset[class="toc"]')
.before($(document).data('logo'));
$(document).removeData('logo');
9. Extending for the good
jQuery.extend([deep], target[, object1][, objectN])
var defaults = {
validate: false,
limit: {max: 5, min: 1},
name: "foo"
};
var options = {
validate: true,
limit: {max:10}
};
var settings = $.extend(true, {}, defaults, options);
10. Extending for the good (II)
(function($, jQuery, undefined) {
jQuery.fn.myPlugin = function( options ) {
var options = $.extend(
{},
jQuery.fn.myPlugin.defaults,
Options
);
// put plugin code here //
}
jQuery.fn.myPlugin.defaults = {
'color': '#fff',
'myPublicMethod': function(){}
};
})(jQuery, jQuery);
11. jQuery.props[]
Register of translations
Used by .attr()
jQuery.props = {
"for" : "htmlFor",
"class" : "className",
"frameborder" : "frameBorder",
…
};
jQuery.props['uiwDiv'] =
'ui-jeopardysection-gameboard-header';
24. jQuery UI
$.extend('ui.autosuggest.prototype, {
_search: function( value ) {
// always save the actual value,
// not the one passed as an argument
this.term = this.element
.addClass( "ui-autocomplete-loading"
.val();
this.source( { term: value }, this.response );
});
25. Sizzle.selectors
jQuery.expr.filters
jQuery.expr[':']
$.extend(
$.expr.filters,
{
"myPseudoSelector": function( node, index, match ) {
// return true, if s.th. Was selected
// return false, if not.
}
});
26. Book recommendation
Jakob Westhoff
http://westhoffswelt.de
ISBN:
978-3-86802-052-6
E-Book-ISBN:
978-3-86802-237-7
28. License
This set of slides and the source code included
in the download package is licensed under the
Creative Commons Attribution-
Noncommercial-Share Alike 2.0 Generic
License
http://creativecommons.org/licenses/by-nc-sa/2.0/deed.en