Last active
August 29, 2015 14:03
-
-
Save kanreisa/77bd26bd5e5ae0f02855 to your computer and use it in GitHub Desktop.
TypeScriptified Flagrate (working)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare module Flagrate { | |
var className: string; | |
function identity<T>(a: T): T; | |
function extendObject<T, U>(b: T, a: U): T; | |
function emptyFunction(): void; | |
/** | |
* Json Pointer Implementation. | |
* @namespace Flagrate.jsonPointer | |
**/ | |
module jsonPointer { | |
function get(object: Object, pointer: string): any; | |
function set<T>(object: Object, pointer: string, value: T): T; | |
} | |
interface IElementClass { | |
new? (tagName?: string, attribute?: any): IElement; | |
(tagName?: string, attribute?: any): void; | |
prototype?: IElementInstance; | |
cache?: Object; | |
_insertionTranslation?: IElementInsertion; | |
/** | |
* Tells whether `element` is visible | |
* @param element target. | |
**/ | |
visible? <T extends HTMLElement>(element: T): boolean; | |
/** | |
* Tells whether `element` is exists on document. | |
* @param element target. | |
**/ | |
exists? <T extends HTMLElement>(element: T): boolean; | |
/** | |
* Toggles the visibility of `element`. Returns `element`. | |
* @param element target. | |
**/ | |
toggle? <T extends HTMLElement>(element: T): T; | |
/** | |
* Sets `display: none` on `element`. Returns `element`. | |
* @param element target. | |
**/ | |
hide? <T extends HTMLElement>(element: T): T; | |
/** | |
* Removes `display: none` on `element`. Returns `element`. | |
* @param element target. | |
**/ | |
show? <T extends HTMLElement>(element: T): T; | |
/** | |
* Completely removes `element` from the document and returns it. | |
* @param element target. | |
**/ | |
remove? <T extends HTMLElement>(element: T): T; | |
update? <T extends HTMLElement>(element: T, content?: string): T; | |
update? <T extends HTMLElement>(element: T, content?: number): T; | |
update? <T extends HTMLElement, U extends HTMLElement>(element: T, content?: U): T; | |
updateText? <T extends HTMLElement>(element: T, content?: string): T; | |
updateText? <T extends HTMLElement>(element: T, content?: number): T; | |
insert? <T extends HTMLElement>(element: T, content: string): T; | |
insert? <T extends HTMLElement>(element: T, content: number): T; | |
insert? <T extends HTMLElement, U extends HTMLElement>(element: T, content: U): T; | |
insert? <T extends HTMLElement>(element: T, content: IElementInsertion): T; | |
insertText? <T extends HTMLElement>(element: T, content: string): T; | |
insertText? <T extends HTMLElement>(element: T, content: number): T; | |
insertText? <T extends HTMLElement>(element: T, content: IElementInsertion): T; | |
insertTo? <T extends HTMLElement, U extends HTMLElement>(element: T, to: U, position: 'before'): T; | |
insertTo? <T extends HTMLElement, U extends HTMLElement>(element: T, to: U, position: 'top'): T; | |
insertTo? <T extends HTMLElement, U extends HTMLElement>(element: T, to: U, position: 'bottom'): T; | |
insertTo? <T extends HTMLElement, U extends HTMLElement>(element: T, to: U, position: 'after'): T; | |
insertTo? <T extends HTMLElement, U extends HTMLElement>(element: T, to: U, position?: any): T; | |
wrap? <T extends HTMLElement, U extends HTMLElement>(element: T, wrapper?: U, attribute?: any): T; | |
wrap? <T extends HTMLElement>(element: T, wrapper?: string, attribute?: any): T; | |
readAttribute? <T extends HTMLElement>(element: T, name: string): string; | |
writeAttribute? <T extends HTMLElement>(element: T, attributeName: string, value?: boolean): T; | |
writeAttribute? <T extends HTMLElement>(element: T, attributeName: string, value?: string): T; | |
writeAttribute? <T extends HTMLElement>(element: T, attribute: any): T; | |
getDimensions? <T extends HTMLElement>(element: T): IElementDimension; | |
getHeight? <T extends HTMLElement>(element: T): number; | |
getWidth? <T extends HTMLElement>(element: T): number; | |
cumulativeOffset? <T extends HTMLElement>(element: T): IElementOffset; | |
cumulativeScrollOffset? <T extends HTMLElement>(element: T): IElementOffset; | |
hasClassName? <T extends HTMLElement>(element: T, className: string): boolean; | |
addClassName? <T extends HTMLElement>(element: T, className: string): T; | |
removeClassName? <T extends HTMLElement>(element: T, className: string): T; | |
toggleClassName? <T extends HTMLElement>(element: T, className: string): T; | |
getStyle? <T extends HTMLElement>(element: T, propertyName: string): any; | |
getStyle? <T extends HTMLElement>(element: T, propertyName: 'opacity'): number; | |
getStyle? <T extends HTMLElement>(element: T, propertyName: any): any; | |
setStyle? <T extends HTMLElement>(element: T, style: any): T; | |
on? <T extends HTMLElement>(element: T, eventType: string, listener: EventListener, useCapture?: boolean): T; | |
off? <T extends HTMLElement>(element: T, eventType: string, listener?: EventListener, useCapture?: boolean): T; | |
fire? <T extends HTMLElement>(element: T, eventType: string, property?: any): T; | |
emit? <T extends HTMLElement>(element: T, eventType: string, property?: any): T; | |
extend? <T extends HTMLElement>(element: T): IElement; | |
} | |
interface IElement extends IElementInstance, HTMLElement { | |
} | |
interface IElementInstance { | |
isFlagrated?: boolean; | |
/** Tells whether the visibility. */ | |
visible? (): boolean; | |
/** Tells whether `element` is exists on document. */ | |
exists? (): boolean; | |
/** Toggles the visibility of `element`. Returns `element`. */ | |
toggle? (): IElement; | |
/** Sets `display: none` on `element`. Returns `element`. */ | |
hide? (): IElement; | |
/** Removes `display: none` on `element`. Returns `element`. */ | |
show? (): IElement; | |
/** Completely removes `element` from the document and returns it. */ | |
remove? (): IElement; | |
update? (content?: string): IElement; | |
update? (content?: number): IElement; | |
update? <T extends HTMLElement>(content?: T): IElement; | |
updateText? (content?: string): IElement; | |
updateText? (content?: number): IElement; | |
insert? (content: string): IElement; | |
insert? (content: number): IElement; | |
insert? <T extends HTMLElement>(content: T): IElement; | |
insert? (content: IElementInsertion): IElement; | |
insertText? (content: string): IElement; | |
insertText? (content: number): IElement; | |
insertText? (content: IElementInsertion): IElement; | |
insertTo? <T extends HTMLElement>(to: T, position: 'before'): IElement; | |
insertTo? <T extends HTMLElement>(to: T, position: 'top'): IElement; | |
insertTo? <T extends HTMLElement>(to: T, position: 'bottom'): IElement; | |
insertTo? <T extends HTMLElement>(to: T, position: 'after'): IElement; | |
insertTo? <T extends HTMLElement>(to: T, position?: any): IElement; | |
wrap? <T extends HTMLElement>(wrapper?: T, attribute?: any): IElement; | |
wrap? (wrapper?: string, attribute?: any): IElement; | |
readAttribute? (name: string): string; | |
writeAttribute? (attributeName: string, value?: boolean): IElement; | |
writeAttribute? (attributeName: string, value?: string): IElement; | |
writeAttribute? (attribute: any): IElement; | |
getDimensions? (): IElementDimension; | |
getHeight? (): number; | |
getWidth? (): number; | |
cumulativeOffset? (): IElementOffset; | |
cumulativeScrollOffset? (): IElementOffset; | |
hasClassName? (className: string): boolean; | |
addClassName? (className: string): IElement; | |
removeClassName? (className: string): IElement; | |
toggleClassName? (className: string): IElement; | |
getStyle? (propertyName: string): any; | |
getStyle? (propertyName: 'opacity'): number; | |
getStyle? (propertyName: any): any; | |
setStyle? (style: any): IElement; | |
on? (eventType: string, listener: EventListener, useCapture?: boolean): IElement; | |
off? (eventType: string, listener?: EventListener, useCapture?: boolean): IElement; | |
fire? (eventType: string, property?: any): IElement; | |
emit? (eventType: string, property?: any): IElement; | |
} | |
interface IElementDimension { | |
width: number; | |
height: number; | |
} | |
interface IElementOffset { | |
top: number; | |
left: number; | |
} | |
interface IElementInsertion { | |
before? <T extends HTMLElement, U extends HTMLElement>(element: T, node: U): void; | |
top? <T extends HTMLElement, U extends HTMLElement>(element: T, node: U): void; | |
bottom? <T extends HTMLElement, U extends HTMLElement>(element: T, node: U): void; | |
after? <T extends HTMLElement, U extends HTMLElement>(element: T, node: U): void; | |
} | |
var Element: IElementClass; | |
/** | |
* Creates an HTML element with `tagName` as the tag name, optionally with the given attributes. | |
* @param tagName The name of the HTML element to create. | |
* @param attribute An optional group of attribute/value pairs to set on the element. | |
**/ | |
function createElement(tagName?: string, attribute?: any): IElement; | |
interface IButtonClass { | |
new? (option?: IButtonOption): IButton; | |
(option?: IButtonOption): void; | |
prototype: IButtonInstance; | |
} | |
interface IButton extends IButtonInstance, IElement { | |
} | |
interface IButtonInstance extends IElementInstance { | |
select(): IButton; | |
disable(): IButton; | |
enable(): IButton; | |
isEnabled(): boolean; | |
setLabel(label: string): IButton; | |
setColor(color?: string): IButton; | |
getColor(): string; | |
setIcon(url?: string): IButton; | |
getIcon(): string; | |
_label?: IElement; | |
_removeButton?: IElement; | |
_onSelectHandler(event: any): void; | |
_onRemoveHandler(event: any): void; | |
} | |
interface IButtonOption { | |
/** id attribute. */ | |
id?: string; | |
/** class attribute. */ | |
className?: string; | |
/** attribute/value pairs properties. */ | |
attribute?: any; | |
/** CSS style properties (uses Flagrate.Element.setStyle). */ | |
style?: any; | |
/** Color (uses Flagrate.Button#setColor). */ | |
color?: string; | |
/** Label text. */ | |
label?: string; | |
/** icon image URL. */ | |
icon?: string; | |
/** default is false. */ | |
isFocused?: boolean; | |
/** default is false. */ | |
isDisabled?: boolean; | |
/** default is false. */ | |
isRemovableByUser?: boolean; | |
onSelect? (event?: any, button?: IButton): void; | |
onRemove? (event?: any, button?: IButton): void; | |
} | |
var Button: IButtonClass; | |
function createButton(option?: IButtonOption): IButton; | |
interface IButtonsClass { | |
new? (option?: IButtonsOption): IButtons; | |
(option?: IButtonsOption): void; | |
prototype: IButtonsInstance; | |
} | |
interface IButtons extends IButtonsInstance, IElement { | |
} | |
interface IButtonsInstance extends IElementInstance { | |
push(button: IButtonsItemOption): IButtons; | |
getButtonByKey(key: string): IButton; | |
getButtons(): IButton[]; | |
} | |
interface IButtonsOption { | |
/** id attribute. */ | |
id?: string; | |
/** class attribute. */ | |
className?: string; | |
/** attribute/value pairs properties. */ | |
attribute?: any; | |
/** CSS style properties (uses Flagrate.Element.setStyle). */ | |
style?: any; | |
/** Button items */ | |
items?: IButtonsItemOption[]; | |
onSelect? (event?: any, buttons?: IButtons): void; | |
} | |
interface IButtonsItemOption extends IButtonOption { | |
/** key */ | |
key?: string; | |
} | |
var Buttons: IButtonsClass; | |
function createButtons(option?: IButtonsOption): IButtons; | |
interface IMenuClass { | |
new? (option?: IMenuOption): IMenu; | |
(option?: IMenuOption): void; | |
prototype: IMenuInstance; | |
} | |
interface IMenu extends IMenuInstance, IElement { | |
} | |
interface IMenuInstance extends IElementInstance { | |
push(item: IMenuItemOption): IMenu; | |
getButtonByKey(key: string): IButton; | |
getButtons(): IButton[]; | |
} | |
interface IMenuOption { | |
/** id attribute. */ | |
id?: string; | |
/** class attribute. */ | |
className?: string; | |
/** attribute/value pairs properties. */ | |
attribute?: any; | |
/** CSS style properties (uses Flagrate.Element.setStyle). */ | |
style?: any; | |
/** Button items */ | |
items?: IMenuItemOption[]; | |
onSelect? (event?: any, menu?: IMenu): void; | |
} | |
interface IMenuItemOption extends IButtonOption { | |
/** key */ | |
key?: string; | |
} | |
var Menu: IMenuClass; | |
function createMenu(option?: IMenuOption): IMenu; | |
interface IPulldownClass { | |
new? (option?: IPulldownOption): IPulldown; | |
(option?: IPulldownOption): void; | |
prototype: IPulldownInstance; | |
} | |
interface IPulldown extends IPulldownInstance, IButton { | |
} | |
interface IPulldownInstance extends IButtonInstance { | |
_menu?: IMenu; | |
} | |
interface IPulldownOption { | |
/** id attribute. */ | |
id?: string; | |
/** class attribute. */ | |
className?: string; | |
/** attribute/value pairs properties. */ | |
attribute?: any; | |
/** CSS style properties (uses Flagrate.Element.setStyle). */ | |
style?: any; | |
/** Color (uses Flagrate.Button#setColor). */ | |
color?: string; | |
/** Label text. */ | |
label?: string; | |
/** icon image URL. */ | |
icon?: string; | |
/** default is false. */ | |
isDisabled?: boolean; | |
/** Button items */ | |
items?: IMenuItemOption[]; | |
onSelect? (event?: any, button?: IPulldown): void; | |
} | |
var Pulldown: IPulldownClass; | |
function createPulldown(option?: IPulldownOption): IPulldown; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(m){var p;(function(b){function n(a){return!(!a||1!==a.nodeType)}b.className="flagrate";b.identity=function(a){return a};b.extendObject=function(a,c){for(var d in c)a[d]=c[d];return a};b.emptyFunction=function(){};(function(a){function c(a){return a.replace(/~[01]/g,function(a){switch(a){case "~0":return"~";case "~1":return"/"}throw Error("Invalid tilde escape: "+a);})}function d(a,b,e,k){var l=c(b.shift());if(0!==b.length)return k&&"object"!==typeof a[l]&&(a[l]={}),d(a[l],b,e,k);if(void 0=== | |
e)return a[l];null===e?delete a[l]:a[l]=e;return e}function b(a,c){if("object"!==typeof a)throw Error("Invalid input object.");if(""===c)return[];if(!c)throw Error("Invalid JSON pointer.");var d=c.split("/");if(""!==d.shift())throw Error("Invalid JSON pointer.");return d}a.get=function(a,c){var h=b(a,c);return 0===h.length?a:d(a,h)};a.set=function(a,c,h){if(""===c&&"object"===typeof h)return q.extendObject(a,h),h;c=b(a,c);if(0===c.length)throw Error("Invalid JSON pointer for set.");return d(a,c,h, | |
!0)}})(b.jsonPointer||(b.jsonPointer={}));b.Element=function(a,c){"undefined"===typeof a&&(a="div");var d;b.Element.cache[a]?d=b.Element.cache[a].cloneNode(!1):c&&c.hasOwnProperty("type")||"select"===a?d=document.createElement(a):(d=document.createElement(a),b.Element.cache[a]=d.cloneNode(!1));b.extendObject(d,this);return c?d.writeAttribute(c):d};b.createElement=function(a,c){return new b.Element(a,c)};b.Element.cache={};b.Element.prototype={isFlagrated:!0,visible:function(){return b.Element.visible(this)}, | |
exists:function(){return b.Element.exists(this)},toggle:function(){return b.Element.toggle(this)},hide:function(){return b.Element.hide(this)},show:function(){return b.Element.show(this)},remove:function(){return b.Element.remove(this)},update:function(a){return b.Element.update(this,a)},updateText:function(a){return b.Element.updateText(this,a)},insert:function(a){return b.Element.insert(this,a)},insertText:function(a){return b.Element.insertText(this,a)},insertTo:function(a,c){return b.Element.insertTo(this, | |
a,c)},readAttribute:function(a){return b.Element.readAttribute(this,a)},writeAttribute:function(a,c){return b.Element.writeAttribute(this,a,c)},getDimensions:function(){return b.Element.getDimensions(this)},getHeight:function(){return b.Element.getHeight(this)},getWidth:function(){return b.Element.getWidth(this)},cumulativeOffset:function(){return b.Element.cumulativeOffset(this)},cumulativeScrollOffset:function(){return b.Element.cumulativeScrollOffset(this)},hasClassName:function(a){return b.Element.hasClassName(this, | |
a)},addClassName:function(a){return b.Element.addClassName(this,a)},removeClassName:function(a){return b.Element.removeClassName(this,a)},toggleClassName:function(a){return b.Element.toggleClassName(this,a)},getStyle:function(a){return b.Element.getStyle(this,a)},setStyle:function(a){return b.Element.setStyle(this,a)},on:function(a,c,d){return b.Element.on(this,a,c,d)},off:function(a,c,d){return b.Element.off(this,a,c,d)},fire:function(a,c){return b.Element.fire(this,a,c)}};b.Element.prototype.emit= | |
b.Element.prototype.fire;b.Element.visible=function(a){return"none"!==a.style.display};b.Element.exists=function(a){if(a.parentNode)for(;null!==(a=a.parentNode);)if(a===document)return!0;return!1};b.Element.toggle=function(a){return b.Element[b.Element.visible(a)?"hide":"show"](a)};b.Element.hide=function(a){a.style.display="none";return a};b.Element.show=function(a){a.style.display="";return a};b.Element.remove=function(a){a.parentNode&&a.parentNode.removeChild(a);return a};b.Element.update=function(a, | |
c){for(var d=a.childNodes.length;d--;)b.Element.remove(a.childNodes[d]);if(!c)return a;if(!0===n(c))return a.appendChild(c),a;"string"!==typeof c&&(c=c.toString(10));a.innerHTML=c;return a};b.Element.updateText=function(a,c){for(var d=a.childNodes.length;d--;)b.Element.remove(a.childNodes[d]);if(!c)return a;if(!0===n(c)&&void 0!==c.toString)return b.Element.updateText(a,c.toString());"string"!==typeof c&&(c=c.toString(10));a.appendChild(document.createTextNode(c));return a};b.Element.insert=function(a, | |
c){if("string"===typeof c||"number"===typeof c||!0===n(c))c={bottom:c};var d,e,f,g;for(d in c)if(c.hasOwnProperty(d))if(e=c[d],d=d.toLowerCase(),f=b.Element._insertionTranslation[d],!0===n(e))f(a,e);else for("string"!==typeof e&&(e=e.toString(10)),g=new b.Element,g.innerHTML=e,"top"!==d&&"after"!==d||g.childNodes.reverse();0!==g.childNodes.length;)f(a,g.childNodes[0]);return a};b.Element.insertText=function(a,c){if("string"===typeof c||"number"===typeof c)c={bottom:c};var d,e,f;for(d in c)c.hasOwnProperty(d)&& | |
(e=c[d],d=d.toLowerCase(),f=b.Element._insertionTranslation[d],"string"!==typeof e&&(e=e.toString(10)),f(a,document.createTextNode(e)));return a};b.Element.insertTo=function(a,c,d){"undefined"===typeof d&&(d="bottom");var e={};d?e[d]=a:e.bottom=a;b.Element.insert(c,e);return a};b.Element.wrap=function(a,c,d){!0===n(c)?d&&b.Element.writeAttribute(c,d):c="string"===typeof c?new b.Element(c,d):new b.Element("div",c);a.parentNode&&a.parentNode.replaceChild(c,a);c.appendChild(a);return c};b.Element.readAttribute= | |
function(a,c){return a.getAttribute(c)};b.Element.writeAttribute=function(a,c,b){var e={};"object"===typeof c?e=c:e[c]=void 0===b?!0:b;for(var f in e)e.hasOwnProperty(f)&&(b=e[f],!1===b||null===b?a.removeAttribute(f):!0===b?a.setAttribute(f,f):void 0!==b&&a.setAttribute(f,b));return a};b.Element.getDimensions=function(a){var c=b.Element.getStyle(a,"display");if(c&&"none"!==c)return{width:a.offsetWidth,height:a.offsetHeight};var c={visibility:a.style.visibility,position:a.style.position,display:a.style.display}, | |
d={visibility:"hidden",display:"block"};"fixed"!==c.position&&(d.position="absolute");b.Element.setStyle(a,d);d={width:a.offsetWidth,height:a.offsetHeight};b.Element.setStyle(a,c);return d};b.Element.getHeight=function(a){return b.Element.getDimensions(a).height};b.Element.getWidth=function(a){return b.Element.getDimensions(a).width};b.Element.cumulativeOffset=function(a){var c=0,b=0;if(a.parentNode){do c+=a.offsetTop||0,b+=a.offsetLeft||0,a=a.offsetParent;while(a)}return{top:c,left:b}};b.Element.cumulativeScrollOffset= | |
function(a){var c=0,b=0;do c+=a.scrollTop||0,b+=a.scrollLeft||0,a=a.parentNode===document.body&&0!==document.documentElement.scrollTop?document.documentElement:a.parentNode;while(a);return{top:c,left:b}};b.Element.hasClassName=function(a,c){return 0<a.className.length&&(a.className===c||RegExp("(^|\\s)"+c+"(\\s|$)").test(a.className))};b.Element.addClassName=function(a,c){b.Element.hasClassName(a,c)||(a.className+=(a.className?" ":"")+c);return a};b.Element.removeClassName=function(a,c){a.className= | |
a.className.replace(RegExp("(^|\\s+)"+c+"(\\s+|$)")," ").trim();return a};b.Element.toggleClassName=function(a,c){return b.Element[b.Element.hasClassName(a,c)?"removeClassName":"addClassName"](a,c)};b.Element.getStyle=function(a,c){c="float"===c?"cssFloat":c.replace(/-+([a-z])?/g,function(a,c){return c?c.toUpperCase():""});var b=a.style[c];b&&"auto"!==b||(b=(b=document.defaultView.getComputedStyle(a,null))&&void 0!==b[c]&&""!==b[c]?b[c]:null);return"opacity"===c?b?parseFloat(b):1:"auto"===b?null: | |
b};b.Element.setStyle=function(a,c){for(var b in c)c.hasOwnProperty(b)&&(a.style["float"===b||"cssFloat"===b?"cssFloat":b]=c[b]);return a};b.Element.on=function(a,c,b,e){a.addEventListener(c,b,e||!1);return a};b.Element.off=function(a,c,b,e){a.removeEventListener(c,b,e||!1);return a};b.Element.fire=function(a,c,d){var e=document.createEvent("HTMLEvents");e.initEvent(c,!0,!0);d&&b.extendObject(e,d);a.dispatchEvent(e);return a};b.Element.emit=b.Element.fire;b.Element.extend=function(a){if(a.isFlagrated)return a; | |
b.extendObject(a,b.Element.prototype);return a};b.Element._insertionTranslation={before:function(a,c){a.parentNode.insertBefore(c,a)},top:function(a,c){a.insertBefore(c,a.firstChild)},bottom:function(a,c){a.appendChild(c)},after:function(a,c){a.parentNode.insertBefore(c,a.nextSibling)}};b.Button=function(a){"undefined"===typeof a&&(a={});a.label=a.label||"";a.isRemovableByUser=a.isRemovableByUser||!1;this.onSelect=a.onSelect||b.emptyFunction;this.onRemove=a.onRemove||b.emptyFunction;var c=a.attribute|| | |
{};a.id&&(c.id=a.id);a.isFocused&&(c.autofocus=!0);c.type||(c.type="button");c=new b.Element("button",c);b.extendObject(c,this);c._label=(new b.Element("span")).updateText(a.label).insertTo(c);c.addClassName(b.className+" "+b.className+"-button");a.className&&c.addClassName(a.className);c.on("click",c._onSelectHandler.bind(c),!0);a.isRemovableByUser&&(c.addClassName(b.className+"-button-removable"),c._removeButton=(new b.Element("button",{type:"button","class":b.className+"-button-remove"})).insertTo(c), | |
c._removeButton.on("click",c._onRemoveHandler.bind(c),!0));a.style&&c.setStyle(a.style);a.color&&c.setColor(a.color);a.icon&&c.setIcon(a.icon);a.isDisabled&&c.disable();return c};b.createButton=function(a){return new b.Button(a)};b.Button.prototype={select:function(){return this._onSelectHandler(null)},disable:function(){this.addClassName(b.className+"-disabled");this.writeAttribute("disabled",!0);return this},enable:function(){this.removeClassName(b.className+"-disabled");this.writeAttribute("disabled", | |
!1);return this},isEnabled:function(){return!this.hasClassName(b.className+"-disabled")},setLabel:function(a){this._label.updateText(a);return this},setColor:function(a){"@"===a.charAt(0)?(this.style.backgroundColor="",this.addClassName(b.className+"-button-color-"+a.slice(1))):this.style.backgroundColor=a;this._color=a;return this},getColor:function(){return this._color||""},setIcon:function(a){return(this._iconIdentifier=a)?this.addClassName(b.className+"-icon").setStyle({backgroundImage:"url("+ | |
a+")"}):this.removeClassName(b.className+"-icon").setStyle({backgroundImage:"none"})},getIcon:function(){return this._iconIdentifier||""},_onSelectHandler:function(a){if(!1!==this.isEnabled()){if(this._removeButton&&a&&a.layerX){var c=this.getWidth(),b=this.getHeight(),e=null===this._removeButton.getStyle("margin-right")?0:parseInt(this._removeButton.getStyle("margin-right").replace("px",""),10),f=this._removeButton.getWidth(),g=this._removeButton.getHeight(),h=a.layerX,k=a.layerY;if(h>c-e-f&&h<c- | |
e&&k>b-(b-g)/2-g&&k<b-(b-g)/2)return this._onRemoveHandler(a),this}a.targetButton=this;this.onSelect(a,this);this.fire("select",{targetButton:this})}},_onRemoveHandler:function(a){if(this.isEnabled()&&this.remove())this.onRemove(a)}};b.Buttons=function(a){"undefined"===typeof a&&(a={});a.items=a.items||[];this.onSelect=a.onSelect||b.emptyFunction;var c=a.attribute||{};a.id&&(c.id=a.id);c=new b.Element("div",c);b.extendObject(c,this);c.addClassName(b.className+" "+b.className+"-buttons");a.className&& | |
c.addClassName(a.className);a.style&&c.setStyle(a.style);var d,e;d=0;for(e=a.items.length;d<e;d++)c.push(a.items[d]);c.on("click",function(a){a.stopPropagation();a.preventDefault()});return c};b.createButtons=function(a){return new b.Buttons(a)};b.Buttons.prototype={push:function(a){var c=this;if(a.onSelect)var d=a.onSelect;a.onSelect=function(a){d&&d(a);c.onSelect(a)};var e=b.createButton(a).insertTo(this);a.key&&(e.dataset._key=a.key);return this},getButtonByKey:function(a){var b=null,d=this.childNodes, | |
e,f;e=0;for(f=d.length;e<f;e++)if(d[e].dataset._key===a){b=d[e];break}return b},getButtons:function(){return this.childNodes||[]}};b.Menu=function(a){"undefined"===typeof a&&(a={});a.items=a.items||[];this.onSelect=a.onSelect||b.emptyFunction;var c=a.attribute||{};a.id&&(c.id=a.id);c=new b.Element("div",c);b.extendObject(c,this);c.addClassName(b.className+" "+b.className+"-menu");a.className&&c.addClassName(a.className);a.style&&c.setStyle(a.style);var d,e;d=0;for(e=a.items.length;d<e;d++)c.push(a.items[d]); | |
c.on("click",function(a){a.stopPropagation();a.preventDefault()});c.on("mouseup",function(a){a.stopPropagation()});return c};b.createMenu=function(a){return new b.Menu(a)};b.Menu.prototype={push:function(a){var c=this;if("string"===typeof a)b.createElement("hr").insertTo(this);else{if(a.onSelect)var d=a.onSelect;a.onSelect=function(a){d&&d(a);c.onSelect(a)};var e=b.createButton(a).insertTo(this);a.key&&(e.dataset._key=a.key)}return this},getButtonByKey:b.Buttons.prototype.getButtonByKey,getButtons:b.Buttons.prototype.getButtons}; | |
b.Pulldown=function(a){"undefined"===typeof a&&(a={});a.label=a.label||"";this.items=a.items||[];var c=a.attribute||{};a.id&&(c.id=a.id);var d=new b.Button({attribute:c,label:a.label,icon:a.icon,onSelect:function(){if(d._menu)e();else{d._menu=b.createMenu({className:b.className+"-pulldown-menu",items:d.items,onSelect:function(){if(a.onSelect)a.onSelect();e()}});d._menu.style.top=d.offsetTop+d.getHeight()+"px";d._menu.style.left=d.offsetLeft+"px";d.insert({after:d._menu});var c=d._menu.getHeight(), | |
g=parseInt(d._menu.getStyle("margin-top").replace("px",""),10),h=d.cumulativeOffset().top,k=-m.pageYOffset+h,h=m.pageYOffset+m.innerHeight-h-d.getHeight();c+g>h&&(k>h?(k<c+g&&(c=k-g-g,d._menu.style.maxHeight=c+"px"),d._menu.style.top=d.offsetTop-c-2*g+"px"):d._menu.style.maxHeight=h-g-g+"px");setTimeout(function(){document.body.addEventListener("click",e);d.parentNode.addEventListener("click",e);d.on("click",e)},0)}}});b.extendObject(d,this);d.addClassName(b.className+"-pulldown");a.className&&d.addClassName(a.className); | |
b.createElement("span",{"class":b.className+"-pulldown-triangle"}).insertTo(d);a.style&&d.setStyle(a.style);a.color&&d.setColor(a.color);a.isDisabled&&d.disable();var e=function(){document.body.removeEventListener("click",e);d.parentNode.removeEventListener("click",e);d.off("click",e);d._menu.style.opacity="0";setTimeout(function(){d._menu&&(d._menu.remove(),delete d._menu)},250)};return d};b.createPulldown=function(a){return new b.Pulldown(a)}})(p||(p={}));var q=p;m.Flagrate=p;m.flagrate=q})(window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment