jQuery: The Write Less, Do More JavaScript Library

Ticket #1813 (new enhancement)

Opened 10 months ago

Last modified 8 months ago

Enhancement of the jQuery.fn.load ...?

Reported by: yereth Assigned to: anonymous
Type: enhancement Priority: minor
Milestone: 1.2.2 Component: ajax
Version: 1.2.1 Keywords: load, hybrid, jQuery.fn.load
Cc: Needs: Review

Description

I use this a lot myself; I needed a universal way to load any kind of link to any kind of item, so I changed the jQuery.fn.load in the following way:

(function($) {
$.fn._load = $.fn.load;
$.fn.extend({
	load: function(url, args, callback) {
		// Backwards compatibility for the jquery load function
		if ($.isFunction(url)) return $(this)._load(url, args, callback);
		if (!this.length) return this;
		var url2 = url;
		if (args) url2 += (url2.match(/\?/) ? "&" : "?") + $.param(args);
		return this.each(function() {
			if (typeof this['location'] == 'object') this.location.href = url2;
			else if (typeof this['href'] != 'undefined') this.href = url2;
			else if (typeof this['src'] != 'undefined') this.src = url2;
			else {
				// Backwards compatibility for the jquery load function
				$(this)._load(url, args, callback);
			}
		})
	}
});
})(jQuery);

Probably it's not perfect and can use refining. Perhaps I also missed a bit here, but it seems to work properly right now. Perhaps this can be added the the jQuery.fn.load native function?

Attachments

Change History

Changed 8 months ago by john

  • owner deleted
  • component changed from core to ajax
Note: See TracTickets for help on using tickets.