1/** 2 * a very simple 'View' framework to attach component behaviour / JS code to DOM elements 3 * - this framework nucleus must be available before each code based on that approach is loaded > 'head' 4 * - during page load the registering of View types is done immediately 5 * - after content loading all registered Types are initialized / attached to appropriate DOM elements 6 * - this initial class can be extended by an additional 'body' clientlib that's adding prototype functions 7 * to support all what's needed in the project, see 'view.js' in the general 'common' clientlib (xmpl.common) 8 */ 9class View { 10 11 constructor(el) { 12 this.el = el; 13 } 14 15 /** 16 * if a view is no longer used... extension hook, e.g. to remove event listeners too 17 * @return the DOM element of the discarded view, e.g. for a chained remove (view.discard().remove()) 18 */ 19 discard() { 20 const el = this.el; 21 const key = View.typeName(this.constructor); 22 if (el.view) { 23 key && delete el.view[key]; 24 } 25 console.debug(`discarded: ${key} [${el.classList}]`); 26 delete this.el; 27 return el; 28 } 29 30 // View types registry... 31 32 static registry = []; 33 34 /** 35 * registers a view type and the DOM element selector to attach that view 36 * @param selector the DOM query selector string 37 * @param viewType the class to attach 38 */ 39 static register(selector, viewType) { 40 if (selector && View.typeName(viewType)) { 41 View.registry.push({selector: selector, viewType: viewType}); 42 } 43 } 44 45 static typeName(viewType) { 46 return typeof viewType === 'function' ? viewType.name : undefined; 47 } 48}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.