dist/up.js in upjs-rails-0.6.1 vs dist/up.js in upjs-rails-0.6.2

- old
+ new

@@ -23,11 +23,11 @@ (function() { var __slice = [].slice; up.util = (function() { - var $createElementFromSelector, ANIMATION_PROMISE_KEY, CONSOLE_PLACEHOLDERS, ajax, castsToFalse, castsToTrue, clientSize, contains, copy, copyAttributes, createElement, createElementFromHtml, createSelectorFromElement, cssAnimate, debug, detect, each, error, escapePressed, extend, findWithSelf, finishCssAnimate, forceCompositing, get, ifGiven, isArray, isBlank, isDeferred, isDefined, isElement, isFunction, isGiven, isHash, isJQuery, isMissing, isNull, isObject, isPresent, isPromise, isStandardPort, isString, isUndefined, isUnmodifiedKeyEvent, isUnmodifiedMouseEvent, keys, last, locationFromXhr, measure, merge, methodFromXhr, nextFrame, normalizeMethod, normalizeUrl, nullJquery, only, option, options, prependGhost, presence, presentAttr, resolvableWhen, resolvedDeferred, resolvedPromise, select, setMissingAttrs, stringSet, stringifyConsoleArgs, temporaryCss, toArray, trim, unwrap; + var $createElementFromSelector, ANIMATION_PROMISE_KEY, CONSOLE_PLACEHOLDERS, ajax, castsToFalse, castsToTrue, clientSize, contains, copy, copyAttributes, createElement, createElementFromHtml, createSelectorFromElement, cssAnimate, debug, detect, each, error, escapePressed, extend, findWithSelf, finishCssAnimate, forceCompositing, get, ifGiven, isArray, isBlank, isDeferred, isDefined, isElement, isFunction, isGiven, isHash, isJQuery, isMissing, isNull, isObject, isPresent, isPromise, isStandardPort, isString, isUndefined, isUnmodifiedKeyEvent, isUnmodifiedMouseEvent, keys, last, locationFromXhr, measure, merge, methodFromXhr, nextFrame, normalizeMethod, normalizeUrl, nullJquery, only, option, options, prependGhost, presence, presentAttr, resolvableWhen, resolvedDeferred, resolvedPromise, select, setMissingAttrs, stringSet, stringifyConsoleArgs, temporaryCss, times, toArray, trim, unwrap; get = function(url, options) { options = options || {}; options.url = url; return ajax(options); }; @@ -274,10 +274,18 @@ item = collection[index]; _results.push(block(item, index)); } return _results; }; + times = function(count, block) { + var iteration, _i, _ref, _results; + _results = []; + for (iteration = _i = 0, _ref = count - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; iteration = 0 <= _ref ? ++_i : --_i) { + _results.push(block(iteration)); + } + return _results; + }; isNull = function(object) { return object === null; }; isUndefined = function(object) { return object === void(0); @@ -746,10 +754,11 @@ options: options, option: option, error: error, debug: debug, each: each, + times: times, detect: detect, select: select, last: last, isNull: isNull, isDefined: isDefined, @@ -1254,11 +1263,11 @@ selector = u.presence(selectorOrElement) ? selectorOrElement : u.createSelectorFromElement($(selectorOrElement)); if (!up.browser.canPushState() && !u.castsToFalse(options.history)) { if (!options.preload) { up.browser.loadPage(url, u.only(options, 'method')); } - return; + return u.resolvedPromise(); } request = { url: url, method: options.method, selector: selector, @@ -2652,17 +2661,17 @@ }; normalizeRequest = function(request) { if (!u.isHash(request)) { debugger; } - if (!request._requestNormalized) { + if (!request._normalized) { request.method = u.normalizeMethod(request.method); if (request.url) { request.url = u.normalizeUrl(request.url); } request.selector || (request.selector = 'body'); - request._requestNormalized = true; + request._normalized = true; } return request; }; alias = function(oldRequest, newRequest) { var promise; @@ -2691,11 +2700,11 @@ */ ajax = function(options) { var forceCache, ignoreCache, promise, request; forceCache = u.castsToTrue(options.cache); ignoreCache = u.castsToFalse(options.cache); - request = u.only(options, 'url', 'method', 'selector'); + request = u.only(options, 'url', 'method', 'selector', '_normalized'); if (!isIdempotent(request) && !forceCache) { clear(); promise = u.ajax(request); } else if ((promise = get(request)) && !ignoreCache) { promise; @@ -2716,10 +2725,15 @@ isFresh = function(promise) { var timeSinceTouch; timeSinceTouch = timestamp() - promise.timestamp; return timeSinceTouch < config.cacheExpiry; }; + + /** + @protected + @method up.proxy.get + */ get = function(request) { var key, promise; key = cacheKey(request); if (promise = cache[key]) { if (!isFresh(promise)) { @@ -2733,23 +2747,38 @@ } else { u.debug("Cache miss for %o (%o)", request.url, request); return void 0; } }; + + /** + @protected + @method up.proxy.set + */ set = function(request, promise) { var key; trim(); key = cacheKey(request); promise.timestamp = timestamp(); cache[key] = promise; return promise; }; + + /** + @protected + @method up.proxy.remove + */ remove = function(request) { var key; key = cacheKey(request); return delete cache[key]; }; + + /** + @protected + @method up.proxy.clear + */ clear = function() { return cache = {}; }; checkPreload = function($link) { var curriedPreload, delay; @@ -2768,16 +2797,32 @@ }; cancelDelay = function() { clearTimeout(delayTimer); return delayTimer = null; }; - preload = function(link, options) { - options = u.options(); - ensureIsIdempotent(options); - u.debug("Preloading %o", link); - options.preload = true; - return up.link.follow(link, options); + + /** + @protected + @method up.proxy.preload + @return + A promise that will be resolved when the request was loaded and cached + */ + preload = function(linkOrSelector, options) { + var $link, method; + $link = $(linkOrSelector); + options = u.options(options); + method = up.link.followMethod($link, options); + if (isIdempotent({ + method: method + })) { + u.debug("Preloading %o", $link); + options.preload = true; + return up.link.follow($link, options); + } else { + u.debug("Won't preload %o due to unsafe method %o", $link, method); + return u.resolvedPromise(); + } }; reset = function() { cancelDelay(); return cache = {}; }; @@ -2789,11 +2834,11 @@ mouse/finger down (before releasing). This way the response will already be cached when the user performs the click, making the interaction feel instant. @method [up-preload] - @param [[up-delay]=50] + @param [up-delay=75] The number of milliseconds to wait between hovering and preloading. Increasing this will lower the load in your server, but will also make the interaction feel less instant. @ujs */ @@ -2900,11 +2945,11 @@ @class up.link */ (function() { up.link = (function() { - var activeInstantLink, childClicked, follow, resolve, u, visit; + var activeInstantLink, childClicked, follow, followMethod, resolve, u, visit; u = up.util; /** Visits the given URL without a full page load. This is done by fetching `url` through an AJAX request @@ -2966,13 +3011,23 @@ selector = u.option(options.target, $link.attr('up-target'), 'body'); options.transition = u.option(options.transition, $link.attr('up-transition'), $link.attr('up-animation')); options.history = u.option(options.history, $link.attr('up-history')); options.scroll = u.option(options.scroll, $link.attr('up-scroll'), 'body'); options.cache = u.option(options.cache, $link.attr('up-cache')); + options.method = followMethod($link, options); options = u.merge(options, up.motion.animateOptions(options, $link)); return up.replace(selector, url, options); }; + + /** + @protected + @method up.link.followMethod + */ + followMethod = function($link, options) { + options = u.options(options); + return u.option(options.method, $link.attr('up-method'), $link.attr('data-method'), 'get').toUpperCase(); + }; resolve = function(element) { var $element, followAttr; $element = $(element); followAttr = $element.attr('up-follow'); if ($element.is('a') || (u.isPresent(followAttr) && !u.castsToTrue(followAttr))) { @@ -3112,11 +3167,11 @@ } }); up.on('mousedown', '[up-follow][up-instant]', function(event, $link) { if (activeInstantLink(event, $link)) { event.preventDefault(); - return up.follow(resolve($link)); + return follow(resolve($link)); } }); /** Marks up the current link to be followed *as fast as possible*. @@ -3159,13 +3214,15 @@ } u.setMissingAttrs($element, newAttrs); return $element.removeAttr('up-dash'); }); return { + knife: eval(typeof Knife !== "undefined" && Knife !== null ? Knife.point : void 0), visit: visit, follow: follow, resolve: resolve, - childClicked: childClicked + childClicked: childClicked, + followMethod: followMethod }; })(); up.visit = up.link.visit;