-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjquery.push.min.js
More file actions
4 lines (4 loc) · 2.02 KB
/
jquery.push.min.js
File metadata and controls
4 lines (4 loc) · 2.02 KB
1
2
3
4
/**
* https://github.com/ProtoGit/jquery.push
*/
(function(e){function t(e){if(typeof e=="string"){return e}if(typeof e=="object"){var t=e.get?e.get(0):unkown;if(t.tagName){var n=t.tagName.toLowerCase();if(n=="form"){return t.action}else if(n=="a"){return t.href}}}throw new Error("Invalid push() URI argument")}function n(e,t,n,i){var s={uri:e};if(t){s.postData=t}if(typeof n=="string"){s.target=n}if(typeof i=="function"){s.callback=i.toString()}window.history.pushState(s,"",e);r(s,false)}function r(t,n){var r={url:t.uri,complete:function(e){i(e,t,n)}};if(t.postData){r.type="POST";r.data=t.postData}e.ajax(r)}function i(t,n,r){if(!t.responseJSON&&!n.target){throw new Error("Response must be valid JSON, or HTML with a predefined output selector")}if(t.responseJSON){if(t.responseJSON.title){window.document.title=t.responseJSON.title}if(n.target&&t.responseJSON.content){e(n.target).html(t.responseJSON.content)}if(t.responseJSON.fragments){e.each(t.responseJSON.fragments,function(t,n){var r=e("#"+t);if(r.length){r.html(n)}})}}else{if(n.target&&t.responseText){e(n.target).html(t.responseText)}}if(n.callback){var i=Function("return "+n.callback)();if(t.responseJSON){i(t.responseJSON,r)}else{i(t.responseText,r)}}}if(!"history"in window||!"pushState"in window.history){throw new Error("No pushState API support")}e.push=function(){if(arguments.length===0){throw new Error("Invalid push() arguments")}if(arguments.length===1){return n(t(arguments[0]))}if(arguments.length===2&&typeof arguments[1]=="function"){return n(t(arguments[0]),null,null,arguments[1])}return n(t(arguments[0]),null,arguments[1],arguments[2])};e.postPush=function(){if(arguments.length<2){throw new Error("Invalid postPush() arguments")}if(arguments.length===2){return n(t(arguments[0]),arguments[1])}if(arguments.length===3&&typeof arguments[2]=="function"){return n(t(arguments[0]),arguments[1],null,arguments[2])}return n(t(arguments[0]),arguments[1],arguments[2],arguments[3])};e(window).on("popstate",function(e){if(e.originalEvent.state){r(e.originalEvent.state,true)}})})(jQuery);