5937 lines · 345.1 KB · JavaScript
RawDownload
/*! * Knockout JavaScript library v3.4.2 * (c) The Knockout.js team - http://knockoutjs.com/ * License: MIT (http://www.opensource.org/licenses/mit-license.php) */ (function () {    var DEBUG = true;    (function (undefined) {        // (0, eval)('this') is a robust way of getting a reference to the global object        // For details, see http://stackoverflow.com/questions/14119988/return-this-0-evalthis/14120023#14120023        var window = this || (0, eval)('this'),            document = window['document'],            navigator = window['navigator'],            jQueryInstance = window["jQuery"],            JSON = window["JSON"];        (function (factory) {            // Support three module loading scenarios            if (typeof define === 'function' && define['amd']) {                // [1] AMD anonymous module                define(['exports', 'require'], factory);            } else if (typeof exports === 'object' && typeof module === 'object') {                // [2] CommonJS/Node.js                factory(module['exports'] || exports);  // module.exports is for Node.js            } else {                // [3] No module loader (plain <script> tag) - put directly in global namespace                factory(window['ko'] = {});            }        }(function (koExports, amdRequire) {            // Internally, all KO objects are attached to koExports (even the non-exported ones whose names will be minified by the closure compiler).            // In the future, the following "ko" variable may be made distinct from "koExports" so that private objects are not externally reachable.            var ko = typeof koExports !== 'undefined' ? koExports : {};            // Google Closure Compiler helpers (used only to make the minified file smaller)            ko.exportSymbol = function (koPath, object) {                var tokens = koPath.split(".");                 // In the future, "ko" may become distinct from "koExports" (so that non-exported objects are not reachable)                // At that point, "target" would be set to: (typeof koExports !== "undefined" ? koExports : ko)                var target = ko;                 for (var i = 0; i < tokens.length - 1; i++)                    target = target[tokens[i]];                target[tokens[tokens.length - 1]] = object;            };            ko.exportProperty = function (owner, publicName, object) {                owner[publicName] = object;            };            ko.version = "3.4.2";             ko.exportSymbol('version', ko.version);            // For any options that may affect various areas of Knockout and aren't directly associated with data binding.            ko.options = {                'deferUpdates': false,                'useOnlyNativeEvents': false            };             //ko.exportSymbol('options', ko.options);   // 'options' isn't minified            ko.utils = (function () {                function objectForEach(obj, action) {                    for (var prop in obj) {                        if (obj.hasOwnProperty(prop)) {                            action(prop, obj[prop]);                        }                    }                }                 function extend(target, source) {                    if (source) {                        for (var prop in source) {                            if (source.hasOwnProperty(prop)) {                                target[prop] = source[prop];                            }                        }                    }                    return target;                }                 function setPrototypeOf(obj, proto) {                    obj.__proto__ = proto;                    return obj;                }                 var canSetPrototype = ({ __proto__: [] } instanceof Array);                var canUseSymbols = !DEBUG && typeof Symbol === 'function';                 // Represent the known event types in a compact way, then at runtime transform it into a hash with event name as key (for fast lookup)                var knownEvents = {}, knownEventTypesByEventName = {};                var keyEventTypeName = (navigator && /Firefox\/2/i.test(navigator.userAgent)) ? 'KeyboardEvent' : 'UIEvents';                knownEvents[keyEventTypeName] = ['keyup', 'keydown', 'keypress'];                knownEvents['MouseEvents'] = ['click', 'dblclick', 'mousedown', 'mouseup', 'mousemove', 'mouseover', 'mouseout', 'mouseenter', 'mouseleave'];                objectForEach(knownEvents, function (eventType, knownEventsForType) {                    if (knownEventsForType.length) {                        for (var i = 0, j = knownEventsForType.length; i < j; i++)                            knownEventTypesByEventName[knownEventsForType[i]] = eventType;                    }                });                var eventsThatMustBeRegisteredUsingAttachEvent = { 'propertychange': true }; // Workaround for an IE9 issue - https://github.com/SteveSanderson/knockout/issues/406                 // Detect IE versions for bug workarounds (uses IE conditionals, not UA string, for robustness)                // Note that, since IE 10 does not support conditional comments, the following logic only detects IE < 10.                // Currently this is by design, since IE 10+ behaves correctly when treated as a standard browser.                // If there is a future need to detect specific versions of IE10+, we will amend this.                var ieVersion = document && (function () {                    var version = 3, div = document.createElement('div'), iElems = div.getElementsByTagName('i');                     // Keep constructing conditional HTML blocks until we hit one that resolves to an empty fragment                    while (                        div.innerHTML = '<!--[if gt IE ' + (++version) + ']><i></i><![endif]-->',                        iElems[0]                    ) { }                    return version > 4 ? version : undefined;                }());                var isIe6 = ieVersion === 6,                    isIe7 = ieVersion === 7;                 function isClickOnCheckableElement(element, eventType) {                    if ((ko.utils.tagNameLower(element) !== "input") || !element.type) return false;                    if (eventType.toLowerCase() != "click") return false;                    var inputType = element.type;                    return (inputType == "checkbox") || (inputType == "radio");                }                 // For details on the pattern for changing node classes                // see: https://github.com/knockout/knockout/issues/1597                var cssClassNameRegex = /\S+/g;                 function toggleDomNodeCssClass(node, classNames, shouldHaveClass) {                    var addOrRemoveFn;                    if (classNames) {                        if (typeof node.classList === 'object') {                            addOrRemoveFn = node.classList[shouldHaveClass ? 'add' : 'remove'];                            ko.utils.arrayForEach(classNames.match(cssClassNameRegex), function (className) {                                addOrRemoveFn.call(node.classList, className);                            });                        } else if (typeof node.className['baseVal'] === 'string') {                            // SVG tag .classNames is an SVGAnimatedString instance                            toggleObjectClassPropertyString(node.className, 'baseVal', classNames, shouldHaveClass);                        } else {                            // node.className ought to be a string.                            toggleObjectClassPropertyString(node, 'className', classNames, shouldHaveClass);                        }                    }                }                 function toggleObjectClassPropertyString(obj, prop, classNames, shouldHaveClass) {                    // obj/prop is either a node/'className' or a SVGAnimatedString/'baseVal'.                    var currentClassNames = obj[prop].match(cssClassNameRegex) || [];                    ko.utils.arrayForEach(classNames.match(cssClassNameRegex), function (className) {                        ko.utils.addOrRemoveItem(currentClassNames, className, shouldHaveClass);                    });                    obj[prop] = currentClassNames.join(" ");                }                 return {                    fieldsIncludedWithJsonPost: ['authenticity_token', /^__RequestVerificationToken(_.*)?$/],                     arrayForEach: function (array, action) {                        for (var i = 0, j = array.length; i < j; i++)                            action(array[i], i);                    },                     arrayIndexOf: function (array, item) {                        if (typeof Array.prototype.indexOf == "function")                            return Array.prototype.indexOf.call(array, item);                        for (var i = 0, j = array.length; i < j; i++)                            if (array[i] === item)                                return i;                        return -1;                    },                     arrayFirst: function (array, predicate, predicateOwner) {                        for (var i = 0, j = array.length; i < j; i++)                            if (predicate.call(predicateOwner, array[i], i))                                return array[i];                        return null;                    },                     arrayRemoveItem: function (array, itemToRemove) {                        var index = ko.utils.arrayIndexOf(array, itemToRemove);                        if (index > 0) {                            array.splice(index, 1);                        }                        else if (index === 0) {                            array.shift();                        }                    },                     arrayGetDistinctValues: function (array) {                        array = array || [];                        var result = [];                        for (var i = 0, j = array.length; i < j; i++) {                            if (ko.utils.arrayIndexOf(result, array[i]) < 0)                                result.push(array[i]);                        }                        return result;                    },                     arrayMap: function (array, mapping) {                        array = array || [];                        var result = [];                        for (var i = 0, j = array.length; i < j; i++)                            result.push(mapping(array[i], i));                        return result;                    },                     arrayFilter: function (array, predicate) {                        array = array || [];                        var result = [];                        for (var i = 0, j = array.length; i < j; i++)                            if (predicate(array[i], i))                                result.push(array[i]);                        return result;                    },                     arrayPushAll: function (array, valuesToPush) {                        if (valuesToPush instanceof Array)                            array.push.apply(array, valuesToPush);                        else                            for (var i = 0, j = valuesToPush.length; i < j; i++)                                array.push(valuesToPush[i]);                        return array;                    },                     addOrRemoveItem: function (array, value, included) {                        var existingEntryIndex = ko.utils.arrayIndexOf(ko.utils.peekObservable(array), value);                        if (existingEntryIndex < 0) {                            if (included)                                array.push(value);                        } else {                            if (!included)                                array.splice(existingEntryIndex, 1);                        }                    },                     canSetPrototype: canSetPrototype,                     extend: extend,                     setPrototypeOf: setPrototypeOf,                     setPrototypeOfOrExtend: canSetPrototype ? setPrototypeOf : extend,                     objectForEach: objectForEach,                     objectMap: function (source, mapping) {                        if (!source)                            return source;                        var target = {};                        for (var prop in source) {                            if (source.hasOwnProperty(prop)) {                                target[prop] = mapping(source[prop], prop, source);                            }                        }                        return target;                    },                     emptyDomNode: function (domNode) {                        while (domNode.firstChild) {                            ko.removeNode(domNode.firstChild);                        }                    },                     moveCleanedNodesToContainerElement: function (nodes) {                        // Ensure it's a real array, as we're about to reparent the nodes and                        // we don't want the underlying collection to change while we're doing that.                        var nodesArray = ko.utils.makeArray(nodes);                        var templateDocument = (nodesArray[0] && nodesArray[0].ownerDocument) || document;                         var container = templateDocument.createElement('div');                        for (var i = 0, j = nodesArray.length; i < j; i++) {                            container.appendChild(ko.cleanNode(nodesArray[i]));                        }                        return container;                    },                     cloneNodes: function (nodesArray, shouldCleanNodes) {                        for (var i = 0, j = nodesArray.length, newNodesArray = []; i < j; i++) {                            var clonedNode = nodesArray[i].cloneNode(true);                            newNodesArray.push(shouldCleanNodes ? ko.cleanNode(clonedNode) : clonedNode);                        }                        return newNodesArray;                    },                     setDomNodeChildren: function (domNode, childNodes) {                        ko.utils.emptyDomNode(domNode);                        if (childNodes) {                            for (var i = 0, j = childNodes.length; i < j; i++)                                domNode.appendChild(childNodes[i]);                        }                    },                     replaceDomNodes: function (nodeToReplaceOrNodeArray, newNodesArray) {                        var nodesToReplaceArray = nodeToReplaceOrNodeArray.nodeType ? [nodeToReplaceOrNodeArray] : nodeToReplaceOrNodeArray;                        if (nodesToReplaceArray.length > 0) {                            var insertionPoint = nodesToReplaceArray[0];                            var parent = insertionPoint.parentNode;                            for (var i = 0, j = newNodesArray.length; i < j; i++)                                parent.insertBefore(newNodesArray[i], insertionPoint);                            for (var i = 0, j = nodesToReplaceArray.length; i < j; i++) {                                ko.removeNode(nodesToReplaceArray[i]);                            }                        }                    },                     fixUpContinuousNodeArray: function (continuousNodeArray, parentNode) {                        // Before acting on a set of nodes that were previously outputted by a template function, we have to reconcile                        // them against what is in the DOM right now. It may be that some of the nodes have already been removed, or that                        // new nodes might have been inserted in the middle, for example by a binding. Also, there may previously have been                        // leading comment nodes (created by rewritten string-based templates) that have since been removed during binding.                        // So, this function translates the old "map" output array into its best guess of the set of current DOM nodes.                        //                        // Rules:                        //   [A] Any leading nodes that have been removed should be ignored                        //       These most likely correspond to memoization nodes that were already removed during binding                        //       See https://github.com/knockout/knockout/pull/440                        //   [B] Any trailing nodes that have been remove should be ignored                        //       This prevents the code here from adding unrelated nodes to the array while processing rule [C]                        //       See https://github.com/knockout/knockout/pull/1903                        //   [C] We want to output a continuous series of nodes. So, ignore any nodes that have already been removed,                        //       and include any nodes that have been inserted among the previous collection                         if (continuousNodeArray.length) {                            // The parent node can be a virtual element; so get the real parent node                            parentNode = (parentNode.nodeType === 8 && parentNode.parentNode) || parentNode;                             // Rule [A]                            while (continuousNodeArray.length && continuousNodeArray[0].parentNode !== parentNode)                                continuousNodeArray.splice(0, 1);                             // Rule [B]                            while (continuousNodeArray.length > 1 && continuousNodeArray[continuousNodeArray.length - 1].parentNode !== parentNode)                                continuousNodeArray.length--;                             // Rule [C]                            if (continuousNodeArray.length > 1) {                                var current = continuousNodeArray[0], last = continuousNodeArray[continuousNodeArray.length - 1];                                // Replace with the actual new continuous node set                                continuousNodeArray.length = 0;                                while (current !== last) {                                    continuousNodeArray.push(current);                                    current = current.nextSibling;                                }                                continuousNodeArray.push(last);                            }                        }                        return continuousNodeArray;                    },                     setOptionNodeSelectionState: function (optionNode, isSelected) {                        // IE6 sometimes throws "unknown error" if you try to write to .selected directly, whereas Firefox struggles with setAttribute. Pick one based on browser.                        if (ieVersion < 7)                            optionNode.setAttribute("selected", isSelected);                        else                            optionNode.selected = isSelected;                    },                     stringTrim: function (string) {                        return string === null || string === undefined ? '' :                            string.trim ?                                string.trim() :                                string.toString().replace(/^[\s\xa0]+|[\s\xa0]+$/g, '');                    },                     stringStartsWith: function (string, startsWith) {                        string = string || "";                        if (startsWith.length > string.length)                            return false;                        return string.substring(0, startsWith.length) === startsWith;                    },                     domNodeIsContainedBy: function (node, containedByNode) {                        if (node === containedByNode)                            return true;                        if (node.nodeType === 11)                            return false; // Fixes issue #1162 - can't use node.contains for document fragments on IE8                        if (containedByNode.contains)                            return containedByNode.contains(node.nodeType === 3 ? node.parentNode : node);                        if (containedByNode.compareDocumentPosition)                            return (containedByNode.compareDocumentPosition(node) & 16) == 16;                        while (node && node != containedByNode) {                            node = node.parentNode;                        }                        return !!node;                    },                     domNodeIsAttachedToDocument: function (node) {                        return ko.utils.domNodeIsContainedBy(node, node.ownerDocument.documentElement);                    },                     anyDomNodeIsAttachedToDocument: function (nodes) {                        return !!ko.utils.arrayFirst(nodes, ko.utils.domNodeIsAttachedToDocument);                    },                     tagNameLower: function (element) {                        // For HTML elements, tagName will always be upper case; for XHTML elements, it'll be lower case.                        // Possible future optimization: If we know it's an element from an XHTML document (not HTML),                        // we don't need to do the .toLowerCase() as it will always be lower case anyway.                        return element && element.tagName && element.tagName.toLowerCase();                    },                     catchFunctionErrors: function (delegate) {                        return ko['onError'] ? function () {                            try {                                return delegate.apply(this, arguments);                            } catch (e) {                                ko['onError'] && ko['onError'](e);                                throw e;                            }                        } : delegate;                    },                     setTimeout: function (handler, timeout) {                        return setTimeout(ko.utils.catchFunctionErrors(handler), timeout);                    },                     deferError: function (error) {                        setTimeout(function () {                            ko['onError'] && ko['onError'](error);                            throw error;                        }, 0);                    },                     registerEventHandler: function (element, eventType, handler) {                        var wrappedHandler = ko.utils.catchFunctionErrors(handler);                         var mustUseAttachEvent = ieVersion && eventsThatMustBeRegisteredUsingAttachEvent[eventType];                        if (!ko.options['useOnlyNativeEvents'] && !mustUseAttachEvent && jQueryInstance) {                            jQueryInstance(element)['bind'](eventType, wrappedHandler);                        } else if (!mustUseAttachEvent && typeof element.addEventListener == "function")                            element.addEventListener(eventType, wrappedHandler, false);                        else if (typeof element.attachEvent != "undefined") {                            var attachEventHandler = function (event) { wrappedHandler.call(element, event); },                                attachEventName = "on" + eventType;                            element.attachEvent(attachEventName, attachEventHandler);                             // IE does not dispose attachEvent handlers automatically (unlike with addEventListener)                            // so to avoid leaks, we have to remove them manually. See bug #856                            ko.utils.domNodeDisposal.addDisposeCallback(element, function () {                                element.detachEvent(attachEventName, attachEventHandler);                            });                        } else                            throw new Error("Browser doesn't support addEventListener or attachEvent");                    },                     triggerEvent: function (element, eventType) {                        if (!(element && element.nodeType))                            throw new Error("element must be a DOM node when calling triggerEvent");                         // For click events on checkboxes and radio buttons, jQuery toggles the element checked state *after* the                        // event handler runs instead of *before*. (This was fixed in 1.9 for checkboxes but not for radio buttons.)                        // IE doesn't change the checked state when you trigger the click event using "fireEvent".                        // In both cases, we'll use the click method instead.                        var useClickWorkaround = isClickOnCheckableElement(element, eventType);                         if (!ko.options['useOnlyNativeEvents'] && jQueryInstance && !useClickWorkaround) {                            jQueryInstance(element)['trigger'](eventType);                        } else if (typeof document.createEvent == "function") {                            if (typeof element.dispatchEvent == "function") {                                var eventCategory = knownEventTypesByEventName[eventType] || "HTMLEvents";                                var event = document.createEvent(eventCategory);                                event.initEvent(eventType, true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, element);                                element.dispatchEvent(event);                            }                            else                                throw new Error("The supplied element doesn't support dispatchEvent");                        } else if (useClickWorkaround && element.click) {                            element.click();                        } else if (typeof element.fireEvent != "undefined") {                            element.fireEvent("on" + eventType);                        } else {                            throw new Error("Browser doesn't support triggering events");                        }                    },                     unwrapObservable: function (value) {                        return ko.isObservable(value) ? value() : value;                    },                     peekObservable: function (value) {                        return ko.isObservable(value) ? value.peek() : value;                    },                     toggleDomNodeCssClass: toggleDomNodeCssClass,                     setTextContent: function (element, textContent) {                        var value = ko.utils.unwrapObservable(textContent);                        if ((value === null) || (value === undefined))                            value = "";                         // We need there to be exactly one child: a text node.                        // If there are no children, more than one, or if it's not a text node,                        // we'll clear everything and create a single text node.                        var innerTextNode = ko.virtualElements.firstChild(element);                        if (!innerTextNode || innerTextNode.nodeType != 3 || ko.virtualElements.nextSibling(innerTextNode)) {                            ko.virtualElements.setDomNodeChildren(element, [element.ownerDocument.createTextNode(value)]);                        } else {                            innerTextNode.data = value;                        }                         ko.utils.forceRefresh(element);

Lines 1–500 of 5937.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t