| 1 |
if (!Object.prototype.watchChange) { |
| 2 |
var isFunction = function (fn) { |
| 3 |
return fn && {}.toString.call(fn) === '[object Function]'; |
| 4 |
}; |
| 5 |
Object.defineProperty( |
| 6 |
Object.prototype, |
| 7 |
'watchChange', |
| 8 |
{ |
| 9 |
enumerable: false, |
| 10 |
configurable: true, |
| 11 |
writable: false, |
| 12 |
value: function (prop, handler) { |
| 13 |
var obj = this; |
| 14 |
|
| 15 |
function x(prop, handler) { |
| 16 |
var oldval = obj[prop], |
| 17 |
newval = oldval, |
| 18 |
getter = function () { |
| 19 |
return newval; |
| 20 |
}, |
| 21 |
setter = function (val) { |
| 22 |
return newval = handler.call(obj, prop, oldval, val); |
| 23 |
}; |
| 24 |
|
| 25 |
if (delete obj[prop]) { |
| 26 |
Object.defineProperty( |
| 27 |
obj, |
| 28 |
prop, |
| 29 |
{ |
| 30 |
get: getter, |
| 31 |
set: setter, |
| 32 |
enumerable: true, |
| 33 |
configurable: true |
| 34 |
} |
| 35 |
); |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
if (isFunction(prop)) { |
| 40 |
for (var k in this) { |
| 41 |
new x(k, prop); |
| 42 |
} |
| 43 |
} else { |
| 44 |
new x(prop, handler) |
| 45 |
} |
| 46 |
} |
| 47 |
}); |
| 48 |
} |
| 49 |
|
| 50 |
if (!Object.prototype.unwatchChange) { |
| 51 |
Object.defineProperty( |
| 52 |
Object.prototype, |
| 53 |
'unwatchChange', |
| 54 |
{ |
| 55 |
enumerable: false, |
| 56 |
configurable: true, |
| 57 |
writable: false, |
| 58 |
value: function (prop) { |
| 59 |
var val = this[prop]; |
| 60 |
delete this[prop]; |
| 61 |
this[prop] = val; |
| 62 |
} |
| 63 |
} |
| 64 |
); |
| 65 |
} |
| 66 |
/*! |
| 67 |
* jQuery.scrollTo |
| 68 |
* Copyright (c) 2007-2015 Ariel Flesler - aflesler ○ gmail • com | http://flesler.blogspot.com |
| 69 |
* Licensed under MIT |
| 70 |
* http://flesler.blogspot.com/2007/10/jqueryscrollto.html |
| 71 |
* @projectDescription Lightweight, cross-browser and highly customizable animated scrolling with jQuery |
| 72 |
* @author Ariel Flesler |
| 73 |
* @version 2.1.2 |
| 74 |
*/ |
| 75 |
;(function(factory) { |
| 76 |
'use strict'; |
| 77 |
if (typeof define === 'function' && define.amd) { |
| 78 |
// AMD |
| 79 |
define(['jquery'], factory); |
| 80 |
} else if (typeof module !== 'undefined' && module.exports) { |
| 81 |
// CommonJS |
| 82 |
module.exports = factory(require('jquery')); |
| 83 |
} else { |
| 84 |
// Global |
| 85 |
factory(jQuery); |
| 86 |
} |
| 87 |
})(function($) { |
| 88 |
'use strict'; |
| 89 |
|
| 90 |
var $scrollTo = $.scrollTo = function(target, duration, settings) { |
| 91 |
return $(window).scrollTo(target, duration, settings); |
| 92 |
}; |
| 93 |
|
| 94 |
$scrollTo.defaults = { |
| 95 |
axis:'xy', |
| 96 |
duration: 0, |
| 97 |
limit:true |
| 98 |
}; |
| 99 |
|
| 100 |
function isWin(elem) { |
| 101 |
return !elem.nodeName || |
| 102 |
$.inArray(elem.nodeName.toLowerCase(), ['iframe','#document','html','body']) !== -1; |
| 103 |
} |
| 104 |
|
| 105 |
$.fn.scrollTo = function(target, duration, settings) { |
| 106 |
if (typeof duration === 'object') { |
| 107 |
settings = duration; |
| 108 |
duration = 0; |
| 109 |
} |
| 110 |
if (typeof settings === 'function') { |
| 111 |
settings = { onAfter:settings }; |
| 112 |
} |
| 113 |
if (target === 'max') { |
| 114 |
target = 9e9; |
| 115 |
} |
| 116 |
|
| 117 |
settings = $.extend({}, $scrollTo.defaults, settings); |
| 118 |
// Speed is still recognized for backwards compatibility |
| 119 |
duration = duration || settings.duration; |
| 120 |
// Make sure the settings are given right |
| 121 |
var queue = settings.queue && settings.axis.length > 1; |
| 122 |
if (queue) { |
| 123 |
// Let's keep the overall duration |
| 124 |
duration /= 2; |
| 125 |
} |
| 126 |
settings.offset = both(settings.offset); |
| 127 |
settings.over = both(settings.over); |
| 128 |
|
| 129 |
return this.each(function() { |
| 130 |
// Null target yields nothing, just like jQuery does |
| 131 |
if (target === null) return; |
| 132 |
|
| 133 |
var win = isWin(this), |
| 134 |
elem = win ? this.contentWindow || window : this, |
| 135 |
$elem = $(elem), |
| 136 |
targ = target, |
| 137 |
attr = {}, |
| 138 |
toff; |
| 139 |
|
| 140 |
switch (typeof targ) { |
| 141 |
// A number will pass the regex |
| 142 |
case 'number': |
| 143 |
case 'string': |
| 144 |
if (/^([+-]=?)?\d+(\.\d+)?(px|%)?$/.test(targ)) { |
| 145 |
targ = both(targ); |
| 146 |
// We are done |
| 147 |
break; |
| 148 |
} |
| 149 |
// Relative/Absolute selector |
| 150 |
targ = win ? $(targ) : $(targ, elem); |
| 151 |
/* falls through */ |
| 152 |
case 'object': |
| 153 |
if (targ.length === 0) return; |
| 154 |
// DOMElement / jQuery |
| 155 |
if (targ.is || targ.style) { |
| 156 |
// Get the real position of the target |
| 157 |
toff = (targ = $(targ)).offset(); |
| 158 |
} |
| 159 |
} |
| 160 |
|
| 161 |
var offset = $.isFunction(settings.offset) && settings.offset(elem, targ) || settings.offset; |
| 162 |
|
| 163 |
$.each(settings.axis.split(''), function(i, axis) { |
| 164 |
var Pos = axis === 'x' ? 'Left' : 'Top', |
| 165 |
pos = Pos.toLowerCase(), |
| 166 |
key = 'scroll' + Pos, |
| 167 |
prev = $elem[key](), |
| 168 |
max = $scrollTo.max(elem, axis); |
| 169 |
|
| 170 |
if (toff) {// jQuery / DOMElement |
| 171 |
attr[key] = toff[pos] + (win ? 0 : prev - $elem.offset()[pos]); |
| 172 |
|
| 173 |
// If it's a dom element, reduce the margin |
| 174 |
if (settings.margin) { |
| 175 |
attr[key] -= parseInt(targ.css('margin'+Pos), 10) || 0; |
| 176 |
attr[key] -= parseInt(targ.css('border'+Pos+'Width'), 10) || 0; |
| 177 |
} |
| 178 |
|
| 179 |
attr[key] += offset[pos] || 0; |
| 180 |
|
| 181 |
if (settings.over[pos]) { |
| 182 |
// Scroll to a fraction of its width/height |
| 183 |
attr[key] += targ[axis === 'x'?'width':'height']() * settings.over[pos]; |
| 184 |
} |
| 185 |
} else { |
| 186 |
var val = targ[pos]; |
| 187 |
// Handle percentage values |
| 188 |
attr[key] = val.slice && val.slice(-1) === '%' ? |
| 189 |
parseFloat(val) / 100 * max |
| 190 |
: val; |
| 191 |
} |
| 192 |
|
| 193 |
// Number or 'number' |
| 194 |
if (settings.limit && /^\d+$/.test(attr[key])) { |
| 195 |
// Check the limits |
| 196 |
attr[key] = attr[key] <= 0 ? 0 : Math.min(attr[key], max); |
| 197 |
} |
| 198 |
|
| 199 |
// Don't waste time animating, if there's no need. |
| 200 |
if (!i && settings.axis.length > 1) { |
| 201 |
if (prev === attr[key]) { |
| 202 |
// No animation needed |
| 203 |
attr = {}; |
| 204 |
} else if (queue) { |
| 205 |
// Intermediate animation |
| 206 |
animate(settings.onAfterFirst); |
| 207 |
// Don't animate this axis again in the next iteration. |
| 208 |
attr = {}; |
| 209 |
} |
| 210 |
} |
| 211 |
}); |
| 212 |
|
| 213 |
animate(settings.onAfter); |
| 214 |
|
| 215 |
function animate(callback) { |
| 216 |
var opts = $.extend({}, settings, { |
| 217 |
// The queue setting conflicts with animate() |
| 218 |
// Force it to always be true |
| 219 |
queue: true, |
| 220 |
duration: duration, |
| 221 |
complete: callback && function() { |
| 222 |
callback.call(elem, targ, settings); |
| 223 |
} |
| 224 |
}); |
| 225 |
$elem.animate(attr, opts); |
| 226 |
} |
| 227 |
}); |
| 228 |
}; |
| 229 |
|
| 230 |
// Max scrolling position, works on quirks mode |
| 231 |
// It only fails (not too badly) on IE, quirks mode. |
| 232 |
$scrollTo.max = function(elem, axis) { |
| 233 |
var Dim = axis === 'x' ? 'Width' : 'Height', |
| 234 |
scroll = 'scroll'+Dim; |
| 235 |
|
| 236 |
if (!isWin(elem)) |
| 237 |
return elem[scroll] - $(elem)[Dim.toLowerCase()](); |
| 238 |
|
| 239 |
var size = 'client' + Dim, |
| 240 |
doc = elem.ownerDocument || elem.document, |
| 241 |
html = doc.documentElement, |
| 242 |
body = doc.body; |
| 243 |
|
| 244 |
return Math.max(html[scroll], body[scroll]) - Math.min(html[size], body[size]); |
| 245 |
}; |
| 246 |
|
| 247 |
function both(val) { |
| 248 |
return $.isFunction(val) || $.isPlainObject(val) ? val : { top:val, left:val }; |
| 249 |
} |
| 250 |
|
| 251 |
// Add special hooks so that window scroll properties can be animated |
| 252 |
$.Tween.propHooks.scrollLeft = |
| 253 |
$.Tween.propHooks.scrollTop = { |
| 254 |
get: function(t) { |
| 255 |
return $(t.elem)[t.prop](); |
| 256 |
}, |
| 257 |
set: function(t) { |
| 258 |
var curr = this.get(t); |
| 259 |
// If interrupt is true and user scrolled, stop animating |
| 260 |
if (t.options.interrupt && t._last && t._last !== curr) { |
| 261 |
return $(t.elem).stop(); |
| 262 |
} |
| 263 |
var next = Math.round(t.now); |
| 264 |
// Don't waste CPU |
| 265 |
// Browsers don't render floating point scroll |
| 266 |
if (curr !== next) { |
| 267 |
$(t.elem)[t.prop](next); |
| 268 |
t._last = this.get(t); |
| 269 |
} |
| 270 |
} |
| 271 |
}; |
| 272 |
|
| 273 |
// AMD requirement |
| 274 |
return $scrollTo; |
| 275 |
}); |
| 276 |
(function (e) { |
| 277 |
e.backward_timer = function (t) { |
| 278 |
var n = {seconds: 5, step: 1, format: "h%:m%:s%", value_setter: undefined, on_exhausted: function (e) { |
| 279 |
}, on_tick : function (e) { |
| 280 |
}}, r = this; |
| 281 |
r.seconds_left = 0; |
| 282 |
r.target = e(t); |
| 283 |
r.timeout = undefined; |
| 284 |
r.settings = {}; |
| 285 |
r.methods = {init : function (t) { |
| 286 |
r.settings = e.extend({}, n, t); |
| 287 |
if (r.settings.value_setter == undefined) { |
| 288 |
if (r.target.is("input")) { |
| 289 |
r.settings.value_setter = "val" |
| 290 |
} else { |
| 291 |
r.settings.value_setter = "text" |
| 292 |
} |
| 293 |
} |
| 294 |
r.methods.reset() |
| 295 |
}, start : function () { |
| 296 |
if (r.timeout == undefined) { |
| 297 |
var e = r.seconds_left == r.settings.seconds ? 0 : r.settings.step * 1e3; |
| 298 |
setTimeout(r.methods._on_tick, e, e) |
| 299 |
} |
| 300 |
}, cancel : function () { |
| 301 |
if (r.timeout != undefined) { |
| 302 |
clearTimeout(r.timeout); |
| 303 |
r.timeout = undefined |
| 304 |
} |
| 305 |
}, reset : function () { |
| 306 |
r.seconds_left = r.settings.seconds; |
| 307 |
r.methods._render_seconds() |
| 308 |
}, _on_tick : function (e) { |
| 309 |
if (e != 0) { |
| 310 |
r.settings.on_tick(r) |
| 311 |
} |
| 312 |
r.methods._render_seconds(); |
| 313 |
if (r.seconds_left > 0) { |
| 314 |
if (r.seconds_left < r.settings.step) { |
| 315 |
var t = r.seconds_left |
| 316 |
} else { |
| 317 |
var t = r.settings.step |
| 318 |
} |
| 319 |
r.seconds_left -= t; |
| 320 |
var n = t * 1e3; |
| 321 |
r.timeout = setTimeout(r.methods._on_tick, n, n) |
| 322 |
} else { |
| 323 |
r.timeout = undefined; |
| 324 |
r.settings.on_exhausted(r) |
| 325 |
} |
| 326 |
}, _render_seconds : function () { |
| 327 |
var e = r.methods._seconds_to_dhms(r.seconds_left), t = r.settings.format; |
| 328 |
if (t.indexOf("d%") !== -1) { |
| 329 |
t = t.replace("d%", e.d).replace("h%", r.methods._check_leading_zero(e.h)) |
| 330 |
} else { |
| 331 |
t = t.replace("h%", e.d * 24 + e.h) |
| 332 |
} |
| 333 |
t = t.replace("m%", r.methods._check_leading_zero(e.m)).replace("s%", r.methods._check_leading_zero(e.s)); |
| 334 |
r.target[r.settings.value_setter](t) |
| 335 |
}, _seconds_to_dhms : function (e) { |
| 336 |
var t = Math.floor(e / (24 * 3600)), e = e - t * 24 * 3600, n = Math.floor(e / 3600), e = e - n * 3600, r = Math.floor(e / 60), i = Math.floor(e - r * 60); |
| 337 |
return{d: t, h: n, m: r, s: i} |
| 338 |
}, _check_leading_zero: function (e) { |
| 339 |
return e < 10 ? "0" + e : "" + e |
| 340 |
}} |
| 341 |
}; |
| 342 |
e.fn.backward_timer = function (t) { |
| 343 |
var n = arguments; |
| 344 |
return this.each(function () { |
| 345 |
var r = e(this).data("backward_timer"); |
| 346 |
if (r == undefined) { |
| 347 |
r = new e.backward_timer(this); |
| 348 |
e(this).data("backward_timer", r) |
| 349 |
} |
| 350 |
if (r.methods[t]) { |
| 351 |
return r.methods[t].apply(this, Array.prototype.slice.call(n, 1)) |
| 352 |
} else if (typeof t === "object" || !t) { |
| 353 |
return r.methods.init.apply(this, n) |
| 354 |
} else { |
| 355 |
e.error("Method " + t + " does not exist on jQuery.backward_timer") |
| 356 |
} |
| 357 |
}) |
| 358 |
} |
| 359 |
})(jQuery); |
| 360 |
|