/ittf/meta/html/main.js.ittf (primary)
1 module2 kind es63 $include js/wz/core4 $include js/wz/ace5 $include js/editManager6 $include js/modalManager7 $include js/dataManager8 $include js/clickListener9 _ wz.contentLoaded10 function11 log '*** content loaded'12 var editorImpl13 new AceEditor14 {15 @ key 'ittf-editor'16 @ editorElementId 'editorContainer'17 @ width '1100px'18 @ height '600px'19 var ctx20 {21 @ editorImpl editorImpl22 @ editSaveUrl '/api/v1/wizzifs/ittf'23 @ editSaveHttpMethod 'put'24 @ modalsContainerId 'modalsContainer'25 set ctx.editManager26 new EditManager27 @ ctx28 {29 @ dataHashKey 'ittfhash'30 @ dataContentKey 'ittfcontent'31 @ dataPrettyKey 'ittfpretty'32 @ dataTitleKey 'ittftitle'33 set ctx.modalManager = new ModalManager(ctx)34 set ctx.dataManager = new DataManager(ctx)35 set ctx.clickHandler = ctx.editManager36 _ setupClickListener37 @ ctx38 {39 @ containerId 'mc-wrapper'40 @ targetClass 'edit-ittf-content-button'41 @ dataField42 [43 @ 'ittfhash'44 @ 'ittfcontent'45 @ 'ittfpretty'46 @ 'ittftitle'
/t/js/wz/core.js.ittf
1 $group2 $include polyfill3 iife4 var wz = window.wz = {}5 var rclass = /[\n\t\r]/g6 var rnotwhite = (/\S+/g)7 $include eventTarget8 $include global9 $include events10 $include verify11 set wz.element12 function13 param element14 if typeof element === 'string'15 var e = document.querySelector(element)16 if !e17 try18 set e = document.querySelector("#" + element)19 catch ex20 return null21 return e22 else23 return element24 set wz.hide25 function26 param element27 var e = wz.element(element)28 set e.style.display = 'none'29 set wz.show30 function31 param element32 var e = wz.element(element)33 set e.style.display = 'block'34 set wz.hasClass35 function36 param element37 param selector38 var e = wz.element(element)39 if (" " + e.className + " ").replace(rclass, " ").indexOf(" " + selector + " ") > -140 return true41 return false42 set wz.addClass43 function44 param element45 param value46 param options47 var e = wz.element(element)48 var classes, cur, finalValue49 if options && options.removeOnClass50 var elements = document.getElementsByClassName(options.removeOnClass)51 _ Array.from(elements).forEach52 function53 param element54 _ wz.removeClass(element, value)55 if value && typeof value === "string"56 set classes = ( value || "" ).match( rnotwhite ) || []57 if !e.className && classes.length === 158 set e.className = value59 else60 set cur = " " + e.className + " "61 foreach clazz in classes62 if cur.indexOf( " " + clazz + " " ) < 063 set cur += clazz + " "64 set finalValue = cur.trim()65 if e.className !== finalValue66 set e.className = finalValue67 set wz.removeClass68 function69 param element70 param value71 var e = wz.element(element)72 var classes, cur, finalValue73 if value && typeof value === "string"74 set classes = ( value || "" ).match( rnotwhite ) || []75 set cur = e.className ? ( " " + e.className + " " ).replace( rclass, " " ) : ""76 foreach clazz in classes77 while cur.indexOf( " " + clazz + " " ) >= 078 set cur = cur.replace( " " + clazz + " ", " " )79 set finalValue = cur.trim()80 if e.className !== finalValue81 set e.className = finalValue82 set wz.toggleClass83 function84 param element85 param value86 if wz.hasClass(element, value)87 _ wz.removeClass(element, value)88 else89 _ wz.addClass(element, value)90 set wz.attribute91 function92 param element93 param name94 param value95 var e = wz.element(element)96 if typeof value === 'undefined'97 return e.getAttribute(name)98 else99 _ e.setAttribute(name, value)100 set wz.style101 function102 param element103 param name104 param value105 var e = wz.element(element)106 if typeof value === 'undefined'107 return e.style[name]108 else109 set e.style[name] = value110 set wz.text111 function112 param element113 param value114 var e = wz.element(element)115 if typeof value === 'undefined'116 return e.textContent117 elif e.textContent !== value118 set e.textContent = value119 set wz.html120 function121 param element122 param html123 var saveElementForLog = element124 if typeof element === "string"125 set element = wz.element(element)126 if !element127 log 'element', saveElementForLog128 throw new Error('In wz.html the element parameter must be an html element or the id of an html element. Received: ' + saveElementForLog)129 if typeof html === 'undefined'130 return element.innerHTML131 else132 set element.innerHTML = html133 set wz.htmlEscaped134 function135 param element136 param html137 _ wz.html138 @ element139 _ wz.escapeHtml(html)140 set wz.replaceChildren141 function142 param element143 param nodes144 var saveElementForLog = element145 if typeof element === "string"146 set element = wz.element(element)147 if !element148 log 'element', saveElementForLog149 throw new Error('In wz.replaceChildren the element parameter must be an html element or the id of an html element. Received: ' + saveElementForLog)150 set element.innerHTML = ''151 if nodes.length152 foreach node in nodes153 _ element.appendChild( node )154 else155 _ element.appendChild( nodes )156 set wz.value157 function158 param element159 param value160 var saveElementForLog = element161 if typeof element === "string"162 set element = wz.element(element)163 if !element164 log 'element', saveElementForLog165 throw new Error('In wz.value the element parameter must be an html element or the id of an html element. Received: ' + saveElementForLog)166 if typeof value === 'undefined'167 return element.value168 elif element.value !== value169 set element.value = value170 set wz.val = wz.value171 set wz.click172 function173 param element174 param handler175 param useCapture176 _ window.addEvent177 @ wz.element(element)178 @ 'click'179 @ handler180 @ useCapture181 set wz.clickClass182 function183 param classname184 param handler185 param useCapture186 var elements = document.getElementsByClassName(classname)187 _ Array.from(elements).forEach188 function189 param element190 _ wz.click191 @ element192 @ handler193 @ useCapture194 set wz.unclick195 function196 param element197 param handler198 param useCapture199 _ window.removeEvent200 @ wz.element(element)201 @ 'click'202 @ handler203 @ useCapture204 set wz.blur205 function206 param element207 param handler208 param useCapture209 _ window.addEvent210 @ wz.element(element)211 @ 'blur'212 @ handler213 @ useCapture214 set wz.unblur215 function216 param element217 param handler218 param useCapture219 _ window.removeEvent220 @ wz.element(element)221 @ 'blur'222 @ handler223 @ useCapture224 set wz.change225 function226 param element227 param handler228 param useCapture229 _ window.addEvent230 @ wz.element(element)231 @ 'change'232 @ handler233 @ useCapture234 set wz.unchange235 function236 param element237 param handler238 param useCapture239 _ window.removeEvent240 @ wz.element(element)241 @ 'change'242 @ handler243 @ useCapture244 set wz.contextmenu245 function246 param element247 param handler248 param useCapture249 _ window.addEvent250 @ wz.element(element)251 @ 'contextmenu'252 @ handler253 @ useCapture254 set wz.uncontextmenu255 function256 param element257 param handler258 param useCapture259 _ window.removeEvent260 @ wz.element(element)261 @ 'contextmenu'262 @ handler263 @ useCapture264 set wz.keypress265 function266 param element267 param handler268 param useCapture269 _ window.addEvent270 @ wz.element(element)271 @ 'keypress'272 @ handler273 @ useCapture274 set wz.unkeypress275 function276 param element277 param handler278 param useCapture279 _ window.removeEvent280 @ wz.element(element)281 @ 'keypress'282 @ handler283 @ useCapture284 set wz.contentLoaded285 function286 param fn287 # from Diego Perini https://raw.githubusercontent.com/dperini/ContentLoaded/master/src/contentloaded.js288 var289 decl done = false290 decl top = true291 decl doc = window.document292 decl root = doc.documentElement293 decl modern = doc.addEventListener294 decl add = modern ? 'addEventListener' : 'attachEvent'295 decl rem = modern ? 'removeEventListener' : 'detachEvent'296 decl pre = modern ? '' : 'on'297 decl init298 function299 param e300 if (e.type == 'readystatechange') && (doc.readyState != 'complete')301 return302 _ (e.type == 'load' ? window : doc)[rem]303 @ pre + e.type304 @ init305 @ false306 if !(done) && (done = true)307 _ fn.call(window, (e.type || e))308 decl poll309 function310 try311 _ root.doScroll('left')312 catch e313 _ setTimeout(poll, 50)314 return315 _ init('poll')316 if doc.readyState == 'complete'317 _ fn.call(window, 'lazy')318 else319 if !(modern) && root.doScroll320 try321 set top = !(window.frameElement)322 catch e323 if top324 _ poll()325 _ doc[add]326 @ pre + 'DOMContentLoaded'327 @ init328 @ false329 _ doc[add]330 @ pre + 'readystatechange'331 @ init332 @ false333 _ window[add]334 @ pre + 'load'335 @ init336 @ false337 set wz.loaded = wz.contentLoaded338 var entityMap339 {340 @ '&' '&'341 @ '<' '<'342 @ '>' '>'343 @ '"' '"'344 @ "'" '''345 @ '/' '/'346 @ '`' '`'347 @ '=' '='348 set wz.escapeHtml349 function escapeHtml350 param string351 return352 _ String(string).replace353 @ /[&<>"'`=\/]/g354 function fromEntityMap355 param s356 return entityMap[s]357 set wz.unescapeHtml358 function359 param string360 return361 _ wz.replace362 _ wz.replace363 _ wz.replace364 @ string365 @ '<'366 @ '<'367 @ '>'368 @ '>'369 @ '&'370 @ '&'371 ()
/t/js/wz/ace.js.ittf
1 $group2 var AceEditor_mimemap3 {4 @ js 'javascript'5 var AceEditor_defaults6 {7 @ key 'ace'8 @ editorElementId 'aceEditor'9 @ mode 'text'10 @ theme 'monokai'11 @ fontSize '11pt'12 class AceEditor13 ctor14 param options15 #16 # params17 # { options18 # string editorElementId19 # string mode20 # string theme21 # number width22 # number height23 set this.options24 _ Object.assign25 @ AceEditor_defaults26 @ options27 set this.elementId = this.options.editorElementId28 set this.key = this.options.key29 set this.editor = null30 set this.events = {}31 m getValue32 if this.editor33 return this.editor.getValue()34 m setValue35 param value36 if !this.editor37 _ this.initialize()38 _ this.editor.setValue(value, 1)39 m setMime40 param value41 _ this.setMode42 @ AceEditor_mimemap[value] || value43 m setMode44 param value45 if this.editor46 _ this.editor.getSession().setMode47 @ "ace/mode/" + value48 m setTheme49 param value50 if this.editor51 _ this.editor.setTheme52 @ "ace/theme/" + value53 m readOnly54 param value55 if typeof value === 'undefined'56 return57 _ this.editor.getReadOnly()58 else59 _ this.editor.setReadOnly(value)60 m onChange61 param handler62 set this.onChange = handler63 m initialize64 if this.editor65 return66 log 'AceEditor.initialize start on', this.options.editorElementId67 if typeof ace === 'undefined' || !ace.edit68 throw new Error('wz.ace initialize methods requires the `ace` component. Check that the ace script has been included.')69 set this.element = wz.element('#' + this.options.editorElementId)70 if !this.element71 throw new Error('wz.ace initialize methods requires an existing `options.editorElementId` : ' + this.options.editorElementId + ' html element.')72 _ wz.style(this.element, 'width', this.options.width)73 _ wz.style(this.element, 'height', this.options.height)74 set this.editor75 _ ace.edit76 @ this.options.editorElementId77 _ this.editor.setOptions78 {79 @ fontSize this.options.fontSize80 _ this.setMode81 @ this.options.mode82 _ this.setTheme83 @ this.options.theme84 var that = this85 _ this.editor.getSession().on86 @ 'change'87 function88 _ that.fire89 @ 'change'90 [91 _ that.getValue92 log 'AceEditor.initialize end'93 m on94 param name95 param handler96 if this.events.hasOwnProperty(name)97 _ this.events[name].push(handler)98 else99 set this.events[name] = [handler]100 m off101 param name102 param handler103 if !this.events.hasOwnProperty(name)104 return105 var index = this.events[name].indexOf(handler)106 if index != -1107 _ this.events[name].splice(index, 1)108 m fire109 param name110 param args111 if !this.events.hasOwnProperty(name)112 return113 if !args || !args.length114 set args = []115 foreach ev in this.events[name]116 _ ev.apply(null, args)
/ittf/meta/html/t/js/editManager.js.ittf
1 $group2 #3 # implements clickHandler4 # params5 # { ctx6 # { editorImpl7 # { modalManager8 # string editorKey9 #10 class EditManager11 ctor12 param ctx13 param options14 set this.ctx = ctx15 set this.options = options16 set this.editorImpl = ctx.editorImpl17 # do not set this in the constructor, could be yet uncreated18 # set this.modalManager = ctx.modalManager19 set this.dataHashKey = options.dataHashKey20 set this.dataContentKey = options.dataContentKey21 set this.dataPrettyKey = options.dataPrettyKey22 set this.dataTitleKey = options.dataTitleKey23 set this.contentHash = null24 set this.contentOriginal = null25 m initEditor26 if this.editor27 return28 _ this.editorImpl.initialize29 set this.editor = this.editorImpl30 var that = this31 var saveEl = wz.element('#' + this.editor.key + '-save')32 var saveRefreshEl = wz.element('#' + this.editor.key + '-save-refresh')33 var cancelEl = wz.element('#' + this.editor.key + '-cancel')34 set this.titleElement = wz.element('#' + this.editor.key + '-title')35 _ wz.click36 @ cancelEl37 function38 _ that.ctx.modalManager.hide39 @ that.editor.key40 _ wz.click41 @ saveEl42 function43 if that.editor.getValue() !== that.contentOriginal44 _ that.ctx.dataManager.editSave45 @ that.contentHash46 _ that.editor.getValue47 _ that.ctx.modalManager.hide48 @ that.editor.key49 _ wz.click50 @ saveRefreshEl51 function52 if that.editor.getValue() !== that.contentOriginal53 _ that.ctx.dataManager.editSave54 @ that.contentHash55 _ that.editor.getValue56 _ that.ctx.modalManager.hide57 @ that.editor.key58 set location.href= location.pathname59 m onSave60 param data61 _ wz.value62 @ this.contentElementId63 @ data.content64 _ wz.html65 @ this.prettyElementId66 @ data.pretty && data.pretty.prettyLines ? data.pretty.prettyLines.join('') : data.pretty67 m setEditor68 param options69 if this.editor70 _ this.editor.setValue71 @ options.value72 if this.titleElement73 _ wz.text(this.titleElement, options.title)74 m edit75 param options76 # log 'wz.editManager.edit.options', options77 _ this.initEditor78 _ this.setEditor79 @ options80 m handleClick81 param target82 param dataValue83 # log 'wz.editManager.handleClick.dataValue', dataValue84 set this.contentElementId = dataValue[this.dataContentKey]85 set this.prettyElementId = dataValue[this.dataPrettyKey]86 set this.contentHash = dataValue[this.dataHashKey]87 set this.contentOriginal = wz.value(this.contentElementId)88 _ this.edit89 {90 @ value wz.value(this.contentElementId)91 @ title dataValue[this.dataTitleKey]92 _ this.ctx.modalManager.show93 @ this.editor.key94 @ this.editor.key + '-form'95 m checkClick96 param target97 if this.editor98 return99 _ this.ctx.modalManager.checkClick100 @ this.editor.key + '-form'101 @ target102 return false
/ittf/meta/html/t/js/modalManager.js.ittf
1 $group2 class ModalManager3 ctor4 param ctx5 set this.ctx = ctx6 set this.dialogs = {}7 m checkClick8 param dialogKey9 param target10 # Not implemented yet11 # log 'wz.ModalManager.checkClick', target12 return false13 m show14 param dialogKey15 param formId16 var dialogData17 _ this.createMarkup18 @ dialogKey19 if !dialogData.currentContent20 var formEl21 _ wz.element( '#' + formId)22 if !formEl23 throw new Error('In wz.modalManager.show() the formId is not an existing html element: ' + formId)24 _ dialogData.modalContentElement.appendChild25 @ formEl26 set formEl.style.display = "block"27 set dialogData.currentContent = formEl28 set dialogData.modalElement.style.display = "block"29 m hide30 param dialogKey31 var dialogData32 _ this.createMarkup33 @ dialogKey34 if !dialogData35 throw new Error('In wz.modalManager.hide() the dialogKey is unknown: ' + dialogKey)36 set dialogData.modalElement.style.display = "none"37 m createMarkup38 param dialogKey39 if !this.dialogs[dialogKey]40 set this.dialogs[dialogKey] = {}41 var dialog = this.dialogs[dialogKey]42 if dialog.modalElement43 return dialog44 var modalsContainer = wz.element('#' + this.ctx.modalsContainerId)45 if !modalsContainer46 set modalsContainer = document.createElement('div')47 _ modalsContainer.setAttribute('id', this.ctx.modalsContainerId)48 _ document.body.appendChild(modalsContainer)49 # . modal50 # id edit-modal51 # . modal-content52 # id edit-modal-content53 # span ×54 # class modal-close55 var spanClose = document.createElement('span')56 _ spanClose.setAttribute('class', 'modal-close')57 _ wz.text(spanClose, 'X')58 var that = this59 _ wz.click60 @ spanClose61 function62 _ that.hide63 @ dialogKey64 set dialog.modalContentElement = document.createElement('div')65 _ dialog.modalContentElement.setAttribute('class', 'modal-content')66 _ dialog.modalContentElement.setAttribute('id', dialogKey + '-modal-content')67 set dialog.modalElement = document.createElement('div')68 _ dialog.modalElement.setAttribute('class', 'modal')69 _ dialog.modalElement.setAttribute('id', dialogKey + '-modal')70 _ dialog.modalContentElement.appendChild(spanClose)71 _ dialog.modalElement.appendChild(dialog.modalContentElement)72 _ modalsContainer.appendChild(dialog.modalElement)73 return dialog
/ittf/meta/html/t/js/dataManager.js.ittf
1 $group2 #3 # implements editSave4 # params5 # { ctx6 #7 class DataManager8 ctor9 param ctx10 set this.ctx = ctx11 set this.editSaveUrl = ctx.editSaveUrl12 set this.editSaveHttpMethod = ctx.editSaveHttpMethod13 m editSave14 param hash15 param content16 log 'wz.DataManager.editSave', hash, content17 _ fetch18 @ this.editSaveUrl19 {20 @ method this.editSaveHttpMethod.toUpperCase()21 { headers22 @ "Content-Type" "application/json"23 @ body24 _ JSON.stringify25 {26 @ hash hash27 @ content content28 @ prettify true29 ._ then30 =>31 param response32 _ response.json()33 ._ then34 =>35 param json36 $if true37 _ alert38 @ 'editSave: ' + JSON.stringify(json, null, 2)39 if this.ctx.editManager && this.ctx.editManager.onSave40 set json.data.hash = hash41 set json.data.content = content42 #43 _ alert44 @ 'editSave: ' + JSON.stringify(json, null, 2)45 _ this.ctx.editManager.onSave46 @ json.data47 ._ catch48 =>49 param err50 error err51 _ alert52 @ 'editSave error: ' + err
/ittf/meta/html/t/js/clickListener.js.ittf
1 $group2 #3 # params4 # { ctx5 # { clickHandler6 # { options7 # string container8 # string class9 # string dataField10 # optional11 function setupClickListener12 param ctx13 param options14 var el = wz.element('#' + options.containerId)15 if !el16 throw new Error('wz.setupClickHandler requires an existing `options.containerId` html element. Received: ' + options.container)17 _ wz.click18 @ el19 @ create_clickListener(ctx, options)20 function create_clickListener21 param ctx22 param options23 return24 function clickListener25 param event26 # log 'clickListener.target', event.target27 var dataValue = null28 if options.dataField29 if Array.isArray(options.dataField)30 set dataValue = {}31 foreach item in options.dataField32 set dataValue[item] = event.target.dataset[item]33 else34 set dataValue = event.target.dataset[options.dataField]35 # log 'clickListener.target.dataValue', dataValue36 # log 'has class ' + options.targetClass, wz.hasClass(event.target, options.targetClass)37 if wz.hasClass(event.target, options.targetClass)38 _ ctx.clickHandler.handleClick39 @ event.target40 @ dataValue41 _ event.preventDefault()42 _ event.stopPropagation()43 else44 if ctx.clickHandler.checkClick(event.target)45 _ event.preventDefault()46 _ event.stopPropagation()
/t/js/wz/t/polyfill.js.ittf
1 $group2 if typeof Array.isArray === 'undefined'3 set Array.isArray4 function5 param obj6 return Object.prototype.toString.call(obj) === '[object Array]'
/t/js/wz/t/eventTarget.js.ittf
1 $group2 class wz_EventTarget3 ctor4 set this.handlers = {}5 m __is_Event6 param name7 return Array.isArray(this.events) == false || this.events.indexOf(name) > -18 m emit9 param name10 var args = [].slice.call(arguments, 1)11 # log 'wz_EventTarget.emit.args', arguments, args12 if this.__is_Event(name)13 if this.handlers[name] instanceof Array14 foreach handle in this.handlers[name]15 # log 'handle.context', handle.context16 _ handle.callback.apply(handle.context, args)17 else18 throw new Error(name + ' event cannot be found on TreeView.')19 m on20 param name21 param callback22 param scope23 # log 'EventTarget.on.name,scope', name, scope24 if this.__is_Event(name)25 if !this.handlers[name]26 set this.handlers[name] = []27 _ this.handlers[name].push28 {29 @ callback callback30 @ context scope31 else32 throw new Error(name + ' is not supported by TreeView.')33 m off34 param name35 param callback36 var37 decl index38 decl found = false39 if this.handlers[name] instanceof Array40 _ this.handlers[name].forEach41 function42 param handle43 param i44 set index = i45 if handle.callback === callback && !found46 set found = true47 if found48 _ this.handlers[name].splice(index, 1)49 set wz.EventTarget = wz_EventTarget
/t/js/wz/t/global.js.ittf
1 $group2 class wz_global : wz.EventTarget3 set wz.global = new wz_global()
/t/js/wz/t/events.js.ittf
1 $group2 iife3 if document.addEventListener4 set window.addEvent =5 function6 param elem7 param type8 param handler9 param useCapture10 _ elem.addEventListener(type, handler, !(!(useCapture)))11 return handler12 set window.removeEvent =13 function14 param elem15 param type16 param handler17 param useCapture18 _ elem.removeEventListener(type, handler, !(!(useCapture)))19 return true20 elif document.attachEvent21 set window.addEvent =22 function23 param elem24 param type25 param handler26 set type = ("on" + type)27 var boundedHandler28 function29 return handler.apply(elem, arguments)30 _ elem.attachEvent(type, boundedHandler)31 return boundedHandler32 set window.removeEvent =33 function34 param elem35 param type36 param handler37 set type = ("on" + type)38 _ elem.detachEvent(type, handler)39 return true40 ()
/t/js/wz/t/verify.js.ittf
1 $group2 set wz.isString3 function4 param test5 return test !== null && typeof(test) === 'string'6 set wz.isEmpty7 function8 param test9 return wz.isString(test) == false || test.length == 010 set wz.isObject11 function12 param test13 if test === null || typeof(test) === 'undefined'14 return false15 return {}.toString.call(test) === '[object Object]'16 set wz.isArray17 function18 param test19 if test === null || typeof(test) === 'undefined'20 return false21 if Array.isArray22 return Array.isArray(test);23 return {}.toString.call(test) === '[object Array]'24 set wz.clone25 function26 param obj27 if wz.isArray(obj)28 var ret29 [30 foreach item in obj31 var value32 _ clone33 @ item34 if value !== null35 _ ret.push(value)36 return ret37 elif wz.isObject(obj)38 var ret39 {40 for var prop in obj41 if obj.hasOwnProperty(prop)42 set ret[prop] = clone(obj[prop])43 return ret44 else45 return obj46 set wz.replace47 function48 param text49 param find50 param replace51 if wz.isEmpty(text)52 return text53 return54 _ text.replace55 new RegExp56 _ wz.escapeRegExp(find)57 @ 'g'58 @ replace59 set wz.escapeRegExp60 function61 param text62 if wz.isEmpty(text)63 return text64 return text.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1")