You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
3 lines
8.9 KiB
3 lines
8.9 KiB
/*! dialogs-manager v4.1.0 | (c) Kobi Zaltzberg | https://github.com/kobizz/dialogs-manager/blob/master/LICENSE.txt
|
|
2018-01-02 13:00 */
|
|
!function(a,b){"use strict";var c={widgetsTypes:{},createWidgetType:function(b,d,e){e||(e=this.Widget);var f=function(){e.apply(this,arguments)},g=f.prototype=new e(b);return g.types=g.types.concat([b]),a.extend(g,d),g.constructor=f,f.extend=function(a,b){return c.createWidgetType(a,b,f)},f},addWidgetType:function(a,b,c){return b&&b.prototype instanceof this.Widget?this.widgetsTypes[a]=b:this.widgetsTypes[a]=this.createWidgetType(a,b,c)},getWidgetType:function(a){return this.widgetsTypes[a]}};c.Instance=function(){var b=this,d={},e={},f=function(){d.body=a("body")},g=function(b){var c={classPrefix:"dialog",effects:{show:"fadeIn",hide:"fadeOut"}};a.extend(e,c,b)};this.createWidget=function(a,d){var e=c.getWidgetType(a),f=new e(a);return d=d||{},f.init(b,d),f.setMessage(d.message),f},this.getSettings=function(a){return a?e[a]:Object.create(e)},this.init=function(a){return g(a),f(),b},b.init()},c.Widget=function(b){var d=this,e={},f={},g={},h=0,i=["refreshPosition"],j=function(){g.window.on("keyup",s),e.hide.onOutsideClick&&g.window[0].addEventListener("click",r,!0),(e.hide.onClick||e.hide.onBackgroundClick)&&g.widget.on("click",q),e.position.autoRefresh&&g.window.on("resize",d.refreshPosition)},k=function(b,c){var d=e.effects[b],f=g.widget;if(a.isFunction(d))d.apply(f,c);else{if(!f[d])throw"Reference Error: The effect "+d+" not found";f[d].apply(f,c)}},l=function(){var b=i.concat(d.getClosureMethods());a.each(b,function(){var a=this,b=d[a];d[a]=function(){b.apply(d,arguments)}})},m=function(){d.addElement("widget"),d.addElement("message"),d.addElement("window",window),d.addElement("container",e.container);var b=d.getSettings("id");b&&d.setID(b);var c=[];a.each(d.types,function(){c.push(e.classes.globalPrefix+"-type-"+this)}),c.push(d.getSettings("className")),d.getElements("widget").addClass(c.join(" "))},n=function(c,f){var g=a.extend(!0,{},c.getSettings());e={effects:g.effects,classes:{globalPrefix:g.classPrefix,prefix:g.classPrefix+"-"+b},selectors:{preventClose:"."+g.classPrefix+"-prevent-close"},container:"body",position:{element:"widget",my:"center",at:"center",of:"container",enable:!0,autoRefresh:!1},hide:{auto:!1,autoDelay:5e3,onClick:!1,onOutsideClick:!0,onBackgroundClick:!0}},a.extend(!0,e,d.getDefaultSettings(),f),o()},o=function(){a.each(e,function(a){var b=a.match(/^on([A-Z].*)/);b&&(b=b[1].charAt(0).toLowerCase()+b[1].slice(1),d.on(b,this))})},p=function(a){return a.replace(/([a-z])([A-Z])/g,function(){return arguments[1]+"-"+arguments[2].toLowerCase()})},q=function(b){if(e.hide.onClick){if(a(b.target).closest(e.selectors.preventClose).length)return}else if(b.target!==this)return;d.hide()},r=function(b){a(b.target).closest(g.widget).length||d.hide()},s=function(a){var b=27,c=a.which;b===c&&d.hide()},t=function(){g.window.off("keyup",s),e.hide.onOutsideClick&&g.window[0].removeEventListener("click",r,!0),(e.hide.onClick||e.hide.onBackgroundClick)&&g.widget.off("click",q),e.position.autoRefresh&&g.window.off("resize",d.refreshPosition)};this.addElement=function(b,c,d){var f=g[b]=a(c||"<div>"),h=p(b),i=[];return d&&i.push(e.classes.globalPrefix+"-"+d),i.push(e.classes.globalPrefix+"-"+h),i.push(e.classes.prefix+"-"+h),f.addClass(i.join(" ")),f},this.getSettings=function(a){var b=Object.create(e);return a?b[a]:b},this.init=function(a,b){if(!(a instanceof c.Instance))throw"The "+d.widgetName+" must to be initialized from an instance of DialogsManager.Instance";return l(),d.trigger("init",b),n(a,b),m(),d.buildWidget(),d.attachEvents&&d.attachEvents(),d.trigger("ready"),d},this.getElements=function(a){return a?g[a]:g},this.hide=function(){return clearTimeout(h),k("hide",arguments),t(),d.trigger("hide"),d},this.on=function(b,c){if("object"==typeof b)return a.each(b,function(a){d.on(a,this)}),d;var e=b.split(" ");return e.forEach(function(a){f[a]||(f[a]=[]),f[a].push(c)}),d},this.setMessage=function(a){return g.message.html(a),d},this.setID=function(a){return d.getElements("widget").attr("id",a),d},this.setSettings=function(b,c){return"object"==typeof c?a.extend(!0,e[b],c):e[b]=c,d},this.show=function(){return g.widget.appendTo(g.container).hide(),k("show",arguments),d.refreshPosition(),e.hide.auto&&(h=setTimeout(d.hide,e.hide.autoDelay)),j(),d.trigger("show"),d},this.refreshPosition=function(){if(e.position.enable){var b=a.extend({},e.position);g[b.of]&&(b.of=g[b.of]),g[b.element].position(b)}},this.trigger=function(b,c){var e="on"+b[0].toUpperCase()+b.slice(1);d[e]&&d[e](c);var g=f[b];if(g)return a.each(g,function(a,b){b.call(d,c)}),d},this.destroy=function(){return t(),g.widget.remove(),d.trigger("destroy"),d}},c.Widget.prototype.types=[],c.Widget.prototype.buildWidget=function(){var a=this.getElements();a.widget.html(a.message)},c.Widget.prototype.getDefaultSettings=function(){return{}},c.Widget.prototype.getClosureMethods=function(){return[]},c.Widget.prototype.onHide=function(){},c.Widget.prototype.onShow=function(){},c.Widget.prototype.onInit=function(){},c.Widget.prototype.onReady=function(){},c.widgetsTypes.simple=c.Widget,c.addWidgetType("buttons",{activeKeyUp:function(a){var b=9;a.which===b&&a.preventDefault(),this.hotKeys[a.which]&&this.hotKeys[a.which](this)},activeKeyDown:function(a){var b=9;if(a.which===b){a.preventDefault();var c,d=this.focusedButton.index();a.shiftKey?(c=d-1,c<0&&(c=this.buttons.length-1)):(c=d+1,c>=this.buttons.length&&(c=0)),this.focusedButton=this.buttons[c].focus()}},addButton:function(b){var c=this,d=c.addElement(b.name,a("<"+this.getSettings("buttonTag")+">").text(b.text),"button");c.buttons.push(d);var e=function(){c.getSettings("hide").onButtonClick&&c.hide(),a.isFunction(b.callback)&&b.callback.call(this,c)};return d.on("click",e),b.hotKey&&(this.hotKeys[b.hotKey]=e),this.getElements("buttonsWrapper").append(d),b.focus&&(this.focusedButton=d),c},bindHotKeys:function(){this.getElements("window").on({keyup:this.activeKeyUp,keydown:this.activeKeyDown})},buildWidget:function(){c.Widget.prototype.buildWidget.apply(this,arguments);var a=this.addElement("buttonsWrapper");this.getElements("widget").append(a)},getClosureMethods:function(){return["activeKeyUp","activeKeyDown"]},getDefaultSettings:function(){return{hide:{onButtonClick:!0},buttonTag:"button"}},onHide:function(){this.unbindHotKeys()},onInit:function(){this.buttons=[],this.hotKeys={},this.focusedButton=null},onShow:function(){this.bindHotKeys(),this.focusedButton||(this.focusedButton=this.buttons[0]),this.focusedButton&&this.focusedButton.focus()},unbindHotKeys:function(){this.getElements("window").off({keyup:this.activeKeyUp,keydown:this.activeKeyDown})}}),c.addWidgetType("lightbox",c.getWidgetType("buttons").extend("lightbox",{getDefaultSettings:function(){var b=c.getWidgetType("buttons").prototype.getDefaultSettings.apply(this,arguments);return a.extend(!0,b,{headerMessage:"",contentWidth:"auto",contentHeight:"auto",closeButton:!1,closeButtonClass:"fa fa-times",position:{element:"widgetContent",of:"widget",autoRefresh:!0}})},buildWidget:function(){c.getWidgetType("buttons").prototype.buildWidget.apply(this,arguments);var a=this.addElement("widgetHeader"),b=this.addElement("widgetContent"),d=this.getElements();if(b.append(a,d.message,d.buttonsWrapper),d.widget.html(b),this.getSettings("closeButton")){var e=this.addElement("closeButton",'<div><i class="'+this.getSettings("closeButtonClass")+'"></i></div>');b.prepend(e)}},attachEvents:function(){this.getSettings("closeButton")&&this.getElements("closeButton").on("click",this.hide)},onReady:function(){var a=this.getElements(),b=this.getSettings();"auto"!==b.contentWidth&&a.message.width(b.contentWidth),"auto"!==b.contentHeight&&a.message.height(b.contentHeight),this.setHeaderMessage(b.headerMessage)},setHeaderMessage:function(a){return this.getElements("widgetHeader").html(a),this}})),c.addWidgetType("confirm",c.getWidgetType("lightbox").extend("confirm",{onReady:function(){c.getWidgetType("lightbox").prototype.onReady.apply(this,arguments);var a=this.getSettings("strings"),b="cancel"===this.getSettings("defaultOption");this.addButton({name:"cancel",text:a.cancel,callback:function(a){a.trigger("cancel")},focus:b}),this.addButton({name:"ok",text:a.confirm,callback:function(a){a.trigger("confirm")},focus:!b})},getDefaultSettings:function(){var a=c.getWidgetType("lightbox").prototype.getDefaultSettings.apply(this,arguments);return a.strings={confirm:"OK",cancel:"Cancel"},a.defaultOption="cancel",a}})),c.addWidgetType("alert",c.getWidgetType("lightbox").extend("alert",{onReady:function(){c.getWidgetType("lightbox").prototype.onReady.apply(this,arguments);var a=this.getSettings("strings");this.addButton({name:"ok",text:a.confirm,callback:function(a){a.trigger("confirm")}})},getDefaultSettings:function(){var a=c.getWidgetType("lightbox").prototype.getDefaultSettings.apply(this,arguments);return a.strings={confirm:"OK"},a}})),b.DialogsManager=c}("function"==typeof require?require("jquery"):jQuery,"undefined"!=typeof module?module.exports:window); |