<commit_before>/**
 *  Global Build-in Directives
 */

'use strict';

var $ = require('./dm')
var conf = require('./conf')
var util = require('./util')
var consoler = require('./consoler')
var Expression = require('./expression')

function noop () {}

module.exports = {
    'attr': {
        multi: true,
        bind: function(attname) {
            this.attname = attname
            this._$el = $(this.$el)
        },
        update: function(next) {
            if (util.isUndef(next)) {
                this._$el.removeAttr(this.attname)
            } else {
                this._$el.attr(this.attname, next)
            }
        },
        unbind: function () {
            this._$el = null
        }
    },
    'class': {
        multi: true,
        bind: function(className) {
            this.className = className
            this._$el = $(this.$el)
        },
        update: function(next) {
            if (next) this._$el.addClass(this.className)
            else this._$el.removeClass(this.className)
        },
        unbind: function () {
            this._$el = null
        }
    },
    'html': {
        update: function(nextHTML) {
            this.$el.innerHTML = util.isUndef(nextHTML) ? '' : nextHTML
        }
    },
    'on': {
        multi: true,
        bind: function(evtType, handler, expression) {
            this._expr = expression
            this.type = evtType
        },
        update: function(handler) {
            this.unbind()

            var fn = handler
            if (util.type(fn) !== 'function')
                return consoler.warn('"' + conf.namespace + 'on" only accept function. {' + this._expr + '}')

            // this.fn = util.bind(fn, this.$vm)
            var that = this
            this.fn = function (e) {
                e.$currentTarget = that.$el
                fn.call(that.$vm, e)
            }
            $(this.$el).on(this.type, this.fn, false)

        },
        unbind: function() {
            if (this.fn) {
                $(this.$el).off(this.type, this.fn)
                this.fn = null
            }
        }
    },
    'show': {
        update: function(next) {
            this.$el.style.display = next ? '' : 'none'
        }
    },
    'style': {
        multi: true,
        bind: function(sheet) {
            this.sheet = sheet
        },
        update: function(next) {
            this.$el.style && (this.$el.style[this.sheet] = next)
        }
    },
    'text': {
        bind: function () {
            var reg = Expression.exprRegexp
            var expr = this.expr = this.$el.innerHTML
            var veilExpr = Expression.veil(expr)
            var expressions = this.expressions = util.map(veilExpr.match(reg), function (exp) {
                return Expression.strip(exp)
            })
            var parts = veilExpr.split(reg)
            var cache = this.cache = new Array(expressions.length)
            var that = this

            var $textNode = this.textNode = new Text()
            this.render = function () {
                // set value
                util.forEach(expressions, function(exp, index) {
                    var v = that.$exec(exp)
                    if (!v[0]) cache[index] = v[1]
                })
                // get content
                var frags = []
                util.forEach(parts, function(item, index) {
                    frags.push(item)
                    if (index < expressions.length) {
                        frags.push(cache[index])
                    }
                })
                // TODO, Number Mobile bug, trying to using replaceChild
                $textNode.nodeValue = Expression.unveil(frags.join(''))
            }<commit_msg>using createTextNode() instead of  new Text()<commit_after>/**
 *  Global Build-in Directives
 */

'use strict';

var $ = require('./dm')
var conf = require('./conf')
var util = require('./util')
var consoler = require('./consoler')
var Expression = require('./expression')

function noop () {}

module.exports = {
    'attr': {
        multi: true,
        bind: function(attname) {
            this.attname = attname
            this._$el = $(this.$el)
        },
        update: function(next) {
            if (util.isUndef(next)) {
                this._$el.removeAttr(this.attname)
            } else {
                this._$el.attr(this.attname, next)
            }
        },
        unbind: function () {
            this._$el = null
        }
    },
    'class': {
        multi: true,
        bind: function(className) {
            this.className = className
            this._$el = $(this.$el)
        },
        update: function(next) {
            if (next) this._$el.addClass(this.className)
            else this._$el.removeClass(this.className)
        },
        unbind: function () {
            this._$el = null
        }
    },
    'html': {
        update: function(nextHTML) {
            this.$el.innerHTML = util.isUndef(nextHTML) ? '' : nextHTML
        }
    },
    'on': {
        multi: true,
        bind: function(evtType, handler, expression) {
            this._expr = expression
            this.type = evtType
        },
        update: function(handler) {
            this.unbind()

            var fn = handler
            if (util.type(fn) !== 'function')
                return consoler.warn('"' + conf.namespace + 'on" only accept function. {' + this._expr + '}')

            // this.fn = util.bind(fn, this.$vm)
            var that = this
            this.fn = function (e) {
                e.$currentTarget = that.$el
                fn.call(that.$vm, e)
            }
            $(this.$el).on(this.type, this.fn, false)

        },
        unbind: function() {
            if (this.fn) {
                $(this.$el).off(this.type, this.fn)
                this.fn = null
            }
        }
    },
    'show': {
        update: function(next) {
            this.$el.style.display = next ? '' : 'none'
        }
    },
    'style': {
        multi: true,
        bind: function(sheet) {
            this.sheet = sheet
        },
        update: function(next) {
            this.$el.style && (this.$el.style[this.sheet] = next)
        }
    },
    'text': {
        bind: function () {
            var reg = Expression.exprRegexp
            var expr = this.expr = this.$el.innerHTML
            var veilExpr = Expression.veil(expr)
            var expressions = this.expressions = util.map(veilExpr.match(reg), function (exp) {
                return Expression.strip(exp)
            })
            var parts = veilExpr.split(reg)
            var cache = this.cache = new Array(expressions.length)
            var that = this

            var $textNode = this.textNode = document.createTextNode('')
            this.render = function () {
                // set value
                util.forEach(expressions, function(exp, index) {
                    var v = that.$exec(exp)
                    if (!v[0]) cache[index] = v[1]
                })
                // get content
                var frags = []
                util.forEach(parts, function(item, index) {
                    frags.push(item)
                    if (index < expressions.length) {
                        frags.push(cache[index])
                    }
                })
                // TODO, Number Mobile bug, trying to using replaceChild
                $textNode.nodeValue = Expression.unveil(frags.join(''))
            }
{'fraction_non_alphanumeric': 0.13437625350982751, 'fraction_numerical': 0.0005348308597406071, 'mean_word_length': 1.3208191126279865, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4069156', 'n_tokens_mistral': 2107, 'n_tokens_neox': 2051, 'n_words': 430}