From 6476aa0790ba3d14dd96eed02556bb5793ac6242 Mon Sep 17 00:00:00 2001 From: Jonathan Horowitz Date: Mon, 3 Oct 2016 10:50:53 -0700 Subject: [PATCH] Fix #61 - Add support for jQuery UI 1.12. Add custom.combobox widget from jquery-ui.com Autocomplete example. Add CommonJS support. Signed-off-by: Jonathan Horowitz --- Gruntfile.js | 6 ++--- README.md | 3 +-- dist/amd/accordion.js | 11 ++++++--- dist/amd/autocomplete.js | 16 +++++++------ dist/amd/bindingHandler.js | 3 +-- dist/amd/button.js | 14 ++++++++--- dist/amd/buttonset.js | 3 +-- dist/amd/checkboxradio.js | 39 +++++++++++++++++++++++++++++++ dist/amd/controlgroup.js | 30 ++++++++++++++++++++++++ dist/amd/custom.combobox.js | 31 +++++++++++++++++++++++++ dist/amd/datepicker.js | 3 +-- dist/amd/dialog.js | 40 ++++++++++++++++---------------- dist/amd/menu.js | 12 +++++----- dist/amd/progressbar.js | 11 +++++---- dist/amd/selectmenu.js | 9 +++++--- dist/amd/slider.js | 7 ++++-- dist/amd/spinner.js | 46 +++++++++++++++---------------------- dist/amd/tabs.js | 11 ++++++--- dist/amd/tooltip.js | 7 ++++-- dist/amd/utils.js | 3 +-- grunt/concat.js | 19 ++++++++------- grunt/meta.js | 22 ++++++++++++++++-- package.json | 38 +++++++++++++++++------------- src/accordion.js | 11 ++++++--- src/autocomplete.js | 16 +++++++------ src/bindingHandler.js | 3 +-- src/button.js | 14 ++++++++--- src/buttonset.js | 3 +-- src/checkboxradio.js | 39 +++++++++++++++++++++++++++++++ src/controlgroup.js | 30 ++++++++++++++++++++++++ src/custom.combobox.js | 31 +++++++++++++++++++++++++ src/datepicker.js | 3 +-- src/dialog.js | 40 ++++++++++++++++---------------- src/menu.js | 12 +++++----- src/progressbar.js | 11 +++++---- src/selectmenu.js | 9 +++++--- src/slider.js | 7 ++++-- src/spinner.js | 7 ++++-- src/tabs.js | 11 ++++++--- src/tooltip.js | 7 ++++-- src/utils.js | 3 +-- 41 files changed, 455 insertions(+), 186 deletions(-) create mode 100644 dist/amd/checkboxradio.js create mode 100644 dist/amd/controlgroup.js create mode 100644 dist/amd/custom.combobox.js create mode 100644 src/checkboxradio.js create mode 100644 src/controlgroup.js create mode 100644 src/custom.combobox.js diff --git a/Gruntfile.js b/Gruntfile.js index e465527..c18d09d 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -10,9 +10,9 @@ module.exports = function (grunt) { tunnelId: Math.floor((new Date()).getTime() / 1000 - 1230768000).toString(), coreFiles: ['src/utils.js', 'src/bindingHandler.js'], widgets: ['src/accordion.js', 'src/autocomplete.js', 'src/button.js', - 'src/buttonset.js', 'src/datepicker.js', 'src/dialog.js', 'src/menu.js', - 'src/progressbar.js', 'src/selectmenu.js', 'src/slider.js', - 'src/spinner.js', 'src/tabs.js', 'src/tooltip.js'] + 'src/buttonset.js', 'src/checkboxradio.js', 'src/controlgroup.js', 'src/custom.combobox.js', + 'src/datepicker.js', 'src/dialog.js', 'src/menu.js', 'src/progressbar.js', 'src/selectmenu.js', + 'src/slider.js', 'src/spinner.js', 'src/tabs.js', 'src/tooltip.js'] } }); }; diff --git a/README.md b/README.md index e6ba171..25c0af3 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,5 @@ Tests Compatibility ----- -From jQuery UI 1.8 to jQuery UI 1.11.x. -jQuery UI 1.12 deprecated some API and the "compatibility layer" is broken. +From jQuery UI 1.8 to jQuery UI 1.12.x. diff --git a/dist/amd/accordion.js b/dist/amd/accordion.js index a27a6e4..78fc1b8 100644 --- a/dist/amd/accordion.js +++ b/dist/amd/accordion.js @@ -1,3 +1,4 @@ +/*jshint strict: false */ /*global define*/ define( @@ -11,8 +12,6 @@ define( function ($, ko, utils, BindingHandler) { - 'use strict'; - var Accordion = function () { /// Constructor. @@ -25,12 +24,18 @@ define( this.events = ['change', 'changestart', 'create']; this.hasRefresh = false; this.eventToWatch = 'change'; - } else { + } else if (utils.uiVersion.major === 1 && (utils.uiVersion.minor >= 9 && utils.uiVersion.minor <= 11)) { this.options = ['active', 'animate', 'collapsible', 'disabled', 'event', 'header', 'heightStyle', 'icons']; this.events = ['activate', 'beforeActivate', 'create']; this.hasRefresh = true; this.eventToWatch = 'activate'; + } else { + this.options = ['active', 'animate', 'classes', 'collapsible', 'disabled', + 'event', 'header', 'heightStyle', 'icons']; + this.events = ['activate', 'beforeActivate', 'create']; + this.hasRefresh = true; + this.eventToWatch = 'activate'; } }; diff --git a/dist/amd/autocomplete.js b/dist/amd/autocomplete.js index 90aa16e..dcd16ee 100644 --- a/dist/amd/autocomplete.js +++ b/dist/amd/autocomplete.js @@ -1,3 +1,4 @@ +/*jshint strict: false */ /*global define*/ define( @@ -9,8 +10,6 @@ define( function (BindingHandler, utils) { - 'use strict'; - var Autocomplete = function () { /// Constructor. @@ -18,14 +17,17 @@ define( this.options = ['appendTo', 'autoFocus', 'delay', 'disabled', 'minLength', 'position', 'source']; + this.events = ['change', 'close', 'create', 'focus', 'open', 'search', + 'select']; - if (utils.uiVersion.major === 1 && utils.uiVersion.minor === 8) { - this.events = ['change', 'close', 'create', 'focus', 'open', 'search', - 'select']; + if (utils.uiVersion.major === 1 && (utils.uiVersion.minor >= 9 && utils.uiVersion.minor <= 11)) { + this.events.push('response'); + this.options.push('messages'); } else { + this.events.push('response'); this.options.push('messages'); - this.events = ['change', 'close', 'create', 'focus', 'open', 'response', - 'search', 'select']; + this.options.push('classes'); + } }; diff --git a/dist/amd/bindingHandler.js b/dist/amd/bindingHandler.js index c1d82d6..c39e219 100644 --- a/dist/amd/bindingHandler.js +++ b/dist/amd/bindingHandler.js @@ -1,3 +1,4 @@ +/*jshint strict: false */ /*global define*/ define( @@ -10,8 +11,6 @@ define( function ($, ko, utils) { - 'use strict'; - var domDataKey, filterAndUnwrapProperties, subscribeToRefreshOn, BindingHandler; domDataKey = '__kojqui_options'; diff --git a/dist/amd/button.js b/dist/amd/button.js index 0cde999..bcbc2a8 100644 --- a/dist/amd/button.js +++ b/dist/amd/button.js @@ -1,3 +1,4 @@ +/*jshint strict: false */ /*global define*/ define( @@ -9,15 +10,22 @@ define( function (BindingHandler, utils) { - 'use strict'; - var Button = function () { /// Constructor. BindingHandler.call(this, 'button'); - this.options = ['disabled', 'icons', 'label', 'text']; + this.options = ['disabled', 'label']; this.events = ['create']; + if (utils.uiVersion.major === 1 && (utils.uiVersion.minor >= 8 && utils.uiVersion.minor <= 11)) { + this.options.push('icons'); + this.options.push('text'); + } else { + this.options.push('classes'); + this.options.push('icon'); + this.options.push('iconPosition'); + this.options.push('showLabel'); + } this.hasRefresh = true; }; diff --git a/dist/amd/buttonset.js b/dist/amd/buttonset.js index d608639..695d3d3 100644 --- a/dist/amd/buttonset.js +++ b/dist/amd/buttonset.js @@ -1,3 +1,4 @@ +/*jshint strict: false */ /*global define*/ define( @@ -9,8 +10,6 @@ define( function (BindingHandler, utils) { - 'use strict'; - var Buttonset = function () { /// Constructor. diff --git a/dist/amd/checkboxradio.js b/dist/amd/checkboxradio.js new file mode 100644 index 0000000..516472f --- /dev/null +++ b/dist/amd/checkboxradio.js @@ -0,0 +1,39 @@ +/*jshint strict: false */ +/*global define*/ +define( + + [ + './bindingHandler', + './utils', + 'jquery-ui/checkboxradio' + ], + + function (BindingHandler, utils) { + + var Checkboxradio = function () { + /// Constructor. + + BindingHandler.call(this, 'checkboxradio'); + + this.options = ['classes', 'disabled', 'icon', 'label']; + this.events = ['create']; + if (utils.uiVersion.major === 1 && (utils.uiVersion.minor >= 8 && utils.uiVersion.minor <= 11)) { + this.options.push('icons'); + this.options.push('text'); + } else { + this.options.push('classes'); + this.options.push('icon'); + this.options.push('iconPosition'); + this.options.push('showLabel'); + } + this.hasRefresh = true; + }; + + Checkboxradio.prototype = utils.createObject(BindingHandler.prototype); + Checkboxradio.prototype.constructor = Checkboxradio; + + utils.register(Checkboxradio); + + return Checkboxradio; + } +); diff --git a/dist/amd/controlgroup.js b/dist/amd/controlgroup.js new file mode 100644 index 0000000..47f64da --- /dev/null +++ b/dist/amd/controlgroup.js @@ -0,0 +1,30 @@ +/*jshint strict: false */ +/*global define*/ +define( + + [ + './bindingHandler', + './utils', + 'jquery-ui/controlgroup' + ], + + function (BindingHandler, utils) { + + var Controlgroup = function () { + /// Constructor. + + BindingHandler.call(this, 'controlgroup'); + + this.options = ['classes', 'direction', 'disabled', 'items', 'onlyVisible']; + this.events = ['create']; + this.hasRefresh = true; + }; + + Controlgroup.prototype = utils.createObject(BindingHandler.prototype); + Controlgroup.prototype.constructor = Controlgroup; + + utils.register(Controlgroup); + + return Controlgroup; + } +); diff --git a/dist/amd/custom.combobox.js b/dist/amd/custom.combobox.js new file mode 100644 index 0000000..7a02af7 --- /dev/null +++ b/dist/amd/custom.combobox.js @@ -0,0 +1,31 @@ +/*jshint strict: false */ +/*global define*/ +define( + + [ + './bindingHandler', + './utils', + 'jquery-ui/autocomplete', + 'jquery-ui/button', + 'jquery-ui/tooltip' + ], + + function (BindingHandler, utils) { + + var CustomCombobox = function () { + /// Constructor. + + BindingHandler.call(this, 'combobox'); + + this.options = ['removeIfInvalid', 'buttonTooltip']; + this.events = []; + }; + + CustomCombobox.prototype = utils.createObject(BindingHandler.prototype); + CustomCombobox.prototype.constructor = CustomCombobox; + + utils.register(CustomCombobox); + + return CustomCombobox; + } +); diff --git a/dist/amd/datepicker.js b/dist/amd/datepicker.js index 77d0c58..56e0e43 100644 --- a/dist/amd/datepicker.js +++ b/dist/amd/datepicker.js @@ -1,3 +1,4 @@ +/*jshint strict: false */ /*global define*/ define( @@ -11,8 +12,6 @@ define( function ($, ko, BindingHandler, utils) { - 'use strict'; - var Datepicker = function () { /// Constructor. diff --git a/dist/amd/dialog.js b/dist/amd/dialog.js index cfaa583..adff164 100644 --- a/dist/amd/dialog.js +++ b/dist/amd/dialog.js @@ -1,3 +1,4 @@ +/*jshint strict: false */ /*global define*/ /*jslint browser:true*/ define( @@ -12,34 +13,33 @@ define( function ($, ko, BindingHandler, utils) { - 'use strict'; - var Dialog = function () { /// Constructor. BindingHandler.call(this, 'dialog'); + this.events = ['beforeClose', 'create', 'open', 'focus', 'dragStart', + 'drag', 'dragStop', 'resizeStart', 'resize', 'resizeStop', 'close']; + this.options = ['autoOpen', 'buttons', 'closeOnEscape', + 'closeText', 'dialogClass', 'draggable', 'height', + 'maxHeight', 'maxWidth', 'minHeight', 'minWidth', 'modal', 'position', + 'resizable', 'show', 'title', 'width']; + if (utils.uiVersion.major === 1 && utils.uiVersion.minor === 8) { - this.options = ['autoOpen', 'buttons', 'closeOnEscape', 'closeText', - 'dialogClass', 'disabled', 'draggable', 'height', 'maxHeight', - 'maxWidth', 'minHeight', 'minWidth', 'modal', 'position', 'resizable', - 'show', 'stack', 'title', 'width', 'zIndex']; - this.events = ['beforeClose', 'create', 'open', 'focus', 'dragStart', - 'drag', 'dragStop', 'resizeStart', 'resize', 'resizeStop', 'close']; + this.options.push('disabled'); + this.options.push('stack'); + this.options.push('zIndex'); } else if (utils.uiVersion.major === 1 && utils.uiVersion.minor === 9) { - this.options = ['autoOpen', 'buttons', 'closeOnEscape', 'closeText', - 'dialogClass', 'draggable', 'height', 'hide', 'maxHeight', 'maxWidth', - 'minHeight', 'minWidth', 'modal', 'position', 'resizable', 'show', - 'stack', 'title', 'width', 'zIndex']; - this.events = ['beforeClose', 'create', 'open', 'focus', 'dragStart', - 'drag', 'dragStop', 'resizeStart', 'resize', 'resizeStop', 'close']; + this.options.push('stack'); + this.options.push('zIndex'); + this.options.push('hide'); + } else if (utils.uiVersion.major === 1 && (utils.uiVersion.minor === 10 || utils.uiVersion.minor === 11)) { + this.options.push('appendTo'); + this.options.push('hide'); } else { - this.options = ['appendTo', 'autoOpen', 'buttons', 'closeOnEscape', - 'closeText', 'dialogClass', 'draggable', 'height', 'hide', - 'maxHeight', 'maxWidth', 'minHeight', 'minWidth', 'modal', 'position', - 'resizable', 'show', 'title', 'width']; - this.events = ['beforeClose', 'create', 'open', 'focus', 'dragStart', - 'drag', 'dragStop', 'resizeStart', 'resize', 'resizeStop', 'close']; + this.options.push('appendTo'); + this.options.push('hide'); + this.options.push('classes'); } }; diff --git a/dist/amd/menu.js b/dist/amd/menu.js index 1fa62b0..1fcebe4 100644 --- a/dist/amd/menu.js +++ b/dist/amd/menu.js @@ -1,3 +1,4 @@ +/*jshint strict: false */ /*global define*/ define( @@ -9,18 +10,17 @@ define( function (BindingHandler, utils) { - 'use strict'; - var Menu = function () { /// Constructor. BindingHandler.call(this, 'menu'); - if (utils.uiVersion.major === 1 && utils.uiVersion.minor < 11) { - this.options = ['disabled', 'icons', 'menus', 'position', 'role']; + this.options = ['disabled', 'icons', 'menus', 'position', 'role']; + if (utils.uiVersion.major === 1 && utils.uiVersion.minor === 11) { + this.options.push('items'); } else { - this.options = ['disabled', 'icons', 'items', 'menus', 'position', - 'role']; + this.options.push('items'); + this.options.push('classes'); } this.events = ['blur', 'create', 'focus', 'select']; diff --git a/dist/amd/progressbar.js b/dist/amd/progressbar.js index 487c5a8..b3f01cc 100644 --- a/dist/amd/progressbar.js +++ b/dist/amd/progressbar.js @@ -1,3 +1,4 @@ +/*jshint strict: false */ /*global define*/ define( @@ -9,20 +10,20 @@ define( function (BindingHandler, utils) { - 'use strict'; - var Progressbar = function () { /// Constructor. BindingHandler.call(this, 'progressbar'); + this.options = ['disabled', 'value']; this.events = ['change', 'create', 'complete']; this.hasRefresh = true; - if (utils.uiVersion.major === 1 && utils.uiVersion.minor === 8) { - this.options = ['disabled', 'value']; + if (utils.uiVersion.major === 1 && (utils.uiVersion.minor >= 9 && utils.uiVersion.minor <= 11)) { + this.options.push('max'); } else { - this.options = ['disabled', 'max', 'value']; + this.options.push('max'); + this.options.push('classes'); } }; diff --git a/dist/amd/selectmenu.js b/dist/amd/selectmenu.js index 95a6764..0badff5 100644 --- a/dist/amd/selectmenu.js +++ b/dist/amd/selectmenu.js @@ -1,4 +1,5 @@ -/*global define*/ +/*jshint strict: false */ +/*global define*/ define( [ @@ -11,8 +12,6 @@ define( function ($, ko, BindingHandler, utils) { - 'use strict'; - var domDataKey, Selectmenu; domDataKey = '__kojqui_selectmenu_value'; @@ -26,6 +25,10 @@ define( this.options = ['appendTo', 'disabled', 'icons', 'position', 'width']; this.events = ['change', 'close', 'create', 'focus', 'open', 'select']; this.hasRefresh = true; + + if (utils.uiVersion.major !== 1 || utils.uiVersion.minor !== 11) { + this.options.push('classes'); + } }; Selectmenu.prototype = utils.createObject(BindingHandler.prototype); diff --git a/dist/amd/slider.js b/dist/amd/slider.js index fb573a7..537879a 100644 --- a/dist/amd/slider.js +++ b/dist/amd/slider.js @@ -1,3 +1,4 @@ +/*jshint strict: false */ /*global define*/ define( @@ -11,8 +12,6 @@ define( function ($, ko, BindingHandler, utils) { - 'use strict'; - var domDataKey, Slider; domDataKey = '__kojqui_options'; @@ -26,6 +25,10 @@ define( this.options = ['animate', 'disabled', 'max', 'min', 'orientation', 'range', 'step', 'value', 'values']; this.events = ['create', 'start', 'slide', 'change', 'stop']; + + if (utils.uiVersion.major !== 1 || utils.uiVersion.minor > 11) { + this.options.push('classes'); + } }; Slider.prototype = utils.createObject(BindingHandler.prototype); diff --git a/dist/amd/spinner.js b/dist/amd/spinner.js index 9ff42fa..03850ec 100644 --- a/dist/amd/spinner.js +++ b/dist/amd/spinner.js @@ -1,3 +1,4 @@ +/*jshint strict: false */ /*global define*/ define( @@ -11,8 +12,6 @@ define( function ($, ko, BindingHandler, utils) { - 'use strict'; - var Spinner = function () { /// Constructor. @@ -22,12 +21,16 @@ define( this.options = ['culture', 'disabled', 'icons', 'incremental', 'max', 'min', 'numberFormat', 'page', 'step']; this.events = ['create', 'start', 'spin', 'stop', 'change']; + + if (utils.uiVersion.major !== 1 || utils.uiVersion.minor > 11) { + this.options.push('classes'); + } }; Spinner.prototype = utils.createObject(BindingHandler.prototype); Spinner.prototype.constructor = Spinner; - Spinner.prototype.init = function (element, valueAccessor, allBindingsAccessor) { + Spinner.prototype.init = function (element, valueAccessor) { /// Keeps the value binding property in sync with the spinner's /// value. /// @@ -51,31 +54,20 @@ define( }); } - // If 'value' is an observable writeable, then add an event handler so that - // when the spinner increments/decrements the 'value' observable can be - // mutated. - // Which event we listen for depends upon if any of the KO valueUpdate options - // have been specified. - // 1. When there is no valueUpdate in the binding, 'value' will be mutated in - // response to the 'spinchange' event which occurs whenever the input loses - // focus. - // 2. If any of the KO valueUpdate options ("keyup", "keypress", - // "afterkeydown") are specified in the binding, this implies that you - // wish to mutate the 'value' observable in real-time. In this case the - // 'spin' event is used so that 'value' can be updated everytime there is - // an inc/dec, and done so immediately. if (ko.isWriteableObservable(value.value)) { - if (allBindingsAccessor().valueUpdate) { - /*jslint unparam:true*/ - this.on(element, 'spin', function (ev, ui) { - value.value(ui.value); - }); - /*jslint unparam:false*/ - } else { - this.on(element, 'change', function () { - value.value($(element)[widgetName]('value')); - }); - } + // The spin event is raised immediately when the value is changed with the + // up/down buttons, while the change event is raised when the value is set + // via the widget's value() method. Let's listen to both events. + + /*jslint unparam:true*/ + this.on(element, 'spin', function (ev, ui) { + value.value(ui.value); + }); + /*jslint unparam:false*/ + + this.on(element, 'change', function () { + value.value($(element)[widgetName]('value')); + }); } return result; diff --git a/dist/amd/tabs.js b/dist/amd/tabs.js index 114114c..9f8dc26 100644 --- a/dist/amd/tabs.js +++ b/dist/amd/tabs.js @@ -1,3 +1,4 @@ +/*jshint strict: false */ /*global define*/ define( @@ -11,8 +12,6 @@ define( function ($, ko, BindingHandler, utils) { - 'use strict'; - var postInitHandler18, postInitHandler, Tabs; postInitHandler18 = function (element, valueAccessor) { @@ -69,12 +68,18 @@ define( this.events = ['add', 'create', 'disable', 'enable', 'load', 'remove', 'select', 'show']; this.hasRefresh = false; - } else { + } else if (utils.uiVersion.major === 1 && (utils.uiVersion.minor >= 9 && utils.uiVersion.minor <= 11)) { this.options = ['active', 'collapsible', 'disabled', 'event', 'heightStyle', 'hide', 'show']; this.events = ['activate', 'beforeActivate', 'beforeLoad', 'create', 'load']; this.hasRefresh = true; + } else { + this.options = ['active', 'classes', 'collapsible', 'disabled', 'event', + 'heightStyle', 'hide', 'show']; + this.events = ['activate', 'beforeActivate', 'beforeLoad', 'create', + 'load']; + this.hasRefresh = true; } }; diff --git a/dist/amd/tooltip.js b/dist/amd/tooltip.js index 4a3b415..33fb49d 100644 --- a/dist/amd/tooltip.js +++ b/dist/amd/tooltip.js @@ -1,3 +1,4 @@ +/*jshint strict: false */ /*global define*/ define( @@ -11,8 +12,6 @@ define( function ($, ko, BindingHandler, utils) { - 'use strict'; - var Tooltip = function () { /// Constructor. @@ -21,6 +20,10 @@ define( this.options = ['content', 'disabled', 'hide', 'items', 'position', 'show', 'tooltipClass', 'track']; this.events = ['create', 'open', 'close']; + + if (utils.uiVersion.major !== 1 || utils.uiVersion.minor > 11) { + this.options.push('classes'); + } }; Tooltip.prototype = utils.createObject(BindingHandler.prototype); diff --git a/dist/amd/utils.js b/dist/amd/utils.js index 6bfaa15..c899691 100644 --- a/dist/amd/utils.js +++ b/dist/amd/utils.js @@ -1,3 +1,4 @@ +/*jshint strict: false */ /*global define*/ define( @@ -9,8 +10,6 @@ define( function ($, ko) { - 'use strict'; - var match, uiVersion, descendantControllingBindings, createObject, register; /*jslint regexp:true*/ diff --git a/grunt/concat.js b/grunt/concat.js index e8ffcdd..9b90a00 100644 --- a/grunt/concat.js +++ b/grunt/concat.js @@ -27,36 +27,34 @@ module.exports = function (grunt, options) { if (match) { // './BindingHandler' -> root.kojqui.BindingHandler if (match[1] === 'utils') { - return 'root.kojqui.utils'; + return 'kojqui.utils'; } - return 'root.kojqui.' + changeCase.pascalCase(match[1]); + return 'kojqui.' + changeCase.pascalCase(match[1]); } match = dependency.match(/^jquery-ui\/(.*)/); if (match) { // 'jquery-ui/autocomplete' -> root.jQuery.ui.autocomplete - return 'root.jQuery.ui.' + match[1]; + return 'jQuery.ui.' + match[1]; } if (dependency === 'jquery') { // 'jquery' -> root.jQuery - return 'root.jQuery'; + return 'jQuery'; } if (dependency === 'knockout') { // 'knockout' -> root.ko - return 'root.ko'; + return 'ko'; } throw new Error('Unexpected dependency: ' + dependency); }) .join(', '); - return '(function (root, factory) {\r\n\r\n' + - ' \'use strict\';\r\n\r\n' + - ' root.kojqui.' + name + ' = factory(' + dependencies + ');\r\n' + - '}(this,\r\n' + - ' ' + match[2] + '));'; + return ' (function (factory) {\r\n\r\n' + + ' kojqui.' + name + ' = factory(' + dependencies + ');\r\n' + + ' }(' + match[2] + '));'; } return { @@ -64,6 +62,7 @@ module.exports = function (grunt, options) { nonull: true, separator: '\r\n', banner: '<%= meta.banner %>', + footer: '<%= meta.footer %>', process: convert }, build: { diff --git a/grunt/meta.js b/grunt/meta.js index 6662945..269e7ac 100644 --- a/grunt/meta.js +++ b/grunt/meta.js @@ -4,6 +4,24 @@ module.exports = { banner: '/*! <%= meta.name %> - v<%= package.version %> - <%= grunt.template.today("m/d/yyyy") %>\r\n' + '* <%= package.homepage %>\r\n' + '* Copyright (c) <%= grunt.template.today("yyyy") %> <%= package.author.name %> Licensed <%= package.license %> */\r\n' + - '/*jslint browser:true*/\r\n\r\n' + - 'window.kojqui = { version: \'<%= package.version %>\' };\r\n\r\n' + '/*jslint browser:true*/\r\n' + + '/*globals global, self, window, require, module, define*/\r\n\r\n' + + '(function (factory, global) {\r\n' + + ' \'use strict\';\r\n\r\n' + + ' // Module systems magic dance.\r\n' + + ' if (typeof require === \'function\' && typeof exports === \'object\' && typeof module === \'object\') {\r\n' + + ' // CommonJS or Node: hard-coded dependency on \'knockout\'\r\n' + + ' module.exports = factory(require(\'jquery\'), require(\'knockout\'), require(\'jquery-ui\'));\r\n' + + ' } else if (typeof define === \'function\' && define.amd) {\r\n' + + ' // AMD anonymous module with hard-coded dependency on \'knockout\'\r\n' + + ' define([\'jquery\', \'knockout\', \'jquery-ui\', \'exports\'], factory);\r\n' + + ' } else {\r\n' + + ' //