/** * jGrowl 1.4.3 * * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses. * * Written by Stan Lemon * Last updated: 2015.02.01 */ (function($) { /** jGrowl Wrapper - Establish a base jGrowl Container for compatibility with older releases. **/ $.jGrowl = function( m , o ) { // To maintain compatibility with older version that only supported one instance we'll create the base container. if ( $('#jGrowl').length === 0 ) $('
').addClass( (o && o.position) ? o.position : $.jGrowl.defaults.position ).appendTo( (o && o.appendTo) ? o.appendTo : $.jGrowl.defaults.appendTo ); // Create a notification on the container. $('#jGrowl').jGrowl(m,o); }; /** Raise jGrowl Notification on a jGrowl Container **/ $.fn.jGrowl = function( m , o ) { // Short hand for passing in just an object to this method if ( o === undefined && $.isPlainObject(m) ) { o = m; m = o.message; } if ( $.isFunction(this.each) ) { var args = arguments; return this.each(function() { /** Create a jGrowl Instance on the Container if it does not exist **/ if ( $(this).data('jGrowl.instance') === undefined ) { $(this).data('jGrowl.instance', $.extend( new $.fn.jGrowl(), { notifications: [], element: null, interval: null } )); $(this).data('jGrowl.instance').startup( this ); } /** Optionally call jGrowl instance methods, or just raise a normal notification **/ if ( $.isFunction($(this).data('jGrowl.instance')[m]) ) { $(this).data('jGrowl.instance')[m].apply( $(this).data('jGrowl.instance') , $.makeArray(args).slice(1) ); } else { $(this).data('jGrowl.instance').create( m , o ); } }); } }; $.extend( $.fn.jGrowl.prototype , { /** Default JGrowl Settings **/ defaults: { pool: 0, header: '', group: '', sticky: false, position: 'top-right', appendTo: 'body', glue: 'after', theme: 'default', themeState: 'highlight', corners: '10px', check: 250, life: 3000, closeDuration: 'normal', openDuration: 'normal', easing: 'swing', closer: true, closeTemplate: '×', closerTemplate: '
[ close all ]
', log: function() {}, beforeOpen: function() {}, afterOpen: function() {}, open: function() {}, beforeClose: function() {}, close: function() {}, click: function() {}, animateOpen: { opacity: 'show' }, animateClose: { opacity: 'hide' } }, notifications: [], /** jGrowl Container Node **/ element: null, /** Interval Function **/ interval: null, /** Create a Notification **/ create: function( message , options ) { var o = $.extend({}, this.defaults, options); /* To keep backward compatibility with 1.24 and earlier, honor 'speed' if the user has set it */ if (typeof o.speed !== 'undefined') { o.openDuration = o.speed; o.closeDuration = o.speed; } this.notifications.push({ message: message , options: o }); o.log.apply( this.element , [this.element,message,o] ); }, render: function( n ) { var self = this; var message = n.message; var o = n.options; // Support for jQuery theme-states, if this is not used it displays a widget header o.themeState = (o.themeState === '') ? '' : 'ui-state-' + o.themeState; var notification = $('
') .addClass('jGrowl-notification alert ' + o.themeState + ' ui-corner-all' + ((o.group !== undefined && o.group !== '') ? ' ' + o.group : '')) .append($(''; } state += '
'; $state = $(state).css({display:'none'}); $state.on('impromptu:submit', stateobj.submit); if(afterState !== undefined){ t.getState(afterState).after($state); } else{ $jqistates.append($state); } t.options.states[statename] = stateobj; return $state; }, /** * removeState - Removes a state from the prompt * @param state String - Name of the state * @param newState String - Name of the state to transition to * @return Boolean - returns true on success, false on failure */ removeState: function(state, newState) { var t = this, $state = t.getState(state), rm = function(){ $state.remove(); }; if($state.length === 0){ return false; } // transition away from it before deleting if($state.css('display') !== 'none'){ if(newState !== undefined && t.getState(newState).length > 0){ t.goToState(newState, false, rm); } else if($state.next().length > 0){ t.nextState(rm); } else if($state.prev().length > 0){ t.prevState(rm); } else{ t.close(); } } else{ $state.slideUp('slow', rm); } return true; }, /** * getApi - Get the api, so you can extract it from $.prompt stack * @return jQuery - the prompt */ getApi: function() { return this; }, /** * getBox - Get the box containing fade and prompt * @return jQuery - the prompt */ getBox: function() { return this.jqib; }, /** * getPrompt - Get the prompt * @return jQuery - the prompt */ getPrompt: function() { return this.jqi; }, /** * getState - Get the state by its name * @param statename String - Name of the state * @return jQuery - the state */ getState: function(statename) { return this.jqi.find('[data-jqi-name="'+ statename +'"]'); }, /** * getCurrentState - Get the current visible state * @return jQuery - the current visible state */ getCurrentState: function() { return this.getState(this.getCurrentStateName()); }, /** * getCurrentStateName - Get the name of the current visible state/substate * @return String - the current visible state's name */ getCurrentStateName: function() { return this.currentStateName; }, /** * disableStateButtons - Disables the buttons in a state * @param statename String - Name of the state containing buttons * @param buttons Array - Array of button values to disable. By default all are disabled * @param enable Boolean - True to enable the buttons instead of disabling (internally use only) * @return Void */ disableStateButtons: function(statename, buttons, enable) { var t = this; if($.isArray(statename)){ buttons = statename; statename = null; } t.getState(statename || t.getCurrentStateName()).find('.'+ t.options.prefix + 'button').each(function(i,btn){ if(buttons === undefined || $.inArray(btn.value, buttons) !== -1){ btn.disabled = !enable; } }); }, /** * enableStateButtons - Enables the buttons in a state * @param statename String - Name of the state containing buttons. Defaults to current state * @param buttons Array - Array of button values to enable. By default all are enabled * @return Void */ enableStateButtons: function(statename, buttons) { this.disableStateButtons(statename, buttons, true); }, /** * position - Repositions the prompt (Used internally) * @return void */ position: function(e){ var t = this, restoreFx = $.fx.off, $state = t.getCurrentState(), stateObj = t.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, scrollTop = parseInt($window.scrollTop(),10), top = scrollTop + (t.options.top.toString().indexOf('%') >= 0? (windowHeight*(parseInt(t.options.top,10)/100)) : parseInt(t.options.top,10)); // when resizing the window turn off animation if(e !== undefined && e.data.animate === false){ $.fx.off = true; } t.jqib.css({ position: "absolute", height: height, width: "100%", top: 0, left: 0, right: 0, bottom: 0 }); t.jqif.css({ position: "fixed", height: height, width: "100%", top: 0, left: 0, right: 0, bottom: 0 }); // tour positioning if(pos && pos.container){ var offset = $(pos.container).offset(), hasScrolled = false; if($.isPlainObject(offset) && offset.top !== undefined){ top = (offset.top + pos.y) - (t.options.top.toString().indexOf('%') >= 0? (windowHeight*(parseInt(t.options.top,10)/100)) : parseInt(t.options.top,10)); t.jqi.css({ position: "absolute" }); t.jqi.animate({ top: offset.top + pos.y, left: offset.left + pos.x, marginLeft: 0, width: (pos.width !== undefined)? pos.width : null }, function(){ // if it didn't scroll before, check that the bottom is within view. Since width // is animated we must use the callback before we know the height if(!hasScrolled && (offset.top + pos.y + t.jqi.outerHeight(true)) > (scrollTop + windowHeight)){ $('html,body').animate({ scrollTop: top }, 'slow', 'swing', function(){}); hasScrolled = true; } }); // scroll if the top is out of the viewing area if(top < scrollTop || top > scrollTop + windowHeight){ $('html,body').animate({ scrollTop: top }, 'slow', 'swing', function(){}); hasScrolled = true; } } } // custom state width animation else if(pos && pos.width){ t.jqi.css({ position: "absolute", left: '50%' }); t.jqi.animate({ top: pos.y || top, left: pos.x || '50%', marginLeft: ((pos.width/2)*-1), width: pos.width }); } // standard prompt positioning else{ t.jqi.css({ position: "absolute", top: top, left: '50%',//$window.width()/2, marginLeft: ((t.jqi.outerWidth(false)/2)*-1) }); } // restore fx settings if(e !== undefined && e.data.animate === false){ $.fx.off = restoreFx; } }, /** * style - Restyles the prompt (Used internally) * @return void */ style: function(){ var t = this; t.jqif.css({ zIndex: t.options.zIndex, display: "none", opacity: t.options.opacity }); t.jqi.css({ zIndex: t.options.zIndex+1, display: "none" }); t.jqib.css({ zIndex: t.options.zIndex }); }, /** * goToState - Goto the specified state * @param state String - name of the state to transition to * @param subState Boolean - true to be a sub state within the currently open state * @param callback Function - called when the transition is complete * @return jQuery - the newly active state */ goToState: function(state, subState, callback) { var t = this, $jqi = t.jqi, jqiopts = t.options, $state = t.getState(state), stateobj = jqiopts.states[$state.data('jqi-name')], promptstatechanginge = new $.Event('impromptu:statechanging'), opts = t.options; if(stateobj !== undefined){ if (typeof stateobj.html === 'function') { var contentLaterFunc = stateobj.html; $state.find('.' + opts.prefix +'message ').html(contentLaterFunc()); } // subState can be ommitted if(typeof subState === 'function'){ callback = subState; subState = false; } t.jqib.trigger(promptstatechanginge, [t.getCurrentStateName(), state]); if(!promptstatechanginge.isDefaultPrevented() && $state.length > 0){ t.jqi.find('.'+ opts.prefix +'parentstate').removeClass(opts.prefix +'parentstate'); if(subState){ // hide any open substates // get rid of any substates t.jqi.find('.'+ opts.prefix +'substate').not($state) .slideUp(jqiopts.promptspeed) .removeClass('.'+ opts.prefix +'substate') .find('.'+ opts.prefix +'arrow').hide(); // add parent state class so it can be visible, but blocked t.jqi.find('.'+ opts.prefix +'state:visible').addClass(opts.prefix +'parentstate'); // add substate class so we know it will be smaller $state.addClass(opts.prefix +'substate'); } else{ // hide any open states t.jqi.find('.'+ opts.prefix +'state').not($state) .slideUp(jqiopts.promptspeed) .find('.'+ opts.prefix +'arrow').hide(); } t.currentStateName = stateobj.name; $state.slideDown(jqiopts.promptspeed,function(){ var $t = $(this); t.enableStateButtons(); // if focus is a selector, find it, else its button index if(typeof(stateobj.focus) === 'string'){ $t.find(stateobj.focus).eq(0).focus(); } else{ $t.find('.'+ opts.prefix +'defaultbutton').focus(); } $t.find('.'+ opts.prefix +'arrow').show(jqiopts.promptspeed); if (typeof callback === 'function'){ t.jqib.on('impromptu:statechanged', callback); } t.jqib.trigger('impromptu:statechanged', [state]); if (typeof callback === 'function'){ t.jqib.off('impromptu:statechanged', callback); } }); if(!subState){ t.position(); } } // end isDefaultPrevented() }// end stateobj !== undefined return $state; }, /** * nextState - Transition to the next state * @param callback Function - called when the transition is complete * @return jQuery - the newly active state */ nextState: function(callback) { var t = this, $next = t.getCurrentState().next(); if($next.length > 0){ t.goToState( $next.data('jqi-name'), callback ); } return $next; }, /** * prevState - Transition to the previous state * @param callback Function - called when the transition is complete * @return jQuery - the newly active state */ prevState: function(callback) { var t = this, $prev = t.getCurrentState().prev(); if($prev.length > 0){ t.goToState( $prev.data('jqi-name'), callback ); } return $prev; } }; // ######################################################################## // $.prompt will manage a queue of Impromptu instances // ######################################################################## /** * $.prompt create a new Impromptu instance and push it on the stack of instances * @param message String/Object - String of html or Object of states * @param options Object - Options to set the prompt * @return jQuery - the jQuery object of the prompt within the modal */ $.prompt = function(message, options){ var api = new Imp(message, options); return api.jqi; }; /** * Copy over static methods */ $.each(Imp, function(k,v){ $.prompt[k] = v; }); /** * Create a proxy for accessing all instance methods. The close method pops from queue. */ $.each(Imp.prototype, function(k,v){ $.prompt[k] = function(){ var api = Imp.getLast(); // always use the last instance on the stack if(api && typeof api[k] === "function"){ return api[k].apply(api, arguments); } }; }); // ######################################################################## // jQuery Plugin and public access // ######################################################################## /** * Enable using $('.selector').prompt({}); * This will grab the html within the prompt as the prompt message */ $.fn.prompt = function(options){ if(options === undefined){ options = {}; } if(options.withDataAndEvents === undefined){ options.withDataAndEvents = false; } $.prompt($(this).clone(options.withDataAndEvents).html(),options); }; /** * Export it as Impromptu and $.prompt * Can be used from here forth as new Impromptu(states, opts) */ window.Impromptu = Imp; })); /*! * jQuery Cookie Plugin v1.4.1 * https://github.com/carhartl/jquery-cookie * * Copyright 2013 Klaus Hartl * Released under the MIT license */ (function (factory) { if (typeof define === 'function' && define.amd) { // AMD define(['jquery'], factory); } else if (typeof exports === 'object') { // CommonJS factory(require('jquery')); } else { // Browser globals factory(jQuery); } }(function ($) { var pluses = /\+/g; function encode(s) { return config.raw ? s : encodeURIComponent(s); } function decode(s) { return config.raw ? s : decodeURIComponent(s); } function stringifyCookieValue(value) { return encode(config.json ? JSON.stringify(value) : String(value)); } function parseCookieValue(s) { if (s.indexOf('"') === 0) { // This is a quoted cookie as according to RFC2068, unescape... s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\'); } try { // Replace server-side written pluses with spaces. // If we can't decode the cookie, ignore it, it's unusable. // If we can't parse the cookie, ignore it, it's unusable. s = decodeURIComponent(s.replace(pluses, ' ')); return config.json ? JSON.parse(s) : s; } catch(e) {} } function read(s, converter) { var value = config.raw ? s : parseCookieValue(s); return $.isFunction(converter) ? converter(value) : value; } var config = $.cookie = function (key, value, options) { // Write if (value !== undefined && !$.isFunction(value)) { options = $.extend({}, config.defaults, options); if (typeof options.expires === 'number') { var days = options.expires, t = options.expires = new Date(); t.setTime(+t + days * 864e+5); } return (document.cookie = [ encode(key), '=', stringifyCookieValue(value), options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE options.path ? '; path=' + options.path : '', options.domain ? '; domain=' + options.domain : '', options.secure ? '; secure' : '' ].join('')); } // Read var result = key ? undefined : {}; // To prevent the for loop in the first place assign an empty array // in case there are no cookies at all. Also prevents odd result when // calling $.cookie(). var cookies = document.cookie ? document.cookie.split('; ') : []; for (var i = 0, l = cookies.length; i < l; i++) { var parts = cookies[i].split('='); var name = decode(parts.shift()); var cookie = parts.join('='); if (key && key === name) { // If second argument (value) is a function it's a converter... result = read(cookie, value); break; } // Prevent storing a cookie that we couldn't decode. if (!key && (cookie = read(cookie)) !== undefined) { result[name] = cookie; } } return result; }; config.defaults = {}; $.removeCookie = function (key, options) { if ($.cookie(key) === undefined) { return false; } // Must not alter options, thus extending a fresh object... $.cookie(key, '', $.extend({}, options, { expires: -1 })); return !$.cookie(key); }; }));