Browse Source

Merge pull request #737 from petemill/patch-1

knockout-sortable - prioritise global dependencies if available
pull/741/head
Lebedev Konstantin 9 years ago
parent
commit
6963281a2b
  1. 60
      knockout-sortable.js

60
knockout-sortable.js

@ -1,16 +1,54 @@
(function (factory) { (function (factory) {
"use strict"; "use strict";
if (typeof define === "function" && define.amd) { //get ko ref via global or require
// AMD anonymous module var koRef;
define(["knockout", "./Sortable"], factory); if (typeof ko !== 'undefined') {
} else if (typeof require === "function" && typeof exports === "object" && typeof module === "object") { //global ref already defined
// CommonJS module koRef = ko;
var ko = require("knockout"); }
var Sortable = require('./Sortable'); else if (typeof require === 'function' && typeof exports === 'object' && typeof module === 'object') {
factory(ko, Sortable); //commonjs / node.js
} else { koRef = require('knockout');
// No module loader (plain <script> tag) - put directly in global namespace }
factory(window.ko, window.Sortable); //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) { })(function (ko, Sortable) {
"use strict"; "use strict";

Loading…
Cancel
Save