PHP Classes

File: public/js/lib/vue/src/directives/element/slot.js

Recommend this page to a friend!
  Classes of Sergey Beskorovayniy   Silex MVC Blog   public/js/lib/vue/src/directives/element/slot.js   Download  
File: public/js/lib/vue/src/directives/element/slot.js
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: Silex MVC Blog
MVC based blog using on the Silex micro-framework
Author: By
Last change:
Date: 8 years ago
Size: 1,578 bytes
 

Contents

Class file image Download
import { SLOT } from '../priorities' import { extractContent, replace, remove } from '../../util/index' export default { priority: SLOT, params: ['name'], bind () { // this was resolved during component transclusion var name = this.params.name || 'default' var content = this.vm._slotContents && this.vm._slotContents[name] if (!content || !content.hasChildNodes()) { this.fallback() } else { this.compile(content.cloneNode(true), this.vm._context, this.vm) } }, compile (content, context, host) { if (content && context) { if ( this.el.hasChildNodes() && content.childNodes.length === 1 && content.childNodes[0].nodeType === 1 && content.childNodes[0].hasAttribute('v-if') ) { // if the inserted slot has v-if // inject fallback content as the v-else const elseBlock = document.createElement('template') elseBlock.setAttribute('v-else', '') elseBlock.innerHTML = this.el.innerHTML // the else block should be compiled in child scope elseBlock._context = this.vm content.appendChild(elseBlock) } const scope = host ? host._scope : this._scope this.unlink = context.$compile( content, host, scope, this._frag ) } if (content) { replace(this.el, content) } else { remove(this.el) } }, fallback () { this.compile(extractContent(this.el, true), this.vm) }, unbind () { if (this.unlink) { this.unlink() } } }