Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
### Issue

1. Try [dev](https://github.com/RubaXa/Sortable/tree/dev/)-branch, perhaps the problem has been solved;
2. [Use the search](https://github.com/RubaXa/Sortable/search?q=problem), maybe already have an answer;
2. [Use the search](https://github.com/RubaXa/Sortable/search?type=Issues&q=problem), maybe already have an answer;
3. If not found, create example on [jsbin.com (draft)](http://jsbin.com/zunibaxada/1/edit?html,js,output) and describe the problem.

---
Expand Down
8 changes: 7 additions & 1 deletion Sortable.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
})(function () {
"use strict";

if (typeof window == "undefined" || typeof window.document == "undefined") {
return function() {
throw new Error( "Sortable.js requires a window with a document" );
}
}

var dragEl,
parentEl,
ghostEl,
Expand Down Expand Up @@ -329,7 +335,7 @@
_this._disableDelayedDrag();

// Make the element draggable
dragEl.draggable = true;
dragEl.draggable = _this.nativeDraggable;

// Chosen item
_toggleClass(dragEl, _this.options.chosenClass, true);
Expand Down
60 changes: 49 additions & 11 deletions knockout-sortable.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,54 @@
(function (factory) {
"use strict";
if (typeof define === "function" && define.amd) {
// AMD anonymous module
define(["knockout", "./Sortable"], factory);
} else if (typeof require === "function" && typeof exports === "object" && typeof module === "object") {
// CommonJS module
var ko = require("knockout");
var Sortable = require('./Sortable');
factory(ko, Sortable);
} else {
// No module loader (plain <script> tag) - put directly in global namespace
factory(window.ko, window.Sortable);
//get ko ref via global or require
var koRef;
if (typeof ko !== 'undefined') {
//global ref already defined
koRef = ko;
}
else if (typeof require === 'function' && typeof exports === 'object' && typeof module === 'object') {
//commonjs / node.js
koRef = require('knockout');
}
//get sortable ref via global or require
var sortableRef;
if (typeof Sortable !== 'undefined') {
//global ref already defined
sortableRef = Sortable;
}
else if (typeof require === 'function' && typeof exports === 'object' && typeof module === 'object') {
//commonjs / node.js
sortableRef = require('sortablejs');
}
//use references if we found them
if (koRef !== undefined && sortableRef !== undefined) {
factory(koRef, sortableRef);
}
//if both references aren't found yet, get via AMD if available
else if (typeof define === 'function' && define.amd){
//we may have a reference to only 1, or none
if (koRef !== undefined && sortableRef === undefined) {
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) {
define(['knockout', './Sortable'], factory);
}
}
//no more routes to get references
else {
//report specific error
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');
}
else if (koRef === undefined && sortableRef === undefined) {
throw new Error('knockout-sortable could not get reference to Knockout or Sortable');
}
}
})(function (ko, Sortable) {
"use strict";
Expand Down