UNPKG

silk-gui

Version:

GUI for developers and Node OS

72 lines (64 loc) 1.51 kB
var _ = require('../util') var compile = require('../compiler/compile') /** * Set instance target element and kick off the compilation * process. The passed in `el` can be a selector string, an * existing Element, or a DocumentFragment (for block * instances). * * @param {Element|DocumentFragment|string} el * @public */ exports.$mount = function (el) { if (this._isCompiled) { _.warn('$mount() should be called only once.') return } if (!el) { el = document.createElement('div') } else if (typeof el === 'string') { var selector = el el = document.querySelector(el) if (!el) { _.warn('Cannot find element: ' + selector) return } } this._compile(el) this._isCompiled = true this._callHook('compiled') if (_.inDoc(this.$el)) { this._callHook('attached') this._initDOMHooks() ready.call(this) } else { this._initDOMHooks() this.$once('hook:attached', ready) } return this } /** * Mark an instance as ready. */ function ready () { this._isAttached = true this._isReady = true this._callHook('ready') } /** * Teardown the instance, simply delegate to the internal * _destroy. */ exports.$destroy = function (remove, deferCleanup) { this._destroy(remove, deferCleanup) } /** * Partially compile a piece of DOM and return a * decompile function. * * @param {Element|DocumentFragment} el * @return {Function} */ exports.$compile = function (el) { return compile(el, this.$options, true)(this, el) }