diff --git a/lobibox/lobibox-tests.ts b/lobibox/lobibox-tests.ts new file mode 100644 index 000000000..78637114a --- /dev/null +++ b/lobibox/lobibox-tests.ts @@ -0,0 +1,144 @@ +/** + * Created by itboy on 11/22/2015. + */ + /// + /// + + + //Run test : LobiboxTest.test() after window load event +class LobiboxTest { + static test() { + // extending default parameters + Lobibox.notify.DEFAULTS = $.extend({}, Lobibox.notify.DEFAULTS, { + //override any options from default options + delay: false, + soundPath: '/libraries/lobibox/sounds/', + size: 'mini' + }); + +// notify + Lobibox.notify("error", {msg: "Hello world"}); + Lobibox.notify("success", {msg: "Hello world"}); + Lobibox.notify("warning", {msg: "Hello world"}); + Lobibox.notify("info", {msg: "Hello world"}); + +// alert + Lobibox.alert("error", {msg: "Hello world"}); + Lobibox.alert("success", {msg: "Hello world"}); + Lobibox.alert("warning", {msg: "Hello world"}); + Lobibox.alert("info", {msg: "Hello world"}); + +//alert with more options + Lobibox.alert('error', { + msg: 'This is an error message', + //buttons: ['ok', 'cancel', 'yes', 'no'], + //Or more powerfull way + buttons: { + ok: { + 'class': 'btn btn-info', + closeOnClick: false + }, + cancel: { + 'class': 'btn btn-danger', + closeOnClick: false + }, + yes: { + 'class': 'btn btn-success', + closeOnClick: false + }, + no: { + 'class': 'btn btn-warning', + closeOnClick: false + }, + custom: { + 'class': 'btn btn-default', + text: 'Custom' + } + }, + callback: function (lobibox:any, type:string):any { + let btnType:string = ""; + if (type === 'no') { + btnType = 'warning'; + } else if (type === 'yes') { + btnType = 'success'; + } else if (type === 'ok') { + btnType = 'info'; + } else if (type === 'cancel') { + btnType = 'error'; + } + Lobibox.notify(btnType, { + size: 'mini', + msg: 'This is ' + btnType + ' message' + }); + } + }); + +// confirm + Lobibox.confirm({ + msg: "Are you ok", + }); + +// prompt + Lobibox.prompt("text", { + title: 'Please enter username', + //Attributes of + attrs: { + placeholder: "Username" + } + }); + +// progress + Lobibox.progress({ + title: 'Please wait', + label: 'Uploading files...', + onShow: function ($this:any):void { + var i = 0; + var inter = setInterval(function ():void { + window.console.log(i); + if (i > 100) { + clearInterval(inter); + } + i = i + 0.1; + $this.setProgress(i); + }, 10); + } + }); + +// window + Lobibox.window({ + title: 'Window title', + //Available types: string, jquery object, function + content: function ():any { + return $('.container'); + }, + url: 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.css', + autoload: false, + loadMethod: 'GET', + //Load parameters + params: { + param1: 'Lorem', + param2: 'Ipsum' + }, + buttons: { + load: { + text: 'Load from url' + }, + close: { + text: 'Close', + closeOnClick: true + } + }, + callback: function ($this:any, type:string, ev:any):void { + if (type === 'load') { + $this.load(function ():any { + //Do something when content is loaded + }); + } + } + }); + } +} + +window.onload = (): void => { + LobiboxTest.test(); +}; diff --git a/lobibox/lobibox.d.ts b/lobibox/lobibox.d.ts new file mode 100644 index 000000000..d8a7588d5 --- /dev/null +++ b/lobibox/lobibox.d.ts @@ -0,0 +1,197 @@ +// Type definitions for lobibox 1.0.1 +// Project: https://github.com/arboshiki/lobibox +// Definitions by: Sabeeh Ul Hussnain +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare var Lobibox: LobiboxModule.LobiboxStatic; +declare module "Lobibox" { + export = Lobibox; +} +declare module LobiboxModule { + interface MessageBoxesDefault { + title? : string; + horizontalOffset?: number; + width? : number; + height? : string; // Height is automatically given calculated by width + closeButton? : boolean; // Show close button or not + draggable? : boolean; // Make messagebox draggable + customBtnClass? : string; // Class for custom buttons + modal? : boolean; + debug? : boolean; + buttonsAlign? : string; // Position where buttons should be aligned + closeOnEsc? : boolean; // Close messagebox on Esc press + delayToRemove? : number; + baseClass? : string; + showClass? : string; + hideClass? : string; + msg? : string; + + // methods + hide? (): MessageBoxesDefault; + show? (): MessageBoxesDefault; + setWidth? (width?: number): MessageBoxesDefault; + setHeight? (height?: number): MessageBoxesDefault; + setSize? (width?: number, height?: number): MessageBoxesDefault; + setPosition? (left?: number|string, top?: number): MessageBoxesDefault; + setTitle? (title?: string): MessageBoxesDefault; + getTitle? (): string; + + // events + // when messagebox show is called but before it is actually shown + onShow? (lobibox:any): void ; + // after messagebox is shown + shown? (lobibox:any): void; + // when messagebox remove method is called but before it is actually hidden + beforeClose? (lobibox:any): void; + // after messagebox is hidden + closed? (lobibox:any): void; + } + + interface MessageBoxesOptions extends MessageBoxesDefault { + bodyClass? : string; + modalClasses? : { + 'error'? : string, + 'success'? : string, + 'info'? : string, + 'warning'? : string, + 'confirm'? : string, + 'progress'? : string, + 'prompt'? : string, + 'default'? : string, + 'window'? : string + }, + buttonsAlign?: any; + buttons?: { + ok?: { + 'class'?: string, + text?: string, + closeOnClick?: boolean + }, + cancel?: { + 'class'?: string, + text?: string, + closeOnClick?: boolean + }, + yes?: { + 'class'?: string, + text?: string, + closeOnClick?: boolean + }, + no?: { + 'class'?: string, + text?: string, + closeOnClick?: boolean + }, + }|any; + callback? (lobibox:any, type?:string, ev?: any): void; + } + interface ConfirmOptions extends MessageBoxesOptions { + title? : string; + width? : number; + iconClass? : string; + } + + interface PromptOptions extends MessageBoxesOptions, PromptMethods { + width?: number; + attrs?: any; // Object of any valid attribute of input field + value?: string; // Value which is given to textfield when messagebox is created + multiline?: boolean; // Set this true for multiline prompt + lines?: number; // This works only for multiline prompt. Number of lines + type?: string; // Prompt type. Available types (text|number|color) + label?: string; // Set some text which will be shown exactly on top of textfield + } + interface AlertOptions extends MessageBoxesOptions { + warning?: { + title?: string, + iconClass?: string // Change warning alert icon globally + }; + info?:{ + title?: string, + iconClass?: string // Change info alert icon globally + }; + success?: { + title?: string, + iconClass?: string // Change success alert icon globally + }; + error?: { + title?: string, + iconClass?: string // Change error alert icon globally + }; + } + interface ProgressOptions extends MessageBoxesOptions, ProgressMethods, ProgressEvents { + width? : number; + showProgressLabel? : boolean; // Show percentage of progress + label? : string; // Show progress label + progressTpl? : boolean; //Template of progress bar + + //Events + progressUpdated? : any; + progressCompleted? : any; + } + interface WindowOptions extends MessageBoxesOptions { + width? : number; + height? : any; + content? : any; // HTML Content of window + url? : string; // URL which will be used to load content + draggable? : boolean; // Override default option + autoload? : boolean; // Auto load from given url when window is created + loadMethod? : string; // Ajax method to load content + showAfterLoad? : boolean; // Show window after content is loaded or show and then load content + params? : {}; // Parameters which will be send by ajax for loading content + } + interface ProgressEvents { + progressUpdated? (lobibox:LobiboxStatic): void; + progressComplete? (lobibox:LobiboxStatic): void; + } + interface PromptMethods { + setValue? (val?:string): PromptMethods; + getValue? (): string; + } + interface ProgressMethods { + setProgress? (progress:number): ProgressMethods; + getProgress? (): number; + } + + interface NotifyDefault { + title?: boolean; // Title of notification. If you do not include the title in options it will automatically takes its value + //from Lobibox.notify.OPTIONS object depending of the type of the notifications or set custom string. Set this false to disable title + size?: string; // normal, mini, large + soundPath?: string; // The folder path where sounds are located + soundExt?: string; // Default extension for all sounds + showClass?: string; // Show animation class. + hideClass?: string; // Hide animation class. + icon?: boolean; // Icon of notification. Leave as is for default icon or set custom string + msg?: string; // Message of notification + img?: string; // Image source string + closable?: boolean; // Make notifications closable + delay?: number; // Hide notification after this time (in miliseconds) + delayIndicator?: boolean; // Show timer indicator + closeOnClick?: boolean; // Close notifications by clicking on them + width?: number; // Width of notification box + sound?: boolean; // Sound of notification. Set this false to disable sound. Leave as is for default sound or set custom soud path + position?: string; // Place to show notification. Available options: "top left", "top right", "bottom left", "bottom right" + } + interface NotifyOptions extends NotifyDefault, NotifyMethods { + 'class'?: string; //You can override options for large notifications from here + large?: {width?: number}; //You can override options for small notifications from here + mini?: {'class'?: string}; //Default options of different style notifications + success?: {'class'?: string, 'title'?: string,'icon'?: string,sound?: string}; + error?: {'class'?: string, 'title'?: string,'icon'?: string,sound?: string}; + warning?: {'class'?: string, 'title'?: string,'icon'?: string,sound?: string}; + info?: {'class'?: string, 'title'?: string,'icon'?: string,sound?: string}; + } + + interface NotifyMethods { + remove? (): any; + } + + interface LobiboxStatic { + base: {OPTIONS: MessageBoxesOptions, DEFAULTS: MessageBoxesDefault}; + alert: {(type: string, options?: T): LobiboxStatic, DEFAULTS: AlertOptions}; + prompt: {(type: string, options?: T): LobiboxStatic, DEFAULTS: PromptOptions}; + confirm: {(options?: ConfirmOptions): T, DEFAULTS: ConfirmOptions}; + progress: {(options: ProgressOptions): T, DEFAULTS: ProgressOptions}; + window: {(options: WindowOptions): T, DEFAULTS: WindowOptions}; + notify: {(type: string, options?: NotifyOptions): T, DEFAULTS?: NotifyDefault,OPTIONS?:NotifyOptions}; + } +}