Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial changes to have pjax support Zepto.

  • Loading branch information...
commit 20a8d695c504499666f709a74be39e594880fa72 1 parent 749dd26
Jim Isaacs authored
Showing with 43 additions and 11 deletions.
  1. +17 −0 zepto.cookie.js
  2. +26 −11 jquery.pjax.js → zepto.pjax.js
View
17 zepto.cookie.js
@@ -0,0 +1,17 @@
+(function($){
+ $.cookie = function (name, data, options) {
+ if (arguments.length > 1 && String(data) !== "[object Object]") {
+ options = $.extend({}, options);
+ if (data === null || data === undefined) options.expires = -1;
+ if (typeof options.expires == "number") {
+ var d = options.expires, e = options.expires = new Date;
+ e.setDate(e.getDate() + d)
+ }
+ data = String(data);
+ return document.cookie = [encodeURIComponent(name), "=", options.raw ? data : encodeURIComponent(data), options.expires ? "; expires=" + options.expires.toUTCString() : "", options.path ? "; path=" + options.path : "", options.domain ? "; domain=" + options.domain : "", options.secure ? "; secure" : ""].join("")
+ }
+ options = data || {};
+ var f, g = options.raw ? function(name) {return name} : decodeURIComponent;
+ return (f = (new RegExp("(?:^|; )" + encodeURIComponent(name) + "=([^;]*)")).exec(document.cookie)) ? g(f[1]) : null
+ }
+})(Zepto || jQuery);
View
37 jquery.pjax.js → zepto.pjax.js
@@ -1,9 +1,21 @@
-// jquery.pjax.js
-// copyright chris wanstrath
-// https://github.com/defunkt/pjax
+// zepto.pjax.js
+// https://github.com/jimisaacs/zepto-pjax
+// Forked from - https://github.com/defunkt/jquery-pjax
(function($){
+/**
+ * Add noop to Zepto - should be in there already
+ * It's good to have to only reference one dummy function rather than create multiple empties.
+ */
+ $.noop = function(){};
+
+/**
+ * Add isPlainObject to Zepto - This one is questionable.
+ * It's good to have to not need to rewrite this plugin, but is it needed in a minimal framework?
+ */
+ $.isPlainObject = function( obj ){ return typeof obj === 'object' && obj.constructor === Object };
+
// When called on a link, fetches the href with ajax into the
// container specified as the first parameter or with the data-pjax
// attribute on the link itself.
@@ -97,7 +109,7 @@ $.pjax = function( options ) {
success: function(data){
// If we got no data or an entire web page, go directly
// to the page and let normal error handling happen.
- if ( !$.trim(data) || /<html/i.test(data) )
+ if ( !data.trim() || /<html/i.test(data) )
return window.location = options.url
// Make it happen.
@@ -105,9 +117,12 @@ $.pjax = function( options ) {
// If there's a <title> tag in the response, use it as
// the page's title.
- var oldTitle = document.title,
- title = $.trim( $container.find('title').remove().text() )
- if ( title ) document.title = title
+ var oldTitle = document.title,
+ newTitle = $('title', $container);
+ if (newTitle.length) {
+ title = newTitle.remove().text().trim()
+ if ( title ) document.title = title
+ }
var state = {
pjax: options.container,
@@ -146,7 +161,7 @@ $.pjax = function( options ) {
}
}
- options = $.extend(true, {}, defaults, options)
+ options = $.extend(defaults, options)
if ( $.isFunction(options.url) ) {
options.url = options.url()
@@ -200,8 +215,8 @@ $(window).bind('popstate', function(event) {
// Add the state property to jQuery's event object so we can use it in
// $(window).bind('popstate')
-if ( $.event.props.indexOf('state') < 0 )
- $.event.props.push('state')
+//if ( $.event.props.indexOf('state') < 0 )
+ //$.event.props.push('state')
// Fall back to normalcy for older browsers.
@@ -211,4 +226,4 @@ if ( !window.history || !window.history.pushState ) {
}
-})(jQuery);
+})(Zepto || jQuery);
Please sign in to comment.
Something went wrong with that request. Please try again.