diff --git a/index.html b/index.html index 4d70fb545..dd5fec23b 100644 --- a/index.html +++ b/index.html @@ -41,7 +41,7 @@ Link used for inline installation of chrome desktop streaming extension, is updated automatically from the code with the value defined in config.js --> - +
diff --git a/libs/jquery-impromptu.js b/libs/jquery-impromptu.js index 6cc82bd16..f7f1e09cd 100644 --- a/libs/jquery-impromptu.js +++ b/libs/jquery-impromptu.js @@ -1,209 +1,51 @@ -/*! jQuery-Impromptu - v5.1.1 -* http://trentrichardson.com/Impromptu -* Copyright (c) 2013 Trent Richardson; Licensed MIT */ -(function($) { - "use strict"; +/*! jQuery-Impromptu - v6.0.0 - 2014-12-27 +* http://trentrichardson.com/Impromptu +* Copyright (c) 2014 Trent Richardson; Licensed MIT */ +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + define(['jquery'], factory); + } else { + factory(root.jQuery); + } +}(this, function($) { + 'use strict'; + + // ######################################################################## + // Base object + // ######################################################################## /** - * setDefaults - Sets the default options + * Imp - Impromptu object - passing no params will not open, only return the instance * @param message String/Object - String of html or Object of states * @param options Object - Options to set the prompt - * @return jQuery - container with overlay and prompt + * @return Imp - the instance of this Impromptu object */ - $.prompt = function(message, options) { - // only for backwards compat, to be removed in future version - if(options !== undefined && options.classes !== undefined && typeof options.classes === 'string'){ - options = { box: options.classes }; + var Imp = function(message, options){ + var t = this; + t.id = Imp.count++; + + Imp.lifo.push(t); + + if(message){ + t.open(message, options); } - - $.prompt.options = $.extend({},$.prompt.defaults,options); - $.prompt.currentPrefix = $.prompt.options.prefix; - - // Be sure any previous timeouts are destroyed - if($.prompt.timeout){ - clearTimeout($.prompt.timeout); - } - $.prompt.timeout = false; - - var opts = $.prompt.options, - $body = $(document.body), - $window = $(window); - - //build the box and fade - var msgbox = ''; - - $.prompt.jqib = $(msgbox).appendTo($body); - $.prompt.jqi = $.prompt.jqib.children('.'+ opts.prefix);//.data('jqi',opts); - $.prompt.jqif = $.prompt.jqib.children('.'+ opts.prefix +'fade'); - - //if a string was passed, convert to a single state - if(message.constructor === String){ - message = { - state0: { - title: opts.title, - html: message, - buttons: opts.buttons, - position: opts.position, - focus: opts.focus, - submit: opts.submit - } - }; - } - - //build the states - $.prompt.options.states = {}; - var k,v; - for(k in message){ - v = $.extend({},$.prompt.defaults.state,{name:k},message[k]); - $.prompt.addState(v.name, v); - - if($.prompt.currentStateName === ''){ - $.prompt.currentStateName = v.name; - } - } - - // Go ahead and transition to the first state. It won't be visible just yet though until we show the prompt - var $firstState = $.prompt.jqi.find('.'+ opts.prefix +'states .'+ opts.prefix +'state').eq(0); - $.prompt.goToState($firstState.data('jqi-name')); - - //Events - $.prompt.jqi.on('click', '.'+ opts.prefix +'buttons button', function(e){ - var $t = $(this), - $state = $t.parents('.'+ opts.prefix +'state'), - stateobj = $.prompt.options.states[$state.data('jqi-name')], - msg = $state.children('.'+ opts.prefix +'message'), - clicked = stateobj.buttons[$t.text()] || stateobj.buttons[$t.html()], - forminputs = {}; - - // if for some reason we couldn't get the value - if(clicked === undefined){ - for(var i in stateobj.buttons){ - if(stateobj.buttons[i].title === $t.text() || stateobj.buttons[i].title === $t.html()){ - clicked = stateobj.buttons[i].value; - } - } - } - - //collect all form element values from all states. - $.each($.prompt.jqi.children('form').serializeArray(),function(i,obj){ - if (forminputs[obj.name] === undefined) { - forminputs[obj.name] = obj.value; - } else if (typeof forminputs[obj.name] === Array || typeof forminputs[obj.name] === 'object') { - forminputs[obj.name].push(obj.value); - } else { - forminputs[obj.name] = [forminputs[obj.name],obj.value]; - } - }); - - // trigger an event - var promptsubmite = new $.Event('impromptu:submit'); - promptsubmite.stateName = stateobj.name; - promptsubmite.state = $state; - $state.trigger(promptsubmite, [clicked, msg, forminputs]); - - if(!promptsubmite.isDefaultPrevented()){ - $.prompt.close(true, clicked,msg,forminputs); - } - }); - - // if the fade is clicked blink the prompt - var fadeClicked = function(){ - if(opts.persistent){ - var offset = (opts.top.toString().indexOf('%') >= 0? ($window.height()*(parseInt(opts.top,10)/100)) : parseInt(opts.top,10)), - top = parseInt($.prompt.jqi.css('top').replace('px',''),10) - offset; - - //$window.scrollTop(top); - $('html,body').animate({ scrollTop: top }, 'fast', function(){ - var i = 0; - $.prompt.jqib.addClass(opts.prefix +'warning'); - var intervalid = setInterval(function(){ - $.prompt.jqib.toggleClass(opts.prefix +'warning'); - if(i++ > 1){ - clearInterval(intervalid); - $.prompt.jqib.removeClass(opts.prefix +'warning'); - } - }, 100); - }); - } - else { - $.prompt.close(true); - } - }; - - // listen for esc or tab keys - var keyPressEventHandler = function(e){ - var key = (window.event) ? event.keyCode : e.keyCode; - - //escape key closes - if(key===27) { - fadeClicked(); - } - - //constrain tabs, tabs should iterate through the state and not leave - if (key === 9){ - var $inputels = $('input,select,textarea,button',$.prompt.getCurrentState()); - var fwd = !e.shiftKey && e.target === $inputels[$inputels.length-1]; - var back = e.shiftKey && e.target === $inputels[0]; - if (fwd || back) { - setTimeout(function(){ - if (!$inputels){ - return; - } - var el = $inputels[back===true ? $inputels.length-1 : 0]; - - if (el){ - el.focus(); - } - },10); - return false; - } - } - }; - - $.prompt.position(); - $.prompt.style(); - - $.prompt.jqif.click(fadeClicked); - $window.resize({animate:false}, $.prompt.position); - $.prompt.jqi.find('.'+ opts.prefix +'close').click($.prompt.close); - $.prompt.jqib.on("keydown",keyPressEventHandler) - .on('impromptu:loaded', opts.loaded) - .on('impromptu:close', opts.close) - .on('impromptu:statechanging', opts.statechanging) - .on('impromptu:statechanged', opts.statechanged); - - // Show it - $.prompt.jqif[opts.show](opts.overlayspeed); - $.prompt.jqi[opts.show](opts.promptspeed, function(){ - $.prompt.jqib.trigger('impromptu:loaded'); - }); - - // Timeout - if(opts.timeout > 0){ - $.prompt.timeout = setTimeout(function(){ $.prompt.close(true); },opts.timeout); - } - - return $.prompt.jqib; + return t; }; - - $.prompt.defaults = { + + // ######################################################################## + // static properties and methods + // ######################################################################## + + /** + * defaults - the default options + */ + Imp.defaults = { prefix:'jqi', classes: { box: '', fade: '', prompt: '', + form: '', close: '', title: '', message: '', @@ -226,13 +68,14 @@ overlayspeed: 'slow', promptspeed: 'fast', show: 'fadeIn', + hide: 'fadeOut', focus: 0, defaultButton: 0, useiframe: false, top: '15%', - position: { - container: null, - x: null, + position: { + container: null, + x: null, y: null, arrow: null, width: null @@ -249,9 +92,9 @@ }, focus: 0, defaultButton: 0, - position: { - container: null, - x: null, + position: { + container: null, + x: null, y: null, arrow: null, width: null @@ -261,393 +104,741 @@ } } }; - - /** - * currentPrefix String - At any time this show be the prefix - * of the current prompt ex: "jqi" - */ - $.prompt.currentPrefix = $.prompt.defaults.prefix; - - /** - * currentStateName String - At any time this is the current state - * of the current prompt ex: "state0" - */ - $.prompt.currentStateName = ""; - + /** * setDefaults - Sets the default options * @param o Object - Options to set as defaults * @return void */ - $.prompt.setDefaults = function(o) { - $.prompt.defaults = $.extend({}, $.prompt.defaults, o); + Imp.setDefaults = function(o) { + Imp.defaults = $.extend({}, Imp.defaults, o); }; - + /** * setStateDefaults - Sets the default options for a state * @param o Object - Options to set as defaults * @return void */ - $.prompt.setStateDefaults = function(o) { - $.prompt.defaults.state = $.extend({}, $.prompt.defaults.state, o); + Imp.setStateDefaults = function(o) { + Imp.defaults.state = $.extend({}, Imp.defaults.state, o); }; /** - * position - Repositions the prompt (Used internally) - * @return void + * @var Int - A counter used to provide a unique ID for new prompts */ - $.prompt.position = function(e){ - var restoreFx = $.fx.off, - $state = $.prompt.getCurrentState(), - stateObj = $.prompt.options.states[$state.data('jqi-name')], - pos = stateObj? stateObj.position : undefined, - $window = $(window), - bodyHeight = document.body.scrollHeight, //$(document.body).outerHeight(true), - windowHeight = $(window).height(), - documentHeight = $(document).height(), - height = bodyHeight > windowHeight ? bodyHeight : windowHeight, - top = parseInt($window.scrollTop(),10) + ($.prompt.options.top.toString().indexOf('%') >= 0? - (windowHeight*(parseInt($.prompt.options.top,10)/100)) : parseInt($.prompt.options.top,10)); + Imp.count = 0; - // when resizing the window turn off animation - if(e !== undefined && e.data.animate === false){ - $.fx.off = true; - } - - $.prompt.jqib.css({ - position: "absolute", - height: height, - width: "100%", - top: 0, - left: 0, - right: 0, - bottom: 0 - }); - $.prompt.jqif.css({ - position: "fixed", - height: height, - width: "100%", - top: 0, - left: 0, - right: 0, - bottom: 0 - }); + /** + * @var Array - An array of Impromptu intances in a LIFO queue (last in first out) + */ + Imp.lifo = []; - // tour positioning - if(pos && pos.container){ - var offset = $(pos.container).offset(); - - if($.isPlainObject(offset) && offset.top !== undefined){ - $.prompt.jqi.css({ - position: "absolute" - }); - $.prompt.jqi.animate({ - top: offset.top + pos.y, - left: offset.left + pos.x, - marginLeft: 0, - width: (pos.width !== undefined)? pos.width : null - }); - top = (offset.top + pos.y) - ($.prompt.options.top.toString().indexOf('%') >= 0? (windowHeight*(parseInt($.prompt.options.top,10)/100)) : parseInt($.prompt.options.top,10)); - $('html,body').animate({ scrollTop: top }, 'slow', 'swing', function(){}); + /** + * getLast - get the last element from the queue (doesn't pop, just returns) + * @return Imp - the instance of this Impromptu object or false if queue is empty + */ + Imp.getLast = function(){ + var l = Imp.lifo.length; + return (l > 0)? Imp.lifo[l-1] : false; + }; + + /** + * removeFromStack - remove an element from the lifo stack by its id + * @param id int - id of the instance to remove + * @return api - The api of the element removed from the stack or void + */ + Imp.removeFromStack = function(id){ + for(var i=Imp.lifo.length-1; i>=0; i--){ + if(Imp.lifo[i].id === id){ + return Imp.lifo.splice(i,1)[0]; } } - // custom state width animation - else if(pos && pos.width){ - $.prompt.jqi.css({ - position: "absolute", - left: '50%' + }; + + // ######################################################################## + // extend our object instance properties and methods + // ######################################################################## + Imp.prototype = { + + /** + * @var Int - A unique id, simply an autoincremented number + */ + id: null, + + /** + * open - Opens the prompt + * @param message String/Object - String of html or Object of states + * @param options Object - Options to set the prompt + * @return Imp - the instance of this Impromptu object + */ + open: function(message, options) { + var t = this; + + t.options = $.extend({},Imp.defaults,options); + + // Be sure any previous timeouts are destroyed + if(t.timeout){ + clearTimeout(t.timeout); + } + t.timeout = false; + + var opts = t.options, + $body = $(document.body), + $window = $(window); + + //build the box and fade + var msgbox = '