Browse Source

* code style

experimental
RubaXa 9 years ago
parent
commit
b1defd32ff
  1. 9
      Sortable.js
  2. 2
      Sortable.min.js
  3. 110
      knockout-sortable.js

9
Sortable.js

@ -4,7 +4,6 @@
* @license MIT * @license MIT
*/ */
(function (factory) { (function (factory) {
"use strict"; "use strict";
@ -24,10 +23,10 @@
})(function () { })(function () {
"use strict"; "use strict";
if (typeof window == "undefined" || typeof window.document == "undefined") { if (typeof window == "undefined" || !window.document) {
return function() { return function SortableError() {
throw new Error( "Sortable.js requires a window with a document" ); throw new Error("Sortable.js requires a window with a document");
} };
} }
var dragEl, var dragEl,

2
Sortable.min.js vendored

File diff suppressed because one or more lines are too long

110
knockout-sortable.js

@ -1,55 +1,61 @@
/*global ko*/
(function (factory) { (function (factory) {
"use strict"; "use strict";
//get ko ref via global or require //get ko ref via global or require
var koRef; var koRef;
if (typeof ko !== 'undefined') { if (typeof ko !== 'undefined') {
//global ref already defined //global ref already defined
koRef = ko; koRef = ko;
} }
else if (typeof require === 'function' && typeof exports === 'object' && typeof module === 'object') { else if (typeof require === 'function' && typeof exports === 'object' && typeof module === 'object') {
//commonjs / node.js //commonjs / node.js
koRef = require('knockout'); koRef = require('knockout');
} }
//get sortable ref via global or require //get sortable ref via global or require
var sortableRef; var sortableRef;
if (typeof Sortable !== 'undefined') { if (typeof Sortable !== 'undefined') {
//global ref already defined //global ref already defined
sortableRef = Sortable; sortableRef = Sortable;
} }
else if (typeof require === 'function' && typeof exports === 'object' && typeof module === 'object') { else if (typeof require === 'function' && typeof exports === 'object' && typeof module === 'object') {
//commonjs / node.js //commonjs / node.js
sortableRef = require('sortablejs'); sortableRef = require('sortablejs');
} }
//use references if we found them //use references if we found them
if (koRef !== undefined && sortableRef !== undefined) { if (koRef !== undefined && sortableRef !== undefined) {
factory(koRef, sortableRef); factory(koRef, sortableRef);
} }
//if both references aren't found yet, get via AMD if available //if both references aren't found yet, get via AMD if available
else if (typeof define === 'function' && define.amd){ else if (typeof define === 'function' && define.amd) {
//we may have a reference to only 1, or none //we may have a reference to only 1, or none
if (koRef !== undefined && sortableRef === undefined) { if (koRef !== undefined && sortableRef === undefined) {
define(['./Sortable'], function(amdSortableRef){ factory(koRef, amdSortableRef); }); define(['./Sortable'], function (amdSortableRef) {
} factory(koRef, amdSortableRef);
else if (koRef === undefined && sortableRef !== undefined) { });
define(['knockout'], function(amdKnockout){ factory(amdKnockout, sortableRef); }); }
} else if (koRef === undefined && sortableRef !== undefined) {
else if (koRef === undefined && sortableRef === undefined) { define(['knockout'], function (amdKnockout) {
define(['knockout', './Sortable'], factory); factory(amdKnockout, sortableRef);
} });
} }
//no more routes to get references else if (koRef === undefined && sortableRef === undefined) {
else { define(['knockout', './Sortable'], factory);
//report specific error }
if (koRef !== undefined && sortableRef === undefined) { }
throw new Error('knockout-sortable could not get reference to Sortable'); //no more routes to get references
} else {
else if (koRef === undefined && sortableRef !== undefined) { //report specific error
throw new Error('knockout-sortable could not get reference to Knockout'); if (koRef !== undefined && sortableRef === undefined) {
} throw new Error('knockout-sortable could not get reference to Sortable');
else if (koRef === undefined && sortableRef === undefined) { }
throw new Error('knockout-sortable could not get reference to Knockout or Sortable'); else if (koRef === undefined && sortableRef !== undefined) {
} throw new Error('knockout-sortable could not get reference to Knockout');
} }
else if (koRef === undefined && sortableRef === undefined) {
throw new Error('knockout-sortable could not get reference to Knockout or Sortable');
}
}
})(function (ko, Sortable) { })(function (ko, Sortable) {
"use strict"; "use strict";
@ -127,7 +133,7 @@
originalIndex = fromArray.indexOf(itemVM), originalIndex = fromArray.indexOf(itemVM),
newIndex = e.newIndex; newIndex = e.newIndex;
// We have to find out the actual desired index of the to array, // We have to find out the actual desired index of the to array,
// as this might be a computed array. We could otherwise potentially // as this might be a computed array. We could otherwise potentially
// drop an item above the 3rd visible item, but the 2nd visible item // drop an item above the 3rd visible item, but the 2nd visible item
// has an actual index of 5. // has an actual index of 5.

Loading…
Cancel
Save