toloframework
Version:
Javascript/HTML/CSS compiler for Firefox OS or nodewebkit apps using modules in the nodejs style.
1 lines • 83.9 kB
JavaScript
{"intl":"","src":"require( 'wdg', function(exports, module) { 'use strict';\r\n\r\n/**\r\n * Widgets inherit this class.\r\n */\r\nfunction Widget(options) {\r\n this.__data = {};\r\n try {\r\n var e;\r\n if (typeof options === 'undefined') options = {};\r\n if (typeof options.innerHTML !== 'undefined' && typeof options.childNodes !== 'undefined') {\r\n // On passe directement un élément.\r\n options = {element: options};\r\n }\r\n if (typeof options.tag === 'undefined') options.tag = \"div\";\r\n if (options.element) {\r\n this.element(options.element);\r\n } else if (typeof options.id !== 'undefined') {\r\n e = window.document.getElementById(options.id);\r\n if (!e) {\r\n throw Error(\"Can't find element with id: \\\"\" + options.id + \"\\\"!\");\r\n }\r\n this.element(e);\r\n } else {\r\n this.element(window.document.createElement(options.tag));\r\n this.addClass(\"wdg\", \"custom\");\r\n }\r\n }\r\n catch (ex) {\r\n console.error(\"[widget] \", ex);\r\n console.error(\"[Widget] \", JSON.stringify(options));\r\n throw Error(ex);\r\n }\r\n}\r\n\r\nWidget.prototype = {\r\n /**\r\n * Accessor for attribute element\r\n * @return element\r\n */\r\n element: function(v) {\r\n if (v === undefined) return this._element;\r\n if (typeof v === 'string') {\r\n v = window.document.querySelector(v);\r\n }\r\n this._element = v;\r\n return this;\r\n },\r\n\r\n data: function(k, v) {\r\n if (typeof v === 'undefined') {\r\n return this.__data[k];\r\n }\r\n this.__data[k] = v;\r\n return this;\r\n },\r\n\r\n /**\r\n * @description\r\n * Remove this element from its parent.\r\n * @memberof wdg\r\n */\r\n detach: function() {\r\n var e = this._element;\r\n if (e) {\r\n var p = e.parentNode;\r\n if (p) {\r\n p.removeChild(e);\r\n }\r\n }\r\n return this;\r\n },\r\n\r\n /**\r\n * @description\r\n *\r\n * @param name\r\n * @memberof wdg\r\n */\r\n addEvent: function(name, slot, sender) {\r\n if (typeof slot === 'string') {\r\n var that = this, key = slot;\r\n if (typeof sender === 'undefined') sender = this;\r\n slot = function(x) {\r\n var f = sender[key];\r\n if (typeof f === 'function') {\r\n f.call(sender, x);\r\n } else {\r\n throw Error(\"\\\"\" + slot + \"\\\" is not a function of: \" + sender);\r\n }\r\n };\r\n }\r\n var e = this.element();\r\n if (name == 'tap') {\r\n e.addEventListener(\r\n \"mousedown\",\r\n function(evt) {\r\n evt.preventDefault();\r\n evt.stopPropagation();\r\n },\r\n false\r\n );\r\n e.addEventListener(\r\n \"mouseup\",\r\n function(evt) {\r\n evt.preventDefault();\r\n evt.stopPropagation();\r\n slot(evt);\r\n },\r\n false\r\n );\r\n e.addEventListener(\"touchend\", slot, false);\r\n\r\n } else {\r\n e.addEventListener(name, slot, false);\r\n }\r\n return this;\r\n },\r\n\r\n /**\r\n * Retire un attribut à l'élément sous-jacent.\r\n * @example\r\n * this.removeAttr(\"selected\");\r\n * @memberof wdg\r\n */\r\n removeAttr: function() {\r\n if (this._element) {\r\n var i, arg;\r\n for (i = 0 ; i < arguments.length ; i++) {\r\n arg = arguments[i];\r\n this._element.removeAttribute(arg);\r\n }\r\n }\r\n return this;\r\n },\r\n\r\n /**\r\n * Teste l'existence d'un attribut dans l'élément sous-jacent.\r\n * @memberof wdg\r\n */\r\n hasAttribute: function(key) {\r\n if (!this._element) return false;\r\n return this._element.hasAttribute(key);\r\n },\r\n\r\n /**\r\n * Lit ou affecte la valeur d'un attribut de l'élément sous-jacent.\r\n * @example\r\n * // Le pseudo attribut '$' sert à insérer du texte.\r\n * var div = new Widget();\r\n * div.attr({$: 'Hello world!', title: 'Typical first sentence...'});\r\n * @param key Nom de l'attribut ou dictionnaire des attributs.\r\n * @param val [Facultatif] Valeur de l'attribut. Si elle est omise, la méthode retourne la valeur actuelle.\r\n * @param ns [Facultatif] Namespace éventuel.\r\n * @memberof wdg\r\n */\r\n attr: function(key, val, ns) {\r\n var k;\r\n if (!this._element || !this._element.getAttribute) return null;\r\n if (typeof key == \"string\") {\r\n if (val !== undefined) {\r\n if (key == \"class\") {\r\n this._element.className = val;\r\n return this;\r\n }\r\n if (ns && this._element.setAttributeNS) {\r\n this._element.setAttributeNS(ns, key, val);\r\n }\r\n else {\r\n this._element.setAttribute(key, val);\r\n }\r\n return this;\r\n }\r\n return this._element.getAttribute(key);\r\n }\r\n if (typeof key == \"object\") {\r\n for (k in key) {\r\n if (k == \"class\") {\r\n this._element.className = key[k];\r\n } else if (k == \"$\") {\r\n this.text(key[k]);\r\n } else {\r\n this._element.setAttribute(k, key[k]);\r\n }\r\n }\r\n }\r\n return this;\r\n },\r\n\r\n\r\n /**\r\n * Permet de changer le style de l'élément sous-jacent.\r\n * @example\r\n * this.css(\"color\", \"red\");\r\n * alert(this.css(\"display\"));\r\n * this.css(\r\n * {\r\n * margin: \"0px\",\r\n * padding: \"3px\",\r\n * border: \"1px solid black\"\r\n * }\r\n * );\r\n * @param key Nom du champ de style ou dictionnaire clefs/valeurs.\r\n * @param val Valeur du champ key. S'il est omis et que \"key\"\r\n * est de type string, alors la méthode retourne la valeur\r\n * actuelle.\r\n * @memberof wdg\r\n */\r\n css: function(key, val) {\r\n var k, e = this._element;\r\n if (!e) return null;\r\n if (typeof e.style !== 'object') {\r\n console.error(\"[wdg.css] This element does not support styles!\", e);\r\n e.style = {};\r\n }\r\n if (typeof key == 'string') {\r\n if (val) {\r\n e.style[key] = val;\r\n return this;\r\n }\r\n return e.style[key];\r\n }\r\n if (typeof key == 'object') {\r\n for (k in key) {\r\n try {\r\n e.style[k] = key[k];\r\n } catch (x) {\r\n console.error(\"[wdg.css] Bad CSS attribute \" + k + \": \" + key[k]);\r\n }\r\n }\r\n }\r\n return this;\r\n },\r\n\r\n insertAfter: function(target) {\r\n if (typeof target.element === 'function') {\r\n target = target.element();\r\n }\r\n target.parentNode.insertBefore(this.element(), target.nextSibling);\r\n return this;\r\n },\r\n\r\n insertBefore: function(target) {\r\n if (typeof target.element === 'function') {\r\n target = target.element();\r\n }\r\n target.parentNode.insertBefore(this.element(), target);\r\n return this;\r\n },\r\n\r\n /**\r\n * Append children to this widget.\r\n */\r\n append: function() {\r\n var i, arg;\r\n for (i = 0 ; i < arguments.length ; i++) {\r\n arg = arguments[i];\r\n if (typeof arg === 'number') arg = \"\" + arg;\r\n if (typeof arg === 'undefined' || (typeof arg !== 'object' && typeof arg !== 'string')) {\r\n console.error(\"[Widget.append] Argument #\" + i + \" is invalid!\", arguments);\r\n console.error(\"[Widget.append] Is type is: \" + (typeof arg));\r\n continue;\r\n };\r\n if (typeof arg === 'string') {\r\n if (arg.length < 1) arg = \" \";\r\n arg = window.document.createTextNode(arg);\r\n if (!arg) {\r\n console.error(\r\n \"[Widget.append] Unable to create a text node with this text: \", arg\r\n );\r\n console.error(\"[wdg] arguments=...\", arguments);\r\n throw Error(\r\n \"[Widget.append] Unable to create a text node with this text: \"\r\n + JSON.stringify(arg)\r\n );\r\n }\r\n }\r\n if (Array.isArray(arg)) {\r\n arg.forEach(\r\n function(item) {\r\n this.append(item);\r\n }, this\r\n );\r\n } else {\r\n var e = typeof arg.element === 'function' ? arg.element() : arg;\r\n this._element.appendChild(e);\r\n /*\r\n if (typeof arg.onAppend === 'function') {\r\n arg.onAppend.call(arg);\r\n }\r\n */\r\n }\r\n }\r\n return this;\r\n },\r\n\r\n /**\r\n * @description\r\n * Append this widget to a parent.\r\n * @param parent\r\n * @memberof wdg\r\n */\r\n appendTo: function(parent) {\r\n if (!parent) return this;\r\n if (typeof parent.append === 'function') {\r\n parent.append(this);\r\n } else if (typeof parent.appendChild === 'function') {\r\n parent.appendChild(this._element);\r\n this.onAppend();\r\n }\r\n return this;\r\n },\r\n\r\n /**\r\n * @description\r\n * Append this widget to BODY.\r\n * @memberof wdg\r\n */\r\n appendToBody: function() {\r\n window.document.body.appendChild(this._element);\r\n return this;\r\n },\r\n\r\n hasClass: function() {\r\n var e = this._element.classList;\r\n var i, arg;\r\n for (i = 0 ; i < arguments.length ; i++) {\r\n arg = arguments[i];\r\n if (!e.contains(arg)) return false;\r\n }\r\n return true;\r\n },\r\n\r\n /**\r\n * @description\r\n * Add CSS classe(s) to this widget.\r\n * @memberof wdg\r\n */\r\n addClass: function() {\r\n var e = this._element.classList;\r\n var i, arg;\r\n for (i = 0 ; i < arguments.length ; i++) {\r\n arg = arguments[i];\r\n if (typeof arg === 'string') {\r\n arg = arg.trim();\r\n if (arg.length > 0) e.add(arg);\r\n } else {\r\n console.error(\"[wdg.addClass] Arguments with bad type!\", arguments);\r\n }\r\n }\r\n return this;\r\n },\r\n\r\n /**\r\n * @description\r\n * Remove CSS classe(s) to this widget.\r\n * @memberof wdg\r\n */\r\n removeClass: function() {\r\n var e = this._element.classList;\r\n var i, arg;\r\n for (i = 0 ; i < arguments.length ; i++) {\r\n arg = arguments[i];\r\n e.remove(arg);\r\n }\r\n return this;\r\n },\r\n\r\n /**\r\n * @description\r\n * Toggle CSS classe(s) to this widget.\r\n * @memberof wdg\r\n */\r\n toggleClass: function() {\r\n var e = this._element.classList;\r\n var i, arg;\r\n for (i = 0 ; i < arguments.length ; i++) {\r\n arg = arguments[i];\r\n e.toggle(arg);\r\n }\r\n return this;\r\n },\r\n\r\n /**\r\n * Remove all children of this widget.\r\n * Any argument passed will be appended to this widget.\r\n * @memberof wdg\r\n */\r\n clear: function() {\r\n // (!) On préfère retirer les éléments un par un du DOM plutôt que d'utiliser simplement\r\n // this.html(\"\").\r\n // En effet, le code simplifié a des conséquences inattendues dans IE9 et IE10 au moins.\r\n // Le bug des markers qui disparaissaients sur les cartes de Trail-Passion 4 a été corrigé\r\n // avec cette modification.\r\n var e = this.element();\r\n while(e.firstChild){\r\n e.removeChild(e.firstChild);\r\n }\r\n var i, arg;\r\n for (i = 0 ; i < arguments.length ; i++) {\r\n arg = arguments[i];\r\n this.append(arg);\r\n }\r\n\r\n return this;\r\n },\r\n\r\n /**\r\n * 1) Sans argument, cette fonction retourne le texte contenu\r\n * dans ce widget.\r\n * 2) Avec un texte en argument, cette fonction retire tous\r\n * les enfants de ce widget et les remplace par un noeud\r\n * texte.\r\n * 3) Avec un élément du DOM en argument, cette fonction\r\n * retourne le texte contenu par ce dernier.\r\n * @memberof tfw.Widget\r\n */\r\n text: function(arg) {\r\n var e, text, i, child;\r\n if (typeof arg == 'string' || typeof arg == 'number') {\r\n arg = '' + arg;\r\n if (arg.substr(0, 6) == '<html>') return this.html( arg.substr( 6 ) );\r\n \r\n this.clear();\r\n this._element.appendChild(window.document.createTextNode(arg));\r\n return this;\r\n } else {\r\n // On retourne le contenu textuel de ce widget.\r\n e = this._element;\r\n if (arg !== undefined) {\r\n // On peut passer un élément du DOM pour en extraire son contenu textuel.\r\n e = arg;\r\n }\r\n text = \"\";\r\n if (e.childNodes) {\r\n for (i=0 ; i<e.childNodes.length ; i++) {\r\n child = e.childNodes[i];\r\n if (child.nodeType == 3) {\r\n if (child.nodeValue) {\r\n text += child.nodeValue;\r\n }\r\n } else {\r\n text += this.text( child );\r\n }\r\n }\r\n }\r\n return text;\r\n }\r\n },\r\n\r\n /**\r\n * @description\r\n *\r\n * @param html\r\n * @memberof wdg\r\n */\r\n html: function(html) {\r\n if (typeof html === 'undefined') return this._element.innerHTML;\r\n if (this._element) this._element.innerHTML = html;\r\n return this;\r\n },\r\n\r\n /**\r\n * @description\r\n * If applicable, give focus to this element.\r\n * @memberof wdg\r\n */\r\n focus: function() {\r\n var e = this._element;\r\n if (!e) return this;\r\n if (typeof e.focus === 'function') {\r\n e.focus();\r\n }\r\n return this;\r\n },\r\n\r\n /**\r\n * @description\r\n * Returns the bounds of the underlying element.\r\n * @memberof wdg\r\n */\r\n rect: function() {\r\n var e = this._element;\r\n if (!e) return null;\r\n return e.getBoundingClientRect();\r\n },\r\n\r\n /**\r\n * @description\r\n *\r\n * @param\r\n * @memberof wdg\r\n */\r\n Tap: function(slot, sender) {\r\n if (typeof slot === 'undefined') return this._Tap;\r\n var that = this;\r\n if (typeof sender === 'undefined') sender = that;\r\n if (typeof slot === 'string') slot = sender[slot];\r\n if (!this._Tap) {\r\n this.activatePointerEvents();\r\n }\r\n this._Tap = [slot, sender];\r\n return this;\r\n }\r\n};\r\n\r\n/**\r\n * @return void\r\n */\r\nWidget.prototype.activatePointerEvents = function() {\r\n if (this._pointerEvents) return this;\r\n this._pointerEvents = {start: 0};\r\n\r\n /*\r\n interact(this.element()).on(\"tap\", function(evt) {\r\n var slot = that._Tap;\r\n if (slot) {\r\n slot[0].call(slot[1], {x: evt.x, y: evt.y});\r\n }\r\n });\r\n return this;\r\n */\r\n var pe = this._pointerEvents;\r\n var that = this;\r\n this.addEvent(\r\n \"touchstart\",\r\n function(evt) {\r\n evt.preventDefault();\r\n evt.stopPropagation();\r\n pe.touch = 1;\r\n pe.start = Date.now();\r\n }\r\n );\r\n this.addEvent(\r\n \"touchend\",\r\n function(evt) {\r\n evt.preventDefault();\r\n evt.stopPropagation();\r\n var tap = that._Tap;\r\n if (!tap) return;\r\n pe.touch = 0;\r\n var delta = Date.now() - pe.start;\r\n if (delta < 900) {\r\n tap[0].call(tap[1], evt);\r\n }\r\n }\r\n );\r\n this.addEvent(\r\n \"mousedown\",\r\n function(evt) {\r\n evt.preventDefault();\r\n evt.stopPropagation();\r\n if (pe.touch) return;\r\n pe.start = Date.now();\r\n }\r\n );\r\n this.addEvent(\r\n \"mouseup\",\r\n function(evt) {\r\n evt.preventDefault();\r\n evt.stopPropagation();\r\n var tap = that._Tap;\r\n if (!tap) return;\r\n var delta = Date.now() - pe.start;\r\n if (delta < 900) {\r\n tap[0].call(tap[1], evt);\r\n }\r\n }\r\n );\r\n\r\n return this;\r\n};\r\n\r\n/**\r\n * @return void\r\n */\r\nWidget.prototype.div = function() {\r\n var div = new Widget();\r\n for (var i = 0 ; i < arguments.length ; i++) {\r\n div.addClass(arguments[i]);\r\n }\r\n return div;\r\n};\r\n\r\nWidget.prototype.tag = function(tag) {\r\n if (typeof tag === 'undefined') tag = 'div';\r\n var div = new Widget({tag: tag});\r\n for (var i = 1 ; i < arguments.length ; i++) {\r\n div.addClass(arguments[i]);\r\n }\r\n return div;\r\n};\r\n\r\n/**\r\n * @return void\r\n */\r\nWidget.prototype.isInDOM = function() {\r\n return Widget.isInDOM(this.element());\r\n};\r\n\r\n/**\r\n * Fonction à surcharger si on veut réagir lors de l'insertion dans le\r\n * DOM.\r\n */\r\nWidget.prototype.onAppend = function() {};\r\n\r\nWidget.create = function(args) {\r\n return new Widget(args);\r\n};\r\n\r\nWidget.find = function(query) {\r\n return new Widget({element: window.document.querySelector(query)});\r\n};\r\n\r\n\r\n/**\r\n * Create a SVG élément with attributes.\r\n */\r\nWidget.svg = function(tag, attribs) {\r\n var namespace = \"http://www.w3.org/2000/svg\";\r\n if (typeof tag === 'object') {\r\n attribs = tag;\r\n tag = \"svg\";\r\n }\r\n if (typeof tag !== 'string') tag = 'svg';\r\n var e = window.document.createElementNS(namespace, tag);\r\n var w = new Widget({element: e});\r\n if (typeof attribs === 'undefined') attribs = {};\r\n if (tag == 'svg') {\r\n if (typeof attribs.version === 'undefined') attribs.version = \"1.1\";\r\n if (typeof attribs['xmlns:svg'] === 'undefined') {\r\n attribs['xmlns:svg'] = 'http://www.w3.org/2000/svg';\r\n }\r\n if (typeof attribs['xmlns'] === 'undefined') {\r\n attribs['xmlns'] = 'http://www.w3.org/2000/svg';\r\n }\r\n if (typeof attribs['xmlns:xlink'] === 'undefined') {\r\n attribs['xmlns:xlink'] = 'http://www.w3.org/1999/xlink';\r\n }\r\n if (typeof attribs.viewBox === 'undefined'\r\n && typeof attribs.width === 'number'\r\n && typeof attribs.height === 'number')\r\n {\r\n attribs.viewBox = \"0 0 \" + attribs.width + \" \" + attribs.height;\r\n }\r\n }\r\n if (typeof attribs === 'object') {\r\n w.attr(attribs);\r\n }\r\n return w;\r\n};\r\n\r\n/**\r\n * Tester si le widget ou élément est actuellement attaché au DOM.\r\n */\r\nWidget.isInDOM = function(e) {\r\n if (!e) return false;\r\n if (typeof e.element === 'function') {\r\n e = e.element();\r\n }\r\n if (e === window.document) return true;\r\n return Widget.isInDOM(e.parentNode);\r\n};\r\n\r\n/**\r\n * Create a `span` with a text or an HTML content.\r\n * If `txt` starts with `<html>`, we set an HTML content.\r\n */\r\nWidget.fromTextOrHtml = function(txt) {\r\n var e = Widget.span();\r\n if (txt.substr(0, 6) == '<html>') {\r\n e.html(txt.substr(6));\r\n } else {\r\n e.text(txt);\r\n }\r\n return e;\r\n};\r\n\r\n/**\r\n * Create a DIV and apply all arguments as classes to it.\r\n */\r\nWidget.div = function() {\r\n var div = new Widget({tag: \"div\"});\r\n for (var i = 0 ; i < arguments.length ; i++) {\r\n div.addClass(arguments[i]);\r\n }\r\n return div;\r\n};\r\n\r\n/**\r\n * Create a SPAN and apply all arguments as classes to it.\r\n */\r\nWidget.span = function() {\r\n var div = new Widget({tag: \"span\"});\r\n for (var i = 0 ; i < arguments.length ; i++) {\r\n div.addClass(arguments[i]);\r\n }\r\n return div;\r\n};\r\n\r\nWidget.tag = function(tag) {\r\n if (typeof tag === 'undefined') tag = 'div';\r\n var div = new Widget({tag: tag});\r\n for (var i = 1 ; i < arguments.length ; i++) {\r\n div.addClass(arguments[i]);\r\n }\r\n return div;\r\n};\r\n\r\nWidget.id = function(id) {\r\n return new Widget({element: window.document.getElementById(id)});\r\n};\r\n\r\n/**\r\n * Widget defining the `document.body` element.\r\n */\r\nWidget.body = new Widget(window.document.body);\r\n\r\nmodule.exports = Widget;\r\n\r\n\r\n\r\n/*\r\n * classList.js: Cross-browser full element.classList implementation.\r\n * 2014-07-23\r\n *\r\n * http://purl.eligrey.com/github/classList.js/blob/master/classList.js\r\n *\r\n * By Eli Grey, http://eligrey.com\r\n * Public Domain.\r\n * NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.\r\n */\r\n\r\n// Full polyfill for browsers with no classList support\r\nif (!(\"classList\" in window.document.createElement(\"_\"))) {\r\n (function () {\r\n \"use strict\";\r\n\r\n if (!('Element' in window)) return;\r\n\r\n var classListProp = \"classList\";\r\n var protoProp = \"prototype\";\r\n var elemCtrProto = window.Element[protoProp];\r\n var objCtr = Object;\r\n var strTrim = String.prototype.trim || function () {\r\n var rx = new RegExp(\"^\\\\s+|\\\\s+$\", \"g\");\r\n return this.replace(rx, '');\r\n };\r\n var arrIndexOf = Array[protoProp].indexOf || function (item) {\r\n var\r\n i = 0\r\n , len = this.length\r\n ;\r\n for (; i < len; i++) {\r\n if (i in this && this[i] === item) {\r\n return i;\r\n }\r\n }\r\n return -1;\r\n }\r\n // Vendors: please allow content code to instantiate DOMExceptions\r\n , DOMEx = function (type, message) {\r\n this.name = type;\r\n this.code = DOMException[type];\r\n this.message = message;\r\n }\r\n , checkTokenAndGetIndex = function (classList, token) {\r\n if (token === \"\") {\r\n throw new DOMEx(\r\n \"SYNTAX_ERR\"\r\n , \"An invalid or illegal string was specified\"\r\n );\r\n }\r\n if ((new RegExp(\"\\\\s\")).test(token)) {\r\n throw new DOMEx(\r\n \"INVALID_CHARACTER_ERR\"\r\n , \"String contains an invalid character\"\r\n );\r\n }\r\n return arrIndexOf.call(classList, token);\r\n }\r\n , ClassList = function (elem) {\r\n var\r\n trimmedClasses = strTrim.call(elem.getAttribute(\"class\") || \"\")\r\n , classes = trimmedClasses ? trimmedClasses.split(new RegExp(\"\\\\s+\")) : []\r\n , i = 0\r\n , len = classes.length\r\n ;\r\n for (; i < len; i++) {\r\n this.push(classes[i]);\r\n }\r\n this._updateClassName = function () {\r\n elem.setAttribute(\"class\", this.toString());\r\n };\r\n }\r\n , classListProto = ClassList[protoProp] = []\r\n , classListGetter = function () {\r\n return new ClassList(this);\r\n }\r\n ;\r\n\r\n // Most DOMException implementations don't allow calling DOMException's toString()\r\n // on non-DOMExceptions. Error's toString() is sufficient here.\r\n DOMEx[protoProp] = Error[protoProp];\r\n classListProto.item = function (i) {\r\n return this[i] || null;\r\n };\r\n classListProto.contains = function (token) {\r\n token += \"\";\r\n return checkTokenAndGetIndex(this, token) !== -1;\r\n };\r\n classListProto.add = function () {\r\n var\r\n tokens = arguments\r\n , i = 0\r\n , l = tokens.length\r\n , token\r\n , updated = false\r\n ;\r\n do {\r\n token = tokens[i] + \"\";\r\n if (checkTokenAndGetIndex(this, token) === -1) {\r\n this.push(token);\r\n updated = true;\r\n }\r\n }\r\n while (++i < l);\r\n\r\n if (updated) {\r\n this._updateClassName();\r\n }\r\n };\r\n classListProto.remove = function () {\r\n var\r\n tokens = arguments\r\n , i = 0\r\n , l = tokens.length\r\n , token\r\n , updated = false\r\n , index\r\n ;\r\n do {\r\n token = tokens[i] + \"\";\r\n index = checkTokenAndGetIndex(this, token);\r\n while (index !== -1) {\r\n this.splice(index, 1);\r\n updated = true;\r\n index = checkTokenAndGetIndex(this, token);\r\n }\r\n }\r\n while (++i < l);\r\n\r\n if (updated) {\r\n this._updateClassName();\r\n }\r\n };\r\n classListProto.toggle = function (token, force) {\r\n token += \"\";\r\n\r\n var\r\n result = this.contains(token)\r\n , method = result ?\r\n force !== true && \"remove\"\r\n :\r\n force !== false && \"add\"\r\n ;\r\n\r\n if (method) {\r\n this[method](token);\r\n }\r\n\r\n if (force === true || force === false) {\r\n return force;\r\n } else {\r\n return !result;\r\n }\r\n };\r\n classListProto.toString = function () {\r\n return this.join(\" \");\r\n };\r\n\r\n if (objCtr.defineProperty) {\r\n var classListPropDesc = {\r\n get: classListGetter, enumerable: true, configurable: true\r\n };\r\n try {\r\n objCtr.defineProperty(elemCtrProto, classListProp, classListPropDesc);\r\n } catch (ex) { // IE 8 doesn't support enumerable:true\r\n if (ex.number === -0x7FF5EC54) {\r\n classListPropDesc.enumerable = false;\r\n objCtr.defineProperty(elemCtrProto, classListProp, classListPropDesc);\r\n }\r\n }\r\n } else if (objCtr[protoProp].__defineGetter__) {\r\n elemCtrProto.__defineGetter__(classListProp, classListGetter);\r\n }\r\n }());\r\n} else {\r\n // There is full or partial native classList support, so just check if we need\r\n // to normalize the add/remove and toggle APIs.\r\n (function () {\r\n \"use strict\";\r\n\r\n var testElement = window.document.createElement(\"_\");\r\n\r\n testElement.classList.add(\"c1\", \"c2\");\r\n\r\n // Polyfill for IE 10/11 and Firefox <26, where classList.add and\r\n // classList.remove exist but support only one argument at a time.\r\n if (!testElement.classList.contains(\"c2\")) {\r\n var createMethod = function(method) {\r\n var original = DOMTokenList.prototype[method];\r\n\r\n DOMTokenList.prototype[method] = function(token) {\r\n var i, len = arguments.length;\r\n\r\n for (i = 0; i < len; i++) {\r\n token = arguments[i];\r\n original.call(this, token);\r\n }\r\n };\r\n };\r\n createMethod('add');\r\n createMethod('remove');\r\n }\r\n\r\n testElement.classList.toggle(\"c3\", false);\r\n\r\n // Polyfill for IE 10 and Firefox <24, where classList.toggle does not\r\n // support the second argument.\r\n if (testElement.classList.contains(\"c3\")) {\r\n var _toggle = DOMTokenList.prototype.toggle;\r\n\r\n DOMTokenList.prototype.toggle = function(token, force) {\r\n if (1 in arguments && !this.contains(token) === !force) {\r\n return force;\r\n } else {\r\n return _toggle.call(this, token);\r\n }\r\n };\r\n\r\n }\r\n testElement = null;\r\n }());\r\n}\r\n });\r\n","zip":"require(\"wdg\",function(t,e){\"use strict\";function n(t){this.__data={};try{var e;if(\"undefined\"==typeof t&&(t={}),\"undefined\"!=typeof t.innerHTML&&\"undefined\"!=typeof t.childNodes&&(t={element:t}),\"undefined\"==typeof t.tag&&(t.tag=\"div\"),t.element)this.element(t.element);else if(\"undefined\"!=typeof t.id){if(e=window.document.getElementById(t.id),!e)throw Error(\"Can't find element with id: \\\"\"+t.id+'\"!');this.element(e)}else this.element(window.document.createElement(t.tag)),this.addClass(\"wdg\",\"custom\")}catch(n){throw console.error(\"[widget] \",n),console.error(\"[Widget] \",JSON.stringify(t)),Error(n)}}n.prototype={element:function(t){return void 0===t?this._element:(\"string\"==typeof t&&(t=window.document.querySelector(t)),this._element=t,this)},data:function(t,e){return\"undefined\"==typeof e?this.__data[t]:(this.__data[t]=e,this)},detach:function(){var t=this._element;if(t){var e=t.parentNode;e&&e.removeChild(t)}return this},addEvent:function(t,e,n){if(\"string\"==typeof e){var i=e;\"undefined\"==typeof n&&(n=this),e=function(t){var r=n[i];if(\"function\"!=typeof r)throw Error('\"'+e+'\" is not a function of: '+n);r.call(n,t)}}var r=this.element();return\"tap\"==t?(r.addEventListener(\"mousedown\",function(t){t.preventDefault(),t.stopPropagation()},!1),r.addEventListener(\"mouseup\",function(t){t.preventDefault(),t.stopPropagation(),e(t)},!1),r.addEventListener(\"touchend\",e,!1)):r.addEventListener(t,e,!1),this},removeAttr:function(){if(this._element){var t,e;for(t=0;t<arguments.length;t++)e=arguments[t],this._element.removeAttribute(e)}return this},hasAttribute:function(t){return this._element?this._element.hasAttribute(t):!1},attr:function(t,e,n){var i;if(!this._element||!this._element.getAttribute)return null;if(\"string\"==typeof t)return void 0!==e?\"class\"==t?(this._element.className=e,this):(n&&this._element.setAttributeNS?this._element.setAttributeNS(n,t,e):this._element.setAttribute(t,e),this):this._element.getAttribute(t);if(\"object\"==typeof t)for(i in t)\"class\"==i?this._element.className=t[i]:\"$\"==i?this.text(t[i]):this._element.setAttribute(i,t[i]);return this},css:function(t,e){var n,i=this._element;if(!i)return null;if(\"object\"!=typeof i.style&&(console.error(\"[wdg.css] This element does not support styles!\",i),i.style={}),\"string\"==typeof t)return e?(i.style[t]=e,this):i.style[t];if(\"object\"==typeof t)for(n in t)try{i.style[n]=t[n]}catch(r){console.error(\"[wdg.css] Bad CSS attribute \"+n+\": \"+t[n])}return this},insertAfter:function(t){return\"function\"==typeof t.element&&(t=t.element()),t.parentNode.insertBefore(this.element(),t.nextSibling),this},insertBefore:function(t){return\"function\"==typeof t.element&&(t=t.element()),t.parentNode.insertBefore(this.element(),t),this},append:function(){var t,e;for(t=0;t<arguments.length;t++)if(e=arguments[t],\"number\"==typeof e&&(e=\"\"+e),\"undefined\"==typeof e||\"object\"!=typeof e&&\"string\"!=typeof e)console.error(\"[Widget.append] Argument #\"+t+\" is invalid!\",arguments),console.error(\"[Widget.append] Is type is: \"+typeof e);else{if(\"string\"==typeof e&&(e.length<1&&(e=\" \"),e=window.document.createTextNode(e),!e))throw console.error(\"[Widget.append] Unable to create a text node with this text: \",e),console.error(\"[wdg] arguments=...\",arguments),Error(\"[Widget.append] Unable to create a text node with this text: \"+JSON.stringify(e));if(Array.isArray(e))e.forEach(function(t){this.append(t)},this);else{var n=\"function\"==typeof e.element?e.element():e;this._element.appendChild(n)}}return this},appendTo:function(t){return t?(\"function\"==typeof t.append?t.append(this):\"function\"==typeof t.appendChild&&(t.appendChild(this._element),this.onAppend()),this):this},appendToBody:function(){return window.document.body.appendChild(this._element),this},hasClass:function(){var t,e,n=this._element.classList;for(t=0;t<arguments.length;t++)if(e=arguments[t],!n.contains(e))return!1;return!0},addClass:function(){var t,e,n=this._element.classList;for(t=0;t<arguments.length;t++)e=arguments[t],\"string\"==typeof e?(e=e.trim(),e.length>0&&n.add(e)):console.error(\"[wdg.addClass] Arguments with bad type!\",arguments);return this},removeClass:function(){var t,e,n=this._element.classList;for(t=0;t<arguments.length;t++)e=arguments[t],n.remove(e);return this},toggleClass:function(){var t,e,n=this._element.classList;for(t=0;t<arguments.length;t++)e=arguments[t],n.toggle(e);return this},clear:function(){for(var t=this.element();t.firstChild;)t.removeChild(t.firstChild);var e,n;for(e=0;e<arguments.length;e++)n=arguments[e],this.append(n);return this},text:function(t){var e,n,i,r;if(\"string\"==typeof t||\"number\"==typeof t)return t=\"\"+t,\"<html>\"==t.substr(0,6)?this.html(t.substr(6)):(this.clear(),this._element.appendChild(window.document.createTextNode(t)),this);if(e=this._element,void 0!==t&&(e=t),n=\"\",e.childNodes)for(i=0;i<e.childNodes.length;i++)r=e.childNodes[i],3==r.nodeType?r.nodeValue&&(n+=r.nodeValue):n+=this.text(r);return n},html:function(t){return\"undefined\"==typeof t?this._element.innerHTML:(this._element&&(this._element.innerHTML=t),this)},focus:function(){var t=this._element;return t?(\"function\"==typeof t.focus&&t.focus(),this):this},rect:function(){var t=this._element;return t?t.getBoundingClientRect():null},Tap:function(t,e){if(\"undefined\"==typeof t)return this._Tap;var n=this;return\"undefined\"==typeof e&&(e=n),\"string\"==typeof t&&(t=e[t]),this._Tap||this.activatePointerEvents(),this._Tap=[t,e],this}},n.prototype.activatePointerEvents=function(){if(this._pointerEvents)return this;this._pointerEvents={start:0};var t=this._pointerEvents,e=this;return this.addEvent(\"touchstart\",function(e){e.preventDefault(),e.stopPropagation(),t.touch=1,t.start=Date.now()}),this.addEvent(\"touchend\",function(n){n.preventDefault(),n.stopPropagation();var i=e._Tap;if(i){t.touch=0;var r=Date.now()-t.start;900>r&&i[0].call(i[1],n)}}),this.addEvent(\"mousedown\",function(e){e.preventDefault(),e.stopPropagation(),t.touch||(t.start=Date.now())}),this.addEvent(\"mouseup\",function(n){n.preventDefault(),n.stopPropagation();var i=e._Tap;if(i){var r=Date.now()-t.start;900>r&&i[0].call(i[1],n)}}),this},n.prototype.div=function(){for(var t=new n,e=0;e<arguments.length;e++)t.addClass(arguments[e]);return t},n.prototype.tag=function(t){\"undefined\"==typeof t&&(t=\"div\");for(var e=new n({tag:t}),i=1;i<arguments.length;i++)e.addClass(arguments[i]);return e},n.prototype.isInDOM=function(){return n.isInDOM(this.element())},n.prototype.onAppend=function(){},n.create=function(t){return new n(t)},n.find=function(t){return new n({element:window.document.querySelector(t)})},n.svg=function(t,e){var i=\"http://www.w3.org/2000/svg\";\"object\"==typeof t&&(e=t,t=\"svg\"),\"string\"!=typeof t&&(t=\"svg\");var r=window.document.createElementNS(i,t),s=new n({element:r});return\"undefined\"==typeof e&&(e={}),\"svg\"==t&&(\"undefined\"==typeof e.version&&(e.version=\"1.1\"),\"undefined\"==typeof e[\"xmlns:svg\"]&&(e[\"xmlns:svg\"]=\"http://www.w3.org/2000/svg\"),\"undefined\"==typeof e.xmlns&&(e.xmlns=\"http://www.w3.org/2000/svg\"),\"undefined\"==typeof e[\"xmlns:xlink\"]&&(e[\"xmlns:xlink\"]=\"http://www.w3.org/1999/xlink\"),\"undefined\"==typeof e.viewBox&&\"number\"==typeof e.width&&\"number\"==typeof e.height&&(e.viewBox=\"0 0 \"+e.width+\" \"+e.height)),\"object\"==typeof e&&s.attr(e),s},n.isInDOM=function(t){return t?(\"function\"==typeof t.element&&(t=t.element()),t===window.document?!0:n.isInDOM(t.parentNode)):!1},n.fromTextOrHtml=function(t){var e=n.span();return\"<html>\"==t.substr(0,6)?e.html(t.substr(6)):e.text(t),e},n.div=function(){for(var t=new n({tag:\"div\"}),e=0;e<arguments.length;e++)t.addClass(arguments[e]);return t},n.span=function(){for(var t=new n({tag:\"span\"}),e=0;e<arguments.length;e++)t.addClass(arguments[e]);return t},n.tag=function(t){\"undefined\"==typeof t&&(t=\"div\");for(var e=new n({tag:t}),i=1;i<arguments.length;i++)e.addClass(arguments[i]);return e},n.id=function(t){return new n({element:window.document.getElementById(t)})},n.body=new n(window.document.body),e.exports=n,\"classList\"in window.document.createElement(\"_\")?!function(){var t=window.document.createElement(\"_\");if(t.classList.add(\"c1\",\"c2\"),!t.classList.contains(\"c2\")){var e=function(t){var e=DOMTokenList.prototype[t];DOMTokenList.prototype[t]=function(t){var n,i=arguments.length;for(n=0;i>n;n++)t=arguments[n],e.call(this,t)}};e(\"add\"),e(\"remove\")}if(t.classList.toggle(\"c3\",!1),t.classList.contains(\"c3\")){var n=DOMTokenList.prototype.toggle;DOMTokenList.prototype.toggle=function(t,e){return 1 in arguments&&!this.contains(t)==!e?e:n.call(this,t)}}t=null}():!function(){if(\"Element\"in window){var t=\"classList\",e=\"prototype\",n=window.Element[e],i=Object,r=String.prototype.trim||function(){var t=new RegExp(\"^\\\\s+|\\\\s+$\",\"g\");return this.replace(t,\"\")},s=Array[e].indexOf||function(t){for(var e=0,n=this.length;n>e;e++)if(e in this&&this[e]===t)return e;return-1},o=function(t,e){this.name=t,this.code=DOMException[t],this.message=e},a=function(t,e){if(\"\"===e)throw new o(\"SYNTAX_ERR\",\"An invalid or illegal string was specified\");if(new RegExp(\"\\\\s\").test(e))throw new o(\"INVALID_CHARACTER_ERR\",\"String contains an invalid character\");return s.call(t,e)},u=function(t){for(var e=r.call(t.getAttribute(\"class\")||\"\"),n=e?e.split(new RegExp(\"\\\\s+\")):[],i=0,s=n.length;s>i;i++)this.push(n[i]);this._updateClassName=function(){t.setAttribute(\"class\",this.toString())}},l=u[e]=[],d=function(){return new u(this)};if(o[e]=Error[e],l.item=function(t){return this[t]||null},l.contains=function(t){return t+=\"\",-1!==a(this,t)},l.add=function(){var t,e=arguments,n=0,i=e.length,r=!1;do t=e[n]+\"\",-1===a(this,t)&&(this.push(t),r=!0);while(++n<i);r&&this._updateClassName()},l.remove=function(){var t,e,n=arguments,i=0,r=n.length,s=!1;do for(t=n[i]+\"\",e=a(this,t);-1!==e;)this.splice(e,1),s=!0,e=a(this,t);while(++i<r);s&&this._updateClassName()},l.toggle=function(t,e){t+=\"\";var n=this.contains(t),i=n?e!==!0&&\"remove\":e!==!1&&\"add\";return i&&this[i](t),e===!0||e===!1?e:!n},l.toString=function(){return this.join(\" \")},i.defineProperty){var f={get:d,enumerable:!0,configurable:!0};try{i.defineProperty(n,t,f)}catch(h){-2146823252===h.number&&(f.enumerable=!1,i.defineProperty(n,t,f))}}else i[e].__defineGetter__&&n.__defineGetter__(t,d)}}()});\n//# sourceMappingURL=wdg.js.map","map":{"version":3,"file":"wdg.js.map","sources":["wdg.js"],"sourcesContent":["require( 'wdg', function(exports, module) { 'use strict';\r\n\r\n/**\r\n * Widgets inherit this class.\r\n */\r\nfunction Widget(options) {\r\n this.__data = {};\r\n try {\r\n var e;\r\n if (typeof options === 'undefined') options = {};\r\n if (typeof options.innerHTML !== 'undefined' && typeof options.childNodes !== 'undefined') {\r\n // On passe directement un élément.\r\n options = {element: options};\r\n }\r\n if (typeof options.tag === 'undefined') options.tag = \"div\";\r\n if (options.element) {\r\n this.element(options.element);\r\n } else if (typeof options.id !== 'undefined') {\r\n e = window.document.getElementById(options.id);\r\n if (!e) {\r\n throw Error(\"Can't find element with id: \\\"\" + options.id + \"\\\"!\");\r\n }\r\n this.element(e);\r\n } else {\r\n this.element(window.document.createElement(options.tag));\r\n this.addClass(\"wdg\", \"custom\");\r\n }\r\n }\r\n catch (ex) {\r\n console.error(\"[widget] \", ex);\r\n console.error(\"[Widget] \", JSON.stringify(options));\r\n throw Error(ex);\r\n }\r\n}\r\n\r\nWidget.prototype = {\r\n /**\r\n * Accessor for attribute element\r\n * @return element\r\n */\r\n element: function(v) {\r\n if (v === undefined) return this._element;\r\n if (typeof v === 'string') {\r\n v = window.document.querySelector(v);\r\n }\r\n this._element = v;\r\n return this;\r\n },\r\n\r\n data: function(k, v) {\r\n if (typeof v === 'undefined') {\r\n return this.__data[k];\r\n }\r\n this.__data[k] = v;\r\n return this;\r\n },\r\n\r\n /**\r\n * @description\r\n * Remove this element from its parent.\r\n * @memberof wdg\r\n */\r\n detach: function() {\r\n var e = this._element;\r\n if (e) {\r\n var p = e.parentNode;\r\n if (p) {\r\n p.removeChild(e);\r\n }\r\n }\r\n return this;\r\n },\r\n\r\n /**\r\n * @description\r\n *\r\n * @param name\r\n * @memberof wdg\r\n */\r\n addEvent: function(name, slot, sender) {\r\n if (typeof slot === 'string') {\r\n var that = this, key = slot;\r\n if (typeof sender === 'undefined') sender = this;\r\n slot = function(x) {\r\n var f = sender[key];\r\n if (typeof f === 'function') {\r\n f.call(sender, x);\r\n } else {\r\n throw Error(\"\\\"\" + slot + \"\\\" is not a function of: \" + sender);\r\n }\r\n };\r\n }\r\n var e = this.element();\r\n if (name == 'tap') {\r\n e.addEventListener(\r\n \"mousedown\",\r\n function(evt) {\r\n evt.preventDefault();\r\n evt.stopPropagation();\r\n },\r\n false\r\n );\r\n e.addEventListener(\r\n \"mouseup\",\r\n function(evt) {\r\n evt.preventDefault();\r\n evt.stopPropagation();\r\n slot(evt);\r\n },\r\n false\r\n );\r\n e.addEventListener(\"touchend\", slot, false);\r\n\r\n } else {\r\n e.addEventListener(name, slot, false);\r\n }\r\n return this;\r\n },\r\n\r\n /**\r\n * Retire un attribut à l'élément sous-jacent.\r\n * @example\r\n * this.removeAttr(\"selected\");\r\n * @memberof wdg\r\n */\r\n removeAttr: function() {\r\n if (this._element) {\r\n var i, arg;\r\n for (i = 0 ; i < arguments.length ; i++) {\r\n arg = arguments[i];\r\n this._element.removeAttribute(arg);\r\n }\r\n }\r\n return this;\r\n },\r\n\r\n /**\r\n * Teste l'existence d'un attribut dans l'élément sous-jacent.\r\n * @memberof wdg\r\n */\r\n hasAttribute: function(key) {\r\n if (!this._element) return false;\r\n return this._element.hasAttribute(key);\r\n },\r\n\r\n /**\r\n * Lit ou affecte la valeur d'un attribut de l'élément sous-jacent.\r\n * @example\r\n * // Le pseudo attribut '$' sert à insérer du texte.\r\n * var div = new Widget();\r\n * div.attr({$: 'Hello world!', title: 'Typical first sentence...'});\r\n * @param key Nom de l'attribut ou dictionnaire des attributs.\r\n * @param val [Facultatif] Valeur de l'attribut. Si elle est omise, la méthode retourne la valeur actuelle.\r\n * @param ns [Facultatif] Namespace éventuel.\r\n * @memberof wdg\r\n */\r\n attr: function(key, val, ns) {\r\n var k;\r\n if (!this._element || !this._element.getAttribute) return null;\r\n if (typeof key == \"string\") {\r\n if (val !== undefined) {\r\n if (key == \"class\") {\r\n this._element.className = val;\r\n return this;\r\n }\r\n if (ns && this._element.setAttributeNS) {\r\n this._element.setAttributeNS(ns, key, val);\r\n }\r\n else {\r\n this._element.setAttribute(key, val);\r\n }\r\n return this;\r\n }\r\n return this._element.getAttribute(key);\r\n }\r\n if (typeof key == \"object\") {\r\n for (k in key) {\r\n if (k == \"class\") {\r\n this._element.className = key[k];\r\n } else if (k == \"$\") {\r\n this.text(key[k]);\r\n } else {\r\n this._element.setAttribute(k, key[k]);\r\n }\r\n }\r\n }\r\n return this;\r\n },\r\n\r\n\r\n /**\r\n * Permet de changer le style de l'élément sous-jacent.\r\n * @example\r\n * this.css(\"color\", \"red\");\r\n * alert(this.css(\"display\"));\r\n * this.css(\r\n * {\r\n * margin: \"0px\",\r\n * padding: \"3px\",\r\n * border: \"1px solid black\"\r\n * }\r\n * );\r\n * @param key Nom du champ de style ou dictionnaire clefs/valeurs.\r\n * @param val Valeur du champ key. S'il est omis et que \"key\"\r\n * est de type string, alors la méthode retourne la valeur\r\n * actuelle.\r\n * @memberof wdg\r\n */\r\n css: function(key, val) {\r\n var k, e = this._element;\r\n if (!e) return null;\r\n if (typeof e.style !== 'object') {\r\n console.error(\"[wdg.css] This element does not support styles!\", e);\r\n e.style = {};\r\n }\r\n if (typeof key == 'string') {\r\n if (val) {\r\n e.style[key] = val;\r\n return this;\r\n }\r\n return e.style[key];\r\n }\r\n if (typeof key == 'object') {\r\n for (k in key) {\r\n try {\r\n e.style[k] = key[k];\r\n } catch (x) {\r\n console.error(\"[wdg.css] Bad CSS attribute \" + k + \": \" + key[k]);\r\n }\r\n }\r\n }\r\n return this;\r\n },\r\n\r\n insertAfter: function(target) {\r\n if (typeof target.element === 'function') {\r\n target = target.element();\r\n }\r\n target.parentNode.insertBefore(this.element(), target.nextSibling);\r\n return this;\r\n },\r\n\r\n insertBefore: function(target) {\r\n if (typeof target.element === 'function') {\r\n target = target.element();\r\n }\r\n target.parentNode.insertBefore(this.element(), target);\r\n return this;\r\n },\r\n\r\n /**\r\n * Append children to this widget.\r\n */\r\n append: function() {\r\n var i, arg;\r\n for (i = 0 ; i < arguments.length ; i++) {\r\n arg = arguments[i];\r\n if (typeof arg === 'number') arg = \"\" + arg;\r\n if (typeof arg === 'undefined' || (typeof arg !== 'object' && typeof arg !== 'string')) {\r\n console.error(\"[Widget.append] Argument #\" + i + \" is invalid!\", arguments);\r\n console.error(\"[Widget.append] Is type is: \" + (typeof arg));\r\n continue;\r\n };\r\n if (typeof arg === 'string') {\r\n if (arg.length < 1) arg = \" \";\r\n arg = window.document.createTextNode(arg);\r\n if (!arg) {\r\n console.error(\r\n \"[Widget.append] Unable to create a text node with this text: \", arg\r\n );\r\n console