MediaWiki:Common.js: verschil tussen versies
Uit WikiMeneer
| Regel 12: | Regel 12: | ||
* dependency hasn't arrived yet it'll make sure those are loaded before this. | * dependency hasn't arrived yet it'll make sure those are loaded before this. | ||
*/ | */ | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | (function() { | ||
| + | var COUNT_FRAMERATE, COUNT_MS_PER_FRAME, DIGIT_FORMAT, DIGIT_HTML, DIGIT_SPEEDBOOST, DURATION, FORMAT_MARK_HTML, FORMAT_PARSER, FRAMERATE, FRAMES_PER_VALUE, MS_PER_FRAME, MutationObserver, Odometer, RIBBON_HTML, TRANSITION_END_EVENTS, TRANSITION_SUPPORT, VALUE_HTML, addClass, createFromHTML, fractionalPart, now, removeClass, requestAnimationFrame, round, transitionCheckStyles, trigger, truncate, wrapJQuery, _jQueryWrapped, _old, _ref, _ref1, | ||
| + | __slice = [].slice; | ||
| + | |||
| + | VALUE_HTML = '<span class="odometer-value"></span>'; | ||
| + | |||
| + | RIBBON_HTML = '<span class="odometer-ribbon"><span class="odometer-ribbon-inner">' + VALUE_HTML + '</span></span>'; | ||
| + | |||
| + | DIGIT_HTML = '<span class="odometer-digit"><span class="odometer-digit-spacer">8</span><span class="odometer-digit-inner">' + RIBBON_HTML + '</span></span>'; | ||
| + | |||
| + | FORMAT_MARK_HTML = '<span class="odometer-formatting-mark"></span>'; | ||
| + | |||
| + | DIGIT_FORMAT = 'd'; | ||
| + | |||
| + | FORMAT_PARSER = /^\(?([^)]*)\)?(?:(.)(d+))?$/; | ||
| + | |||
| + | FRAMERATE = 30; | ||
| + | |||
| + | DURATION = 2000; | ||
| + | |||
| + | COUNT_FRAMERATE = 20; | ||
| + | |||
| + | FRAMES_PER_VALUE = 2; | ||
| + | |||
| + | DIGIT_SPEEDBOOST = .5; | ||
| + | |||
| + | MS_PER_FRAME = 1000 / FRAMERATE; | ||
| + | |||
| + | COUNT_MS_PER_FRAME = 1000 / COUNT_FRAMERATE; | ||
| + | |||
| + | TRANSITION_END_EVENTS = 'transitionend webkitTransitionEnd oTransitionEnd otransitionend MSTransitionEnd'; | ||
| + | |||
| + | transitionCheckStyles = document.createElement('div').style; | ||
| + | |||
| + | TRANSITION_SUPPORT = (transitionCheckStyles.transition != null) || (transitionCheckStyles.webkitTransition != null) || (transitionCheckStyles.mozTransition != null) || (transitionCheckStyles.oTransition != null); | ||
| + | |||
| + | requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame; | ||
| + | |||
| + | MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver; | ||
| + | |||
| + | createFromHTML = function(html) { | ||
| + | var el; | ||
| + | el = document.createElement('div'); | ||
| + | el.innerHTML = html; | ||
| + | return el.children[0]; | ||
| + | }; | ||
| + | |||
| + | removeClass = function(el, name) { | ||
| + | return el.className = el.className.replace(new RegExp("(^| )" + (name.split(' ').join('|')) + "( |$)", 'gi'), ' '); | ||
| + | }; | ||
| + | |||
| + | addClass = function(el, name) { | ||
| + | removeClass(el, name); | ||
| + | return el.className += " " + name; | ||
| + | }; | ||
| + | |||
| + | trigger = function(el, name) { | ||
| + | var evt; | ||
| + | if (document.createEvent != null) { | ||
| + | evt = document.createEvent('HTMLEvents'); | ||
| + | evt.initEvent(name, true, true); | ||
| + | return el.dispatchEvent(evt); | ||
| + | } | ||
| + | }; | ||
| + | |||
| + | now = function() { | ||
| + | var _ref, _ref1; | ||
| + | return (_ref = (_ref1 = window.performance) != null ? typeof _ref1.now === "function" ? _ref1.now() : void 0 : void 0) != null ? _ref : +(new Date); | ||
| + | }; | ||
| + | |||
| + | round = function(val, precision) { | ||
| + | if (precision == null) { | ||
| + | precision = 0; | ||
| + | } | ||
| + | if (!precision) { | ||
| + | return Math.round(val); | ||
| + | } | ||
| + | val *= Math.pow(10, precision); | ||
| + | val += 0.5; | ||
| + | val = Math.floor(val); | ||
| + | return val /= Math.pow(10, precision); | ||
| + | }; | ||
| + | |||
| + | truncate = function(val) { | ||
| + | if (val < 0) { | ||
| + | return Math.ceil(val); | ||
| + | } else { | ||
| + | return Math.floor(val); | ||
| + | } | ||
| + | }; | ||
| + | |||
| + | fractionalPart = function(val) { | ||
| + | return val - round(val); | ||
| + | }; | ||
| + | |||
| + | _jQueryWrapped = false; | ||
| + | |||
| + | (wrapJQuery = function() { | ||
| + | var property, _i, _len, _ref, _results; | ||
| + | if (_jQueryWrapped) { | ||
| + | return; | ||
| + | } | ||
| + | if (window.jQuery != null) { | ||
| + | _jQueryWrapped = true; | ||
| + | _ref = ['html', 'text']; | ||
| + | _results = []; | ||
| + | for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
| + | property = _ref[_i]; | ||
| + | _results.push((function(property) { | ||
| + | var old; | ||
| + | old = window.jQuery.fn[property]; | ||
| + | return window.jQuery.fn[property] = function(val) { | ||
| + | var _ref1; | ||
| + | if ((val == null) || (((_ref1 = this[0]) != null ? _ref1.odometer : void 0) == null)) { | ||
| + | return old.apply(this, arguments); | ||
| + | } | ||
| + | return this[0].odometer.update(val); | ||
| + | }; | ||
| + | })(property)); | ||
| + | } | ||
| + | return _results; | ||
| + | } | ||
| + | })(); | ||
| + | |||
| + | setTimeout(wrapJQuery, 0); | ||
| + | |||
| + | Odometer = (function() { | ||
| + | function Odometer(options) { | ||
| + | var e, k, property, v, _base, _i, _len, _ref, _ref1, _ref2, | ||
| + | _this = this; | ||
| + | this.options = options; | ||
| + | this.el = this.options.el; | ||
| + | if (this.el.odometer != null) { | ||
| + | return this.el.odometer; | ||
| + | } | ||
| + | this.el.odometer = this; | ||
| + | _ref = Odometer.options; | ||
| + | for (k in _ref) { | ||
| + | v = _ref[k]; | ||
| + | if (this.options[k] == null) { | ||
| + | this.options[k] = v; | ||
| + | } | ||
| + | } | ||
| + | if ((_base = this.options).duration == null) { | ||
| + | _base.duration = DURATION; | ||
| + | } | ||
| + | this.MAX_VALUES = ((this.options.duration / MS_PER_FRAME) / FRAMES_PER_VALUE) | 0; | ||
| + | this.resetFormat(); | ||
| + | this.value = this.cleanValue((_ref1 = this.options.value) != null ? _ref1 : ''); | ||
| + | this.renderInside(); | ||
| + | this.render(); | ||
| + | try { | ||
| + | _ref2 = ['innerHTML', 'innerText', 'textContent']; | ||
| + | for (_i = 0, _len = _ref2.length; _i < _len; _i++) { | ||
| + | property = _ref2[_i]; | ||
| + | if (this.el[property] != null) { | ||
| + | (function(property) { | ||
| + | return Object.defineProperty(_this.el, property, { | ||
| + | get: function() { | ||
| + | var _ref3; | ||
| + | if (property === 'innerHTML') { | ||
| + | return _this.inside.outerHTML; | ||
| + | } else { | ||
| + | return (_ref3 = _this.inside.innerText) != null ? _ref3 : _this.inside.textContent; | ||
| + | } | ||
| + | }, | ||
| + | set: function(val) { | ||
| + | return _this.update(val); | ||
| + | } | ||
| + | }); | ||
| + | })(property); | ||
| + | } | ||
| + | } | ||
| + | } catch (_error) { | ||
| + | e = _error; | ||
| + | this.watchForMutations(); | ||
| + | } | ||
| + | this; | ||
| + | } | ||
| + | |||
| + | Odometer.prototype.renderInside = function() { | ||
| + | this.inside = document.createElement('div'); | ||
| + | this.inside.className = 'odometer-inside'; | ||
| + | this.el.innerHTML = ''; | ||
| + | return this.el.appendChild(this.inside); | ||
| + | }; | ||
| + | |||
| + | Odometer.prototype.watchForMutations = function() { | ||
| + | var e, | ||
| + | _this = this; | ||
| + | if (MutationObserver == null) { | ||
| + | return; | ||
| + | } | ||
| + | try { | ||
| + | if (this.observer == null) { | ||
| + | this.observer = new MutationObserver(function(mutations) { | ||
| + | var newVal; | ||
| + | newVal = _this.el.innerText; | ||
| + | _this.renderInside(); | ||
| + | _this.render(_this.value); | ||
| + | return _this.update(newVal); | ||
| + | }); | ||
| + | } | ||
| + | this.watchMutations = true; | ||
| + | return this.startWatchingMutations(); | ||
| + | } catch (_error) { | ||
| + | e = _error; | ||
| + | } | ||
| + | }; | ||
| + | |||
| + | Odometer.prototype.startWatchingMutations = function() { | ||
| + | if (this.watchMutations) { | ||
| + | return this.observer.observe(this.el, { | ||
| + | childList: true | ||
| + | }); | ||
| + | } | ||
| + | }; | ||
| + | |||
| + | Odometer.prototype.stopWatchingMutations = function() { | ||
| + | var _ref; | ||
| + | return (_ref = this.observer) != null ? _ref.disconnect() : void 0; | ||
| + | }; | ||
| + | |||
| + | Odometer.prototype.cleanValue = function(val) { | ||
| + | var _ref; | ||
| + | if (typeof val === 'string') { | ||
| + | val = val.replace((_ref = this.format.radix) != null ? _ref : '.', '<radix>'); | ||
| + | val = val.replace(/[.,]/g, ''); | ||
| + | val = val.replace('<radix>', '.'); | ||
| + | val = parseFloat(val, 10) || 0; | ||
| + | } | ||
| + | return round(val, this.format.precision); | ||
| + | }; | ||
| + | |||
| + | Odometer.prototype.bindTransitionEnd = function() { | ||
| + | var event, renderEnqueued, _i, _len, _ref, _results, | ||
| + | _this = this; | ||
| + | if (this.transitionEndBound) { | ||
| + | return; | ||
| + | } | ||
| + | this.transitionEndBound = true; | ||
| + | renderEnqueued = false; | ||
| + | _ref = TRANSITION_END_EVENTS.split(' '); | ||
| + | _results = []; | ||
| + | for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
| + | event = _ref[_i]; | ||
| + | _results.push(this.el.addEventListener(event, function() { | ||
| + | if (renderEnqueued) { | ||
| + | return true; | ||
| + | } | ||
| + | renderEnqueued = true; | ||
| + | setTimeout(function() { | ||
| + | _this.render(); | ||
| + | renderEnqueued = false; | ||
| + | return trigger(_this.el, 'odometerdone'); | ||
| + | }, 0); | ||
| + | return true; | ||
| + | }, false)); | ||
| + | } | ||
| + | return _results; | ||
| + | }; | ||
| + | |||
| + | Odometer.prototype.resetFormat = function() { | ||
| + | var format, fractional, parsed, precision, radix, repeating, _ref, _ref1; | ||
| + | format = (_ref = this.options.format) != null ? _ref : DIGIT_FORMAT; | ||
| + | format || (format = 'd'); | ||
| + | parsed = FORMAT_PARSER.exec(format); | ||
| + | if (!parsed) { | ||
| + | throw new Error("Odometer: Unparsable digit format"); | ||
| + | } | ||
| + | _ref1 = parsed.slice(1, 4), repeating = _ref1[0], radix = _ref1[1], fractional = _ref1[2]; | ||
| + | precision = (fractional != null ? fractional.length : void 0) || 0; | ||
| + | return this.format = { | ||
| + | repeating: repeating, | ||
| + | radix: radix, | ||
| + | precision: precision | ||
| + | }; | ||
| + | }; | ||
| + | |||
| + | Odometer.prototype.render = function(value) { | ||
| + | var classes, cls, match, newClasses, theme, _i, _len; | ||
| + | if (value == null) { | ||
| + | value = this.value; | ||
| + | } | ||
| + | this.stopWatchingMutations(); | ||
| + | this.resetFormat(); | ||
| + | this.inside.innerHTML = ''; | ||
| + | theme = this.options.theme; | ||
| + | classes = this.el.className.split(' '); | ||
| + | newClasses = []; | ||
| + | for (_i = 0, _len = classes.length; _i < _len; _i++) { | ||
| + | cls = classes[_i]; | ||
| + | if (!cls.length) { | ||
| + | continue; | ||
| + | } | ||
| + | if (match = /^odometer-theme-(.+)$/.exec(cls)) { | ||
| + | theme = match[1]; | ||
| + | continue; | ||
| + | } | ||
| + | if (/^odometer(-|$)/.test(cls)) { | ||
| + | continue; | ||
| + | } | ||
| + | newClasses.push(cls); | ||
| + | } | ||
| + | newClasses.push('odometer'); | ||
| + | if (!TRANSITION_SUPPORT) { | ||
| + | newClasses.push('odometer-no-transitions'); | ||
| + | } | ||
| + | if (theme) { | ||
| + | newClasses.push("odometer-theme-" + theme); | ||
| + | } else { | ||
| + | newClasses.push("odometer-auto-theme"); | ||
| + | } | ||
| + | this.el.className = newClasses.join(' '); | ||
| + | this.ribbons = {}; | ||
| + | this.formatDigits(value); | ||
| + | return this.startWatchingMutations(); | ||
| + | }; | ||
| + | |||
| + | Odometer.prototype.formatDigits = function(value) { | ||
| + | var digit, valueDigit, valueString, wholePart, _i, _j, _len, _len1, _ref, _ref1; | ||
| + | this.digits = []; | ||
| + | if (this.options.formatFunction) { | ||
| + | valueString = this.options.formatFunction(value); | ||
| + | _ref = valueString.split('').reverse(); | ||
| + | for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
| + | valueDigit = _ref[_i]; | ||
| + | if (valueDigit.match(/0-9/)) { | ||
| + | digit = this.renderDigit(); | ||
| + | digit.querySelector('.odometer-value').innerHTML = valueDigit; | ||
| + | this.digits.push(digit); | ||
| + | this.insertDigit(digit); | ||
| + | } else { | ||
| + | this.addSpacer(valueDigit); | ||
| + | } | ||
| + | } | ||
| + | } else { | ||
| + | wholePart = !this.format.precision || !fractionalPart(value) || false; | ||
| + | _ref1 = value.toString().split('').reverse(); | ||
| + | for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { | ||
| + | digit = _ref1[_j]; | ||
| + | if (digit === '.') { | ||
| + | wholePart = true; | ||
| + | } | ||
| + | this.addDigit(digit, wholePart); | ||
| + | } | ||
| + | } | ||
| + | }; | ||
| + | |||
| + | Odometer.prototype.update = function(newValue) { | ||
| + | var diff, | ||
| + | _this = this; | ||
| + | newValue = this.cleanValue(newValue); | ||
| + | if (!(diff = newValue - this.value)) { | ||
| + | return; | ||
| + | } | ||
| + | removeClass(this.el, 'odometer-animating-up odometer-animating-down odometer-animating'); | ||
| + | if (diff > 0) { | ||
| + | addClass(this.el, 'odometer-animating-up'); | ||
| + | } else { | ||
| + | addClass(this.el, 'odometer-animating-down'); | ||
| + | } | ||
| + | this.stopWatchingMutations(); | ||
| + | this.animate(newValue); | ||
| + | this.startWatchingMutations(); | ||
| + | setTimeout(function() { | ||
| + | _this.el.offsetHeight; | ||
| + | return addClass(_this.el, 'odometer-animating'); | ||
| + | }, 0); | ||
| + | return this.value = newValue; | ||
| + | }; | ||
| + | |||
| + | Odometer.prototype.renderDigit = function() { | ||
| + | return createFromHTML(DIGIT_HTML); | ||
| + | }; | ||
| + | |||
| + | Odometer.prototype.insertDigit = function(digit, before) { | ||
| + | if (before != null) { | ||
| + | return this.inside.insertBefore(digit, before); | ||
| + | } else if (!this.inside.children.length) { | ||
| + | return this.inside.appendChild(digit); | ||
| + | } else { | ||
| + | return this.inside.insertBefore(digit, this.inside.children[0]); | ||
| + | } | ||
| + | }; | ||
| + | |||
| + | Odometer.prototype.addSpacer = function(chr, before, extraClasses) { | ||
| + | var spacer; | ||
| + | spacer = createFromHTML(FORMAT_MARK_HTML); | ||
| + | spacer.innerHTML = chr; | ||
| + | if (extraClasses) { | ||
| + | addClass(spacer, extraClasses); | ||
| + | } | ||
| + | return this.insertDigit(spacer, before); | ||
| + | }; | ||
| + | |||
| + | Odometer.prototype.addDigit = function(value, repeating) { | ||
| + | var chr, digit, resetted, _ref; | ||
| + | if (repeating == null) { | ||
| + | repeating = true; | ||
| + | } | ||
| + | if (value === '-') { | ||
| + | return this.addSpacer(value, null, 'odometer-negation-mark'); | ||
| + | } | ||
| + | if (value === '.') { | ||
| + | return this.addSpacer((_ref = this.format.radix) != null ? _ref : '.', null, 'odometer-radix-mark'); | ||
| + | } | ||
| + | if (repeating) { | ||
| + | resetted = false; | ||
| + | while (true) { | ||
| + | if (!this.format.repeating.length) { | ||
| + | if (resetted) { | ||
| + | throw new Error("Bad odometer format without digits"); | ||
| + | } | ||
| + | this.resetFormat(); | ||
| + | resetted = true; | ||
| + | } | ||
| + | chr = this.format.repeating[this.format.repeating.length - 1]; | ||
| + | this.format.repeating = this.format.repeating.substring(0, this.format.repeating.length - 1); | ||
| + | if (chr === 'd') { | ||
| + | break; | ||
| + | } | ||
| + | this.addSpacer(chr); | ||
| + | } | ||
| + | } | ||
| + | digit = this.renderDigit(); | ||
| + | digit.querySelector('.odometer-value').innerHTML = value; | ||
| + | this.digits.push(digit); | ||
| + | return this.insertDigit(digit); | ||
| + | }; | ||
| + | |||
| + | Odometer.prototype.animate = function(newValue) { | ||
| + | if (!TRANSITION_SUPPORT || this.options.animation === 'count') { | ||
| + | return this.animateCount(newValue); | ||
| + | } else { | ||
| + | return this.animateSlide(newValue); | ||
| + | } | ||
| + | }; | ||
| + | |||
| + | Odometer.prototype.animateCount = function(newValue) { | ||
| + | var cur, diff, last, start, tick, | ||
| + | _this = this; | ||
| + | if (!(diff = +newValue - this.value)) { | ||
| + | return; | ||
| + | } | ||
| + | start = last = now(); | ||
| + | cur = this.value; | ||
| + | return (tick = function() { | ||
| + | var delta, dist, fraction; | ||
| + | if ((now() - start) > _this.options.duration) { | ||
| + | _this.value = newValue; | ||
| + | _this.render(); | ||
| + | trigger(_this.el, 'odometerdone'); | ||
| + | return; | ||
| + | } | ||
| + | delta = now() - last; | ||
| + | if (delta > COUNT_MS_PER_FRAME) { | ||
| + | last = now(); | ||
| + | fraction = delta / _this.options.duration; | ||
| + | dist = diff * fraction; | ||
| + | cur += dist; | ||
| + | _this.render(Math.round(cur)); | ||
| + | } | ||
| + | if (requestAnimationFrame != null) { | ||
| + | return requestAnimationFrame(tick); | ||
| + | } else { | ||
| + | return setTimeout(tick, COUNT_MS_PER_FRAME); | ||
| + | } | ||
| + | })(); | ||
| + | }; | ||
| + | |||
| + | Odometer.prototype.getDigitCount = function() { | ||
| + | var i, max, value, values, _i, _len; | ||
| + | values = 1 <= arguments.length ? __slice.call(arguments, 0) : []; | ||
| + | for (i = _i = 0, _len = values.length; _i < _len; i = ++_i) { | ||
| + | value = values[i]; | ||
| + | values[i] = Math.abs(value); | ||
| + | } | ||
| + | max = Math.max.apply(Math, values); | ||
| + | return Math.ceil(Math.log(max + 1) / Math.log(10)); | ||
| + | }; | ||
| + | |||
| + | Odometer.prototype.getFractionalDigitCount = function() { | ||
| + | var i, parser, parts, value, values, _i, _len; | ||
| + | values = 1 <= arguments.length ? __slice.call(arguments, 0) : []; | ||
| + | parser = /^\-?\d*\.(\d*?)0*$/; | ||
| + | for (i = _i = 0, _len = values.length; _i < _len; i = ++_i) { | ||
| + | value = values[i]; | ||
| + | values[i] = value.toString(); | ||
| + | parts = parser.exec(values[i]); | ||
| + | if (parts == null) { | ||
| + | values[i] = 0; | ||
| + | } else { | ||
| + | values[i] = parts[1].length; | ||
| + | } | ||
| + | } | ||
| + | return Math.max.apply(Math, values); | ||
| + | }; | ||
| + | |||
| + | Odometer.prototype.resetDigits = function() { | ||
| + | this.digits = []; | ||
| + | this.ribbons = []; | ||
| + | this.inside.innerHTML = ''; | ||
| + | return this.resetFormat(); | ||
| + | }; | ||
| + | |||
| + | Odometer.prototype.animateSlide = function(newValue) { | ||
| + | var boosted, cur, diff, digitCount, digits, dist, end, fractionalCount, frame, frames, i, incr, j, mark, numEl, oldValue, start, _base, _i, _j, _k, _l, _len, _len1, _len2, _m, _ref, _results; | ||
| + | oldValue = this.value; | ||
| + | fractionalCount = this.getFractionalDigitCount(oldValue, newValue); | ||
| + | if (fractionalCount) { | ||
| + | newValue = newValue * Math.pow(10, fractionalCount); | ||
| + | oldValue = oldValue * Math.pow(10, fractionalCount); | ||
| + | } | ||
| + | if (!(diff = newValue - oldValue)) { | ||
| + | return; | ||
| + | } | ||
| + | this.bindTransitionEnd(); | ||
| + | digitCount = this.getDigitCount(oldValue, newValue); | ||
| + | digits = []; | ||
| + | boosted = 0; | ||
| + | for (i = _i = 0; 0 <= digitCount ? _i < digitCount : _i > digitCount; i = 0 <= digitCount ? ++_i : --_i) { | ||
| + | start = truncate(oldValue / Math.pow(10, digitCount - i - 1)); | ||
| + | end = truncate(newValue / Math.pow(10, digitCount - i - 1)); | ||
| + | dist = end - start; | ||
| + | if (Math.abs(dist) > this.MAX_VALUES) { | ||
| + | frames = []; | ||
| + | incr = dist / (this.MAX_VALUES + this.MAX_VALUES * boosted * DIGIT_SPEEDBOOST); | ||
| + | cur = start; | ||
| + | while ((dist > 0 && cur < end) || (dist < 0 && cur > end)) { | ||
| + | frames.push(Math.round(cur)); | ||
| + | cur += incr; | ||
| + | } | ||
| + | if (frames[frames.length - 1] !== end) { | ||
| + | frames.push(end); | ||
| + | } | ||
| + | boosted++; | ||
| + | } else { | ||
| + | frames = (function() { | ||
| + | _results = []; | ||
| + | for (var _j = start; start <= end ? _j <= end : _j >= end; start <= end ? _j++ : _j--){ _results.push(_j); } | ||
| + | return _results; | ||
| + | }).apply(this); | ||
| + | } | ||
| + | for (i = _k = 0, _len = frames.length; _k < _len; i = ++_k) { | ||
| + | frame = frames[i]; | ||
| + | frames[i] = Math.abs(frame % 10); | ||
| + | } | ||
| + | digits.push(frames); | ||
| + | } | ||
| + | this.resetDigits(); | ||
| + | _ref = digits.reverse(); | ||
| + | for (i = _l = 0, _len1 = _ref.length; _l < _len1; i = ++_l) { | ||
| + | frames = _ref[i]; | ||
| + | if (!this.digits[i]) { | ||
| + | this.addDigit(' ', i >= fractionalCount); | ||
| + | } | ||
| + | if ((_base = this.ribbons)[i] == null) { | ||
| + | _base[i] = this.digits[i].querySelector('.odometer-ribbon-inner'); | ||
| + | } | ||
| + | this.ribbons[i].innerHTML = ''; | ||
| + | if (diff < 0) { | ||
| + | frames = frames.reverse(); | ||
| + | } | ||
| + | for (j = _m = 0, _len2 = frames.length; _m < _len2; j = ++_m) { | ||
| + | frame = frames[j]; | ||
| + | numEl = document.createElement('div'); | ||
| + | numEl.className = 'odometer-value'; | ||
| + | numEl.innerHTML = frame; | ||
| + | this.ribbons[i].appendChild(numEl); | ||
| + | if (j === frames.length - 1) { | ||
| + | addClass(numEl, 'odometer-last-value'); | ||
| + | } | ||
| + | if (j === 0) { | ||
| + | addClass(numEl, 'odometer-first-value'); | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | if (start < 0) { | ||
| + | this.addDigit('-'); | ||
| + | } | ||
| + | mark = this.inside.querySelector('.odometer-radix-mark'); | ||
| + | if (mark != null) { | ||
| + | mark.parent.removeChild(mark); | ||
| + | } | ||
| + | if (fractionalCount) { | ||
| + | return this.addSpacer(this.format.radix, this.digits[fractionalCount - 1], 'odometer-radix-mark'); | ||
| + | } | ||
| + | }; | ||
| + | |||
| + | return Odometer; | ||
| + | |||
| + | })(); | ||
| + | |||
| + | Odometer.options = (_ref = window.odometerOptions) != null ? _ref : {}; | ||
| + | |||
| + | setTimeout(function() { | ||
| + | var k, v, _base, _ref1, _results; | ||
| + | if (window.odometerOptions) { | ||
| + | _ref1 = window.odometerOptions; | ||
| + | _results = []; | ||
| + | for (k in _ref1) { | ||
| + | v = _ref1[k]; | ||
| + | _results.push((_base = Odometer.options)[k] != null ? (_base = Odometer.options)[k] : _base[k] = v); | ||
| + | } | ||
| + | return _results; | ||
| + | } | ||
| + | }, 0); | ||
| + | |||
| + | Odometer.init = function() { | ||
| + | var el, elements, _i, _len, _ref1, _results; | ||
| + | if (document.querySelectorAll == null) { | ||
| + | return; | ||
| + | } | ||
| + | elements = document.querySelectorAll(Odometer.options.selector || '.odometer'); | ||
| + | _results = []; | ||
| + | for (_i = 0, _len = elements.length; _i < _len; _i++) { | ||
| + | el = elements[_i]; | ||
| + | _results.push(el.odometer = new Odometer({ | ||
| + | el: el, | ||
| + | value: (_ref1 = el.innerText) != null ? _ref1 : el.textContent | ||
| + | })); | ||
| + | } | ||
| + | return _results; | ||
| + | }; | ||
| + | |||
| + | if ((((_ref1 = document.documentElement) != null ? _ref1.doScroll : void 0) != null) && (document.createEventObject != null)) { | ||
| + | _old = document.onreadystatechange; | ||
| + | document.onreadystatechange = function() { | ||
| + | if (document.readyState === 'complete' && Odometer.options.auto !== false) { | ||
| + | Odometer.init(); | ||
| + | } | ||
| + | return _old != null ? _old.apply(this, arguments) : void 0; | ||
| + | }; | ||
| + | } else { | ||
| + | document.addEventListener('DOMContentLoaded', function() { | ||
| + | if (Odometer.options.auto !== false) { | ||
| + | return Odometer.init(); | ||
| + | } | ||
| + | }, false); | ||
| + | } | ||
| + | |||
| + | if (typeof define === 'function' && define.amd) { | ||
| + | define([], function() { | ||
| + | return Odometer; | ||
| + | }); | ||
| + | } else if (typeof exports !== "undefined" && exports !== null) { | ||
| + | module.exports = Odometer; | ||
| + | } else { | ||
| + | window.Odometer = Odometer; | ||
| + | } | ||
| + | |||
| + | }).call(this); | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
Versie van 9 aug 2017 om 15:35
/* JavaScript die hier wordt geplaatst heeft invloed op alle pagina's voor alle gebruikers */
/**
* Keep code in MediaWiki:Common.js to a minimum as it is unconditionally
* loaded for all users on every wiki page. If possible create a gadget that is
* enabled by default instead of adding it here (since gadgets are fully
* optimized ResourceLoader modules with possibility to add dependencies etc.)
*
* Since Common.js isn't a gadget, there is no place to declare its
* dependencies, so we have to lazy load them with mw.loader.using on demand and
* then execute the rest in the callback. In most cases these dependencies will
* be loaded (or loading) already and the callback will not be delayed. In case a
* dependency hasn't arrived yet it'll make sure those are loaded before this.
*/
(function() {
var COUNT_FRAMERATE, COUNT_MS_PER_FRAME, DIGIT_FORMAT, DIGIT_HTML, DIGIT_SPEEDBOOST, DURATION, FORMAT_MARK_HTML, FORMAT_PARSER, FRAMERATE, FRAMES_PER_VALUE, MS_PER_FRAME, MutationObserver, Odometer, RIBBON_HTML, TRANSITION_END_EVENTS, TRANSITION_SUPPORT, VALUE_HTML, addClass, createFromHTML, fractionalPart, now, removeClass, requestAnimationFrame, round, transitionCheckStyles, trigger, truncate, wrapJQuery, _jQueryWrapped, _old, _ref, _ref1,
__slice = [].slice;
VALUE_HTML = '<span class="odometer-value"></span>';
RIBBON_HTML = '<span class="odometer-ribbon"><span class="odometer-ribbon-inner">' + VALUE_HTML + '</span></span>';
DIGIT_HTML = '<span class="odometer-digit"><span class="odometer-digit-spacer">8</span><span class="odometer-digit-inner">' + RIBBON_HTML + '</span></span>';
FORMAT_MARK_HTML = '<span class="odometer-formatting-mark"></span>';
DIGIT_FORMAT = 'd';
FORMAT_PARSER = /^\(?([^)]*)\)?(?:(.)(d+))?$/;
FRAMERATE = 30;
DURATION = 2000;
COUNT_FRAMERATE = 20;
FRAMES_PER_VALUE = 2;
DIGIT_SPEEDBOOST = .5;
MS_PER_FRAME = 1000 / FRAMERATE;
COUNT_MS_PER_FRAME = 1000 / COUNT_FRAMERATE;
TRANSITION_END_EVENTS = 'transitionend webkitTransitionEnd oTransitionEnd otransitionend MSTransitionEnd';
transitionCheckStyles = document.createElement('div').style;
TRANSITION_SUPPORT = (transitionCheckStyles.transition != null) || (transitionCheckStyles.webkitTransition != null) || (transitionCheckStyles.mozTransition != null) || (transitionCheckStyles.oTransition != null);
requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
createFromHTML = function(html) {
var el;
el = document.createElement('div');
el.innerHTML = html;
return el.children[0];
};
removeClass = function(el, name) {
return el.className = el.className.replace(new RegExp("(^| )" + (name.split(' ').join('|')) + "( |$)", 'gi'), ' ');
};
addClass = function(el, name) {
removeClass(el, name);
return el.className += " " + name;
};
trigger = function(el, name) {
var evt;
if (document.createEvent != null) {
evt = document.createEvent('HTMLEvents');
evt.initEvent(name, true, true);
return el.dispatchEvent(evt);
}
};
now = function() {
var _ref, _ref1;
return (_ref = (_ref1 = window.performance) != null ? typeof _ref1.now === "function" ? _ref1.now() : void 0 : void 0) != null ? _ref : +(new Date);
};
round = function(val, precision) {
if (precision == null) {
precision = 0;
}
if (!precision) {
return Math.round(val);
}
val *= Math.pow(10, precision);
val += 0.5;
val = Math.floor(val);
return val /= Math.pow(10, precision);
};
truncate = function(val) {
if (val < 0) {
return Math.ceil(val);
} else {
return Math.floor(val);
}
};
fractionalPart = function(val) {
return val - round(val);
};
_jQueryWrapped = false;
(wrapJQuery = function() {
var property, _i, _len, _ref, _results;
if (_jQueryWrapped) {
return;
}
if (window.jQuery != null) {
_jQueryWrapped = true;
_ref = ['html', 'text'];
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
property = _ref[_i];
_results.push((function(property) {
var old;
old = window.jQuery.fn[property];
return window.jQuery.fn[property] = function(val) {
var _ref1;
if ((val == null) || (((_ref1 = this[0]) != null ? _ref1.odometer : void 0) == null)) {
return old.apply(this, arguments);
}
return this[0].odometer.update(val);
};
})(property));
}
return _results;
}
})();
setTimeout(wrapJQuery, 0);
Odometer = (function() {
function Odometer(options) {
var e, k, property, v, _base, _i, _len, _ref, _ref1, _ref2,
_this = this;
this.options = options;
this.el = this.options.el;
if (this.el.odometer != null) {
return this.el.odometer;
}
this.el.odometer = this;
_ref = Odometer.options;
for (k in _ref) {
v = _ref[k];
if (this.options[k] == null) {
this.options[k] = v;
}
}
if ((_base = this.options).duration == null) {
_base.duration = DURATION;
}
this.MAX_VALUES = ((this.options.duration / MS_PER_FRAME) / FRAMES_PER_VALUE) | 0;
this.resetFormat();
this.value = this.cleanValue((_ref1 = this.options.value) != null ? _ref1 : '');
this.renderInside();
this.render();
try {
_ref2 = ['innerHTML', 'innerText', 'textContent'];
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
property = _ref2[_i];
if (this.el[property] != null) {
(function(property) {
return Object.defineProperty(_this.el, property, {
get: function() {
var _ref3;
if (property === 'innerHTML') {
return _this.inside.outerHTML;
} else {
return (_ref3 = _this.inside.innerText) != null ? _ref3 : _this.inside.textContent;
}
},
set: function(val) {
return _this.update(val);
}
});
})(property);
}
}
} catch (_error) {
e = _error;
this.watchForMutations();
}
this;
}
Odometer.prototype.renderInside = function() {
this.inside = document.createElement('div');
this.inside.className = 'odometer-inside';
this.el.innerHTML = '';
return this.el.appendChild(this.inside);
};
Odometer.prototype.watchForMutations = function() {
var e,
_this = this;
if (MutationObserver == null) {
return;
}
try {
if (this.observer == null) {
this.observer = new MutationObserver(function(mutations) {
var newVal;
newVal = _this.el.innerText;
_this.renderInside();
_this.render(_this.value);
return _this.update(newVal);
});
}
this.watchMutations = true;
return this.startWatchingMutations();
} catch (_error) {
e = _error;
}
};
Odometer.prototype.startWatchingMutations = function() {
if (this.watchMutations) {
return this.observer.observe(this.el, {
childList: true
});
}
};
Odometer.prototype.stopWatchingMutations = function() {
var _ref;
return (_ref = this.observer) != null ? _ref.disconnect() : void 0;
};
Odometer.prototype.cleanValue = function(val) {
var _ref;
if (typeof val === 'string') {
val = val.replace((_ref = this.format.radix) != null ? _ref : '.', '<radix>');
val = val.replace(/[.,]/g, '');
val = val.replace('<radix>', '.');
val = parseFloat(val, 10) || 0;
}
return round(val, this.format.precision);
};
Odometer.prototype.bindTransitionEnd = function() {
var event, renderEnqueued, _i, _len, _ref, _results,
_this = this;
if (this.transitionEndBound) {
return;
}
this.transitionEndBound = true;
renderEnqueued = false;
_ref = TRANSITION_END_EVENTS.split(' ');
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
event = _ref[_i];
_results.push(this.el.addEventListener(event, function() {
if (renderEnqueued) {
return true;
}
renderEnqueued = true;
setTimeout(function() {
_this.render();
renderEnqueued = false;
return trigger(_this.el, 'odometerdone');
}, 0);
return true;
}, false));
}
return _results;
};
Odometer.prototype.resetFormat = function() {
var format, fractional, parsed, precision, radix, repeating, _ref, _ref1;
format = (_ref = this.options.format) != null ? _ref : DIGIT_FORMAT;
format || (format = 'd');
parsed = FORMAT_PARSER.exec(format);
if (!parsed) {
throw new Error("Odometer: Unparsable digit format");
}
_ref1 = parsed.slice(1, 4), repeating = _ref1[0], radix = _ref1[1], fractional = _ref1[2];
precision = (fractional != null ? fractional.length : void 0) || 0;
return this.format = {
repeating: repeating,
radix: radix,
precision: precision
};
};
Odometer.prototype.render = function(value) {
var classes, cls, match, newClasses, theme, _i, _len;
if (value == null) {
value = this.value;
}
this.stopWatchingMutations();
this.resetFormat();
this.inside.innerHTML = '';
theme = this.options.theme;
classes = this.el.className.split(' ');
newClasses = [];
for (_i = 0, _len = classes.length; _i < _len; _i++) {
cls = classes[_i];
if (!cls.length) {
continue;
}
if (match = /^odometer-theme-(.+)$/.exec(cls)) {
theme = match[1];
continue;
}
if (/^odometer(-|$)/.test(cls)) {
continue;
}
newClasses.push(cls);
}
newClasses.push('odometer');
if (!TRANSITION_SUPPORT) {
newClasses.push('odometer-no-transitions');
}
if (theme) {
newClasses.push("odometer-theme-" + theme);
} else {
newClasses.push("odometer-auto-theme");
}
this.el.className = newClasses.join(' ');
this.ribbons = {};
this.formatDigits(value);
return this.startWatchingMutations();
};
Odometer.prototype.formatDigits = function(value) {
var digit, valueDigit, valueString, wholePart, _i, _j, _len, _len1, _ref, _ref1;
this.digits = [];
if (this.options.formatFunction) {
valueString = this.options.formatFunction(value);
_ref = valueString.split('').reverse();
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
valueDigit = _ref[_i];
if (valueDigit.match(/0-9/)) {
digit = this.renderDigit();
digit.querySelector('.odometer-value').innerHTML = valueDigit;
this.digits.push(digit);
this.insertDigit(digit);
} else {
this.addSpacer(valueDigit);
}
}
} else {
wholePart = !this.format.precision || !fractionalPart(value) || false;
_ref1 = value.toString().split('').reverse();
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
digit = _ref1[_j];
if (digit === '.') {
wholePart = true;
}
this.addDigit(digit, wholePart);
}
}
};
Odometer.prototype.update = function(newValue) {
var diff,
_this = this;
newValue = this.cleanValue(newValue);
if (!(diff = newValue - this.value)) {
return;
}
removeClass(this.el, 'odometer-animating-up odometer-animating-down odometer-animating');
if (diff > 0) {
addClass(this.el, 'odometer-animating-up');
} else {
addClass(this.el, 'odometer-animating-down');
}
this.stopWatchingMutations();
this.animate(newValue);
this.startWatchingMutations();
setTimeout(function() {
_this.el.offsetHeight;
return addClass(_this.el, 'odometer-animating');
}, 0);
return this.value = newValue;
};
Odometer.prototype.renderDigit = function() {
return createFromHTML(DIGIT_HTML);
};
Odometer.prototype.insertDigit = function(digit, before) {
if (before != null) {
return this.inside.insertBefore(digit, before);
} else if (!this.inside.children.length) {
return this.inside.appendChild(digit);
} else {
return this.inside.insertBefore(digit, this.inside.children[0]);
}
};
Odometer.prototype.addSpacer = function(chr, before, extraClasses) {
var spacer;
spacer = createFromHTML(FORMAT_MARK_HTML);
spacer.innerHTML = chr;
if (extraClasses) {
addClass(spacer, extraClasses);
}
return this.insertDigit(spacer, before);
};
Odometer.prototype.addDigit = function(value, repeating) {
var chr, digit, resetted, _ref;
if (repeating == null) {
repeating = true;
}
if (value === '-') {
return this.addSpacer(value, null, 'odometer-negation-mark');
}
if (value === '.') {
return this.addSpacer((_ref = this.format.radix) != null ? _ref : '.', null, 'odometer-radix-mark');
}
if (repeating) {
resetted = false;
while (true) {
if (!this.format.repeating.length) {
if (resetted) {
throw new Error("Bad odometer format without digits");
}
this.resetFormat();
resetted = true;
}
chr = this.format.repeating[this.format.repeating.length - 1];
this.format.repeating = this.format.repeating.substring(0, this.format.repeating.length - 1);
if (chr === 'd') {
break;
}
this.addSpacer(chr);
}
}
digit = this.renderDigit();
digit.querySelector('.odometer-value').innerHTML = value;
this.digits.push(digit);
return this.insertDigit(digit);
};
Odometer.prototype.animate = function(newValue) {
if (!TRANSITION_SUPPORT || this.options.animation === 'count') {
return this.animateCount(newValue);
} else {
return this.animateSlide(newValue);
}
};
Odometer.prototype.animateCount = function(newValue) {
var cur, diff, last, start, tick,
_this = this;
if (!(diff = +newValue - this.value)) {
return;
}
start = last = now();
cur = this.value;
return (tick = function() {
var delta, dist, fraction;
if ((now() - start) > _this.options.duration) {
_this.value = newValue;
_this.render();
trigger(_this.el, 'odometerdone');
return;
}
delta = now() - last;
if (delta > COUNT_MS_PER_FRAME) {
last = now();
fraction = delta / _this.options.duration;
dist = diff * fraction;
cur += dist;
_this.render(Math.round(cur));
}
if (requestAnimationFrame != null) {
return requestAnimationFrame(tick);
} else {
return setTimeout(tick, COUNT_MS_PER_FRAME);
}
})();
};
Odometer.prototype.getDigitCount = function() {
var i, max, value, values, _i, _len;
values = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
for (i = _i = 0, _len = values.length; _i < _len; i = ++_i) {
value = values[i];
values[i] = Math.abs(value);
}
max = Math.max.apply(Math, values);
return Math.ceil(Math.log(max + 1) / Math.log(10));
};
Odometer.prototype.getFractionalDigitCount = function() {
var i, parser, parts, value, values, _i, _len;
values = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
parser = /^\-?\d*\.(\d*?)0*$/;
for (i = _i = 0, _len = values.length; _i < _len; i = ++_i) {
value = values[i];
values[i] = value.toString();
parts = parser.exec(values[i]);
if (parts == null) {
values[i] = 0;
} else {
values[i] = parts[1].length;
}
}
return Math.max.apply(Math, values);
};
Odometer.prototype.resetDigits = function() {
this.digits = [];
this.ribbons = [];
this.inside.innerHTML = '';
return this.resetFormat();
};
Odometer.prototype.animateSlide = function(newValue) {
var boosted, cur, diff, digitCount, digits, dist, end, fractionalCount, frame, frames, i, incr, j, mark, numEl, oldValue, start, _base, _i, _j, _k, _l, _len, _len1, _len2, _m, _ref, _results;
oldValue = this.value;
fractionalCount = this.getFractionalDigitCount(oldValue, newValue);
if (fractionalCount) {
newValue = newValue * Math.pow(10, fractionalCount);
oldValue = oldValue * Math.pow(10, fractionalCount);
}
if (!(diff = newValue - oldValue)) {
return;
}
this.bindTransitionEnd();
digitCount = this.getDigitCount(oldValue, newValue);
digits = [];
boosted = 0;
for (i = _i = 0; 0 <= digitCount ? _i < digitCount : _i > digitCount; i = 0 <= digitCount ? ++_i : --_i) {
start = truncate(oldValue / Math.pow(10, digitCount - i - 1));
end = truncate(newValue / Math.pow(10, digitCount - i - 1));
dist = end - start;
if (Math.abs(dist) > this.MAX_VALUES) {
frames = [];
incr = dist / (this.MAX_VALUES + this.MAX_VALUES * boosted * DIGIT_SPEEDBOOST);
cur = start;
while ((dist > 0 && cur < end) || (dist < 0 && cur > end)) {
frames.push(Math.round(cur));
cur += incr;
}
if (frames[frames.length - 1] !== end) {
frames.push(end);
}
boosted++;
} else {
frames = (function() {
_results = [];
for (var _j = start; start <= end ? _j <= end : _j >= end; start <= end ? _j++ : _j--){ _results.push(_j); }
return _results;
}).apply(this);
}
for (i = _k = 0, _len = frames.length; _k < _len; i = ++_k) {
frame = frames[i];
frames[i] = Math.abs(frame % 10);
}
digits.push(frames);
}
this.resetDigits();
_ref = digits.reverse();
for (i = _l = 0, _len1 = _ref.length; _l < _len1; i = ++_l) {
frames = _ref[i];
if (!this.digits[i]) {
this.addDigit(' ', i >= fractionalCount);
}
if ((_base = this.ribbons)[i] == null) {
_base[i] = this.digits[i].querySelector('.odometer-ribbon-inner');
}
this.ribbons[i].innerHTML = '';
if (diff < 0) {
frames = frames.reverse();
}
for (j = _m = 0, _len2 = frames.length; _m < _len2; j = ++_m) {
frame = frames[j];
numEl = document.createElement('div');
numEl.className = 'odometer-value';
numEl.innerHTML = frame;
this.ribbons[i].appendChild(numEl);
if (j === frames.length - 1) {
addClass(numEl, 'odometer-last-value');
}
if (j === 0) {
addClass(numEl, 'odometer-first-value');
}
}
}
if (start < 0) {
this.addDigit('-');
}
mark = this.inside.querySelector('.odometer-radix-mark');
if (mark != null) {
mark.parent.removeChild(mark);
}
if (fractionalCount) {
return this.addSpacer(this.format.radix, this.digits[fractionalCount - 1], 'odometer-radix-mark');
}
};
return Odometer;
})();
Odometer.options = (_ref = window.odometerOptions) != null ? _ref : {};
setTimeout(function() {
var k, v, _base, _ref1, _results;
if (window.odometerOptions) {
_ref1 = window.odometerOptions;
_results = [];
for (k in _ref1) {
v = _ref1[k];
_results.push((_base = Odometer.options)[k] != null ? (_base = Odometer.options)[k] : _base[k] = v);
}
return _results;
}
}, 0);
Odometer.init = function() {
var el, elements, _i, _len, _ref1, _results;
if (document.querySelectorAll == null) {
return;
}
elements = document.querySelectorAll(Odometer.options.selector || '.odometer');
_results = [];
for (_i = 0, _len = elements.length; _i < _len; _i++) {
el = elements[_i];
_results.push(el.odometer = new Odometer({
el: el,
value: (_ref1 = el.innerText) != null ? _ref1 : el.textContent
}));
}
return _results;
};
if ((((_ref1 = document.documentElement) != null ? _ref1.doScroll : void 0) != null) && (document.createEventObject != null)) {
_old = document.onreadystatechange;
document.onreadystatechange = function() {
if (document.readyState === 'complete' && Odometer.options.auto !== false) {
Odometer.init();
}
return _old != null ? _old.apply(this, arguments) : void 0;
};
} else {
document.addEventListener('DOMContentLoaded', function() {
if (Odometer.options.auto !== false) {
return Odometer.init();
}
}, false);
}
if (typeof define === 'function' && define.amd) {
define([], function() {
return Odometer;
});
} else if (typeof exports !== "undefined" && exports !== null) {
module.exports = Odometer;
} else {
window.Odometer = Odometer;
}
}).call(this);
/* global mw, $, importStylesheet, importScript */
/* jshint strict:false, browser:true */
mw.loader.using( ['mediawiki.util', 'mediawiki.notify', 'jquery.client'] ).done( function () {
/* Begin of mw.loader.using callback */
/**
* Main Page layout fixes
*
* Description: Adds an additional link to the complete list of languages available.
* Maintainers: [[User:AzaToth]], [[User:R. Koot]], [[User:Alex Smotrov]]
*/
if ( mw.config.get( 'wgPageName' ) === 'Main_Page' || mw.config.get( 'wgPageName' ) === 'Talk:Main_Page' ) {
$( function () {
mw.util.addPortletLink( 'p-lang', '//meta.wikimedia.org/wiki/List_of_Wikipedias',
'Complete list', 'interwiki-completelist', 'Complete list of Wikipedias' );
} );
}
/**
* Redirect User:Name/skin.js and skin.css to the current skin's pages
* (unless the 'skin' page really exists)
* @source: http://www.mediawiki.org/wiki/Snippets/Redirect_skin.js
* @rev: 2
*/
if ( mw.config.get( 'wgArticleId' ) === 0 && mw.config.get( 'wgNamespaceNumber' ) === 2 ) {
var titleParts = mw.config.get( 'wgPageName' ).split( '/' );
/* Make sure there was a part before and after the slash
and that the latter is 'skin.js' or 'skin.css' */
if ( titleParts.length == 2 ) {
var userSkinPage = titleParts.shift() + '/' + mw.config.get( 'skin' );
if ( titleParts.slice( -1 ) == 'skin.js' ) {
window.location.href = mw.util.getUrl( userSkinPage + '.js' );
} else if ( titleParts.slice( -1 ) == 'skin.css' ) {
window.location.href = mw.util.getUrl( userSkinPage + '.css' );
}
}
}
/**
* Map addPortletLink to mw.util
* @deprecated: Use mw.util.addPortletLink instead.
*/
mw.log.deprecate( window, 'addPortletLink', mw.util.addPortletLink, 'Use mw.util.addPortletLink instead' );
/**
* Extract a URL parameter from the current URL
* @deprecated: Use mw.util.getParamValue with proper escaping
*/
mw.log.deprecate( window, 'getURLParamValue', mw.util.getParamValue, 'Use mw.util.getParamValue instead' );
/**
* Test if an element has a certain class
* @deprecated: Use $(element).hasClass() instead.
*/
mw.log.deprecate( window, 'hasClass', function ( element, className ) {
return $( element ).hasClass( className );
}, 'Use jQuery.hasClass() instead' );
/**
* @source www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
* @rev 6
*/
var extraCSS = mw.util.getParamValue( 'withCSS' ),
extraJS = mw.util.getParamValue( 'withJS' );
if ( extraCSS ) {
if ( extraCSS.match( /^MediaWiki:[^&<>=%#]*\.css$/ ) ) {
importStylesheet( extraCSS );
} else {
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withCSS value' } );
}
}
if ( extraJS ) {
if ( extraJS.match( /^MediaWiki:[^&<>=%#]*\.js$/ ) ) {
importScript( extraJS );
} else {
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withJS value' } );
}
}
/**
* Import more specific scripts if necessary
*/
if ( mw.config.get( 'wgAction' ) === 'edit' || mw.config.get( 'wgAction' ) === 'submit' || mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Upload' ) {
/* scripts specific to editing pages */
importScript( 'MediaWiki:Common.js/edit.js' );
} else if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Watchlist' ) {
/* watchlist scripts */
importScript( 'MediaWiki:Common.js/watchlist.js' );
}
if ( mw.config.get( 'wgNamespaceNumber' ) === 6 ) {
/* file description page scripts */
importScript( 'MediaWiki:Common.js/file.js' );
}
/**
* Helper script for .hlist class in Common.css
* Add pseudo-selector class to last-child list items in IE8
* @source mediawiki.org/wiki/Snippets/Horizontal_lists
* @revision 6 (2014-08-23)
* @author [[User:Edokter]]
*/
( function ( mw, $ ) {
var profile = $.client.profile();
if ( profile.name === 'msie' && profile.versionNumber === 8 ) {
mw.hook( 'wikipage.content' ).add( function ( $content ) {
$content.find( '.hlist' ).find( 'dd:last-child, dt:last-child, li:last-child' )
.addClass( 'hlist-last-child' );
} );
}
}( mediaWiki, jQuery ) );
/**
* Fix for Windows XP Unicode font rendering
*/
if ( navigator.appVersion.search(/windows nt 5/i) !== -1 ) {
mw.util.addCSS( '.IPA { font-family: "Lucida Sans Unicode", "Arial Unicode MS"; } ' +
'.Unicode { font-family: "Arial Unicode MS", "Lucida Sans Unicode"; } ' );
}
/**
* WikiMiniAtlas
*
* Description: WikiMiniAtlas is a popup click and drag world map.
* This script causes all of our coordinate links to display the WikiMiniAtlas popup button.
* The script itself is located on meta because it is used by many projects.
* See [[Meta:WikiMiniAtlas]] for more information.
* Maintainers: [[User:Dschwen]]
*/
( function () {
var require_wikiminiatlas = false;
var coord_filter = /geohack/;
$( function () {
$( 'a.external.text' ).each( function( key, link ) {
if ( link.href && coord_filter.exec( link.href ) ) {
require_wikiminiatlas = true;
// break from loop
return false;
}
} );
if ( $( 'div.kmldata' ).length ) {
require_wikiminiatlas = true;
}
if ( require_wikiminiatlas ) {
mw.loader.load( '//meta.wikimedia.org/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript' );
}
} );
} )();
/**
* Collapsible tables
*
* Allows tables to be collapsed, showing only the header. See [[Wikipedia:NavFrame]].
*
* @version 2.0.3 (2014-03-14)
* @source https://www.mediawiki.org/wiki/MediaWiki:Gadget-collapsibleTables.js
* @author [[User:R. Koot]]
* @author [[User:Krinkle]]
* @deprecated Since MediaWiki 1.20: Use class="mw-collapsible" instead which
* is supported in MediaWiki core.
*/
var autoCollapse = 2;
var collapseCaption = 'hide';
var expandCaption = 'show';
var tableIndex = 0;
function collapseTable( tableIndex ) {
var Button = document.getElementById( 'collapseButton' + tableIndex );
var Table = document.getElementById( 'collapsibleTable' + tableIndex );
if ( !Table || !Button ) {
return false;
}
var Rows = Table.rows;
var i;
if ( Button.firstChild.data === collapseCaption ) {
for ( i = 1; i < Rows.length; i++ ) {
Rows[i].style.display = 'none';
}
Button.firstChild.data = expandCaption;
} else {
for ( i = 1; i < Rows.length; i++ ) {
Rows[i].style.display = Rows[0].style.display;
}
Button.firstChild.data = collapseCaption;
}
}
function createClickHandler( tableIndex ) {
return function ( e ) {
e.preventDefault();
collapseTable( tableIndex );
};
}
function createCollapseButtons( $content ) {
var NavigationBoxes = {};
var $Tables = $content.find( 'table' );
var i;
$Tables.each( function( i, table ) {
if ( $(table).hasClass( 'collapsible' ) ) {
/* only add button and increment count if there is a header row to work with */
var HeaderRow = table.getElementsByTagName( 'tr' )[0];
if ( !HeaderRow ) {
return;
}
var Header = table.getElementsByTagName( 'th' )[0];
if ( !Header ) {
return;
}
NavigationBoxes[ tableIndex ] = table;
table.setAttribute( 'id', 'collapsibleTable' + tableIndex );
var Button = document.createElement( 'span' );
var ButtonLink = document.createElement( 'a' );
var ButtonText = document.createTextNode( collapseCaption );
// Styles are declared in [[MediaWiki:Common.css]]
Button.className = 'collapseButton';
ButtonLink.style.color = Header.style.color;
ButtonLink.setAttribute( 'id', 'collapseButton' + tableIndex );
ButtonLink.setAttribute( 'href', '#' );
$( ButtonLink ).on( 'click', createClickHandler( tableIndex ) );
ButtonLink.appendChild( ButtonText );
Button.appendChild( document.createTextNode( '[' ) );
Button.appendChild( ButtonLink );
Button.appendChild( document.createTextNode( ']' ) );
Header.insertBefore( Button, Header.firstChild );
tableIndex++;
}
} );
for ( i = 0; i < tableIndex; i++ ) {
if ( $( NavigationBoxes[i] ).hasClass( 'collapsed' ) ||
( tableIndex >= autoCollapse && $( NavigationBoxes[i] ).hasClass( 'autocollapse' ) )
) {
collapseTable( i );
}
else if ( $( NavigationBoxes[i] ).hasClass ( 'innercollapse' ) ) {
var element = NavigationBoxes[i];
while ((element = element.parentNode)) {
if ( $( element ).hasClass( 'outercollapse' ) ) {
collapseTable ( i );
break;
}
}
}
}
}
mw.hook( 'wikipage.content' ).add( createCollapseButtons );
/**
* Dynamic Navigation Bars (experimental)
*
* Description: See [[Wikipedia:NavFrame]].
* Maintainers: UNMAINTAINED
*/
/* set up the words in your language */
var NavigationBarHide = '[' + collapseCaption + ']';
var NavigationBarShow = '[' + expandCaption + ']';
var indexNavigationBar = 0;
/**
* Shows and hides content and picture (if available) of navigation bars
* Parameters:
* indexNavigationBar: the index of navigation bar to be toggled
**/
window.toggleNavigationBar = function ( indexNavigationBar, event ) {
var NavToggle = document.getElementById( 'NavToggle' + indexNavigationBar );
var NavFrame = document.getElementById( 'NavFrame' + indexNavigationBar );
var NavChild;
if ( !NavFrame || !NavToggle ) {
return false;
}
/* if shown now */
if ( NavToggle.firstChild.data === NavigationBarHide ) {
for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) {
NavChild.style.display = 'none';
}
}
NavToggle.firstChild.data = NavigationBarShow;
/* if hidden now */
} else if ( NavToggle.firstChild.data === NavigationBarShow ) {
for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) {
NavChild.style.display = 'block';
}
}
NavToggle.firstChild.data = NavigationBarHide;
}
event.preventDefault();
};
/* adds show/hide-button to navigation bars */
function createNavigationBarToggleButton( $content ) {
var NavChild;
/* iterate over all < div >-elements */
var $divs = $content.find( 'div' );
$divs.each( function ( i, NavFrame ) {
/* if found a navigation bar */
if ( $( NavFrame ).hasClass( 'NavFrame' ) ) {
indexNavigationBar++;
var NavToggle = document.createElement( 'a' );
NavToggle.className = 'NavToggle';
NavToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar );
NavToggle.setAttribute( 'href', '#' );
$( NavToggle ).on( 'click', $.proxy( window.toggleNavigationBar, window, indexNavigationBar ) );
var isCollapsed = $( NavFrame ).hasClass( 'collapsed' );
/**
* Check if any children are already hidden. This loop is here for backwards compatibility:
* the old way of making NavFrames start out collapsed was to manually add style="display:none"
* to all the NavPic/NavContent elements. Since this was bad for accessibility (no way to make
* the content visible without JavaScript support), the new recommended way is to add the class
* "collapsed" to the NavFrame itself, just like with collapsible tables.
*/
for ( NavChild = NavFrame.firstChild; NavChild != null && !isCollapsed; NavChild = NavChild.nextSibling ) {
if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( 'NavContent' ) ) {
if ( NavChild.style.display === 'none' ) {
isCollapsed = true;
}
}
}
if ( isCollapsed ) {
for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( 'NavContent' ) ) {
NavChild.style.display = 'none';
}
}
}
var NavToggleText = document.createTextNode( isCollapsed ? NavigationBarShow : NavigationBarHide );
NavToggle.appendChild( NavToggleText );
/* Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked) */
for( var j = 0; j < NavFrame.childNodes.length; j++ ) {
if ( $( NavFrame.childNodes[j] ).hasClass( 'NavHead' ) ) {
NavToggle.style.color = NavFrame.childNodes[j].style.color;
NavFrame.childNodes[j].appendChild( NavToggle );
}
}
NavFrame.setAttribute( 'id', 'NavFrame' + indexNavigationBar );
}
} );
}
mw.hook( 'wikipage.content' ).add( createNavigationBarToggleButton );
/**
* Uploadwizard_newusers
* Switches in a message for non-autoconfirmed users at [[Wikipedia:Upload]]
*
* Maintainers: [[User:Krimpet]]
*/
function uploadwizard_newusers() {
if ( mw.config.get( 'wgNamespaceNumber' ) === 4 && mw.config.get( 'wgTitle' ) === 'Upload' && mw.config.get( 'wgAction' ) === 'view' ) {
var oldDiv = document.getElementById( 'autoconfirmedusers' ),
newDiv = document.getElementById( 'newusers' );
if ( oldDiv && newDiv ) {
var userGroups = mw.config.get( 'wgUserGroups' );
if ( userGroups ) {
for ( var i = 0; i < userGroups.length; i++ ) {
if ( userGroups[i] === 'autoconfirmed' ) {
oldDiv.style.display = 'block';
newDiv.style.display = 'none';
return;
}
}
}
oldDiv.style.display = 'none';
newDiv.style.display = 'block';
return;
}
}
}
$(uploadwizard_newusers);
/**
* Magic editintros ****************************************************
*
* Description: Adds editintros on disambiguation pages and BLP pages.
* Maintainers: [[User:RockMFR]]
*/
function addEditIntro( name ) {
$( '.mw-editsection, #ca-edit' ).find( 'a' ).each( function ( i, el ) {
el.href = $( this ).attr( 'href' ) + '&editintro=' + name;
} );
}
if ( mw.config.get( 'wgNamespaceNumber' ) === 0 ) {
$( function () {
if ( document.getElementById( 'disambigbox' ) ) {
addEditIntro( 'Template:Disambig_editintro' );
}
} );
$( function () {
var cats = mw.config.get('wgCategories');
if ( !cats ) {
return;
}
if ( $.inArray( 'Living people', cats ) !== -1 || $.inArray( 'Possibly living people', cats ) !== -1 ) {
addEditIntro( 'Template:BLP_editintro' );
}
} );
}
/* End of mw.loader.using callback */
} );
/* DO NOT ADD CODE BELOW THIS LINE */