From fc71057a056d7c08791d99b2c00dde1be76f8830 Mon Sep 17 00:00:00 2001 From: Binyamin Laukstein <7raivis@inbox.lv> Date: Mon, 18 Feb 2013 08:48:46 +0200 Subject: [PATCH] Returned improved crawlable feature * Improved crawlable feature turned on by default * Fixes issue #56 rewrite `/#/url` to `/#!/url` (no more use for `/#/url`) * Fixes issue #109 use `.on()` and `.off()` besides of outdated `.bind()` and `.unbind()` * Specify plugin version also in development file * Begin to add commented descriptions in development file --- src/jquery.address.js | 128 ++++++++++++++++++++++++------------------ 1 file changed, 73 insertions(+), 55 deletions(-) diff --git a/src/jquery.address.js b/src/jquery.address.js index 8e17f18..ad955f4 100644 --- a/src/jquery.address.js +++ b/src/jquery.address.js @@ -1,4 +1,4 @@ -/*! jQuery Address v${version} | (c) 2009, 2013 Rostislav Hristov | jquery.org/license */ +/*! jQuery Address v1.6 | (c) 2013 Rostislav Hristov | jquery.org/license */ (function ($) { $.address = (function () { @@ -25,24 +25,24 @@ _array = function(obj) { return Array.prototype.slice.call(obj); }, - _bind = function(value, data, fn) { - $().bind.apply($($.address), Array.prototype.slice.call(arguments)); + _on = function(value, data, fn) { + $().on.apply($($.address), Array.prototype.slice.call(arguments)); return $.address; }, - _unbind = function(value, fn) { - $().unbind.apply($($.address), Array.prototype.slice.call(arguments)); + _off = function(value, fn) { + $().off.apply($($.address), Array.prototype.slice.call(arguments)); return $.address; }, _supportsState = function() { return (_h.pushState && _opts.state !== UNDEFINED); }, _hrefState = function() { - return ('/' + _l.pathname.replace(new RegExp(_opts.state), '') + + return ('/' + _l.pathname.replace(new RegExp(_opts.state), '') + _l.search + (_hrefHash() ? '#' + _hrefHash() : '')).replace(_re, '/'); }, _hrefHash = function() { - var index = _l.href.indexOf('#'); - return index != -1 ? _l.href.substr(index + 1) : ''; + var index = _l.href.indexOf('#!'); + return index != -1 ? _crawl(_l.href.substr(index + 1), FALSE) : ''; }, _href = function() { return _supportsState() ? _hrefState() : _hrefHash(); @@ -50,7 +50,7 @@ _window = function() { try { return top.document !== UNDEFINED && top.document.title !== UNDEFINED ? top : window; - } catch (e) { + } catch (e) { return window; } }, @@ -61,6 +61,12 @@ value = value.toString(); return (_opts.strict && value.substr(0, 1) != '/' ? '/' : '') + value; }, + _crawl = function(value, direction) { + if (_opts.crawlable && direction) { + return (value !== '' ? '!' : '') + value; + } + return value.replace(/^\!/, ''); + }, _cssint = function(el, value) { return parseInt(el.css(value), 10); }, @@ -83,13 +89,13 @@ }, _update = function(internal) { _st(_track, 10); - return _trigger(CHANGE).isDefaultPrevented() || + return _trigger(CHANGE).isDefaultPrevented() || _trigger(internal ? INTERNAL_CHANGE : EXTERNAL_CHANGE).isDefaultPrevented(); }, _track = function() { if (_opts.tracker !== 'null' && _opts.tracker !== NULL) { var fn = $.isFunction(_opts.tracker) ? _opts.tracker : _t[_opts.tracker], - value = (_l.pathname + _l.search + + value = (_l.pathname + _l.search + ($.address && !_supportsState() ? $.address.value() : '')) .replace(/\/\//, '/').replace(/^\/$/, ''); if ($.isFunction(fn)) { @@ -104,9 +110,9 @@ } }, _html = function() { - var src = _js() + ':' + FALSE + ';document.open();document.writeln(\'