From 1345357a5ed55ab660e581df0c013cfe3301b0be Mon Sep 17 00:00:00 2001 From: jcass Date: Sun, 3 Apr 2016 16:06:25 +0200 Subject: [PATCH] Modularise and test setting of jQuery Mobile config options. --- .../static/js/custom_scripting.js | 29 ++++++++++++++---- mopidy_musicbox_webclient/static/mb.appcache | 2 +- tests/js/test_custom_scripting.js | 30 +++++++++++++++++++ 3 files changed, 54 insertions(+), 7 deletions(-) create mode 100644 tests/js/test_custom_scripting.js diff --git a/mopidy_musicbox_webclient/static/js/custom_scripting.js b/mopidy_musicbox_webclient/static/js/custom_scripting.js index 2b544b6..f8b6ca1 100644 --- a/mopidy_musicbox_webclient/static/js/custom_scripting.js +++ b/mopidy_musicbox_webclient/static/js/custom_scripting.js @@ -1,8 +1,25 @@ // jQuery Mobile configuration options // see: http://api.jquerymobile.com/1.3/global-config/ -$(document).bind('mobileinit', function () { - $.extend($.mobile, { - ajaxEnabled: false, - hashListeningEnabled: false - }) -}) +(function (root, factory) { + if (typeof define === 'function' && define.amd) { + define([], factory) + } else if (typeof module === 'object' && module.exports) { + module.exports = factory() + } else { + root.configureJQueryMobile = factory() + } +}(this, function () { + 'use strict' + + function configureJQueryMobile () { + $.extend($.mobile, { + ajaxEnabled: false, + hashListeningEnabled: false + }) + } + + $(document).bind('mobileinit', configureJQueryMobile) + + return configureJQueryMobile +})) + diff --git a/mopidy_musicbox_webclient/static/mb.appcache b/mopidy_musicbox_webclient/static/mb.appcache index 246f924..f21d33f 100644 --- a/mopidy_musicbox_webclient/static/mb.appcache +++ b/mopidy_musicbox_webclient/static/mb.appcache @@ -1,6 +1,6 @@ CACHE MANIFEST -# 2016-04-03:v1 +# 2016-04-03:v2 NETWORK: * diff --git a/tests/js/test_custom_scripting.js b/tests/js/test_custom_scripting.js new file mode 100644 index 0000000..5b3e171 --- /dev/null +++ b/tests/js/test_custom_scripting.js @@ -0,0 +1,30 @@ +var chai = require('chai') +var expect = chai.expect +var assert = chai.assert +chai.use(require('chai-string')) +chai.use(require('chai-jquery')) + +var sinon = require('sinon') + +var configureJQueryMobile = require('../../mopidy_musicbox_webclient/static/js/custom_scripting.js') + +describe('jQuery Defaults', function () { + it('should disable ajax and hashListening', function () { + expect($.mobile.ajaxEnabled).to.be.true + expect($.mobile.hashListeningEnabled).to.be.true + + configureJQueryMobile() + expect($.mobile.ajaxEnabled).to.be.false + expect($.mobile.hashListeningEnabled).to.be.false + }) + + it('should bind to "mobileinit"', function () { + var configSpy = sinon.spy(configureJQueryMobile) + + $(document).bind('mobileinit', configSpy) + expect(configSpy.called).to.be.false + $(document).trigger('mobileinit') + expect(configSpy.called).to.be.true + configSpy.reset() + }) +})