[Pkg-javascript-commits] [rainloop] 04/06: Unbundled node-knockout-sortable and node-knockout-transformations.
Daniel Ring
techwolf-guest at moszumanska.debian.org
Wed Jan 3 10:42:10 UTC 2018
This is an automated email from the git hooks/post-receive script.
techwolf-guest pushed a commit to branch master
in repository rainloop.
commit 5b381678b4f35887bd557652324079a645b1d41b
Author: Daniel Ring <dring at wolfishly.me>
Date: Mon Jan 1 18:42:01 2018 -0800
Unbundled node-knockout-sortable and node-knockout-transformations.
---
debian/Makefile | 4 +-
debian/control | 2 +
debian/copyright | 8 -
.../knockout-projections/knockout-projections.js | 391 ------------------
debian/lib/knockout-sortable/knockout-sortable.js | 440 ---------------------
5 files changed, 4 insertions(+), 841 deletions(-)
diff --git a/debian/Makefile b/debian/Makefile
index 7a036fd..74da443 100644
--- a/debian/Makefile
+++ b/debian/Makefile
@@ -116,8 +116,8 @@ jsLibs = \
/usr/share/javascript/underscore/underscore.js \
/usr/share/javascript/moment/moment.js \
/usr/lib/nodejs/knockout/build/output/knockout-latest.js \
- debian/lib/knockout-projections/knockout-projections.js \
- debian/lib/knockout-sortable/knockout-sortable.js \
+ /usr/lib/nodejs/knockout-transformations/dist/knockout-transformations.js \
+ /usr/lib/nodejs/knockout-sortable/build/knockout-sortable.js \
/usr/lib/nodejs/simplestatemanager/ssm.min.js \
/usr/lib/nodejs/autolinker/Autolinker.min.js \
/usr/lib/nodejs/opentip/lib/opentip.js \
diff --git a/debian/control b/debian/control
index 45d4320..70e70b2 100644
--- a/debian/control
+++ b/debian/control
@@ -21,6 +21,8 @@ Build-Depends:
, node-autolinker
, node-classnames
, node-knockout
+ , node-knockout-sortable
+ , node-knockout-transformations
, node-lightgallery
, node-normalize.css
, node-opentip
diff --git a/debian/copyright b/debian/copyright
index d1e9d56..48d404a 100644
--- a/debian/copyright
+++ b/debian/copyright
@@ -94,14 +94,6 @@ Files: debian/lib/js-cookie/*
Copyright: 2006-2015 Klaus Hartl & Fagner Brack
License: MIT
-Files: debian/lib/knockout-projections/*
-Copyright: Microsoft Corporation
-License: Apache-2.0
-
-Files: debian/lib/knockout-sortable/*
-Copyright: 2016 Ryan Niemeyer
-License: MIT
-
Files: debian/lib/openpgp/*
Copyright: 2017 Bart Butler, Tankred Hase, and Thomas Oberndorfer
License: LGPL-3
diff --git a/debian/lib/knockout-projections/knockout-projections.js b/debian/lib/knockout-projections/knockout-projections.js
deleted file mode 100644
index e5db81d..0000000
--- a/debian/lib/knockout-projections/knockout-projections.js
+++ /dev/null
@@ -1,391 +0,0 @@
-/*! Knockout projections plugin - version 1.1.0
-------------------------------------------------------------------------------
-Copyright (c) Microsoft Corporation
-All rights reserved.
-Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
-THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
-See the Apache Version 2.0 License for specific language governing permissions and limitations under the License.
-------------------------------------------------------------------------------
-*/
-
-(function(global, undefined) {
- 'use strict';
-
- var exclusionMarker = {};
-
- function StateItem(ko, inputItem, initialStateArrayIndex, initialOutputArrayIndex, mappingOptions, arrayOfState, outputObservableArray) {
- // Capture state for later use
- this.inputItem = inputItem;
- this.stateArrayIndex = initialStateArrayIndex;
- this.mappingOptions = mappingOptions;
- this.arrayOfState = arrayOfState;
- this.outputObservableArray = outputObservableArray;
- this.outputArray = this.outputObservableArray.peek();
- this.isIncluded = null; // Means 'not yet determined'
- this.suppressNotification = false; // TODO: Instead of this technique, consider raising a sparse diff with a "mutated" entry when a single item changes, and not having any other change logic inside StateItem
-
- // Set up observables
- this.outputArrayIndex = ko.observable(initialOutputArrayIndex); // When excluded, it's the position the item would go if it became included
- this.disposeFuncFromMostRecentMapping = null;
- this.mappedValueComputed = ko.computed(this.mappingEvaluator, this);
- this.mappedValueComputed.subscribe(this.onMappingResultChanged, this);
- this.previousMappedValue = this.mappedValueComputed.peek();
- }
-
- StateItem.prototype.dispose = function() {
- this.mappedValueComputed.dispose();
- this.disposeResultFromMostRecentEvaluation();
- };
-
- StateItem.prototype.disposeResultFromMostRecentEvaluation = function() {
- if (this.disposeFuncFromMostRecentMapping) {
- this.disposeFuncFromMostRecentMapping();
- this.disposeFuncFromMostRecentMapping = null;
- }
-
- if (this.mappingOptions.disposeItem) {
- var mappedItem = this.mappedValueComputed();
- this.mappingOptions.disposeItem(mappedItem);
- }
- };
-
- StateItem.prototype.mappingEvaluator = function() {
- if (this.isIncluded !== null) { // i.e., not first run
- // This is a replace-in-place, so call any dispose callbacks
- // we have for the earlier value
- this.disposeResultFromMostRecentEvaluation();
- }
-
- var mappedValue;
- if (this.mappingOptions.mapping) {
- mappedValue = this.mappingOptions.mapping(this.inputItem, this.outputArrayIndex);
- } else if (this.mappingOptions.mappingWithDisposeCallback) {
- var mappedValueWithDisposeCallback = this.mappingOptions.mappingWithDisposeCallback(this.inputItem, this.outputArrayIndex);
- if (!('mappedValue' in mappedValueWithDisposeCallback)) {
- throw new Error('Return value from mappingWithDisposeCallback should have a \'mappedItem\' property.');
- }
- mappedValue = mappedValueWithDisposeCallback.mappedValue;
- this.disposeFuncFromMostRecentMapping = mappedValueWithDisposeCallback.dispose;
- } else {
- throw new Error('No mapping callback given.');
- }
-
- var newInclusionState = mappedValue !== exclusionMarker;
-
- // Inclusion state changes can *only* happen as a result of changing an individual item.
- // Structural changes to the array can't cause this (because they don't cause any remapping;
- // they only map newly added items which have no earlier inclusion state to change).
- if (this.isIncluded !== newInclusionState) {
- if (this.isIncluded !== null) { // i.e., not first run
- this.moveSubsequentItemsBecauseInclusionStateChanged(newInclusionState);
- }
-
- this.isIncluded = newInclusionState;
- }
-
- return mappedValue;
- };
-
- StateItem.prototype.onMappingResultChanged = function(newValue) {
- if (newValue !== this.previousMappedValue) {
- if (this.isIncluded) {
- this.outputArray.splice(this.outputArrayIndex.peek(), 1, newValue);
- }
-
- if (!this.suppressNotification) {
- this.outputObservableArray.valueHasMutated();
- }
-
- this.previousMappedValue = newValue;
- }
- };
-
- StateItem.prototype.moveSubsequentItemsBecauseInclusionStateChanged = function(newInclusionState) {
- var outputArrayIndex = this.outputArrayIndex.peek(),
- iterationIndex,
- stateItem;
-
- if (newInclusionState) {
- // Shift all subsequent items along by one space, and increment their indexes.
- // Note that changing their indexes might cause remapping, but won't affect their
- // inclusion status (by definition, inclusion status must not be affected by index,
- // otherwise you get undefined results) so there's no risk of a chain reaction.
- this.outputArray.splice(outputArrayIndex, 0, null);
- for (iterationIndex = this.stateArrayIndex + 1; iterationIndex < this.arrayOfState.length; iterationIndex++) {
- stateItem = this.arrayOfState[iterationIndex];
- stateItem.setOutputArrayIndexSilently(stateItem.outputArrayIndex.peek() + 1);
- }
- } else {
- // Shift all subsequent items back by one space, and decrement their indexes
- this.outputArray.splice(outputArrayIndex, 1);
- for (iterationIndex = this.stateArrayIndex + 1; iterationIndex < this.arrayOfState.length; iterationIndex++) {
- stateItem = this.arrayOfState[iterationIndex];
- stateItem.setOutputArrayIndexSilently(stateItem.outputArrayIndex.peek() - 1);
- }
- }
- };
-
- StateItem.prototype.setOutputArrayIndexSilently = function(newIndex) {
- // We only want to raise one output array notification per input array change,
- // so during processing, we suppress notifications
- this.suppressNotification = true;
- this.outputArrayIndex(newIndex);
- this.suppressNotification = false;
- };
-
- function getDiffEntryPostOperationIndex(diffEntry, editOffset) {
- // The diff algorithm's "index" value refers to the output array for additions,
- // but the "input" array for deletions. Get the output array position.
- if (!diffEntry) { return null; }
- switch (diffEntry.status) {
- case 'added':
- return diffEntry.index;
- case 'deleted':
- return diffEntry.index + editOffset;
- default:
- throw new Error('Unknown diff status: ' + diffEntry.status);
- }
- }
-
- function insertOutputItem(ko, diffEntry, movedStateItems, stateArrayIndex, outputArrayIndex, mappingOptions, arrayOfState, outputObservableArray, outputArray) {
- // Retain the existing mapped value if this is a move, otherwise perform mapping
- var isMoved = typeof diffEntry.moved === 'number',
- stateItem = isMoved ?
- movedStateItems[diffEntry.moved] :
- new StateItem(ko, diffEntry.value, stateArrayIndex, outputArrayIndex, mappingOptions, arrayOfState, outputObservableArray);
- arrayOfState.splice(stateArrayIndex, 0, stateItem);
- if (stateItem.isIncluded) {
- outputArray.splice(outputArrayIndex, 0, stateItem.mappedValueComputed.peek());
- }
-
- // Update indexes
- if (isMoved) {
- // We don't change the index until *after* updating this item's position in outputObservableArray,
- // because changing the index may trigger re-mapping, which in turn would cause the new
- // value to be written to the 'index' position in the output array
- stateItem.stateArrayIndex = stateArrayIndex;
- stateItem.setOutputArrayIndexSilently(outputArrayIndex);
- }
-
- return stateItem;
- }
-
- function deleteOutputItem(diffEntry, arrayOfState, stateArrayIndex, outputArrayIndex, outputArray) {
- var stateItem = arrayOfState.splice(stateArrayIndex, 1)[0];
- if (stateItem.isIncluded) {
- outputArray.splice(outputArrayIndex, 1);
- }
- if (typeof diffEntry.moved !== 'number') {
- // Be careful to dispose only if this item really was deleted and not moved
- stateItem.dispose();
- }
- }
-
- function updateRetainedOutputItem(stateItem, stateArrayIndex, outputArrayIndex) {
- // Just have to update its indexes
- stateItem.stateArrayIndex = stateArrayIndex;
- stateItem.setOutputArrayIndexSilently(outputArrayIndex);
-
- // Return the new value for outputArrayIndex
- return outputArrayIndex + (stateItem.isIncluded ? 1 : 0);
- }
-
- function makeLookupOfMovedStateItems(diff, arrayOfState) {
- // Before we mutate arrayOfComputedMappedValues at all, grab a reference to each moved item
- var movedStateItems = {};
- for (var diffIndex = 0; diffIndex < diff.length; diffIndex++) {
- var diffEntry = diff[diffIndex];
- if (diffEntry.status === 'added' && (typeof diffEntry.moved === 'number')) {
- movedStateItems[diffEntry.moved] = arrayOfState[diffEntry.moved];
- }
- }
- return movedStateItems;
- }
-
- function getFirstModifiedOutputIndex(firstDiffEntry, arrayOfState, outputArray) {
- // Work out where the first edit will affect the output array
- // Then we can update outputArrayIndex incrementally while walking the diff list
- if (!outputArray.length || !arrayOfState[firstDiffEntry.index]) {
- // The first edit is beyond the end of the output or state array, so we must
- // just be appending items.
- return outputArray.length;
- } else {
- // The first edit corresponds to an existing state array item, so grab
- // the first output array index from it.
- return arrayOfState[firstDiffEntry.index].outputArrayIndex.peek();
- }
- }
-
- function respondToArrayStructuralChanges(ko, inputObservableArray, arrayOfState, outputArray, outputObservableArray, mappingOptions) {
- return inputObservableArray.subscribe(function(diff) {
- if (!diff.length) {
- return;
- }
-
- var movedStateItems = makeLookupOfMovedStateItems(diff, arrayOfState),
- diffIndex = 0,
- diffEntry = diff[0],
- editOffset = 0, // A running total of (num(items added) - num(items deleted)) not accounting for filtering
- outputArrayIndex = diffEntry && getFirstModifiedOutputIndex(diffEntry, arrayOfState, outputArray);
-
- // Now iterate over the state array, at each stage checking whether the current item
- // is the next one to have been edited. We can skip all the state array items whose
- // indexes are less than the first edit index (i.e., diff[0].index).
- for (var stateArrayIndex = diffEntry.index; diffEntry || (stateArrayIndex < arrayOfState.length); stateArrayIndex++) {
- // Does the current diffEntry correspond to this position in the state array?
- if (getDiffEntryPostOperationIndex(diffEntry, editOffset) === stateArrayIndex) {
- // Yes - insert or delete the corresponding state and output items
- switch (diffEntry.status) {
- case 'added':
- // Add to output, and update indexes
- var stateItem = insertOutputItem(ko, diffEntry, movedStateItems, stateArrayIndex, outputArrayIndex, mappingOptions, arrayOfState, outputObservableArray, outputArray);
- if (stateItem.isIncluded) {
- outputArrayIndex++;
- }
- editOffset++;
- break;
- case 'deleted':
- // Just erase from the output, and update indexes
- deleteOutputItem(diffEntry, arrayOfState, stateArrayIndex, outputArrayIndex, outputArray);
- editOffset--;
- stateArrayIndex--; // To compensate for the "for" loop incrementing it
- break;
- default:
- throw new Error('Unknown diff status: ' + diffEntry.status);
- }
-
- // We're done with this diff entry. Move on to the next one.
- diffIndex++;
- diffEntry = diff[diffIndex];
- } else if (stateArrayIndex < arrayOfState.length) {
- // No - the current item was retained. Just update its index.
- outputArrayIndex = updateRetainedOutputItem(arrayOfState[stateArrayIndex], stateArrayIndex, outputArrayIndex);
- }
- }
-
- outputObservableArray.valueHasMutated();
- }, null, 'arrayChange');
- }
-
- // Mapping
- function observableArrayMap(ko, mappingOptions) {
- var inputObservableArray = this,
- arrayOfState = [],
- outputArray = [],
- outputObservableArray = ko.observableArray(outputArray),
- originalInputArrayContents = inputObservableArray.peek();
-
- // Shorthand syntax - just pass a function instead of an options object
- if (typeof mappingOptions === 'function') {
- mappingOptions = { mapping: mappingOptions };
- }
-
- // Validate the options
- if (mappingOptions.mappingWithDisposeCallback) {
- if (mappingOptions.mapping || mappingOptions.disposeItem) {
- throw new Error('\'mappingWithDisposeCallback\' cannot be used in conjunction with \'mapping\' or \'disposeItem\'.');
- }
- } else if (!mappingOptions.mapping) {
- throw new Error('Specify either \'mapping\' or \'mappingWithDisposeCallback\'.');
- }
-
- // Initial state: map each of the inputs
- for (var i = 0; i < originalInputArrayContents.length; i++) {
- var inputItem = originalInputArrayContents[i],
- stateItem = new StateItem(ko, inputItem, i, outputArray.length, mappingOptions, arrayOfState, outputObservableArray),
- mappedValue = stateItem.mappedValueComputed.peek();
- arrayOfState.push(stateItem);
-
- if (stateItem.isIncluded) {
- outputArray.push(mappedValue);
- }
- }
-
- // If the input array changes structurally (items added or removed), update the outputs
- var inputArraySubscription = respondToArrayStructuralChanges(ko, inputObservableArray, arrayOfState, outputArray, outputObservableArray, mappingOptions);
-
- // Return value is a readonly computed which can track its own changes to permit chaining.
- // When disposed, it cleans up everything it created.
- var returnValue = ko.computed(outputObservableArray).extend({ trackArrayChanges: true }),
- originalDispose = returnValue.dispose;
- returnValue.dispose = function() {
- inputArraySubscription.dispose();
- ko.utils.arrayForEach(arrayOfState, function(stateItem) {
- stateItem.dispose();
- });
- originalDispose.call(this, arguments);
- };
-
- // Make projections chainable
- addProjectionFunctions(ko, returnValue);
-
- return returnValue;
- }
-
- // Filtering
- function observableArrayFilter(ko, predicate) {
- return observableArrayMap.call(this, ko, function(item) {
- return predicate(item) ? item : exclusionMarker;
- });
- }
-
- // Attaching projection functions
- // ------------------------------
- //
- // Builds a collection of projection functions that can quickly be attached to any object.
- // The functions are predefined to retain 'this' and prefix the arguments list with the
- // relevant 'ko' instance.
-
- var projectionFunctionsCacheName = '_ko.projections.cache';
-
- function attachProjectionFunctionsCache(ko) {
- // Wraps callback so that, when invoked, its arguments list is prefixed by 'ko' and 'this'
- function makeCaller(ko, callback) {
- return function() {
- return callback.apply(this, [ko].concat(Array.prototype.slice.call(arguments, 0)));
- };
- }
- ko[projectionFunctionsCacheName] = {
- map: makeCaller(ko, observableArrayMap),
- filter: makeCaller(ko, observableArrayFilter)
- };
- }
-
- function addProjectionFunctions(ko, target) {
- ko.utils.extend(target, ko[projectionFunctionsCacheName]);
- return target; // Enable chaining
- }
-
- // Module initialisation
- // ---------------------
- //
- // When this script is first evaluated, it works out what kind of module loading scenario
- // it is in (Node.js or a browser `<script>` tag), and then attaches itself to whichever
- // instance of Knockout.js it can find.
-
- function attachToKo(ko) {
- ko.projections = {
- _exclusionMarker: exclusionMarker
- };
- attachProjectionFunctionsCache(ko);
- addProjectionFunctions(ko, ko.observableArray.fn); // Make all observable arrays projectable
- }
-
- // Determines which module loading scenario we're in, grabs dependencies, and attaches to KO
- function prepareExports() {
- if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
- // Node.js case - load KO synchronously
- var ko = require('knockout');
- attachToKo(ko);
- module.exports = ko;
- } else if (typeof define === 'function' && define.amd) {
- define(['knockout'], attachToKo);
- } else if ('ko' in global) {
- // Non-module case - attach to the global instance
- attachToKo(global.ko);
- }
- }
-
- prepareExports();
-
-})(this);
diff --git a/debian/lib/knockout-sortable/knockout-sortable.js b/debian/lib/knockout-sortable/knockout-sortable.js
deleted file mode 100644
index b31e06c..0000000
--- a/debian/lib/knockout-sortable/knockout-sortable.js
+++ /dev/null
@@ -1,440 +0,0 @@
-// knockout-sortable 0.14.1 | (c) 2016 Ryan Niemeyer | http://www.opensource.org/licenses/mit-license
-;(function(factory) {
- if (typeof define === "function" && define.amd) {
- // AMD anonymous module
- define(["knockout", "jquery", "jquery-ui/sortable", "jquery-ui/draggable"], factory);
- } else if (typeof require === "function" && typeof exports === "object" && typeof module === "object") {
- // CommonJS module
- var ko = require("knockout"),
- jQuery = require("jquery");
- require("jquery-ui/sortable");
- require("jquery-ui/draggable");
- factory(ko, jQuery);
- } else {
- // No module loader (plain <script> tag) - put directly in global namespace
- factory(window.ko, window.jQuery);
- }
-})(function(ko, $) {
- var ITEMKEY = "ko_sortItem",
- INDEXKEY = "ko_sourceIndex",
- LISTKEY = "ko_sortList",
- PARENTKEY = "ko_parentList",
- DRAGKEY = "ko_dragItem",
- unwrap = ko.utils.unwrapObservable,
- dataGet = ko.utils.domData.get,
- dataSet = ko.utils.domData.set,
- version = $.ui && $.ui.version,
- //1.8.24 included a fix for how events were triggered in nested sortables. indexOf checks will fail if version starts with that value (0 vs. -1)
- hasNestedSortableFix = version && version.indexOf("1.6.") && version.indexOf("1.7.") && (version.indexOf("1.8.") || version === "1.8.24");
-
- //internal afterRender that adds meta-data to children
- var addMetaDataAfterRender = function(elements, data) {
- ko.utils.arrayForEach(elements, function(element) {
- if (element.nodeType === 1) {
- dataSet(element, ITEMKEY, data);
- dataSet(element, PARENTKEY, dataGet(element.parentNode, LISTKEY));
- }
- });
- };
-
- //prepare the proper options for the template binding
- var prepareTemplateOptions = function(valueAccessor, dataName) {
- var result = {},
- options = unwrap(valueAccessor()) || {},
- actualAfterRender;
-
- //build our options to pass to the template engine
- if (options.data) {
- result[dataName] = options.data;
- result.name = options.template;
- } else {
- result[dataName] = valueAccessor();
- }
-
- ko.utils.arrayForEach(["afterAdd", "afterRender", "as", "beforeRemove", "includeDestroyed", "templateEngine", "templateOptions", "nodes"], function (option) {
- if (options.hasOwnProperty(option)) {
- result[option] = options[option];
- } else if (ko.bindingHandlers.sortable.hasOwnProperty(option)) {
- result[option] = ko.bindingHandlers.sortable[option];
- }
- });
-
- //use an afterRender function to add meta-data
- if (dataName === "foreach") {
- if (result.afterRender) {
- //wrap the existing function, if it was passed
- actualAfterRender = result.afterRender;
- result.afterRender = function(element, data) {
- addMetaDataAfterRender.call(data, element, data);
- actualAfterRender.call(data, element, data);
- };
- } else {
- result.afterRender = addMetaDataAfterRender;
- }
- }
-
- //return options to pass to the template binding
- return result;
- };
-
- var updateIndexFromDestroyedItems = function(index, items) {
- var unwrapped = unwrap(items);
-
- if (unwrapped) {
- for (var i = 0; i < index; i++) {
- //add one for every destroyed item we find before the targetIndex in the target array
- if (unwrapped[i] && unwrap(unwrapped[i]._destroy)) {
- index++;
- }
- }
- }
-
- return index;
- };
-
- //remove problematic leading/trailing whitespace from templates
- var stripTemplateWhitespace = function(element, name) {
- var templateSource,
- templateElement;
-
- //process named templates
- if (name) {
- templateElement = document.getElementById(name);
- if (templateElement) {
- templateSource = new ko.templateSources.domElement(templateElement);
- templateSource.text($.trim(templateSource.text()));
- }
- }
- else {
- //remove leading/trailing non-elements from anonymous templates
- $(element).contents().each(function() {
- if (this && this.nodeType !== 1) {
- element.removeChild(this);
- }
- });
- }
- };
-
- //connect items with observableArrays
- ko.bindingHandlers.sortable = {
- init: function(element, valueAccessor, allBindingsAccessor, data, context) {
- var $element = $(element),
- value = unwrap(valueAccessor()) || {},
- templateOptions = prepareTemplateOptions(valueAccessor, "foreach"),
- sortable = {},
- startActual, updateActual;
-
- stripTemplateWhitespace(element, templateOptions.name);
-
- //build a new object that has the global options with overrides from the binding
- $.extend(true, sortable, ko.bindingHandlers.sortable);
- if (value.options && sortable.options) {
- ko.utils.extend(sortable.options, value.options);
- delete value.options;
- }
- ko.utils.extend(sortable, value);
-
- //if allowDrop is an observable or a function, then execute it in a computed observable
- if (sortable.connectClass && (ko.isObservable(sortable.allowDrop) || typeof sortable.allowDrop == "function")) {
- ko.computed({
- read: function() {
- var value = unwrap(sortable.allowDrop),
- shouldAdd = typeof value == "function" ? value.call(this, templateOptions.foreach) : value;
- ko.utils.toggleDomNodeCssClass(element, sortable.connectClass, shouldAdd);
- },
- disposeWhenNodeIsRemoved: element
- }, this);
- } else {
- ko.utils.toggleDomNodeCssClass(element, sortable.connectClass, sortable.allowDrop);
- }
-
- //wrap the template binding
- ko.bindingHandlers.template.init(element, function() { return templateOptions; }, allBindingsAccessor, data, context);
-
- //keep a reference to start/update functions that might have been passed in
- startActual = sortable.options.start;
- updateActual = sortable.options.update;
-
- //ensure draggable table row cells maintain their width while dragging
- sortable.options.helper = function(e, ui) {
- if (ui.is("tr")) {
- ui.children().each(function() {
- $(this).width($(this).width());
- });
- }
- return ui;
- };
-
- //initialize sortable binding after template binding has rendered in update function
- var createTimeout = setTimeout(function() {
- var dragItem;
- var originalReceive = sortable.options.receive;
-
- $element.sortable(ko.utils.extend(sortable.options, {
- start: function(event, ui) {
- //track original index
- var el = ui.item[0];
- dataSet(el, INDEXKEY, ko.utils.arrayIndexOf(ui.item.parent().children(), el));
-
- //make sure that fields have a chance to update model
- ui.item.find("input:focus").change();
- if (startActual) {
- startActual.apply(this, arguments);
- }
- },
- receive: function(event, ui) {
- //optionally apply an existing receive handler
- if (typeof originalReceive === "function") {
- originalReceive.call(this, event, ui);
- }
-
- dragItem = dataGet(ui.item[0], DRAGKEY);
- if (dragItem) {
- //copy the model item, if a clone option is provided
- if (dragItem.clone) {
- dragItem = dragItem.clone();
- }
-
- //configure a handler to potentially manipulate item before drop
- if (sortable.dragged) {
- dragItem = sortable.dragged.call(this, dragItem, event, ui) || dragItem;
- }
- }
- },
- update: function(event, ui) {
- var sourceParent, targetParent, sourceIndex, targetIndex, arg,
- el = ui.item[0],
- parentEl = ui.item.parent()[0],
- item = dataGet(el, ITEMKEY) || dragItem;
-
- if (!item) {
- $(el).remove();
- }
- dragItem = null;
-
- //make sure that moves only run once, as update fires on multiple containers
- if (item && (this === parentEl) || (!hasNestedSortableFix && $.contains(this, parentEl))) {
- //identify parents
- sourceParent = dataGet(el, PARENTKEY);
- sourceIndex = dataGet(el, INDEXKEY);
- targetParent = dataGet(el.parentNode, LISTKEY);
- targetIndex = ko.utils.arrayIndexOf(ui.item.parent().children(), el);
-
- //take destroyed items into consideration
- if (!templateOptions.includeDestroyed) {
- sourceIndex = updateIndexFromDestroyedItems(sourceIndex, sourceParent);
- targetIndex = updateIndexFromDestroyedItems(targetIndex, targetParent);
- }
-
- //build up args for the callbacks
- if (sortable.beforeMove || sortable.afterMove) {
- arg = {
- item: item,
- sourceParent: sourceParent,
- sourceParentNode: sourceParent && ui.sender || el.parentNode,
- sourceIndex: sourceIndex,
- targetParent: targetParent,
- targetIndex: targetIndex,
- cancelDrop: false
- };
-
- //execute the configured callback prior to actually moving items
- if (sortable.beforeMove) {
- sortable.beforeMove.call(this, arg, event, ui);
- }
- }
-
- //call cancel on the correct list, so KO can take care of DOM manipulation
- if (sourceParent) {
- $(sourceParent === targetParent ? this : ui.sender || this).sortable("cancel");
- }
- //for a draggable item just remove the element
- else {
- $(el).remove();
- }
-
- //if beforeMove told us to cancel, then we are done
- if (arg && arg.cancelDrop) {
- return;
- }
-
- //if the strategy option is unset or false, employ the order strategy involving removal and insertion of items
- if (!sortable.hasOwnProperty("strategyMove") || sortable.strategyMove === false) {
- //do the actual move
- if (targetIndex >= 0) {
- if (sourceParent) {
- sourceParent.splice(sourceIndex, 1);
-
- //if using deferred updates plugin, force updates
- if (ko.processAllDeferredBindingUpdates) {
- ko.processAllDeferredBindingUpdates();
- }
-
- //if using deferred updates on knockout 3.4, force updates
- if (ko.options && ko.options.deferUpdates) {
- ko.tasks.runEarly();
- }
- }
-
- targetParent.splice(targetIndex, 0, item);
- }
-
- //rendering is handled by manipulating the observableArray; ignore dropped element
- dataSet(el, ITEMKEY, null);
- }
- else { //employ the strategy of moving items
- if (targetIndex >= 0) {
- if (sourceParent) {
- if (sourceParent !== targetParent) {
- // moving from one list to another
-
- sourceParent.splice(sourceIndex, 1);
- targetParent.splice(targetIndex, 0, item);
-
- //rendering is handled by manipulating the observableArray; ignore dropped element
- dataSet(el, ITEMKEY, null);
- ui.item.remove();
- }
- else {
- // moving within same list
- var underlyingList = unwrap(sourceParent);
-
- // notify 'beforeChange' subscribers
- if (sourceParent.valueWillMutate) {
- sourceParent.valueWillMutate();
- }
-
- // move from source index ...
- underlyingList.splice(sourceIndex, 1);
- // ... to target index
- underlyingList.splice(targetIndex, 0, item);
-
- // notify subscribers
- if (sourceParent.valueHasMutated) {
- sourceParent.valueHasMutated();
- }
- }
- }
- else {
- // drop new element from outside
- targetParent.splice(targetIndex, 0, item);
-
- //rendering is handled by manipulating the observableArray; ignore dropped element
- dataSet(el, ITEMKEY, null);
- ui.item.remove();
- }
- }
- }
-
- //if using deferred updates plugin, force updates
- if (ko.processAllDeferredBindingUpdates) {
- ko.processAllDeferredBindingUpdates();
- }
-
- //allow binding to accept a function to execute after moving the item
- if (sortable.afterMove) {
- sortable.afterMove.call(this, arg, event, ui);
- }
- }
-
- if (updateActual) {
- updateActual.apply(this, arguments);
- }
- },
- connectWith: sortable.connectClass ? "." + sortable.connectClass : false
- }));
-
- //handle enabling/disabling sorting
- if (sortable.isEnabled !== undefined) {
- ko.computed({
- read: function() {
- $element.sortable(unwrap(sortable.isEnabled) ? "enable" : "disable");
- },
- disposeWhenNodeIsRemoved: element
- });
- }
- }, 0);
-
- //handle disposal
- ko.utils.domNodeDisposal.addDisposeCallback(element, function() {
- //only call destroy if sortable has been created
- if ($element.data("ui-sortable") || $element.data("sortable")) {
- $element.sortable("destroy");
- }
-
- ko.utils.toggleDomNodeCssClass(element, sortable.connectClass, false);
-
- //do not create the sortable if the element has been removed from DOM
- clearTimeout(createTimeout);
- });
-
- return { 'controlsDescendantBindings': true };
- },
- update: function(element, valueAccessor, allBindingsAccessor, data, context) {
- var templateOptions = prepareTemplateOptions(valueAccessor, "foreach");
-
- //attach meta-data
- dataSet(element, LISTKEY, templateOptions.foreach);
-
- //call template binding's update with correct options
- ko.bindingHandlers.template.update(element, function() { return templateOptions; }, allBindingsAccessor, data, context);
- },
- connectClass: 'ko_container',
- allowDrop: true,
- afterMove: null,
- beforeMove: null,
- options: {}
- };
-
- //create a draggable that is appropriate for dropping into a sortable
- ko.bindingHandlers.draggable = {
- init: function(element, valueAccessor, allBindingsAccessor, data, context) {
- var value = unwrap(valueAccessor()) || {},
- options = value.options || {},
- draggableOptions = ko.utils.extend({}, ko.bindingHandlers.draggable.options),
- templateOptions = prepareTemplateOptions(valueAccessor, "data"),
- connectClass = value.connectClass || ko.bindingHandlers.draggable.connectClass,
- isEnabled = value.isEnabled !== undefined ? value.isEnabled : ko.bindingHandlers.draggable.isEnabled;
-
- value = "data" in value ? value.data : value;
-
- //set meta-data
- dataSet(element, DRAGKEY, value);
-
- //override global options with override options passed in
- ko.utils.extend(draggableOptions, options);
-
- //setup connection to a sortable
- draggableOptions.connectToSortable = connectClass ? "." + connectClass : false;
-
- //initialize draggable
- $(element).draggable(draggableOptions);
-
- //handle enabling/disabling sorting
- if (isEnabled !== undefined) {
- ko.computed({
- read: function() {
- $(element).draggable(unwrap(isEnabled) ? "enable" : "disable");
- },
- disposeWhenNodeIsRemoved: element
- });
- }
-
- //handle disposal
- ko.utils.domNodeDisposal.addDisposeCallback(element, function() {
- $(element).draggable("destroy");
- });
-
- return ko.bindingHandlers.template.init(element, function() { return templateOptions; }, allBindingsAccessor, data, context);
- },
- update: function(element, valueAccessor, allBindingsAccessor, data, context) {
- var templateOptions = prepareTemplateOptions(valueAccessor, "data");
-
- return ko.bindingHandlers.template.update(element, function() { return templateOptions; }, allBindingsAccessor, data, context);
- },
- connectClass: ko.bindingHandlers.sortable.connectClass,
- options: {
- helper: "clone"
- }
- };
-});
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/rainloop.git
More information about the Pkg-javascript-commits
mailing list