| 875 |
lars |
1 |
/*! jQuery Address v.1.6 | (c) 2009, 2013 Rostislav Hristov | jquery.org/license */
|
|
|
2 |
(function ($) {
|
|
|
3 |
|
|
|
4 |
$.address = (function () {
|
|
|
5 |
|
|
|
6 |
var _trigger = function(name) {
|
|
|
7 |
var e = $.extend($.Event(name), (function() {
|
|
|
8 |
var parameters = {},
|
|
|
9 |
parameterNames = $.address.parameterNames();
|
|
|
10 |
for (var i = 0, l = parameterNames.length; i < l; i++) {
|
|
|
11 |
parameters[parameterNames[i]] = $.address.parameter(parameterNames[i]);
|
|
|
12 |
}
|
|
|
13 |
return {
|
|
|
14 |
value: $.address.value(),
|
|
|
15 |
path: $.address.path(),
|
|
|
16 |
pathNames: $.address.pathNames(),
|
|
|
17 |
parameterNames: parameterNames,
|
|
|
18 |
parameters: parameters,
|
|
|
19 |
queryString: $.address.queryString()
|
|
|
20 |
};
|
|
|
21 |
}).call($.address));
|
|
|
22 |
$($.address).trigger(e);
|
|
|
23 |
return e;
|
|
|
24 |
},
|
|
|
25 |
_array = function(obj) {
|
|
|
26 |
return Array.prototype.slice.call(obj);
|
|
|
27 |
},
|
|
|
28 |
_bind = function(value, data, fn) {
|
|
|
29 |
$().bind.apply($($.address), Array.prototype.slice.call(arguments));
|
|
|
30 |
return $.address;
|
|
|
31 |
},
|
|
|
32 |
_unbind = function(value, fn) {
|
|
|
33 |
$().unbind.apply($($.address), Array.prototype.slice.call(arguments));
|
|
|
34 |
return $.address;
|
|
|
35 |
},
|
|
|
36 |
_supportsState = function() {
|
|
|
37 |
return (_h.pushState && _opts.state !== UNDEFINED);
|
|
|
38 |
},
|
|
|
39 |
_hrefState = function() {
|
|
|
40 |
return ('/' + _l.pathname.replace(new RegExp(_opts.state), '') +
|
|
|
41 |
_l.search + (_hrefHash() ? '#' + _hrefHash() : '')).replace(_re, '/');
|
|
|
42 |
},
|
|
|
43 |
_hrefHash = function() {
|
|
|
44 |
var index = _l.href.indexOf('#');
|
|
|
45 |
return index != -1 ? _l.href.substr(index + 1) : '';
|
|
|
46 |
},
|
|
|
47 |
_href = function() {
|
|
|
48 |
return _supportsState() ? _hrefState() : _hrefHash();
|
|
|
49 |
},
|
|
|
50 |
_window = function() {
|
|
|
51 |
try {
|
|
|
52 |
return top.document !== UNDEFINED && top.document.title !== UNDEFINED && top.jQuery !== UNDEFINED &&
|
|
|
53 |
top.jQuery.address !== UNDEFINED && top.jQuery.address.frames() !== false ? top : window;
|
|
|
54 |
} catch (e) {
|
|
|
55 |
return window;
|
|
|
56 |
}
|
|
|
57 |
},
|
|
|
58 |
_js = function() {
|
|
|
59 |
return 'javascript';
|
|
|
60 |
},
|
|
|
61 |
_strict = function(value) {
|
|
|
62 |
value = value.toString();
|
|
|
63 |
return (_opts.strict && value.substr(0, 1) != '/' ? '/' : '') + value;
|
|
|
64 |
},
|
|
|
65 |
_cssint = function(el, value) {
|
|
|
66 |
return parseInt(el.css(value), 10);
|
|
|
67 |
},
|
|
|
68 |
_listen = function() {
|
|
|
69 |
if (!_silent) {
|
|
|
70 |
var hash = _href(),
|
|
|
71 |
diff = decodeURI(_value) != decodeURI(hash);
|
|
|
72 |
if (diff) {
|
|
|
73 |
if (_msie && _version < 7) {
|
|
|
74 |
_l.reload();
|
|
|
75 |
} else {
|
|
|
76 |
if (_msie && !_hashchange && _opts.history) {
|
|
|
77 |
_st(_html, 50);
|
|
|
78 |
}
|
|
|
79 |
_value = hash;
|
|
|
80 |
_update(FALSE);
|
|
|
81 |
}
|
|
|
82 |
}
|
|
|
83 |
}
|
|
|
84 |
},
|
|
|
85 |
_update = function(internal) {
|
|
|
86 |
_st(_track, 10);
|
|
|
87 |
return _trigger(CHANGE).isDefaultPrevented() ||
|
|
|
88 |
_trigger(internal ? INTERNAL_CHANGE : EXTERNAL_CHANGE).isDefaultPrevented();
|
|
|
89 |
},
|
|
|
90 |
_track = function() {
|
|
|
91 |
if (_opts.tracker !== 'null' && _opts.tracker !== NULL) {
|
|
|
92 |
var fn = $.isFunction(_opts.tracker) ? _opts.tracker : _t[_opts.tracker],
|
|
|
93 |
value = (_l.pathname + _l.search +
|
|
|
94 |
($.address && !_supportsState() ? $.address.value() : ''))
|
|
|
95 |
.replace(/\/\//, '/').replace(/^\/$/, '');
|
|
|
96 |
if ($.isFunction(fn)) {
|
|
|
97 |
fn(value);
|
|
|
98 |
} else if ($.isFunction(_t.urchinTracker)) {
|
|
|
99 |
_t.urchinTracker(value);
|
|
|
100 |
} else if (_t.pageTracker !== UNDEFINED && $.isFunction(_t.pageTracker._trackPageview)) {
|
|
|
101 |
_t.pageTracker._trackPageview(value);
|
|
|
102 |
} else if (_t._gaq !== UNDEFINED && $.isFunction(_t._gaq.push)) {
|
|
|
103 |
_t._gaq.push(['_trackPageview', decodeURI(value)]);
|
|
|
104 |
}
|
|
|
105 |
}
|
|
|
106 |
},
|
|
|
107 |
_html = function() {
|
|
|
108 |
var src = _js() + ':' + FALSE + ';document.open();document.writeln(\'<html><head><title>' +
|
|
|
109 |
_d.title.replace(/\'/g, '\\\'') + '</title><script>var ' + ID + ' = "' + encodeURIComponent(_href()).replace(/\'/g, '\\\'') +
|
|
|
110 |
(_d.domain != _l.hostname ? '";document.domain="' + _d.domain : '') +
|
|
|
111 |
'";</' + 'script></head></html>\');document.close();';
|
|
|
112 |
if (_version < 7) {
|
|
|
113 |
_frame.src = src;
|
|
|
114 |
} else {
|
|
|
115 |
_frame.contentWindow.location.replace(src);
|
|
|
116 |
}
|
|
|
117 |
},
|
|
|
118 |
_options = function() {
|
|
|
119 |
if (_url && _qi != -1) {
|
|
|
120 |
var i, param, params = _url.substr(_qi + 1).split('&');
|
|
|
121 |
for (i = 0; i < params.length; i++) {
|
|
|
122 |
param = params[i].split('=');
|
|
|
123 |
if (/^(autoUpdate|history|strict|wrap)$/.test(param[0])) {
|
|
|
124 |
_opts[param[0]] = (isNaN(param[1]) ? /^(true|yes)$/i.test(param[1]) : (parseInt(param[1], 10) !== 0));
|
|
|
125 |
}
|
|
|
126 |
if (/^(state|tracker)$/.test(param[0])) {
|
|
|
127 |
_opts[param[0]] = param[1];
|
|
|
128 |
}
|
|
|
129 |
}
|
|
|
130 |
_url = NULL;
|
|
|
131 |
}
|
|
|
132 |
_value = _href();
|
|
|
133 |
},
|
|
|
134 |
_load = function() {
|
|
|
135 |
if (!_loaded) {
|
|
|
136 |
_loaded = TRUE;
|
|
|
137 |
_options();
|
|
|
138 |
$('a[rel*="address:"]').address();
|
|
|
139 |
if (_opts.wrap) {
|
|
|
140 |
var body = $('body'),
|
|
|
141 |
wrap = $('body > *')
|
|
|
142 |
.wrapAll('<div style="padding:' +
|
|
|
143 |
(_cssint(body, 'marginTop') + _cssint(body, 'paddingTop')) + 'px ' +
|
|
|
144 |
(_cssint(body, 'marginRight') + _cssint(body, 'paddingRight')) + 'px ' +
|
|
|
145 |
(_cssint(body, 'marginBottom') + _cssint(body, 'paddingBottom')) + 'px ' +
|
|
|
146 |
(_cssint(body, 'marginLeft') + _cssint(body, 'paddingLeft')) + 'px;" />')
|
|
|
147 |
.parent()
|
|
|
148 |
.wrap('<div id="' + ID + '" style="height:100%;overflow:auto;position:relative;' +
|
|
|
149 |
(_webkit && !window.statusbar.visible ? 'resize:both;' : '') + '" />');
|
|
|
150 |
$('html, body')
|
|
|
151 |
.css({
|
|
|
152 |
height: '100%',
|
|
|
153 |
margin: 0,
|
|
|
154 |
padding: 0,
|
|
|
155 |
overflow: 'hidden'
|
|
|
156 |
});
|
|
|
157 |
if (_webkit) {
|
|
|
158 |
$('<style type="text/css" />')
|
|
|
159 |
.appendTo('head')
|
|
|
160 |
.text('#' + ID + '::-webkit-resizer { background-color: #fff; }');
|
|
|
161 |
}
|
|
|
162 |
}
|
|
|
163 |
if (_msie && !_hashchange) {
|
|
|
164 |
var frameset = _d.getElementsByTagName('frameset')[0];
|
|
|
165 |
_frame = _d.createElement((frameset ? '' : 'i') + 'frame');
|
|
|
166 |
_frame.src = _js() + ':' + FALSE;
|
|
|
167 |
if (frameset) {
|
|
|
168 |
frameset.insertAdjacentElement('beforeEnd', _frame);
|
|
|
169 |
frameset[frameset.cols ? 'cols' : 'rows'] += ',0';
|
|
|
170 |
_frame.noResize = TRUE;
|
|
|
171 |
_frame.frameBorder = _frame.frameSpacing = 0;
|
|
|
172 |
} else {
|
|
|
173 |
_frame.style.display = 'none';
|
|
|
174 |
_frame.style.width = _frame.style.height = 0;
|
|
|
175 |
_frame.tabIndex = -1;
|
|
|
176 |
_d.body.insertAdjacentElement('afterBegin', _frame);
|
|
|
177 |
}
|
|
|
178 |
_st(function() {
|
|
|
179 |
$(_frame).bind('load', function() {
|
|
|
180 |
var win = _frame.contentWindow;
|
|
|
181 |
_value = win[ID] !== UNDEFINED ? win[ID] : '';
|
|
|
182 |
if (_value != _href()) {
|
|
|
183 |
_update(FALSE);
|
|
|
184 |
_l.hash = _value;
|
|
|
185 |
}
|
|
|
186 |
});
|
|
|
187 |
if (_frame.contentWindow[ID] === UNDEFINED) {
|
|
|
188 |
_html();
|
|
|
189 |
}
|
|
|
190 |
}, 50);
|
|
|
191 |
}
|
|
|
192 |
_st(function() {
|
|
|
193 |
_trigger('init');
|
|
|
194 |
_update(FALSE);
|
|
|
195 |
}, 1);
|
|
|
196 |
if (!_supportsState()) {
|
|
|
197 |
if ((_msie && _version > 7) || (!_msie && _hashchange)) {
|
|
|
198 |
if (_t.addEventListener) {
|
|
|
199 |
_t.addEventListener(HASH_CHANGE, _listen, FALSE);
|
|
|
200 |
} else if (_t.attachEvent) {
|
|
|
201 |
_t.attachEvent('on' + HASH_CHANGE, _listen);
|
|
|
202 |
}
|
|
|
203 |
} else {
|
|
|
204 |
_si(_listen, 50);
|
|
|
205 |
}
|
|
|
206 |
}
|
|
|
207 |
if ('state' in window.history) {
|
|
|
208 |
$(window).trigger('popstate');
|
|
|
209 |
}
|
|
|
210 |
}
|
|
|
211 |
},
|
|
|
212 |
_popstate = function() {
|
|
|
213 |
if (decodeURI(_value) != decodeURI(_href())) {
|
|
|
214 |
_value = _href();
|
|
|
215 |
_update(FALSE);
|
|
|
216 |
}
|
|
|
217 |
},
|
|
|
218 |
_unload = function() {
|
|
|
219 |
if (_t.removeEventListener) {
|
|
|
220 |
_t.removeEventListener(HASH_CHANGE, _listen, FALSE);
|
|
|
221 |
} else if (_t.detachEvent) {
|
|
|
222 |
_t.detachEvent('on' + HASH_CHANGE, _listen);
|
|
|
223 |
}
|
|
|
224 |
},
|
|
|
225 |
_uaMatch = function(ua) {
|
|
|
226 |
ua = ua.toLowerCase();
|
|
|
227 |
var match = /(chrome)[ \/]([\w.]+)/.exec( ua ) ||
|
|
|
228 |
/(webkit)[ \/]([\w.]+)/.exec( ua ) ||
|
|
|
229 |
/(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) ||
|
|
|
230 |
/(msie) ([\w.]+)/.exec( ua ) ||
|
|
|
231 |
ua.indexOf('compatible') < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) ||
|
|
|
232 |
[];
|
|
|
233 |
return {
|
|
|
234 |
browser: match[ 1 ] || '',
|
|
|
235 |
version: match[ 2 ] || '0'
|
|
|
236 |
};
|
|
|
237 |
},
|
|
|
238 |
_detectBrowser = function() {
|
|
|
239 |
var browser = {},
|
|
|
240 |
matched = _uaMatch(navigator.userAgent);
|
|
|
241 |
if (matched.browser) {
|
|
|
242 |
browser[matched.browser] = true;
|
|
|
243 |
browser.version = matched.version;
|
|
|
244 |
}
|
|
|
245 |
if (browser.chrome) {
|
|
|
246 |
browser.webkit = true;
|
|
|
247 |
} else if (browser.webkit) {
|
|
|
248 |
browser.safari = true;
|
|
|
249 |
}
|
|
|
250 |
return browser;
|
|
|
251 |
},
|
|
|
252 |
UNDEFINED,
|
|
|
253 |
NULL = null,
|
|
|
254 |
ID = 'jQueryAddress',
|
|
|
255 |
STRING = 'string',
|
|
|
256 |
HASH_CHANGE = 'hashchange',
|
|
|
257 |
INIT = 'init',
|
|
|
258 |
CHANGE = 'change',
|
|
|
259 |
INTERNAL_CHANGE = 'internalChange',
|
|
|
260 |
EXTERNAL_CHANGE = 'externalChange',
|
|
|
261 |
TRUE = true,
|
|
|
262 |
FALSE = false,
|
|
|
263 |
_opts = {
|
|
|
264 |
autoUpdate: TRUE,
|
|
|
265 |
history: TRUE,
|
|
|
266 |
strict: TRUE,
|
|
|
267 |
frames: TRUE,
|
|
|
268 |
wrap: FALSE
|
|
|
269 |
},
|
|
|
270 |
_browser = _detectBrowser(),
|
|
|
271 |
_version = parseFloat(_browser.version),
|
|
|
272 |
_webkit = _browser.webkit || _browser.safari,
|
|
|
273 |
_msie = !$.support.opacity,
|
|
|
274 |
_t = _window(),
|
|
|
275 |
_d = _t.document,
|
|
|
276 |
_h = _t.history,
|
|
|
277 |
_l = _t.location,
|
|
|
278 |
_si = setInterval,
|
|
|
279 |
_st = setTimeout,
|
|
|
280 |
_re = /\/{2,9}/g,
|
|
|
281 |
_agent = navigator.userAgent,
|
|
|
282 |
_hashchange = 'on' + HASH_CHANGE in _t,
|
|
|
283 |
_frame,
|
|
|
284 |
_form,
|
|
|
285 |
_url = $('script:last').attr('src'),
|
|
|
286 |
_qi = _url ? _url.indexOf('?') : -1,
|
|
|
287 |
_title = _d.title,
|
|
|
288 |
_silent = FALSE,
|
|
|
289 |
_loaded = FALSE,
|
|
|
290 |
_juststart = TRUE,
|
|
|
291 |
_updating = FALSE,
|
|
|
292 |
_listeners = {},
|
|
|
293 |
_value = _href();
|
|
|
294 |
|
|
|
295 |
if (_msie) {
|
|
|
296 |
_version = parseFloat(_agent.substr(_agent.indexOf('MSIE') + 4));
|
|
|
297 |
if (_d.documentMode && _d.documentMode != _version) {
|
|
|
298 |
_version = _d.documentMode != 8 ? 7 : 8;
|
|
|
299 |
}
|
|
|
300 |
var pc = _d.onpropertychange;
|
|
|
301 |
_d.onpropertychange = function() {
|
|
|
302 |
if (pc) {
|
|
|
303 |
pc.call(_d);
|
|
|
304 |
}
|
|
|
305 |
if (_d.title != _title && _d.title.indexOf('#' + _href()) != -1) {
|
|
|
306 |
_d.title = _title;
|
|
|
307 |
}
|
|
|
308 |
};
|
|
|
309 |
}
|
|
|
310 |
|
|
|
311 |
if (_h.navigationMode) {
|
|
|
312 |
_h.navigationMode = 'compatible';
|
|
|
313 |
}
|
|
|
314 |
if (document.readyState == 'complete') {
|
|
|
315 |
var interval = setInterval(function() {
|
|
|
316 |
if ($.address) {
|
|
|
317 |
_load();
|
|
|
318 |
clearInterval(interval);
|
|
|
319 |
}
|
|
|
320 |
}, 50);
|
|
|
321 |
} else {
|
|
|
322 |
_options();
|
|
|
323 |
$(_load);
|
|
|
324 |
}
|
|
|
325 |
$(window).bind('popstate', _popstate).bind('unload', _unload);
|
|
|
326 |
|
|
|
327 |
return {
|
|
|
328 |
bind: function(type, data, fn) {
|
|
|
329 |
return _bind.apply(this, _array(arguments));
|
|
|
330 |
},
|
|
|
331 |
unbind: function(type, fn) {
|
|
|
332 |
return _unbind.apply(this, _array(arguments));
|
|
|
333 |
},
|
|
|
334 |
init: function(data, fn) {
|
|
|
335 |
return _bind.apply(this, [INIT].concat(_array(arguments)));
|
|
|
336 |
},
|
|
|
337 |
change: function(data, fn) {
|
|
|
338 |
return _bind.apply(this, [CHANGE].concat(_array(arguments)));
|
|
|
339 |
},
|
|
|
340 |
internalChange: function(data, fn) {
|
|
|
341 |
return _bind.apply(this, [INTERNAL_CHANGE].concat(_array(arguments)));
|
|
|
342 |
},
|
|
|
343 |
externalChange: function(data, fn) {
|
|
|
344 |
return _bind.apply(this, [EXTERNAL_CHANGE].concat(_array(arguments)));
|
|
|
345 |
},
|
|
|
346 |
baseURL: function() {
|
|
|
347 |
var url = _l.href;
|
|
|
348 |
if (url.indexOf('#') != -1) {
|
|
|
349 |
url = url.substr(0, url.indexOf('#'));
|
|
|
350 |
}
|
|
|
351 |
if (/\/$/.test(url)) {
|
|
|
352 |
url = url.substr(0, url.length - 1);
|
|
|
353 |
}
|
|
|
354 |
return url;
|
|
|
355 |
},
|
|
|
356 |
autoUpdate: function(value) {
|
|
|
357 |
if (value !== UNDEFINED) {
|
|
|
358 |
_opts.autoUpdate = value;
|
|
|
359 |
return this;
|
|
|
360 |
}
|
|
|
361 |
return _opts.autoUpdate;
|
|
|
362 |
},
|
|
|
363 |
history: function(value) {
|
|
|
364 |
if (value !== UNDEFINED) {
|
|
|
365 |
_opts.history = value;
|
|
|
366 |
return this;
|
|
|
367 |
}
|
|
|
368 |
return _opts.history;
|
|
|
369 |
},
|
|
|
370 |
state: function(value) {
|
|
|
371 |
if (value !== UNDEFINED) {
|
|
|
372 |
_opts.state = value;
|
|
|
373 |
var hrefState = _hrefState();
|
|
|
374 |
if (_opts.state !== UNDEFINED) {
|
|
|
375 |
if (_h.pushState) {
|
|
|
376 |
if (hrefState.substr(0, 3) == '/#/') {
|
|
|
377 |
_l.replace(_opts.state.replace(/^\/$/, '') + hrefState.substr(2));
|
|
|
378 |
}
|
|
|
379 |
} else if (hrefState != '/' && hrefState.replace(/^\/#/, '') != _hrefHash()) {
|
|
|
380 |
_st(function() {
|
|
|
381 |
_l.replace(_opts.state.replace(/^\/$/, '') + '/#' + hrefState);
|
|
|
382 |
}, 1);
|
|
|
383 |
}
|
|
|
384 |
}
|
|
|
385 |
return this;
|
|
|
386 |
}
|
|
|
387 |
return _opts.state;
|
|
|
388 |
},
|
|
|
389 |
frames: function(value) {
|
|
|
390 |
if (value !== UNDEFINED) {
|
|
|
391 |
_opts.frames = value;
|
|
|
392 |
_t = _window();
|
|
|
393 |
return this;
|
|
|
394 |
}
|
|
|
395 |
return _opts.frames;
|
|
|
396 |
},
|
|
|
397 |
strict: function(value) {
|
|
|
398 |
if (value !== UNDEFINED) {
|
|
|
399 |
_opts.strict = value;
|
|
|
400 |
return this;
|
|
|
401 |
}
|
|
|
402 |
return _opts.strict;
|
|
|
403 |
},
|
|
|
404 |
tracker: function(value) {
|
|
|
405 |
if (value !== UNDEFINED) {
|
|
|
406 |
_opts.tracker = value;
|
|
|
407 |
return this;
|
|
|
408 |
}
|
|
|
409 |
return _opts.tracker;
|
|
|
410 |
},
|
|
|
411 |
wrap: function(value) {
|
|
|
412 |
if (value !== UNDEFINED) {
|
|
|
413 |
_opts.wrap = value;
|
|
|
414 |
return this;
|
|
|
415 |
}
|
|
|
416 |
return _opts.wrap;
|
|
|
417 |
},
|
|
|
418 |
update: function() {
|
|
|
419 |
_updating = TRUE;
|
|
|
420 |
this.value(_value);
|
|
|
421 |
_updating = FALSE;
|
|
|
422 |
return this;
|
|
|
423 |
},
|
|
|
424 |
title: function(value) {
|
|
|
425 |
if (value !== UNDEFINED) {
|
|
|
426 |
_st(function() {
|
|
|
427 |
_title = _d.title = value;
|
|
|
428 |
if (_juststart && _frame && _frame.contentWindow && _frame.contentWindow.document) {
|
|
|
429 |
_frame.contentWindow.document.title = value;
|
|
|
430 |
_juststart = FALSE;
|
|
|
431 |
}
|
|
|
432 |
}, 50);
|
|
|
433 |
return this;
|
|
|
434 |
}
|
|
|
435 |
return _d.title;
|
|
|
436 |
},
|
|
|
437 |
value: function(value) {
|
|
|
438 |
if (value !== UNDEFINED) {
|
|
|
439 |
value = _strict(value);
|
|
|
440 |
if (_value == value && !_updating) {
|
|
|
441 |
return;
|
|
|
442 |
}
|
|
|
443 |
_value = value;
|
|
|
444 |
if (_opts.autoUpdate || _updating) {
|
|
|
445 |
if (_update(TRUE)) {
|
|
|
446 |
return this;
|
|
|
447 |
}
|
|
|
448 |
if (_supportsState()) {
|
|
|
449 |
_h[_opts.history ? 'pushState' : 'replaceState']({}, '',
|
|
|
450 |
_opts.state.replace(/\/$/, '') + (_value === '' ? '/' : _value));
|
|
|
451 |
} else {
|
|
|
452 |
_silent = TRUE;
|
|
|
453 |
if (_webkit) {
|
|
|
454 |
if (_opts.history) {
|
|
|
455 |
_l.hash = '#' + _value;
|
|
|
456 |
} else {
|
|
|
457 |
_l.replace('#' + _value);
|
|
|
458 |
}
|
|
|
459 |
} else if (_value != _href()) {
|
|
|
460 |
if (_opts.history) {
|
|
|
461 |
_l.hash = '#' + _value;
|
|
|
462 |
} else {
|
|
|
463 |
_l.replace('#' + _value);
|
|
|
464 |
}
|
|
|
465 |
}
|
|
|
466 |
if ((_msie && !_hashchange) && _opts.history) {
|
|
|
467 |
_st(_html, 50);
|
|
|
468 |
}
|
|
|
469 |
if (_webkit) {
|
|
|
470 |
_st(function(){ _silent = FALSE; }, 1);
|
|
|
471 |
} else {
|
|
|
472 |
_silent = FALSE;
|
|
|
473 |
}
|
|
|
474 |
}
|
|
|
475 |
}
|
|
|
476 |
return this;
|
|
|
477 |
}
|
|
|
478 |
return _strict(_value);
|
|
|
479 |
},
|
|
|
480 |
path: function(value) {
|
|
|
481 |
if (value !== UNDEFINED) {
|
|
|
482 |
var qs = this.queryString(),
|
|
|
483 |
hash = this.hash();
|
|
|
484 |
this.value(value + (qs ? '?' + qs : '') + (hash ? '#' + hash : ''));
|
|
|
485 |
return this;
|
|
|
486 |
}
|
|
|
487 |
return _strict(_value).split('#')[0].split('?')[0];
|
|
|
488 |
},
|
|
|
489 |
pathNames: function() {
|
|
|
490 |
var path = this.path(),
|
|
|
491 |
names = path.replace(_re, '/').split('/');
|
|
|
492 |
if (path.substr(0, 1) == '/' || path.length === 0) {
|
|
|
493 |
names.splice(0, 1);
|
|
|
494 |
}
|
|
|
495 |
if (path.substr(path.length - 1, 1) == '/') {
|
|
|
496 |
names.splice(names.length - 1, 1);
|
|
|
497 |
}
|
|
|
498 |
return names;
|
|
|
499 |
},
|
|
|
500 |
queryString: function(value) {
|
|
|
501 |
if (value !== UNDEFINED) {
|
|
|
502 |
var hash = this.hash();
|
|
|
503 |
this.value(this.path() + (value ? '?' + value : '') + (hash ? '#' + hash : ''));
|
|
|
504 |
return this;
|
|
|
505 |
}
|
|
|
506 |
var arr = _value.split('?');
|
|
|
507 |
return arr.slice(1, arr.length).join('?').split('#')[0];
|
|
|
508 |
},
|
|
|
509 |
parameter: function(name, value, append) {
|
|
|
510 |
var i, params;
|
|
|
511 |
if (value !== UNDEFINED) {
|
|
|
512 |
var names = this.parameterNames();
|
|
|
513 |
params = [];
|
|
|
514 |
value = value === UNDEFINED || value === NULL ? '' : value.toString();
|
|
|
515 |
for (i = 0; i < names.length; i++) {
|
|
|
516 |
var n = names[i],
|
|
|
517 |
v = this.parameter(n);
|
|
|
518 |
if (typeof v == STRING) {
|
|
|
519 |
v = [v];
|
|
|
520 |
}
|
|
|
521 |
if (n == name) {
|
|
|
522 |
v = (value === NULL || value === '') ? [] :
|
|
|
523 |
(append ? v.concat([value]) : [value]);
|
|
|
524 |
}
|
|
|
525 |
for (var j = 0; j < v.length; j++) {
|
|
|
526 |
params.push(n + '=' + v[j]);
|
|
|
527 |
}
|
|
|
528 |
}
|
|
|
529 |
if ($.inArray(name, names) == -1 && value !== NULL && value !== '') {
|
|
|
530 |
params.push(name + '=' + value);
|
|
|
531 |
}
|
|
|
532 |
this.queryString(params.join('&'));
|
|
|
533 |
return this;
|
|
|
534 |
}
|
|
|
535 |
value = this.queryString();
|
|
|
536 |
if (value) {
|
|
|
537 |
var r = [];
|
|
|
538 |
params = value.split('&');
|
|
|
539 |
for (i = 0; i < params.length; i++) {
|
|
|
540 |
var p = params[i].split('=');
|
|
|
541 |
if (p[0] == name) {
|
|
|
542 |
r.push(p.slice(1).join('='));
|
|
|
543 |
}
|
|
|
544 |
}
|
|
|
545 |
if (r.length !== 0) {
|
|
|
546 |
return r.length != 1 ? r : r[0];
|
|
|
547 |
}
|
|
|
548 |
}
|
|
|
549 |
},
|
|
|
550 |
parameterNames: function() {
|
|
|
551 |
var qs = this.queryString(),
|
|
|
552 |
names = [];
|
|
|
553 |
if (qs && qs.indexOf('=') != -1) {
|
|
|
554 |
var params = qs.split('&');
|
|
|
555 |
for (var i = 0; i < params.length; i++) {
|
|
|
556 |
var name = params[i].split('=')[0];
|
|
|
557 |
if ($.inArray(name, names) == -1) {
|
|
|
558 |
names.push(name);
|
|
|
559 |
}
|
|
|
560 |
}
|
|
|
561 |
}
|
|
|
562 |
return names;
|
|
|
563 |
},
|
|
|
564 |
hash: function(value) {
|
|
|
565 |
if (value !== UNDEFINED) {
|
|
|
566 |
this.value(_value.split('#')[0] + (value ? '#' + value : ''));
|
|
|
567 |
return this;
|
|
|
568 |
}
|
|
|
569 |
var arr = _value.split('#');
|
|
|
570 |
return arr.slice(1, arr.length).join('#');
|
|
|
571 |
}
|
|
|
572 |
};
|
|
|
573 |
})();
|
|
|
574 |
|
|
|
575 |
$.fn.address = function(fn) {
|
|
|
576 |
$(this).each(function(index) {
|
|
|
577 |
if (!$(this).data('address')) {
|
|
|
578 |
$(this).on('click', function(e) {
|
|
|
579 |
if (e.shiftKey || e.ctrlKey || e.metaKey || e.which == 2) {
|
|
|
580 |
return true;
|
|
|
581 |
}
|
|
|
582 |
var target = e.currentTarget;
|
|
|
583 |
if ($(target).is('a')) {
|
|
|
584 |
e.preventDefault();
|
|
|
585 |
var value = fn ? fn.call(target) :
|
|
|
586 |
/address:/.test($(target).attr('rel')) ? $(target).attr('rel').split('address:')[1].split(' ')[0] :
|
|
|
587 |
$.address.state() !== undefined && !/^\/?$/.test($.address.state()) ?
|
|
|
588 |
$(target).attr('href').replace(new RegExp('^(.*' + $.address.state() + '|\\.)'), '') :
|
|
|
589 |
$(target).attr('href').replace(/^(#\!?|\.)/, '');
|
|
|
590 |
$.address.value(value);
|
|
|
591 |
}
|
|
|
592 |
}).on('submit', function(e) {
|
|
|
593 |
var target = e.currentTarget;
|
|
|
594 |
if ($(target).is('form')) {
|
|
|
595 |
e.preventDefault();
|
|
|
596 |
var action = $(target).attr('action'),
|
|
|
597 |
value = fn ? fn.call(target) : (action.indexOf('?') != -1 ? action.replace(/&$/, '') : action + '?') +
|
|
|
598 |
$(target).serialize();
|
|
|
599 |
$.address.value(value);
|
|
|
600 |
}
|
|
|
601 |
}).data('address', true);
|
|
|
602 |
}
|
|
|
603 |
});
|
|
|
604 |
return this;
|
|
|
605 |
};
|
|
|
606 |
|
|
|
607 |
})(jQuery);
|