diff --git a/build/iToolkit_lite.js b/build/iToolkit_lite.js
deleted file mode 100644
index ef52eac..0000000
--- a/build/iToolkit_lite.js
+++ /dev/null
@@ -1,2445 +0,0 @@
-/* Riot v2.2.1, @license MIT, (c) 2015 Muut Inc. + contributors */
-
-;(function(window) {
- 'use strict'
- var riot = { version: 'v2.2.1', settings: {} }
-
- // This globals 'const' helps code size reduction
-
- // for typeof == '' comparisons
- var T_STRING = 'string'
- var T_OBJECT = 'object'
-
- // for IE8 and rest of the world
- var isArray = Array.isArray || (function () {
- var _ts = Object.prototype.toString
- return function (v) { return _ts.call(v) === '[object Array]' }
- })()
-
- // Version# for IE 8-11, 0 for others
- var ieVersion = (function (win) {
- return (win && win.document || {}).documentMode | 0
- })(window)
-
-riot.observable = function(el) {
-
- el = el || {}
-
- var callbacks = {},
- _id = 0
-
- el.on = function(events, fn) {
- if (isFunction(fn)) {
- fn._id = typeof fn._id == 'undefined' ? _id++ : fn._id
-
- events.replace(/\S+/g, function(name, pos) {
- (callbacks[name] = callbacks[name] || []).push(fn)
- fn.typed = pos > 0
- })
- }
- return el
- }
-
- el.off = function(events, fn) {
- if (events == '*') callbacks = {}
- else {
- events.replace(/\S+/g, function(name) {
- if (fn) {
- var arr = callbacks[name]
- for (var i = 0, cb; (cb = arr && arr[i]); ++i) {
- if (cb._id == fn._id) { arr.splice(i, 1); i-- }
- }
- } else {
- callbacks[name] = []
- }
- })
- }
- return el
- }
-
- // only single event supported
- el.one = function(name, fn) {
- function on() {
- el.off(name, on)
- fn.apply(el, arguments)
- }
- return el.on(name, on)
- }
-
- el.trigger = function(name) {
- var args = [].slice.call(arguments, 1),
- fns = callbacks[name] || []
-
- for (var i = 0, fn; (fn = fns[i]); ++i) {
- if (!fn.busy) {
- fn.busy = 1
- fn.apply(el, fn.typed ? [name].concat(args) : args)
- if (fns[i] !== fn) { i-- }
- fn.busy = 0
- }
- }
-
- if (callbacks.all && name != 'all') {
- el.trigger.apply(el, ['all', name].concat(args))
- }
-
- return el
- }
-
- return el
-
-}
-riot.mixin = (function() {
- var mixins = {}
-
- return function(name, mixin) {
- if (!mixin) return mixins[name]
- mixins[name] = mixin
- }
-
-})()
-
-;(function(riot, evt, window) {
-
- // browsers only
- if (!window) return
-
- var loc = window.location,
- fns = riot.observable(),
- win = window,
- started = false,
- current
-
- function hash() {
- return loc.href.split('#')[1] || ''
- }
-
- function parser(path) {
- return path.split('/')
- }
-
- function emit(path) {
- if (path.type) path = hash()
-
- if (path != current) {
- fns.trigger.apply(null, ['H'].concat(parser(path)))
- current = path
- }
- }
-
- var r = riot.route = function(arg) {
- // string
- if (arg[0]) {
- loc.hash = arg
- emit(arg)
-
- // function
- } else {
- fns.on('H', arg)
- }
- }
-
- r.exec = function(fn) {
- fn.apply(null, parser(hash()))
- }
-
- r.parser = function(fn) {
- parser = fn
- }
-
- r.stop = function () {
- if (!started) return
- win.removeEventListener ? win.removeEventListener(evt, emit, false) : win.detachEvent('on' + evt, emit)
- fns.off('*')
- started = false
- }
-
- r.start = function () {
- if (started) return
- win.addEventListener ? win.addEventListener(evt, emit, false) : win.attachEvent('on' + evt, emit)
- started = true
- }
-
- // autostart the router
- r.start()
-
-})(riot, 'hashchange', window)
-/*
-
-//// How it works?
-
-
-Three ways:
-
-1. Expressions: tmpl('{ value }', data).
- Returns the result of evaluated expression as a raw object.
-
-2. Templates: tmpl('Hi { name } { surname }', data).
- Returns a string with evaluated expressions.
-
-3. Filters: tmpl('{ show: !done, highlight: active }', data).
- Returns a space separated list of trueish keys (mainly
- used for setting html classes), e.g. "show highlight".
-
-
-// Template examples
-
-tmpl('{ title || "Untitled" }', data)
-tmpl('Results are { results ? "ready" : "loading" }', data)
-tmpl('Today is { new Date() }', data)
-tmpl('{ message.length > 140 && "Message is too long" }', data)
-tmpl('This item got { Math.round(rating) } stars', data)
-tmpl('
{ title } { body }', data)
-
-
-// Falsy expressions in templates
-
-In templates (as opposed to single expressions) all falsy values
-except zero (undefined/null/false) will default to empty string:
-
-tmpl('{ undefined } - { false } - { null } - { 0 }', {})
-// will return: " - - - 0"
-
-*/
-
-
-var brackets = (function(orig) {
-
- var cachedBrackets,
- r,
- b,
- re = /[{}]/g
-
- return function(x) {
-
- // make sure we use the current setting
- var s = riot.settings.brackets || orig
-
- // recreate cached vars if needed
- if (cachedBrackets !== s) {
- cachedBrackets = s
- b = s.split(' ')
- r = b.map(function (e) { return e.replace(/(?=.)/g, '\\') })
- }
-
- // if regexp given, rewrite it with current brackets (only if differ from default)
- return x instanceof RegExp ? (
- s === orig ? x :
- new RegExp(x.source.replace(re, function(b) { return r[~~(b === '}')] }), x.global ? 'g' : '')
- ) :
- // else, get specific bracket
- b[x]
- }
-})('{ }')
-
-
-var tmpl = (function() {
-
- var cache = {},
- reVars = /(['"\/]).*?[^\\]\1|\.\w*|\w*:|\b(?:(?:new|typeof|in|instanceof) |(?:this|true|false|null|undefined)\b|function *\()|([a-z_$]\w*)/gi
- // [ 1 ][ 2 ][ 3 ][ 4 ][ 5 ]
- // find variable names:
- // 1. skip quoted strings and regexps: "a b", 'a b', 'a \'b\'', /a b/
- // 2. skip object properties: .name
- // 3. skip object literals: name:
- // 4. skip javascript keywords
- // 5. match var name
-
- // build a template (or get it from cache), render with data
- return function(str, data) {
- return str && (cache[str] = cache[str] || tmpl(str))(data)
- }
-
-
- // create a template instance
-
- function tmpl(s, p) {
-
- // default template string to {}
- s = (s || (brackets(0) + brackets(1)))
-
- // temporarily convert \{ and \} to a non-character
- .replace(brackets(/\\{/g), '\uFFF0')
- .replace(brackets(/\\}/g), '\uFFF1')
-
- // split string to expression and non-expresion parts
- p = split(s, extract(s, brackets(/{/), brackets(/}/)))
-
- return new Function('d', 'return ' + (
-
- // is it a single expression or a template? i.e. {x} or {x}
- !p[0] && !p[2] && !p[3]
-
- // if expression, evaluate it
- ? expr(p[1])
-
- // if template, evaluate all expressions in it
- : '[' + p.map(function(s, i) {
-
- // is it an expression or a string (every second part is an expression)
- return i % 2
-
- // evaluate the expressions
- ? expr(s, true)
-
- // process string parts of the template:
- : '"' + s
-
- // preserve new lines
- .replace(/\n/g, '\\n')
-
- // escape quotes
- .replace(/"/g, '\\"')
-
- + '"'
-
- }).join(',') + '].join("")'
- )
-
- // bring escaped { and } back
- .replace(/\uFFF0/g, brackets(0))
- .replace(/\uFFF1/g, brackets(1))
-
- + ';')
-
- }
-
-
- // parse { ... } expression
-
- function expr(s, n) {
- s = s
-
- // convert new lines to spaces
- .replace(/\n/g, ' ')
-
- // trim whitespace, brackets, strip comments
- .replace(brackets(/^[{ ]+|[ }]+$|\/\*.+?\*\//g), '')
-
- // is it an object literal? i.e. { key : value }
- return /^\s*[\w- "']+ *:/.test(s)
-
- // if object literal, return trueish keys
- // e.g.: { show: isOpen(), done: item.done } -> "show done"
- ? '[' +
-
- // extract key:val pairs, ignoring any nested objects
- extract(s,
-
- // name part: name:, "name":, 'name':, name :
- /["' ]*[\w- ]+["' ]*:/,
-
- // expression part: everything upto a comma followed by a name (see above) or end of line
- /,(?=["' ]*[\w- ]+["' ]*:)|}|$/
- ).map(function(pair) {
-
- // get key, val parts
- return pair.replace(/^[ "']*(.+?)[ "']*: *(.+?),? *$/, function(_, k, v) {
-
- // wrap all conditional parts to ignore errors
- return v.replace(/[^&|=!><]+/g, wrap) + '?"' + k + '":"",'
-
- })
-
- }).join('')
-
- + '].join(" ").trim()'
-
- // if js expression, evaluate as javascript
- : wrap(s, n)
-
- }
-
-
- // execute js w/o breaking on errors or undefined vars
-
- function wrap(s, nonull) {
- s = s.trim()
- return !s ? '' : '(function(v){try{v='
-
- // prefix vars (name => data.name)
- + (s.replace(reVars, function(s, _, v) { return v ? '(d.'+v+'===undefined?'+(typeof window == 'undefined' ? 'global.' : 'window.')+v+':d.'+v+')' : s })
-
- // break the expression if its empty (resulting in undefined value)
- || 'x')
- + '}catch(e){'
- + '}finally{return '
-
- // default to empty string for falsy values except zero
- + (nonull === true ? '!v&&v!==0?"":v' : 'v')
-
- + '}}).call(d)'
- }
-
-
- // split string by an array of substrings
-
- function split(str, substrings) {
- var parts = []
- substrings.map(function(sub, i) {
-
- // push matched expression and part before it
- i = str.indexOf(sub)
- parts.push(str.slice(0, i), sub)
- str = str.slice(i + sub.length)
- })
-
- // push the remaining part
- return parts.concat(str)
- }
-
-
- // match strings between opening and closing regexp, skipping any inner/nested matches
-
- function extract(str, open, close) {
-
- var start,
- level = 0,
- matches = [],
- re = new RegExp('('+open.source+')|('+close.source+')', 'g')
-
- str.replace(re, function(_, open, close, pos) {
-
- // if outer inner bracket, mark position
- if (!level && open) start = pos
-
- // in(de)crease bracket level
- level += open ? 1 : -1
-
- // if outer closing bracket, grab the match
- if (!level && close != null) matches.push(str.slice(start, pos+close.length))
-
- })
-
- return matches
- }
-
-})()
-
-// { key, i in items} -> { key, i, items }
-function loopKeys(expr) {
- var b0 = brackets(0),
- els = expr.slice(b0.length).match(/\s*(\S+?)\s*(?:,\s*(\S)+)?\s+in\s+(.+)/)
- return els ? { key: els[1], pos: els[2], val: b0 + els[3] } : { val: expr }
-}
-
-function mkitem(expr, key, val) {
- var item = {}
- item[expr.key] = key
- if (expr.pos) item[expr.pos] = val
- return item
-}
-
-
-/* Beware: heavy stuff */
-function _each(dom, parent, expr) {
-
- remAttr(dom, 'each')
-
- var template = dom.outerHTML,
- root = dom.parentNode,
- placeholder = document.createComment('riot placeholder'),
- tags = [],
- child = getTag(dom),
- checksum
-
- // console.log(expr);
- root.insertBefore(placeholder, dom)
-
- expr = loopKeys(expr)
-
- // clean template code
- parent
- .one('premount', function () {
- if (root.stub) root = parent.root
- // remove the original DOM node
- dom.parentNode.removeChild(dom)
- })
- .on('update', function () {
- var items = tmpl(expr.val, parent),
- test
-
- // object loop. any changes cause full redraw
- if (!isArray(items)) {
- test = checksum
- checksum = items ? JSON.stringify(items) : ''
- if (checksum === test) return
-
- items = !items ? [] :
- Object.keys(items).map(function (key) {
- return mkitem(expr, key, items[key])
- })
- }
- // console.log(items);
- var frag = document.createDocumentFragment(),
- i = tags.length,
- j = items.length
-
- // unmount leftover items
- while (i > j) tags[--i].unmount()
- tags.length = j
-
- test = !checksum && !!expr.key
- for (i = 0; i < j; ++i) {
- var _item = test ? mkitem(expr, items[i], i) : items[i]
-
- if (!tags[i]) {
- // mount new
- (tags[i] = new Tag({ tmpl: template }, {
- parent: parent,
- isLoop: true,
- root: root,
- item: _item
- })
- ).mount()
-
- frag.appendChild(tags[i].root)
- }
-
- tags[i]._item = _item
- tags[i].update(_item)
- }
-
- root.insertBefore(frag, placeholder)
-
- if (child) parent.tags[getTagName(dom)] = tags
-
- }).one('updated', function() {
- var keys = Object.keys(parent)// only set new values
- walk(root, function(node) {
- // only set element node and not isLoop
- if (node.nodeType == 1 && !node.isLoop && !node._looped) {
- node._visited = false // reset _visited for loop node
- node._looped = true // avoid set multiple each
- setNamed(node, parent, keys)
- }
- })
- })
-
-}
-
-
-function parseNamedElements(root, parent, childTags) {
-
- walk(root, function(dom) {
- if (dom.nodeType == 1) {
- dom.isLoop = (dom.parentNode && dom.parentNode.isLoop || dom.getAttribute('each')) ? 1 : 0
-
- // custom child tag
- var child = getTag(dom)
-
- if (child && !dom.isLoop) {
- var tag = new Tag(child, { root: dom, parent: parent }, dom.innerHTML),
- tagName = getTagName(dom),
- ptag = parent,
- cachedTag
-
- while (!getTag(ptag.root)) {
- if (!ptag.parent) break
- ptag = ptag.parent
- }
-
- // fix for the parent attribute in the looped elements
- tag.parent = ptag
-
- cachedTag = ptag.tags[tagName]
-
- // if there are multiple children tags having the same name
- if (cachedTag) {
- // if the parent tags property is not yet an array
- // create it adding the first cached tag
- if (!isArray(cachedTag))
- ptag.tags[tagName] = [cachedTag]
- // add the new nested tag to the array
- ptag.tags[tagName].push(tag)
- } else {
- ptag.tags[tagName] = tag
- }
-
- // empty the child node once we got its template
- // to avoid that its children get compiled multiple times
- dom.innerHTML = ''
- childTags.push(tag)
- }
-
- if (!dom.isLoop)
- setNamed(dom, parent, [])
- }
-
- })
-
-}
-
-function parseExpressions(root, tag, expressions) {
-
- function addExpr(dom, val, extra) {
- if (val.indexOf(brackets(0)) >= 0) {
- var expr = { dom: dom, expr: val }
- expressions.push(extend(expr, extra))
- }
- }
-
- walk(root, function(dom) {
- var type = dom.nodeType
-
- // text node
- if (type == 3 && dom.parentNode.tagName != 'STYLE') addExpr(dom, dom.nodeValue)
- if (type != 1) return
-
- /* element */
-
- // loop
- var attr = dom.getAttribute('each')
-
- if (attr && attr.match(/\{[\s\S]+\}/)) { _each(dom, tag, attr); return false }
-
- // attribute expressions
- each(dom.attributes, function(attr) {
- var name = attr.name,
- bool = name.split('__')[1]
-
- addExpr(dom, attr.value, { attr: bool || name, bool: bool })
- if (bool) { remAttr(dom, name); return false }
-
- })
-
- // skip custom tags
- if (getTag(dom)) return false
-
- })
-
-}
-function Tag(impl, conf, innerHTML) {
-
- var self = riot.observable(this),
- opts = inherit(conf.opts) || {},
- dom = mkdom(impl.tmpl),
- parent = conf.parent,
- isLoop = conf.isLoop,
- item = conf.item,
- expressions = [],
- childTags = [],
- root = conf.root,
- fn = impl.fn,
- tagName = root.tagName.toLowerCase(),
- attr = {},
- loopDom,
- TAG_ATTRIBUTES = /([\w\-]+)\s?=\s?['"]([^'"]+)["']/gim
-
-
- if (fn && root._tag) {
- root._tag.unmount(true)
- }
-
- // not yet mounted
- this.isMounted = false
-
- if (impl.attrs) {
- var attrs = impl.attrs.match(TAG_ATTRIBUTES)
-
- each(attrs, function(a) {
- var kv = a.split(/\s?=\s?/)
- root.setAttribute(kv[0], kv[1].replace(/['"]/g, ''))
- })
-
- }
-
- // keep a reference to the tag just created
- // so we will be able to mount this tag multiple times
- root._tag = this
-
- // create a unique id to this tag
- // it could be handy to use it also to improve the virtual dom rendering speed
- this._id = fastAbs(~~(new Date().getTime() * Math.random()))
-
- extend(this, { parent: parent, root: root, opts: opts, tags: {} }, item)
-
- // grab attributes
- each(root.attributes, function(el) {
- var val = el.value
- // remember attributes with expressions only
- if (brackets(/\{.*\}/).test(val)) attr[el.name] = val
- })
-
- if (dom.innerHTML && !/select|select|optgroup|tbody|tr/.test(tagName)) {
- // replace all the yield tags with the tag inner html
- if (root.tagName !== 'TABLE-VIEW') {
- // console.log(dom.innerHTML);
- // console.log(innerHTML);
- }
- dom.innerHTML = replaceYield(dom.innerHTML, innerHTML)
-
- }
-
- // options
- function updateOpts() {
- // update opts from current DOM attributes
- each(root.attributes, function(el) {
- opts[el.name] = tmpl(el.value, parent || self)
- })
- // recover those with expressions
- each(Object.keys(attr), function(name) {
- opts[name] = tmpl(attr[name], parent || self)
- })
- }
-
- this.update = function(data) {
- extend(self, data)
- updateOpts()
- self.trigger('update', data)
- update(expressions, self, data)
- self.trigger('updated')
- }
-
- this.mixin = function() {
- each(arguments, function(mix) {
- mix = typeof mix == 'string' ? riot.mixin(mix) : mix
- each(Object.keys(mix), function(key) {
- // bind methods to self
- if (key != 'init')
- self[key] = typeof mix[key] == 'function' ? mix[key].bind(self) : mix[key]
- })
- // init method will be called automatically
- if (mix.init) mix.init.bind(self)()
- })
- }
-
- this.mount = function() {
-
- updateOpts()
-
- // initialiation
- fn && fn.call(self, opts)
-
- toggle(true)
-
-
- // parse layout after init. fn may calculate args for nested custom tags
- parseExpressions(dom, self, expressions)
-
- if (!self.parent) self.update()
-
- // internal use only, fixes #403
- self.trigger('premount')
- if (isLoop) {
- // update the root attribute for the looped elements
- self.root = root = loopDom = dom.firstChild
- } else {
- while (dom.firstChild) root.appendChild(dom.firstChild)
- if (root.stub) self.root = root = parent.root
- }
- // if it's not a child tag we can trigger its mount event
- if (!self.parent || self.parent.isMounted) {
- self.isMounted = true
- self.trigger('mount')
- }
- // otherwise we need to wait that the parent event gets triggered
- else self.parent.one('mount', function() {
- // avoid to trigger the `mount` event for the tags
- // not visible included in an if statement
- if (!isInStub(self.root)) {
- self.parent.isMounted = self.isMounted = true
- self.trigger('mount')
- }
- })
- }
-
-
- this.unmount = function(keepRootTag) {
- var el = loopDom || root,
- p = el.parentNode
-
- if (p) {
-
- if (parent) {
- // remove this tag from the parent tags object
- // if there are multiple nested tags with same name..
- // remove this element form the array
- if (isArray(parent.tags[tagName])) {
- each(parent.tags[tagName], function(tag, i) {
- if (tag._id == self._id)
- parent.tags[tagName].splice(i, 1)
- })
- } else
- // otherwise just delete the tag instance
- parent.tags[tagName] = undefined
- } else {
- while (el.firstChild) el.removeChild(el.firstChild)
- }
-
- if (!keepRootTag)
- p.removeChild(el)
-
- }
-
-
- self.trigger('unmount')
- toggle()
- self.off('*')
- // somehow ie8 does not like `delete root._tag`
- root._tag = null
-
- }
-
- function toggle(isMount) {
-
- // mount/unmount children
- each(childTags, function(child) { child[isMount ? 'mount' : 'unmount']() })
-
- // listen/unlisten parent (events flow one way from parent to children)
- if (parent) {
- var evt = isMount ? 'on' : 'off'
-
- // the loop tags will be always in sync with the parent automatically
- if (isLoop)
- parent[evt]('unmount', self.unmount)
- else
- parent[evt]('update', self.update)[evt]('unmount', self.unmount)
- }
- }
-
- // named elements available for fn
- parseNamedElements(dom, this, childTags)
-
-
-}
-
-function setEventHandler(name, handler, dom, tag, item) {
-
- dom[name] = function(e) {
-
- // cross browser event fix
- e = e || window.event
-
- if (!e.which) e.which = e.charCode || e.keyCode
- if (!e.target) e.target = e.srcElement
-
- // ignore error on some browsers
- try {
- e.currentTarget = dom
- } catch (ignored) { '' }
-
- e.item = tag._item ? tag._item : item
-
- // prevent default behaviour (by default)
- if (handler.call(tag, e) !== true && !/radio|check/.test(dom.type)) {
- e.preventDefault && e.preventDefault()
- e.returnValue = false
- }
-
- if (!e.preventUpdate) {
- var el = item ? tag.parent : tag
- el.update()
- }
-
- }
-
-}
-
-// used by if- attribute
-function insertTo(root, node, before) {
- if (root) {
- root.insertBefore(before, node)
- root.removeChild(node)
- }
-}
-
-// item = currently looped item
-function update(expressions, tag, item) {
-
- each(expressions, function(expr, i) {
-
- var dom = expr.dom,
- attrName = expr.attr,
- value = tmpl(expr.expr, tag),
- parent = expr.dom.parentNode
-
- if (value == null) value = ''
-
- // leave out riot- prefixes from strings inside textarea
- if (parent && parent.tagName == 'TEXTAREA') value = value.replace(/riot-/g, '')
-
- // no change
- if (expr.value === value) return
- expr.value = value
-
- // text node
- if (!attrName) return dom.nodeValue = value.toString()
-
- // remove original attribute
- remAttr(dom, attrName)
-
- // event handler
- if (typeof value == 'function') {
- setEventHandler(attrName, value, dom, tag, item)
-
- // if- conditional
- } else if (attrName == 'if') {
- var stub = expr.stub
-
- // add to DOM
- if (value) {
- if (stub) {
- insertTo(stub.parentNode, stub, dom)
- dom.inStub = false
- // avoid to trigger the mount event if the tags is not visible yet
- // maybe we can optimize this avoiding to mount the tag at all
- if (!isInStub(dom)) {
- walk(dom, function(el) {
- if (el._tag && !el._tag.isMounted) el._tag.isMounted = !!el._tag.trigger('mount')
- })
- }
- }
- // remove from DOM
- } else {
- stub = expr.stub = stub || document.createTextNode('')
- insertTo(dom.parentNode, dom, stub)
- dom.inStub = true
- }
- // show / hide
- } else if (/^(show|hide)$/.test(attrName)) {
- if (attrName == 'hide') value = !value
- dom.style.display = value ? '' : 'none'
-
- // field value
- } else if (attrName == 'value') {
- dom.value = value
-
- //
- } else if (attrName.slice(0, 5) == 'riot-' && attrName != 'riot-tag') {
- attrName = attrName.slice(5)
- value ? dom.setAttribute(attrName, value) : remAttr(dom, attrName)
-
- } else {
- if (expr.bool) {
- dom[attrName] = value
- if (!value) return
- value = attrName
- }
-
- if (typeof value != 'object') dom.setAttribute(attrName, value)
-
- }
-
- })
-
-}
-
-function each(els, fn) {
- for (var i = 0, len = (els || []).length, el; i < len; i++) {
- el = els[i]
- // return false -> remove current item during loop
- if (el != null && fn(el, i) === false) i--
- }
- return els
-}
-
-function isFunction(v) {
- return typeof v === 'function' || false // avoid IE problems
-}
-
-function remAttr(dom, name) {
- dom.removeAttribute(name)
-}
-
-function fastAbs(nr) {
- return (nr ^ (nr >> 31)) - (nr >> 31)
-}
-
-function getTagName(dom) {
- var child = getTag(dom),
- namedTag = dom.getAttribute('name'),
- tagName = namedTag && namedTag.indexOf(brackets(0)) < 0 ? namedTag : child.name
-
- return tagName
-}
-
-function extend(src) {
- var obj, args = arguments
- for (var i = 1; i < args.length; ++i) {
- if ((obj = args[i])) {
- for (var key in obj) { // eslint-disable-line guard-for-in
- src[key] = obj[key]
- }
- }
- }
- return src
-}
-
-function mkdom(template) {
- var checkie = ieVersion && ieVersion < 10,
- matches = /^\s*<([\w-]+)/.exec(template),
- tagName = matches ? matches[1].toLowerCase() : '',
- rootTag = (tagName === 'th' || tagName === 'td') ? 'tr' :
- (tagName === 'tr' ? 'tbody' : 'div'),
- el = mkEl(rootTag)
-
- el.stub = true
-
- if (checkie) {
- if (tagName === 'optgroup')
- optgroupInnerHTML(el, template)
- else if (tagName === 'option')
- optionInnerHTML(el, template)
- else if (rootTag !== 'div')
- tbodyInnerHTML(el, template, tagName)
- else
- checkie = 0
- }
- if (!checkie) el.innerHTML = template
-
- return el
-}
-
-function walk(dom, fn) {
- if (dom) {
- if (fn(dom) === false) walk(dom.nextSibling, fn)
- else {
- dom = dom.firstChild
-
- while (dom) {
- walk(dom, fn)
- dom = dom.nextSibling
- }
- }
- }
-}
-
-function isInStub(dom) {
- while (dom) {
- if (dom.inStub) return true
- dom = dom.parentNode
- }
- return false
-}
-
-function mkEl(name) {
- return document.createElement(name)
-}
-
-function replaceYield (tmpl, innerHTML) {
- return tmpl.replace(/<(yield)\/?>(<\/\1>)?/gim, innerHTML || '')
-}
-
-function $$(selector, ctx) {
- return (ctx || document).querySelectorAll(selector)
-}
-
-function inherit(parent) {
- function Child() {}
- Child.prototype = parent
- return new Child()
-}
-
-function setNamed(dom, parent, keys) {
- each(dom.attributes, function(attr) {
- if (dom._visited) return
- if (attr.name === 'id' || attr.name === 'name') {
- dom._visited = true
- var p, v = attr.value
- if (~keys.indexOf(v)) return
-
- p = parent[v]
- if (!p)
- parent[v] = dom
- else
- isArray(p) ? p.push(dom) : (parent[v] = [p, dom])
- }
- })
-}
-/**
- *
- * Hacks needed for the old internet explorer versions [lower than IE10]
- *
- */
-
-function tbodyInnerHTML(el, html, tagName) {
- var div = mkEl('div'),
- loops = /td|th/.test(tagName) ? 3 : 2,
- child
-
- div.innerHTML = ''
- child = div.firstChild
-
- while (loops--) {
- child = child.firstChild
- }
-
- el.appendChild(child)
-
-}
-
-function optionInnerHTML(el, html) {
- var opt = mkEl('option'),
- valRegx = /value=[\"'](.+?)[\"']/,
- selRegx = /selected=[\"'](.+?)[\"']/,
- eachRegx = /each=[\"'](.+?)[\"']/,
- ifRegx = /if=[\"'](.+?)[\"']/,
- innerRegx = />([^<]*),
- valuesMatch = html.match(valRegx),
- selectedMatch = html.match(selRegx),
- innerValue = html.match(innerRegx),
- eachMatch = html.match(eachRegx),
- ifMatch = html.match(ifRegx)
-
- if (innerValue) {
- opt.innerHTML = innerValue[1]
- } else {
- opt.innerHTML = html
- }
-
- if (valuesMatch) {
- opt.value = valuesMatch[1]
- }
-
- if (selectedMatch) {
- opt.setAttribute('riot-selected', selectedMatch[1])
- }
-
- if (eachMatch) {
- opt.setAttribute('each', eachMatch[1])
- }
-
- if (ifMatch) {
- opt.setAttribute('if', ifMatch[1])
- }
-
- el.appendChild(opt)
-}
-
-function optgroupInnerHTML(el, html) {
- var opt = mkEl('optgroup'),
- labelRegx = /label=[\"'](.+?)[\"']/,
- elementRegx = /^<([^>]*)>/,
- tagRegx = /^<([^ \>]*)/,
- labelMatch = html.match(labelRegx),
- elementMatch = html.match(elementRegx),
- tagMatch = html.match(tagRegx),
- innerContent = html
-
- if (elementMatch) {
- var options = html.slice(elementMatch[1].length+2, -tagMatch[1].length-3).trim()
- innerContent = options
- }
-
- if (labelMatch) {
- opt.setAttribute('riot-label', labelMatch[1])
- }
-
- if (innerContent) {
- var innerOpt = mkEl('div')
-
- optionInnerHTML(innerOpt, innerContent)
-
- opt.appendChild(innerOpt.firstChild)
- }
-
- el.appendChild(opt)
-}
-
-/*
- Virtual dom is an array of custom tags on the document.
- Updates and unmounts propagate downwards from parent to children.
-*/
-
-var virtualDom = [],
- tagImpl = {},
- styleNode
-
-var RIOT_TAG = 'riot-tag'
-
-function getTag(dom) {
- return tagImpl[dom.getAttribute(RIOT_TAG) || dom.tagName.toLowerCase()]
-}
-
-function injectStyle(css) {
-
- styleNode = styleNode || mkEl('style')
-
- if (!document.head) return
-
- if (styleNode.styleSheet)
- styleNode.styleSheet.cssText += css
- else
- styleNode.innerHTML += css
-
- if (!styleNode._rendered)
- if (styleNode.styleSheet) {
- document.body.appendChild(styleNode)
- } else {
- var rs = $$('style[type=riot]')[0]
- if (rs) {
- rs.parentNode.insertBefore(styleNode, rs)
- rs.parentNode.removeChild(rs)
- } else {
- document.head.appendChild(styleNode)
- }
- }
-
- styleNode._rendered = true
-
-}
-
-function mountTo(root, tagName, opts) {
- var tag = tagImpl[tagName],
- // cache the inner HTML to fix #855
- innerHTML = root._innerHTML = root._innerHTML || root.innerHTML
- // clear the inner html
- root.innerHTML = ''
- //console.log(innerHTML);
- if (tag && root) tag = new Tag(tag, { root: root, opts: opts }, innerHTML)
-
- if (tag && tag.mount) {
- tag.mount()
- virtualDom.push(tag)
- return tag.on('unmount', function() {
- virtualDom.splice(virtualDom.indexOf(tag), 1)
- })
- }
-
-}
-
-riot.tag = function(name, html, css, attrs, fn) {
- if (isFunction(attrs)) {
- fn = attrs
- if (/^[\w\-]+\s?=/.test(css)) {
- attrs = css
- css = ''
- } else attrs = ''
- }
- if (css) {
- if (isFunction(css)) fn = css
- else injectStyle(css)
- }
- tagImpl[name] = { name: name, tmpl: html, attrs: attrs, fn: fn }
- return name
-}
-
-riot.mount = function(selector, tagName, opts) {
- var els,
- allTags,
- tags = []
-
- // helper functions
-
- function addRiotTags(arr) {
- var list = ''
- each(arr, function (e) {
- list += ', *[riot-tag="'+ e.trim() + '"]'
- })
- return list
- }
-
- function selectAllTags() {
- var keys = Object.keys(tagImpl)
- return keys + addRiotTags(keys)
- }
-
- function pushTags(root) {
- if (root.tagName) {
- if (tagName && !root.getAttribute(RIOT_TAG))
- root.setAttribute(RIOT_TAG, tagName)
-
- var tag = mountTo(root,
- tagName || root.getAttribute(RIOT_TAG) || root.tagName.toLowerCase(), opts)
-
- if (tag) tags.push(tag)
- }
- else if (root.length) {
- each(root, pushTags) // assume nodeList
- }
- }
-
- // ----- mount code -----
-
- if (typeof tagName === T_OBJECT) {
- opts = tagName
- tagName = 0
- }
-
- // crawl the DOM to find the tag
- if (typeof selector === T_STRING) {
- if (selector === '*') {
- // select all the tags registered
- // and also the tags found with the riot-tag attribute set
- selector = allTags = selectAllTags()
- } else {
- // or just the ones named like the selector
- selector += addRiotTags(selector.split(','))
- }
- els = $$(selector)
- }
- else
- // probably you have passed already a tag or a NodeList
- els = selector
-
- // select all the registered and mount them inside their root elements
- if (tagName === '*') {
- // get all custom tags
- tagName = allTags || selectAllTags()
- // if the root els it's just a single tag
- if (els.tagName) {
- els = $$(tagName, els)
- } else {
- // select all the children for all the different root elements
- var nodeList = []
- each(els, function (_el) {
- nodeList.push($$(tagName, _el))
- })
- els = nodeList
- }
- // get rid of the tagName
- tagName = 0
- }
- if (els.tagName)
- pushTags(els)
- else
- each(els, pushTags)
-
- return tags
-}
-
-// update everything
-riot.update = function() {
- return each(virtualDom, function(tag) {
- tag.update()
- })
-}
-
-// @deprecated
-riot.mountTo = riot.mount
-
-
- // share methods for other riot parts, e.g. compiler
- riot.util = { brackets: brackets, tmpl: tmpl }
-
- // support CommonJS, AMD & browser
- if (typeof exports === 'object')
- module.exports = riot
- else if (typeof define === 'function' && define.amd)
- define(function() { return riot })
- else
- window.riot = riot
-
-})(typeof window != 'undefined' ? window : undefined);/*
- * Utils 函数
- */
-var utils = {
- httpGet: function(url, params, callback, complete) {
- var xmlhttp = new XMLHttpRequest();
- var url = utils.concatParams(url, params);
- xmlhttp.open("GET", url, true);
- xmlhttp.send(null);
- xmlhttp.onreadystatechange = function() {
- if (xmlhttp.readyState === 4) {
- if (complete && typeof complete === 'function') {
- complete();
- }
- if (xmlhttp.status === 200) {
- var body = xmlhttp.responseText;
- try {
- if (typeof body === 'string') {
- var data = JSON.parse(body);
- }
- else {
- var data = body;
- }
- }
- catch(e) {
- alert('解析错误');
- }
- callback(data);
- }
- }
- }
- },
-
- httpPost: function(url, params, callback, complete) {
- var xmlhttp = new XMLHttpRequest();
- xmlhttp.open("POST", url, true);
- xmlhttp.setRequestHeader("Content-type", "application/json");
- xmlhttp.send(params);
- xmlhttp.onreadystatechange = function() {
- if (xmlhttp.readyState === 4) {
- if (complete && typeof complete === 'function') {
- complete();
- }
- if (xmlhttp.status === 200) {
- try {
- var data = JSON.parse(xmlhttp.responseText)
- }
- catch(e) {
- console.log('解析错误');
- }
- callback(data);
- }
- else {
- console.log('网络错误');
- }
- }
- };
- },
-
- jsonp: function (url, params, callback) {
- var now = Date.now();
- var script = document.createElement('script');
- var head = document.getElementsByTagName('head')[0];
- var url = utils.concatParams(url, params);
- if (!params.callback) {
- if (url.match(/\?/)) {
- var src = url + '&callback=jsonpCallback' + now;
- }
- else {
- var src = url + '?callback=jsonpCallback' + now;
- }
- var funcName = 'jsonpCallback' + now;
- }
- else {
- var src = url;
- var funcName = params.callback;
- }
- script.src = src;
- head.appendChild(script);
- window[funcName] = function(data) {
- if (typeof data === 'string') {
- try {
- data = JSON.parse(data);
- }
- catch(e) {}
- }
- callback(data);
- }
- script.onerror = function() {
- console.log('jsonp error');
- };
- script.onload = function() {
- head.removeChild(script);
- }
- },
-
- htmlEncode: function(value){
- var div = document.createElement('div');
- div.innerHTML = value;
- return div.innerText;
- },
-
- concatParams: function(url, params) {
- if (url.match(/\?/)) {
- var str = '&'
- }
- else {
- var str = '?'
- }
- for(i in params) {
- str = str + i + '=' + params[i] + '&';
- }
- str = str.replace(/&$/, '');
- return url + str;
- },
-
- setCookie: function(key, value, expires, path) {
- var exp = new Date();
- var path = path || '/';
- exp.setTime(exp.getTime() + expires);
- document.cookie = key + "=" + escape (value) + ";path=" + path + ";expires=" + exp.toGMTString();
- },
-
- transBytes: function(bytes) {
- var sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
- if (bytes == 0) return 'n/a';
- var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
- if (i == 0) return bytes + sizes[i];
- return (bytes / Math.pow(1024, i)).toFixed(1) + sizes[i];
- },
-
- transTimes: function(timeStamp) {
- var timeStamp = parseInt(timeStamp, 10);
- var time = new Date(timeStamp * 1000)
- var now = new Date().getTime()/1000;
- var dv = now - timeStamp;
- if ( dv < 86400) {
- return time.getHours() + ':' + time.getMinutes();
- }
- else if ( dv > 86400 && dv < 172800) {
- return '昨天';
- }
- else if ( dv > 172800) {
- var Y = (time.getFullYear() + '-').substring(2);
- var M = (time.getMonth()+1 < 10 ? '0' + (time.getMonth()+1) : time.getMonth()+1) + '-';
- var D = time.getDate() < 10 ? '0' + time.getDate() : time.getDate();
- return Y + M + D;
- }
- },
-
- hasClass: function (obj, cls) {
- return obj.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'));
- },
-
- addClass: function (obj, cls) {
- obj.className.trim();
- if (!this.hasClass(obj, cls)) obj.className += " " + cls;
- },
-
- removeClass: function (obj, cls) {
- if (utils.hasClass(obj, cls)) {
- var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)');
- obj.className = obj.className.replace(reg, ' ');
- }
- },
-
- toggleClass: function(obj, cls) {
- if (utils.hasClass(obj, cls)) {
- var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)');
- obj.className = obj.className.replace(reg, ' ');
- }
- else {
- obj.className += " " + cls;
- }
- },
-
- insertAfter: function(newElement, targetElement){
- var parent = targetElement.parentNode;
- if (parent.lastChild == targetElement) {
- parent.appendChild(newElement);
- }
- else {
- parent.insertBefore(newElement, targetElement.nextSibling);
- }
- },
-
- insertAfterText: function(newElement, targetElement) {
- var parent = targetElement.parentNode;
- if (parent.lastChild == targetElement) {
- parent.appendChild(newElement);
- }
- else {
- var next = targetElement.nextSibling;
- if (next.nodeType === 3) {
- next = next.nextSibling;
- }
- parent.insertBefore(newElement, next);
- }
- },
-
- isType: function (type) {
- return function (obj) {
- return toString.call(obj) === '[object ' + type + ']';
- }
- },
-
- makeArray: function () {
- return Array.prototype.concat(obj);
- },
-
- extend: function(src, obj) {
- for (var key in obj) {
- if (!src[key]) {
- src[key] = obj[key];
- }
- }
- }
-};
-
-utils.extend(utils, {
- isArray: utils.isType('Array'),
- isObject: utils.isType('Object'),
- isFunction: utils.isType('Function'),
- isElement: function (obj) {
- return toString.call(obj).indexOf('Element') !== -1;
- },
-});
-
-utils.extend(utils, {
- jsLoader: (function () {
- var HEAD_NODE = document.head || document.getElementsByTagName('head')[0];
- var cache = {};
- var _cid = 0;
- var tasks = [];
- var isArray = utils.isArray;
- var isFunction = utils.isFunction;
- var makeArray = utils.makeArray;
- var DONE = 'done';
- var INPROCESS = 'inprocess';
- var REJECTED = 'rejected';
- var PENDING = 'pending';
- var processCache = {};
-
- /**
- * 产生客户端id
- * @return {Number} [description]
- */
- function cid() {
- return _cid++;
- }
-
- function isCSS(css) {
- return css.match(/\.css\??/);
- }
-
- /**
- * Script对象,储存需要加载的脚本的基本信息
- * @param {String} uri 地址
- */
- function Script(uri) {
- this.uri = uri;
- this.cid = cid();
- this.status = PENDING;
- }
-
- /**
- * 从缓存中获取需要的Script对象
- * @param {String} uri [description]
- * @return {Object} 需要的Script对象
- */
- Script.get = function (uri) {
- // 如果不存在于缓存中,创建一个新的Script对象
- return cache[uri] || (cache[uri] = new Script(uri));
- };
-
- /**
- * 当加载完成或失败时调用的处理函数
- * @param {Object} js Script对象
- * @return {[type]} [description]
- */
- Script.resolve = function (js) {
- var self = this;
- self.status++;
- if (js && js.status === REJECTED) {
- var error = Error('Source: ' + js.uri + ' load failed');
- reject(error);
- }
- if (self.status === self.task.length) {
- setTimeout(function () {
- self.callback && self.callback();
- self = null;
- resolve(tasks.shift());
- }, 7);
- }
- };
-
- /**
- * jsLoader
- * @param {[type]} js function or string or array
- * @param {Function} callback 加载完成后的回调
- * @return {Function}
- */
- function jsLoader(js, callback) {
- jsLoader.then(js, callback).start();
- return jsLoader;
- }
-
- /**
- * then方法用于向任务列表增加任务
- * @param {[type]} js function or string or array
- * @param {Function} callback [description]
- * @return {Function} [description]
- */
- jsLoader.then = function (js, callback) {
- if (!js) {
- return jsLoader;
- }
- if (!isArray(js)) {
- js = makeArray(js);
- }
- var resolver = {
- task: [],
- callback: callback,
- status: 0
- };
- for (var i = 0; i < js.length; i++) {
- resolver.task.push(getCache(js[i]));
- }
- tasks.push(resolver);
- // jsLoader.resolve();
- return jsLoader;
- };
-
- /**
- * [reject description]
- * @param {Object} e Object Error
- * @return {[type]} [description]
- */
- function reject(e) {
- throw e;
- }
-
- /**
- * 执行任务序列中的任务
- * @param {Object} resolver [description]
- * @return {[type]} [description]
- */
- function resolve(resolver) {
- if (!resolver) {
- if (!tasks.length) {
- return;
- }
- }
- for (var i = 0; i < resolver.task.length; i++) {
- var js = resolver.task[i];
- request(js, resolver);
- }
- }
-
- /**
- * 开始
- * @return {[type]} [description]
- */
- jsLoader.start = function () {
- resolve(tasks.shift());
- return jsLoader;
- }
-
- function loadStyles(script, resolver) {
- var node = document.createElement('link');
- node.type = 'text/css';
- node.rel = 'stylesheet';
- node.href = script.uri;
- HEAD_NODE.appendChild(node);
- node = null;
- script.status = DONE;
- Script.resolve.call(resolver);
- }
-
- /**
- * [request description]
- * @param {[type]} js [description]
- * @param {[type]} resolver [description]
- * @return {[type]} [description]
- */
- function request(js, resolver) {
- if (isFunction(js.uri)) {
- try {
- js.uri();
- js.status = DONE;
- Script.resolve.call(resolver);
- }
- catch (e) {
- js.status = REJECTED;
- Script.resolve.call(resolver);
- }
- return;
- }
- if (js.status === DONE) {
- Script.resolve.call(resolver);
- return;
- }
- if (isCSS(js.uri)) {
- loadStyles(js, resolver);
- return;
- }
- if (js.status === INPROCESS) {
- // 在loading过程中,标记遇到的resolver
- js.changeStatus = true;
- processCache[js.cid] = processCache[js.cid] || [];
- processCache[js.cid].push({js:js, resolver:resolver});
- return;
- }
- js.status = INPROCESS;
- var node = document.createElement('script');
- node.async = true;
- node.src = js.uri;
- node.onload = node.onerror = onloadResolve;
- HEAD_NODE.appendChild(node);
-
- function onloadResolve(evt) {
- if (evt.type === 'error') {
- js.status = REJECTED;
- }
- if (evt.type === 'load') {
- js.status = DONE;
- }
- Script.resolve.call(resolver, js);
- if (js.changeStatus) {
- // 如果加载完成,处理处在waiting状态下的任务
- js.changeStatus = false;
- for (var i = 0; i < processCache[js.cid].length; i++) {
- var tmp = processCache[js.cid][i];
- Script.resolve.call(tmp.resolver, tmp.js);
- }
- processCache[js.cid] = null;
- }
- node.onload = node.onerror = null;
- HEAD_NODE.removeChild(node);
- node = null;
- }
- }
-
- /**
- * 获取可能存在别名的Script对象
- * @param {String} uri [description]
- * @return {Object} Script Object
- */
- function getCache(uri) {
- var src = getAlias(uri);
- return src ? Script.get(src) : Script.get(uri);
- }
-
- /**
- * 获取真实地址
- * @param {String} str [description]
- * @return {[type]} [description]
- */
- function getAlias(str) {
- return jsLoader.alias[str];
- }
-
- jsLoader.alias = {};
-
- return jsLoader;
-
- })()
-});
-
-/*
- * 全局事件监控
- */
-var EventCtrl = EC = riot.observable();
-
-/*
- * 外部方法传入
- */
-var iToolkit = {};
-iToolkit.methodRegister = function (name, fn) {
- for (var i in iToolkit) {
- if (name === i) {
- return;
- }
- }
- iToolkit[name] = fn;
-};
-iToolkit.tableExtend = {};
-riot.tag('super-div', '', 'super-div{ display: block; }', function(opts) {
-
- var self = this;
- var config = self.opts.opts || self.opts;
- var EL = self.root;
-
- for (i in config) {
- self[i] = config[i];
- }
-
-
- self.getData = function(params) {
- var params = params || {};
- if (EL.getAttribute('data-get')) {
- var method = 'httpGet';
- }
- else if (EL.getAttribute('data-jsonp')) {
- var method = 'jsonp';
- }
-
- utils[method](self.superDivUrl, params, function(data) {
- for (i in data) {
- self.data = {};
- self.data[i] = data[i];
- }
- self.update();
- });
- }
-
- self.on('mount', function() {
- EL.style.display = 'block';
- self.superDivUrl = EL.getAttribute('data-get') || EL.getAttribute('data-jsonp');
- if (self.superDivUrl) {
- self.getData(config.params);
- }
- })
-
-
- self.loadData = EL.loadData = function(newData, colName){
- colName = colName || 'data';
- self[colName] = newData
- self.update();
- }
-
- self.reload = EL.reload = function() {
- if (self.superDivUrl) {
- self.getData(config.params);
- }
- else {
- self.update();
- }
- }
-
-
-});riot.tag('super-form', '', function(opts) {
-
- var self = this;
- var EL = self.root;
- var config = self.opts.opts || self.opts;
- var keyWords = [
- 'insertTip',
- 'ajaxSubmit',
- 'submit',
- 'removeTips',
- 'insertTip',
- 'removeTip',
- 'loadData',
- 'getData',
- 'setData'
- ]; //保留字,不被覆盖
-
- var NUMBER_REGEXP = {
- NON_NEGATIVE_INT: /^0$|^-[1-9]\d*$/, //非负整数(正整数 + 0)
- POSITIVE_INT: /^[1-9]\d*$/, //正整数
- NON_POSITIVE_INT: /^[1-9]\d*$|^0$/, //非正整数(负整数 + 0)
- NEGATIVE_INT: /^-[1-9]\d*$/, //负整数
- INT: /^-?[1-9]\d*$|^0$/, //整数
- NON_NEGATIVE_FLOAT: /^(\d)(\.\d+)?$|^([1-9]\d*)(\.\d+)?$|^0$/, //非负浮点数(正浮点数 + 0)
- POSITIVE_FLOAT: /^(\d)(\.\d+)?$|^([1-9]\d*)(\.\d+)?$/, //正浮点数
- NON_POSITIVE_FLOAT: /^(-\d)(\.\d+)?$|^(-[1-9]\d*)(\.\d+)?$|^0$/,//非正浮点数(负浮点数 + 0)
- NEGATIVE_FLOAT: /^(-\d)(\.\d+)?$|^(-[1-9]\d*)(\.\d+)?$/, //负浮点数
- FLOAT: /^(-?\d)(\.\d+)?$|^(-?[1-9]\d*)(\.\d+)?$|^0$/ //浮点数
- };
-
- self.presentWarning = '必填';
- self.emailWarning = '邮箱格式错误';
- self.mobileWarning = '手机格式错误';
- self.urlWarning = '网址格式错误';
- self.successTips = '通过';
- self.regWarning = '字段不符合验证规则';
- self.numWarning = '数字格式错误';
-
- self.passClass = config.passClass || 'valid-pass';
- self.failedClass = config.failedClass || 'valid-failed';
-
-
- var comparator = function (type) {
- return {
- handler: function (min, max, dom, value, validArr, name) {
- switch (type) {
- case 'number':
- return numComparator(min, max, dom, value, validArr, name);
- case 'string':
- default:
- return strCompatator(min, max, dom, value, validArr, name);
- }
- }
- };
- };
-
-
- function strCompatator(min, max, dom, value, validArr, name) {
- var nMin = isNaN(min);
- var nMax = isNaN(max);
- var len = value.length;
- if (!nMin && !nMax) {
- if (len > max || len < min) {
- validArr.push(name);
- self.onValidRefuse(dom, self.bpWarning(min, max));
- }
- else {
- self.onValidPass(dom, self.successTips);
- }
- }
- else {
- if (!nMin) {
- if (len < min) {
- validArr.push(name);
- self.onValidRefuse(dom, self.minWarning(min));
- }
- else {
- self.onValidPass(dom, self.successTips);
- }
- }
- if (!nMax) {
- if (len > max) {
- validArr.push(name);
- self.onValidRefuse(dom, self.maxWarning(max));
- }
- else {
- self.onValidPass(dom, self.successTips);
- }
- }
- if (nMax && nMin) {
- self.onValidPass(dom, self.successTips);
- }
- }
- }
-
-
- function numComparator(min, max, dom, value, validArr, name) {
- var nMin = isNaN(min);
- var nMax = isNaN(max);
- var value = +value;
- if (!nMin && !nMax) {
- if (value > max || value < min) {
- validArr.push(name);
- self.onValidRefuse(dom, self.numBpWarning(min, max));
- }
- else {
- self.onValidPass(dom, self.successTips);
- }
- }
- else {
- if (!nMin) {
- if (value < min) {
- validArr.push(name);
- self.onValidRefuse(dom, self.minNumWarning(min));
- }
- else {
- self.onValidPass(dom, self.successTips);
- }
- }
- if (!nMax) {
- if (value > max) {
- validArr.push(name);
- self.onValidRefuse(dom, self.maxNumWarning(max));
- }
- else {
- self.onValidPass(dom, self.successTips);
- }
- }
- if (nMax && nMin) {
- self.onValidPass(dom, self.successTips);
- }
- }
- }
-
- self.one('mount', function() {
- EL.style.display = 'block';
- if (config.realTime && config.valid) {
- var elems = self.root.getElementsByTagName('form')[0].elements;
- for (var i = 0, len = elems.length; i < len; i ++) {
- var type = elems[i].type;
- if (type !== 'submit' || type !== 'button') {
- elems[i].addEventListener('input', valueOnChange, false);
- if (type === 'checkbox' || type === 'radio') {
- elems[i].addEventListener('change', valueOnChange, false);
-
- }
- elems[i].addEventListener('input', valueOnChange, false);
- }
-
- }
- }
- });
-
-
- function valueOnChange(e) {
- doCheck([], this);
- }
-
- function isType(obj) {
- return toString.call(obj).match(/\ (.*)\]/)[1];
- }
-
- function dif(obj) {
- var constructor = isType(obj);
- if (constructor === 'Null' || constructor === 'Undefined' || constructor === 'Function') {
- return obj;
- }
- return new window[constructor](obj);
- }
-
- EL.loadData = function(newData, colName){
- if (utils.isObject(newData)) {
- for(var i in newData) {
- newData[i] = dif(newData[i]);
- }
- }
- else {
- newData = dif(newData);
- }
- colName = colName || 'data';
- self[colName] = newData;
-
-
-
-
-
- self.update();
- };
-
- EL.setData = function(newData, name){
- self.data[name] = dif(newData);
- self.update();
- };
-
- self.checkExistKey = function(obj, key, value) {
- if (obj.hasOwnProperty(key)) {
- if (utils.isArray(obj[key])) {
- obj[key].push(value);
- }
- else {
- var arr = [];
- arr.push(obj[key]);
- arr.push(value)
- obj[key] = arr;
- }
- }
- else {
- obj[key] = value;
- }
- }
-
- self.getData = EL.getData = function(){
- var elems = self.root.getElementsByTagName('form')[0].elements;
- var params = {};
- for (var i = 0; i < elems.length; i++) {
- if (elems[i].name) {
- if (elems[i].tagName === "SELECT") {
- var selected = elems[i].selectedOptions;
- for (j = 0; j < selected.length; j++) {
- value = selected[j].value;
- self.checkExistKey(params, elems[i].name, encodeURIComponent(value));
- }
- }
- else if (elems[i].type === "checkbox" || elems[i].type === "radio"){
- if (elems[i].checked) {
- value = elems[i].value;
- self.checkExistKey(params, elems[i].name, encodeURIComponent(value));
- }
- }
- else {
- value = elems[i].value;
- self.checkExistKey(params, elems[i].name, encodeURIComponent(value));
- }
- }
- }
- return params;
- }
-
-
-
- for (i in config) {
- if (keyWords.indexOf(i) < 0) {
- self[i] = config[i];
- }
- }
- self.data = config.data;
-
- self.submitingText = config.submitingText || '提交中...';
- if (config.valid === undefined) {
- config.valid = true;
- }
-
- self.maxWarning = config.maxWarning || function(n) {
- return '不得超过' + n + '个字符';
- }
- self.minWarning = config.minWarning || function(n) {
- return '不得小于' + n + '个字符';
- }
-
- self.bpWarning = config.bpWarning || function (min, max) {
- return '只允许' + min + '-' + max + '个字符';
- }
-
- self.minNumWarning = config.minNumWarning || function (n) {
- return '不得小于' + n;
- }
- self.maxNumWarning = config.maxNumWarning || function (n) {
- return '不得大于' + n;
- }
- self.numBpWarning = config.numBpWarning || function (min, max) {
- return '输入数字应在' + min + '-' + max + '之间';
- }
-
-
- self.removeTips = EL.removeTips = function() {
- var root = self.root;
- var elems = root.getElementsByTagName('form')[0].elements;
- var tips = root.getElementsByClassName('tip-container');
- if (tips && tips.length) {
- del();
- }
-
- function del() {
- for (i = 0; i < tips.length; i++) {
- tips[i].parentNode.removeChild(tips[i]);
- if (tips.length) {
- del();
- }
- }
- }
-
- for (var i = 0; i < elems.length; i++) {
- utils.removeClass(elems[i], self.passClass);
- utils.removeClass(elems[i], self.failedClass);
- }
- }
-
-
- self.removeTip = EL.removeTip = function(dom){
- var tip = dom.nextElementSibling;
- if (tip && tip.className.match(/tip-container/)) {
- dom.parentNode.removeChild(tip);
- }
- utils.removeClass(dom, self.passClass);
- utils.removeClass(dom, self.failedClass);
- };
-
- self.insertTip = EL.insertTip = function(dom, message, className){
- var tip = dom.nextElementSibling;
- if (tip && tip.className.match(/tip-container/)) {
- dom.parentNode.removeChild(tip);
- }
- var tipContainer = document.createElement('span');
- tipContainer.className = className;
- tipContainer.innerHTML = message;
- utils.insertAfterText(tipContainer, dom);
- };
-
- self.onValidRefuse = EL.onValidRefuse = config.onValidRefuse || function(dom, errorTips) {
- self.insertTip(dom, errorTips, 'tip-container');
- utils.removeClass(dom, self.passClass);
- utils.addClass(dom, self.failedClass);
- };
-
- self.onValidPass = EL.onValidPass = config.onValidPass || function(dom, successTips) {
- self.insertTip(dom, successTips, 'tip-container success');
- utils.removeClass(dom, self.failedClass);
- utils.addClass(dom, self.passClass);
- };
-
-
- self.ajaxSubmit = function(elems, url) {
- var params = '';
- for (var i = 0; i < elems.length; i++) {
- if (elems[i].name) {
- if (elems[i].tagName === "SELECT") {
- var selected = elems[i].selectedOptions;
- for (j = 0; j < selected.length; j++) {
- value = selected[j].value;
- params += elems[i].name + "=" + encodeURIComponent(value) + "&";
- }
- }
- else if (elems[i].type === "checkbox" || elems[i].type === "radio"){
- if (elems[i].checked) {
- value = elems[i].value;
- params += elems[i].name + "=" + encodeURIComponent(value) + "&";
- }
- }
- else {
- value = elems[i].value;
- params += elems[i].name + "=" + encodeURIComponent(value) + "&";
- }
- }
- if (elems[i].type === "submit") {
- if (elems[i].tagName === 'BUTTON') {
- var submitbtn = elems[i];
- var submitText = submitbtn.innerHTML;
- submitbtn.disabled = 'disabled';
- submitbtn.innerHTML = self.submitingText;
- }
- else {
- var submitbtn = elems[i];
- var submitText = submitbtn.value;
- submitbtn.disabled = 'disabled';
- submitbtn.value = self.submitingText;
- }
- }
- }
- var xmlhttp = new XMLHttpRequest();
- xmlhttp.open("POST", url, true);
- xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
- xmlhttp.send(params);
- xmlhttp.onreadystatechange = function() {
- if (xmlhttp.readyState === 4) {
- self.removeTips();
- if (submitbtn.tagName === 'BUTTON') {
- submitbtn.innerHTML = submitText;
- }
- else {
- submitbtn.value = submitText;
- }
- submitbtn.disabled = false;
- if (config.complete && typeof config.complete === 'function') {
- config.complete();
- }
- if (xmlhttp.status === 200) {
- try {
- var result = JSON.parse(xmlhttp.responseText);
- config.callback && config.callback(result);
- EC.trigger('submit_success', result);
- }catch(e){
- throw new Error(e.message);
- }
- }
- else {
- config.errCallback && config.errCallback(params);
- EC.trigger('submit_error', params);
- }
- }
- };
- }
-
-
- this.submit = function(e) {
- var validArr = [];
- var elems = self.root.getElementsByTagName('form')[0].elements;
- var action = self.action || self.root.getAttribute('action');
- var url = action;
-
- if (config.valid) {
- for (var i = 0; i < elems.length; i++) {
- doCheck(validArr, elems[i]);
- }
- }
-
- if (!validArr.length) {
- try {
- config.beforeSubmit && config.beforeSubmit(validArr);
- }
- catch (e) {
- validArr.push(e);
- }
- }
-
- if (!validArr.length) {
-
- if (config.normalSubmit) {
- self.root.firstChild.setAttribute('action', action);
- return true;
- }
- else {
- e.preventDefault();
- self.ajaxSubmit(elems, url);
- }
- }
- else {
- return false;
- }
- }.bind(this);
-
-
- function doCheck(validArr, elem) {
- var elem = elem;
- var valid = elem.getAttribute('valid');
- var customValid = elem.getAttribute('customValid');
- var vr = elem.getAttribute('vr');
- var orient = elem.getAttribute('orient');
- var max = parseInt(elem.getAttribute('max'), 10);
- var min = parseInt(elem.getAttribute('min'), 10);
- var type = elem.type;
- var allowEmpty = elem.getAttribute('allowEmpty');
- var v = elem.value;
- var name = elem.name;
- var dom = elem;
-
- if (
- allowEmpty === null
- && isNaN(max)
- && isNaN(min)
- && valid === null
- && customValid === null
- && vr === null
- && orient === null
- ) {
- return;
- }
- if (allowEmpty && (v === '' || typeof v !== 'string')) {
- self.onValidPass(dom, self.successTips);
- return;
- }
- if (name && valid) {
- if (valid === 'email') {
- if (!v.match(/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/)) {
- validArr.push(name);
- self.onValidRefuse(dom, self.emailWarning);
- }
- else {
- self.onValidPass(dom, self.successTips);
- }
- }
- else if (valid === 'mobile') {
- if (!v.match(/^1[3|4|5|8][0-9]\d{4,8}$/)) {
- validArr.push(name);
- self.onValidRefuse(dom, self.mobileWarning);
- }
- else {
- self.onValidPass(dom, self.successTips);
- }
- }
- else if (valid === 'url') {
- if (!v.match(/((http|ftp|https|file):\/\/([\w\-]+\.)+[\w\-]+(\/[\w\u4e00-\u9fa5\-\.\/?\@\%\!\&=\+\~\:\#\;\,]*)?)/)) {
- validArr.push(name);
- self.onValidRefuse(dom, self.urlWarning);
- }
- else {
- self.onValidPass(dom, self.successTips);
- }
- }
- else if (valid === 'present') {
- v = v.replace(' ', '');
- if (!v.length) {
- validArr.push(name);
- self.onValidRefuse(dom, self.presentWarning);
- }
- else {
- comparator('string').handler(min, max, dom, v, validArr, name);
- }
- }
- else if (valid.match(/^\/\S+\/$/)) {
- valid = valid.replace(/^\//, '');
- valid = valid.replace(/\/$/, '');
- var reg = new RegExp(valid);
- if (reg.test(v)) {
- comparator('string').handler(min, max, dom, v, validArr, name);
- }
- else {
- validArr.push(name);
- self.onValidRefuse(dom, self.regWarning);
- }
- }
- else if (NUMBER_REGEXP[valid.toUpperCase()]) {
- var reg = NUMBER_REGEXP[valid.toUpperCase()];
- if (reg.test(v)) {
- comparator('number').handler(min, max, dom, v, validArr, name);
- }
- else {
- validArr.push(name);
- self.onValidRefuse(dom, self.numWarning);
- }
- }
- }
- else if (name && !valid) {
- if (customValid) {
- if (window[customValid]) {
- var reg = window[customValid].regExp;
- var tips = window[customValid].message || self.regWarning;
- if (reg && reg.test(v)) {
- comparator('string').handler(min, max, dom, v, validArr, name);
- }
- else {
- validArr.push(name);
- self.onValidRefuse(dom, tips);
- }
- }
- }
- else {
- if (type === 'text') {
- comparator('string').handler(min, max, dom, v, validArr, name);
- }
- }
- }
- if (orient) {
- var newEle = EL.querySelector(orient);
- if (elem === newEle || !newEle) {
- return;
- }
- elem = newEle;
- vr = elem.getAttribute('vr');
- }
- if (!validArr.length && vr) {
- var arr = vr.split('::');
- var method = arr[0];
- var params = arr[1] ? arr[1].split(',') : undefined;
- var flag = false;
- try {
- if (iToolkit[method]) {
- flag = iToolkit[method].apply(elem, params);
- }
- }
- catch (e) {
- flag = false;
- throw e;
- }
- if (!flag) {
- validArr.push('fail');
- }
- }
- }
-
-
-});
\ No newline at end of file
diff --git a/build/iToolkit_lite.min.js b/build/iToolkit_lite.min.js
deleted file mode 100644
index 68548e5..0000000
--- a/build/iToolkit_lite.min.js
+++ /dev/null
@@ -1,7 +0,0 @@
-/**
- * iToolkit-lite v1.0.0
- * Revised in 2015-08-27 14:49:32
- * Released under the ISC License.
- */
-
-!function(e){"use strict";function t(e){var t=$(0),n=e.slice(t.length).match(/\s*(\S+?)\s*(?:,\s*(\S)+)?\s+in\s+(.+)/);return n?{key:n[1],pos:n[2],val:t+n[3]}:{val:e}}function n(e,t,n){var i={};return i[e.key]=t,e.pos&&(i[e.pos]=n),i}function i(e,i,r){d(e,"each");var a,s=e.outerHTML,u=e.parentNode,l=document.createComment("riot placeholder"),c=[],f=k(e);u.insertBefore(l,e),r=t(r),i.one("premount",function(){u.stub&&(u=i.root),e.parentNode.removeChild(e)}).on("update",function(){var t,d=W(r.val,i);if(!M(d)){if(t=a,a=d?JSON.stringify(d):"",a===t)return;d=d?Object.keys(d).map(function(e){return n(r,e,d[e])}):[]}for(var p=document.createDocumentFragment(),g=c.length,v=d.length;g>v;)c[--g].unmount();for(c.length=v,t=!a&&!!r.key,g=0;v>g;++g){var h=t?n(r,d[g],g):d[g];c[g]||((c[g]=new o({tmpl:s},{parent:i,isLoop:!0,root:u,item:h})).mount(),p.appendChild(c[g].root)),c[g]._item=h,c[g].update(h)}u.insertBefore(p,l),f&&(i.tags[m(e)]=c)}).one("updated",function(){var e=Object.keys(i);h(u,function(t){1!=t.nodeType||t.isLoop||t._looped||(t._visited=!1,t._looped=!0,x(t,i,e))})})}function r(e,t,n){h(e,function(e){if(1==e.nodeType){e.isLoop=e.parentNode&&e.parentNode.isLoop||e.getAttribute("each")?1:0;var i=k(e);if(i&&!e.isLoop){for(var r,a=new o(i,{root:e,parent:t},e.innerHTML),s=m(e),u=t;!k(u.root)&&u.parent;)u=u.parent;a.parent=u,r=u.tags[s],r?(M(r)||(u.tags[s]=[r]),u.tags[s].push(a)):u.tags[s]=a,e.innerHTML="",n.push(a)}e.isLoop||x(e,t,[])}})}function a(e,t,n){function r(e,t,i){if(t.indexOf($(0))>=0){var r={dom:e,expr:t};n.push(g(r,i))}}h(e,function(e){var n=e.nodeType;if(3==n&&"STYLE"!=e.parentNode.tagName&&r(e,e.nodeValue),1==n){var a=e.getAttribute("each");return a&&a.match(/\{[\s\S]+\}/)?(i(e,t,a),!1):(c(e.attributes,function(t){var n=t.name,i=n.split("__")[1];return r(e,t.value,{attr:i||n,bool:i}),i?(d(e,n),!1):void 0}),k(e)?!1:void 0)}})}function o(e,t,n){function i(){c(E.attributes,function(e){f[e.name]=W(e.value,m||u)}),c(Object.keys(k),function(e){f[e]=W(k[e],m||u)})}function o(e){if(c(x,function(t){t[e?"mount":"unmount"]()}),m){var t=e?"on":"off";h?m[t]("unmount",u.unmount):m[t]("update",u.update)[t]("unmount",u.unmount)}}var s,u=_.observable(this),f=N(t.opts)||{},d=v(e.tmpl),m=t.parent,h=t.isLoop,y=t.item,C=[],x=[],E=t.root,w=e.fn,A=E.tagName.toLowerCase(),k={},S=/([\w\-]+)\s?=\s?['"]([^'"]+)["']/gim;if(w&&E._tag&&E._tag.unmount(!0),this.isMounted=!1,e.attrs){var L=e.attrs.match(S);c(L,function(e){var t=e.split(/\s?=\s?/);E.setAttribute(t[0],t[1].replace(/['"]/g,""))})}E._tag=this,this._id=p(~~((new Date).getTime()*Math.random())),g(this,{parent:m,root:E,opts:f,tags:{}},y),c(E.attributes,function(e){var t=e.value;$(/\{.*\}/).test(t)&&(k[e.name]=t)}),d.innerHTML&&!/select|select|optgroup|tbody|tr/.test(A)&&("TABLE-VIEW"!==E.tagName,d.innerHTML=T(d.innerHTML,n)),this.update=function(e){g(u,e),i(),u.trigger("update",e),l(C,u,e),u.trigger("updated")},this.mixin=function(){c(arguments,function(e){e="string"==typeof e?_.mixin(e):e,c(Object.keys(e),function(t){"init"!=t&&(u[t]="function"==typeof e[t]?e[t].bind(u):e[t])}),e.init&&e.init.bind(u)()})},this.mount=function(){if(i(),w&&w.call(u,f),o(!0),a(d,u,C),u.parent||u.update(),u.trigger("premount"),h)u.root=E=s=d.firstChild;else{for(;d.firstChild;)E.appendChild(d.firstChild);E.stub&&(u.root=E=m.root)}!u.parent||u.parent.isMounted?(u.isMounted=!0,u.trigger("mount")):u.parent.one("mount",function(){b(u.root)||(u.parent.isMounted=u.isMounted=!0,u.trigger("mount"))})},this.unmount=function(e){var t=s||E,n=t.parentNode;if(n){if(m)M(m.tags[A])?c(m.tags[A],function(e,t){e._id==u._id&&m.tags[A].splice(t,1)}):m.tags[A]=void 0;else for(;t.firstChild;)t.removeChild(t.firstChild);e||n.removeChild(t)}u.trigger("unmount"),o(),u.off("*"),E._tag=null},r(d,this,x)}function s(t,n,i,r,a){i[t]=function(t){t=t||e.event,t.which||(t.which=t.charCode||t.keyCode),t.target||(t.target=t.srcElement);try{t.currentTarget=i}catch(o){}if(t.item=r._item?r._item:a,n.call(r,t)===!0||/radio|check/.test(i.type)||(t.preventDefault&&t.preventDefault(),t.returnValue=!1),!t.preventUpdate){var s=a?r.parent:r;s.update()}}}function u(e,t,n){e&&(e.insertBefore(n,t),e.removeChild(t))}function l(e,t,n){c(e,function(e,i){var r=e.dom,a=e.attr,o=W(e.expr,t),l=e.dom.parentNode;if(null==o&&(o=""),l&&"TEXTAREA"==l.tagName&&(o=o.replace(/riot-/g,"")),e.value!==o){if(e.value=o,!a)return r.nodeValue=o.toString();if(d(r,a),"function"==typeof o)s(a,o,r,t,n);else if("if"==a){var c=e.stub;o?c&&(u(c.parentNode,c,r),r.inStub=!1,b(r)||h(r,function(e){e._tag&&!e._tag.isMounted&&(e._tag.isMounted=!!e._tag.trigger("mount"))})):(c=e.stub=c||document.createTextNode(""),u(r.parentNode,r,c),r.inStub=!0)}else if(/^(show|hide)$/.test(a))"hide"==a&&(o=!o),r.style.display=o?"":"none";else if("value"==a)r.value=o;else if("riot-"==a.slice(0,5)&&"riot-tag"!=a)a=a.slice(5),o?r.setAttribute(a,o):d(r,a);else{if(e.bool){if(r[a]=o,!o)return;o=a}"object"!=typeof o&&r.setAttribute(a,o)}}})}function c(e,t){for(var n,i=0,r=(e||[]).length;r>i;i++)n=e[i],null!=n&&t(n,i)===!1&&i--;return e}function f(e){return"function"==typeof e||!1}function d(e,t){e.removeAttribute(t)}function p(e){return(e^e>>31)-(e>>31)}function m(e){var t=k(e),n=e.getAttribute("name"),i=n&&n.indexOf($(0))<0?n:t.name;return i}function g(e){for(var t,n=arguments,i=1;iO,n=/^\s*<([\w-]+)/.exec(e),i=n?n[1].toLowerCase():"",r="th"===i||"td"===i?"tr":"tr"===i?"tbody":"div",a=y(r);return a.stub=!0,t&&("optgroup"===i?A(a,e):"option"===i?w(a,e):"div"!==r?E(a,e,i):t=0),t||(a.innerHTML=e),a}function h(e,t){if(e)if(t(e)===!1)h(e.nextSibling,t);else for(e=e.firstChild;e;)h(e,t),e=e.nextSibling}function b(e){for(;e;){if(e.inStub)return!0;e=e.parentNode}return!1}function y(e){return document.createElement(e)}function T(e,t){return e.replace(/<(yield)\/?>(<\/\1>)?/gim,t||"")}function C(e,t){return(t||document).querySelectorAll(e)}function N(e){function t(){}return t.prototype=e,new t}function x(e,t,n){c(e.attributes,function(i){if(!e._visited&&("id"===i.name||"name"===i.name)){e._visited=!0;var r,a=i.value;if(~n.indexOf(a))return;r=t[a],r?M(r)?r.push(e):t[a]=[r,e]:t[a]=e}})}function E(e,t,n){var i,r=y("div"),a=/td|th/.test(n)?3:2;for(r.innerHTML="",i=r.firstChild;a--;)i=i.firstChild;e.appendChild(i)}function w(e,t){var n=y("option"),i=/value=[\"'](.+?)[\"']/,r=/selected=[\"'](.+?)[\"']/,a=/each=[\"'](.+?)[\"']/,o=/if=[\"'](.+?)[\"']/,s=/>([^<]*),u=t.match(i),l=t.match(r),c=t.match(s),f=t.match(a),d=t.match(o);n.innerHTML=c?c[1]:t,u&&(n.value=u[1]),l&&n.setAttribute("riot-selected",l[1]),f&&n.setAttribute("each",f[1]),d&&n.setAttribute("if",d[1]),e.appendChild(n)}function A(e,t){var n=y("optgroup"),i=/label=[\"'](.+?)[\"']/,r=/^<([^>]*)>/,a=/^<([^ \>]*)/,o=t.match(i),s=t.match(r),u=t.match(a),l=t;if(s){var c=t.slice(s[1].length+2,-u[1].length-3).trim();l=c}if(o&&n.setAttribute("riot-label",o[1]),l){var f=y("div");w(f,l),n.appendChild(f.firstChild)}e.appendChild(n)}function k(e){return I[e.getAttribute(H)||e.tagName.toLowerCase()]}function S(e){if(R=R||y("style"),document.head){if(R.styleSheet?R.styleSheet.cssText+=e:R.innerHTML+=e,!R._rendered)if(R.styleSheet)document.body.appendChild(R);else{var t=C("style[type=riot]")[0];t?(t.parentNode.insertBefore(R,t),t.parentNode.removeChild(t)):document.head.appendChild(R)}R._rendered=!0}}function L(e,t,n){var i=I[t],r=e._innerHTML=e._innerHTML||e.innerHTML;return e.innerHTML="",i&&e&&(i=new o(i,{root:e,opts:n},r)),i&&i.mount?(i.mount(),D.push(i),i.on("unmount",function(){D.splice(D.indexOf(i),1)})):void 0}var _={version:"v2.2.1",settings:{}},V="string",j="object",M=Array.isArray||function(){var e=Object.prototype.toString;return function(t){return"[object Array]"===e.call(t)}}(),O=function(e){return 0|(e&&e.document||{}).documentMode}(e);_.observable=function(e){e=e||{};var t={},n=0;return e.on=function(i,r){return f(r)&&(r._id="undefined"==typeof r._id?n++:r._id,i.replace(/\S+/g,function(e,n){(t[e]=t[e]||[]).push(r),r.typed=n>0})),e},e.off=function(n,i){return"*"==n?t={}:n.replace(/\S+/g,function(e){if(i)for(var n,r=t[e],a=0;n=r&&r[a];++a)n._id==i._id&&(r.splice(a,1),a--);else t[e]=[]}),e},e.one=function(t,n){function i(){e.off(t,i),n.apply(e,arguments)}return e.on(t,i)},e.trigger=function(n){for(var i,r=[].slice.call(arguments,1),a=t[n]||[],o=0;i=a[o];++o)i.busy||(i.busy=1,i.apply(e,i.typed?[n].concat(r):r),a[o]!==i&&o--,i.busy=0);return t.all&&"all"!=n&&e.trigger.apply(e,["all",n].concat(r)),e},e},_.mixin=function(){var e={};return function(t,n){return n?void(e[t]=n):e[t]}}(),function(e,t,n){function i(){return s.href.split("#")[1]||""}function r(e){return e.split("/")}function a(e){e.type&&(e=i()),e!=o&&(u.trigger.apply(null,["H"].concat(r(e))),o=e)}if(n){var o,s=n.location,u=e.observable(),l=n,c=!1,f=e.route=function(e){e[0]?(s.hash=e,a(e)):u.on("H",e)};f.exec=function(e){e.apply(null,r(i()))},f.parser=function(e){r=e},f.stop=function(){c&&(l.removeEventListener?l.removeEventListener(t,a,!1):l.detachEvent("on"+t,a),u.off("*"),c=!1)},f.start=function(){c||(l.addEventListener?l.addEventListener(t,a,!1):l.attachEvent("on"+t,a),c=!0)},f.start()}}(_,"hashchange",e);var R,$=function(e){var t,n,i,r=/[{}]/g;return function(a){var o=_.settings.brackets||e;return t!==o&&(t=o,i=o.split(" "),n=i.map(function(e){return e.replace(/(?=.)/g,"\\")})),a instanceof RegExp?o===e?a:new RegExp(a.source.replace(r,function(e){return n[~~("}"===e)]}),a.global?"g":""):i[a]}}("{ }"),W=function(){function t(e,t){return e=(e||$(0)+$(1)).replace($(/\\{/g),"").replace($(/\\}/g),""),t=r(e,a(e,$(/{/),$(/}/))),new Function("d","return "+(t[0]||t[2]||t[3]?"["+t.map(function(e,t){return t%2?n(e,!0):'"'+e.replace(/\n/g,"\\n").replace(/"/g,'\\"')+'"'}).join(",")+'].join("")':n(t[1])).replace(/\uFFF0/g,$(0)).replace(/\uFFF1/g,$(1))+";")}function n(e,t){return e=e.replace(/\n/g," ").replace($(/^[{ ]+|[ }]+$|\/\*.+?\*\//g),""),/^\s*[\w- "']+ *:/.test(e)?"["+a(e,/["' ]*[\w- ]+["' ]*:/,/,(?=["' ]*[\w- ]+["' ]*:)|}|$/).map(function(e){return e.replace(/^[ "']*(.+?)[ "']*: *(.+?),? *$/,function(e,t,n){return n.replace(/[^&|=!><]+/g,i)+'?"'+t+'":"",'})}).join("")+'].join(" ").trim()':i(e,t)}function i(t,n){return t=t.trim(),t?"(function(v){try{v="+(t.replace(s,function(t,n,i){return i?"(d."+i+"===undefined?"+("undefined"==typeof e?"global.":"window.")+i+":d."+i+")":t})||"x")+"}catch(e){}finally{return "+(n===!0?'!v&&v!==0?"":v':"v")+"}}).call(d)":""}function r(e,t){var n=[];return t.map(function(t,i){i=e.indexOf(t),n.push(e.slice(0,i),t),e=e.slice(i+t.length)}),n.concat(e)}function a(e,t,n){var i,r=0,a=[],o=new RegExp("("+t.source+")|("+n.source+")","g");return e.replace(o,function(t,n,o,s){!r&&n&&(i=s),r+=n?1:-1,r||null==o||a.push(e.slice(i,s+o.length))}),a}var o={},s=/(['"\/]).*?[^\\]\1|\.\w*|\w*:|\b(?:(?:new|typeof|in|instanceof) |(?:this|true|false|null|undefined)\b|function *\()|([a-z_$]\w*)/gi;return function(e,n){return e&&(o[e]=o[e]||t(e))(n)}}(),D=[],I={},H="riot-tag";_.tag=function(e,t,n,i,r){return f(i)&&(r=i,/^[\w\-]+\s?=/.test(n)?(i=n,n=""):i=""),n&&(f(n)?r=n:S(n)),I[e]={name:e,tmpl:t,attrs:i,fn:r},e},_.mount=function(e,t,n){function i(e){var t="";return c(e,function(e){t+=', *[riot-tag="'+e.trim()+'"]'}),t}function r(){var e=Object.keys(I);return e+i(e)}function a(e){if(e.tagName){t&&!e.getAttribute(H)&&e.setAttribute(H,t);var i=L(e,t||e.getAttribute(H)||e.tagName.toLowerCase(),n);i&&u.push(i)}else e.length&&c(e,a)}var o,s,u=[];if(typeof t===j&&(n=t,t=0),typeof e===V?("*"===e?e=s=r():e+=i(e.split(",")),o=C(e)):o=e,"*"===t){if(t=s||r(),o.tagName)o=C(t,o);else{var l=[];c(o,function(e){l.push(C(t,e))}),o=l}t=0}return o.tagName?a(o):c(o,a),u},_.update=function(){return c(D,function(e){e.update()})},_.mountTo=_.mount,_.util={brackets:$,tmpl:W},"object"==typeof exports?module.exports=_:"function"==typeof define&&define.amd?define(function(){return _}):e.riot=_}("undefined"!=typeof window?window:void 0);var utils={httpGet:function(e,t,n,i){var r=new XMLHttpRequest,e=utils.concatParams(e,t);r.open("GET",e,!0),r.send(null),r.onreadystatechange=function(){if(4===r.readyState&&(i&&"function"==typeof i&&i(),200===r.status)){var e=r.responseText;try{if("string"==typeof e)var t=JSON.parse(e);else var t=e}catch(a){alert("解析错误")}n(t)}}},httpPost:function(e,t,n,i){var r=new XMLHttpRequest;r.open("POST",e,!0),r.setRequestHeader("Content-type","application/json"),r.send(t),r.onreadystatechange=function(){if(4===r.readyState)if(i&&"function"==typeof i&&i(),200===r.status){try{var e=JSON.parse(r.responseText)}catch(t){console.log("解析错误")}n(e)}else console.log("网络错误")}},jsonp:function(e,t,n){var i=Date.now(),r=document.createElement("script"),a=document.getElementsByTagName("head")[0],e=utils.concatParams(e,t);if(t.callback)var o=e,s=t.callback;else{if(e.match(/\?/))var o=e+"&callback=jsonpCallback"+i;else var o=e+"?callback=jsonpCallback"+i;var s="jsonpCallback"+i}r.src=o,a.appendChild(r),window[s]=function(e){if("string"==typeof e)try{e=JSON.parse(e)}catch(t){}n(e)},r.onerror=function(){console.log("jsonp error")},r.onload=function(){a.removeChild(r)}},htmlEncode:function(e){var t=document.createElement("div");return t.innerHTML=e,t.innerText},concatParams:function(e,t){if(e.match(/\?/))var n="&";else var n="?";for(i in t)n=n+i+"="+t[i]+"&";return n=n.replace(/&$/,""),e+n},setCookie:function(e,t,n,i){var r=new Date,i=i||"/";r.setTime(r.getTime()+n),document.cookie=e+"="+escape(t)+";path="+i+";expires="+r.toGMTString()},transBytes:function(e){var t=["B","KB","MB","GB","TB"];if(0==e)return"n/a";var n=parseInt(Math.floor(Math.log(e)/Math.log(1024)));return 0==n?e+t[n]:(e/Math.pow(1024,n)).toFixed(1)+t[n]},transTimes:function(e){var e=parseInt(e,10),t=new Date(1e3*e),n=(new Date).getTime()/1e3,i=n-e;if(86400>i)return t.getHours()+":"+t.getMinutes();if(i>86400&&172800>i)return"昨天";if(i>172800){var r=(t.getFullYear()+"-").substring(2),a=(t.getMonth()+1<10?"0"+(t.getMonth()+1):t.getMonth()+1)+"-",o=t.getDate()<10?"0"+t.getDate():t.getDate();return r+a+o}},hasClass:function(e,t){return e.className.match(new RegExp("(\\s|^)"+t+"(\\s|$)"))},addClass:function(e,t){e.className.trim(),this.hasClass(e,t)||(e.className+=" "+t)},removeClass:function(e,t){if(utils.hasClass(e,t)){var n=new RegExp("(\\s|^)"+t+"(\\s|$)");e.className=e.className.replace(n," ")}},toggleClass:function(e,t){if(utils.hasClass(e,t)){var n=new RegExp("(\\s|^)"+t+"(\\s|$)");e.className=e.className.replace(n," ")}else e.className+=" "+t},insertAfter:function(e,t){var n=t.parentNode;n.lastChild==t?n.appendChild(e):n.insertBefore(e,t.nextSibling)},insertAfterText:function(e,t){var n=t.parentNode;if(n.lastChild==t)n.appendChild(e);else{var i=t.nextSibling;3===i.nodeType&&(i=i.nextSibling),n.insertBefore(e,i)}},isType:function(e){return function(t){return toString.call(t)==="[object "+e+"]"}},makeArray:function(){return Array.prototype.concat(obj)},extend:function(e,t){for(var n in t)e[n]||(e[n]=t[n])}};utils.extend(utils,{isArray:utils.isType("Array"),isObject:utils.isType("Object"),isFunction:utils.isType("Function"),isElement:function(e){return-1!==toString.call(e).indexOf("Element")}}),utils.extend(utils,{jsLoader:function(){function e(){return d++}function t(e){return e.match(/\.css\??/)}function n(t){this.uri=t,this.cid=e(),this.status=T}function i(e,t){return i.then(e,t).start(),i}function r(e){throw e}function a(e){if(e||p.length)for(var t=0;t","super-div{ display: block; }",function(e){var t=this,n=t.opts.opts||t.opts,r=t.root;for(i in n)t[i]=n[i];t.getData=function(e){var e=e||{};if(r.getAttribute("data-get"))var n="httpGet";else if(r.getAttribute("data-jsonp"))var n="jsonp";utils[n](t.superDivUrl,e,function(e){for(i in e)t.data={},t.data[i]=e[i];t.update()})},t.on("mount",function(){r.style.display="block",t.superDivUrl=r.getAttribute("data-get")||r.getAttribute("data-jsonp"),t.superDivUrl&&t.getData(n.params)}),t.loadData=r.loadData=function(e,n){n=n||"data",t[n]=e,t.update()},t.reload=r.reload=function(){t.superDivUrl?t.getData(n.params):t.update()}}),riot.tag("super-form",'',function(e){function t(e,t,n,i,r,a){var o=isNaN(e),s=isNaN(t),l=i.length;o||s?(o||(e>l?(r.push(a),u.onValidRefuse(n,u.minWarning(e))):u.onValidPass(n,u.successTips)),s||(l>t?(r.push(a),u.onValidRefuse(n,u.maxWarning(t))):u.onValidPass(n,u.successTips)),s&&o&&u.onValidPass(n,u.successTips)):l>t||e>l?(r.push(a),u.onValidRefuse(n,u.bpWarning(e,t))):u.onValidPass(n,u.successTips)}function n(e,t,n,i,r,a){var o=isNaN(e),s=isNaN(t),i=+i;o||s?(o||(e>i?(r.push(a),u.onValidRefuse(n,u.minNumWarning(e))):u.onValidPass(n,u.successTips)),s||(i>t?(r.push(a),u.onValidRefuse(n,u.maxNumWarning(t))):u.onValidPass(n,u.successTips)),s&&o&&u.onValidPass(n,u.successTips)):i>t||e>i?(r.push(a),u.onValidRefuse(n,u.numBpWarning(e,t))):u.onValidPass(n,u.successTips)}function r(e){s([],this)}function a(e){return toString.call(e).match(/\ (.*)\]/)[1]}function o(e){var t=a(e);return"Null"===t||"Undefined"===t||"Function"===t?e:new window[t](e)}function s(e,t){var t=t,n=t.getAttribute("valid"),i=t.getAttribute("customValid"),r=t.getAttribute("vr"),a=t.getAttribute("orient"),o=parseInt(t.getAttribute("max"),10),s=parseInt(t.getAttribute("min"),10),c=t.type,f=t.getAttribute("allowEmpty"),m=t.value,g=t.name,v=t;if(null!==f||!isNaN(o)||!isNaN(s)||null!==n||null!==i||null!==r||null!==a){if(f&&(""===m||"string"!=typeof m))return void u.onValidPass(v,u.successTips);if(g&&n){if("email"===n)m.match(/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/)?u.onValidPass(v,u.successTips):(e.push(g),u.onValidRefuse(v,u.emailWarning));else if("mobile"===n)m.match(/^1[3|4|5|8][0-9]\d{4,8}$/)?u.onValidPass(v,u.successTips):(e.push(g),u.onValidRefuse(v,u.mobileWarning));else if("url"===n)m.match(/((http|ftp|https|file):\/\/([\w\-]+\.)+[\w\-]+(\/[\w\u4e00-\u9fa5\-\.\/?\@\%\!\&=\+\~\:\#\;\,]*)?)/)?u.onValidPass(v,u.successTips):(e.push(g),u.onValidRefuse(v,u.urlWarning));else if("present"===n)m=m.replace(" ",""),m.length?p("string").handler(s,o,v,m,e,g):(e.push(g),u.onValidRefuse(v,u.presentWarning));else if(n.match(/^\/\S+\/$/)){n=n.replace(/^\//,""),n=n.replace(/\/$/,"");var h=new RegExp(n);h.test(m)?p("string").handler(s,o,v,m,e,g):(e.push(g),u.onValidRefuse(v,u.regWarning))}else if(d[n.toUpperCase()]){var h=d[n.toUpperCase()];h.test(m)?p("number").handler(s,o,v,m,e,g):(e.push(g),u.onValidRefuse(v,u.numWarning))}}else if(g&&!n)if(i){if(window[i]){var h=window[i].regExp,b=window[i].message||u.regWarning;h&&h.test(m)?p("string").handler(s,o,v,m,e,g):(e.push(g),u.onValidRefuse(v,b))}}else"text"===c&&p("string").handler(s,o,v,m,e,g);if(a){var y=l.querySelector(a);if(t===y||!y)return;t=y,r=t.getAttribute("vr")}if(!e.length&&r){var T=r.split("::"),C=T[0],N=T[1]?T[1].split(","):void 0,x=!1;try{iToolkit[C]&&(x=iToolkit[C].apply(t,N))}catch(E){throw x=!1,E}x||e.push("fail")}}}var u=this,l=u.root,c=u.opts.opts||u.opts,f=["insertTip","ajaxSubmit","submit","removeTips","insertTip","removeTip","loadData","getData","setData"],d={NON_NEGATIVE_INT:/^0$|^-[1-9]\d*$/,POSITIVE_INT:/^[1-9]\d*$/,NON_POSITIVE_INT:/^[1-9]\d*$|^0$/,NEGATIVE_INT:/^-[1-9]\d*$/,INT:/^-?[1-9]\d*$|^0$/,NON_NEGATIVE_FLOAT:/^(\d)(\.\d+)?$|^([1-9]\d*)(\.\d+)?$|^0$/,POSITIVE_FLOAT:/^(\d)(\.\d+)?$|^([1-9]\d*)(\.\d+)?$/,NON_POSITIVE_FLOAT:/^(-\d)(\.\d+)?$|^(-[1-9]\d*)(\.\d+)?$|^0$/,NEGATIVE_FLOAT:/^(-\d)(\.\d+)?$|^(-[1-9]\d*)(\.\d+)?$/,FLOAT:/^(-?\d)(\.\d+)?$|^(-?[1-9]\d*)(\.\d+)?$|^0$/};u.presentWarning="必填",u.emailWarning="邮箱格式错误",u.mobileWarning="手机格式错误",u.urlWarning="网址格式错误",u.successTips="通过",u.regWarning="字段不符合验证规则",u.numWarning="数字格式错误",u.passClass=c.passClass||"valid-pass",u.failedClass=c.failedClass||"valid-failed";var p=function(e){return{handler:function(i,r,a,o,s,u){switch(e){case"number":return n(i,r,a,o,s,u);case"string":default:return t(i,r,a,o,s,u)}}}};u.one("mount",function(){if(l.style.display="block",c.realTime&&c.valid)for(var e=u.root.getElementsByTagName("form")[0].elements,t=0,n=e.length;n>t;t++){var i=e[t].type;("submit"!==i||"button"!==i)&&(e[t].addEventListener("input",r,!1),("checkbox"===i||"radio"===i)&&e[t].addEventListener("change",r,!1),e[t].addEventListener("input",r,!1))}}),l.loadData=function(e,t){if(utils.isObject(e))for(var n in e)e[n]=o(e[n]);else e=o(e);t=t||"data",u[t]=e,u.update()},l.setData=function(e,t){u.data[t]=o(e),u.update()},u.checkExistKey=function(e,t,n){if(e.hasOwnProperty(t))if(utils.isArray(e[t]))e[t].push(n);else{var i=[];i.push(e[t]),i.push(n),e[t]=i}else e[t]=n},u.getData=l.getData=function(){for(var e=u.root.getElementsByTagName("form")[0].elements,t={},n=0;n 0
- })
- }
- return el
- }
-
- el.off = function(events, fn) {
- if (events == '*') callbacks = {}
- else {
- events.replace(/\S+/g, function(name) {
- if (fn) {
- var arr = callbacks[name]
- for (var i = 0, cb; (cb = arr && arr[i]); ++i) {
- if (cb._id == fn._id) arr.splice(i--, 1)
- }
- } else {
- callbacks[name] = []
- }
- })
- }
- return el
- }
-
- // only single event supported
- el.one = function(name, fn) {
- function on() {
- el.off(name, on)
- fn.apply(el, arguments)
- }
- return el.on(name, on)
- }
-
- el.trigger = function(name) {
- var args = [].slice.call(arguments, 1),
- fns = callbacks[name] || []
-
- for (var i = 0, fn; (fn = fns[i]); ++i) {
- if (!fn.busy) {
- fn.busy = 1
- fn.apply(el, fn.typed ? [name].concat(args) : args)
- if (fns[i] !== fn) { i-- }
- fn.busy = 0
- }
- }
-
- if (callbacks.all && name != 'all') {
- el.trigger.apply(el, ['all', name].concat(args))
- }
-
- return el
- }
-
- return el
-
- }
- riot.mixin = (function() {
- var mixins = {}
-
- return function(name, mixin) {
- if (!mixin) return mixins[name]
- mixins[name] = mixin
- }
-
- })()
-
- ;(function(riot, evt, win) {
-
- // browsers only
- if (!win) return
-
- var loc = win.location,
- fns = riot.observable(),
- started = false,
- current
-
- function hash() {
- return loc.href.split('#')[1] || '' // why not loc.hash.splice(1) ?
- }
-
- function parser(path) {
- return path.split('/')
- }
-
- function emit(path) {
- if (path.type) path = hash()
-
- if (path != current) {
- fns.trigger.apply(null, ['H'].concat(parser(path)))
- current = path
- }
- }
-
- var r = riot.route = function(arg) {
- // string
- if (arg[0]) {
- loc.hash = arg
- emit(arg)
-
- // function
- } else {
- fns.on('H', arg)
- }
- }
-
- r.exec = function(fn) {
- fn.apply(null, parser(hash()))
- }
-
- r.parser = function(fn) {
- parser = fn
- }
-
- r.stop = function () {
- if (started) {
- if (win.removeEventListener) win.removeEventListener(evt, emit, false) //@IE8 - the if()
- else win.detachEvent('on' + evt, emit) //@IE8
- fns.off('*')
- started = false
- }
- }
-
- r.start = function () {
- if (!started) {
- if (win.addEventListener) win.addEventListener(evt, emit, false) //@IE8 - the if()
- else win.attachEvent('on' + evt, emit) //IE8
- started = true
- }
- }
-
- // autostart the router
- r.start()
-
- })(riot, 'hashchange', window)
- /*
-
- //// How it works?
-
-
- Three ways:
-
- 1. Expressions: tmpl('{ value }', data).
- Returns the result of evaluated expression as a raw object.
-
- 2. Templates: tmpl('Hi { name } { surname }', data).
- Returns a string with evaluated expressions.
-
- 3. Filters: tmpl('{ show: !done, highlight: active }', data).
- Returns a space separated list of trueish keys (mainly
- used for setting html classes), e.g. "show highlight".
-
-
- // Template examples
-
- tmpl('{ title || "Untitled" }', data)
- tmpl('Results are { results ? "ready" : "loading" }', data)
- tmpl('Today is { new Date() }', data)
- tmpl('{ message.length > 140 && "Message is too long" }', data)
- tmpl('This item got { Math.round(rating) } stars', data)
- tmpl('{ title } { body }', data)
-
-
- // Falsy expressions in templates
-
- In templates (as opposed to single expressions) all falsy values
- except zero (undefined/null/false) will default to empty string:
-
- tmpl('{ undefined } - { false } - { null } - { 0 }', {})
- // will return: " - - - 0"
-
- */
-
-
- var brackets = (function(orig) {
-
- var cachedBrackets,
- r,
- b,
- re = /[{}]/g
-
- return function(x) {
-
- // make sure we use the current setting
- var s = riot.settings.brackets || orig
-
- // recreate cached vars if needed
- if (cachedBrackets !== s) {
- cachedBrackets = s
- b = s.split(' ')
- r = b.map(function (e) { return e.replace(/(?=.)/g, '\\') })
- }
-
- // if regexp given, rewrite it with current brackets (only if differ from default)
- return x instanceof RegExp ? (
- s === orig ? x :
- new RegExp(x.source.replace(re, function(b) { return r[~~(b === '}')] }), x.global ? 'g' : '')
- ) :
- // else, get specific bracket
- b[x]
- }
- })('{ }')
-
-
- var tmpl = (function() {
-
- var cache = {},
- OGLOB = '"in d?d:' + (window ? 'window).' : 'global).'),
- reVars =
- /(['"\/])(?:[^\\]*?|\\.|.)*?\1|\.\w*|\w*:|\b(?:(?:new|typeof|in|instanceof) |(?:this|true|false|null|undefined)\b|function\s*\()|([A-Za-z_$]\w*)/g
-
- // build a template (or get it from cache), render with data
- return function(str, data) {
- return str && (cache[str] || (cache[str] = tmpl(str)))(data)
- }
-
-
- // create a template instance
-
- function tmpl(s, p) {
-
- if (s.indexOf(brackets(0)) < 0) {
- // return raw text
- s = s.replace(/\n|\r\n?/g, '\n')
- return function () { return s }
- }
-
- // temporarily convert \{ and \} to a non-character
- s = s
- .replace(brackets(/\\{/g), '\uFFF0')
- .replace(brackets(/\\}/g), '\uFFF1')
-
- // split string to expression and non-expresion parts
- p = split(s, extract(s, brackets(/{/), brackets(/}/)))
-
- // is it a single expression or a template? i.e. {x} or {x}
- s = (p.length === 2 && !p[0]) ?
-
- // if expression, evaluate it
- expr(p[1]) :
-
- // if template, evaluate all expressions in it
- '[' + p.map(function(s, i) {
-
- // is it an expression or a string (every second part is an expression)
- return i % 2 ?
-
- // evaluate the expressions
- expr(s, true) :
-
- // process string parts of the template:
- '"' + s
-
- // preserve new lines
- .replace(/\n|\r\n?/g, '\\n')
-
- // escape quotes
- .replace(/"/g, '\\"') +
-
- '"'
-
- }).join(',') + '].join("")'
-
- return new Function('d', 'return ' + s
- // bring escaped { and } back
- .replace(/\uFFF0/g, brackets(0))
- .replace(/\uFFF1/g, brackets(1)) + ';')
-
- }
-
-
- // parse { ... } expression
-
- function expr(s, n) {
- s = s
-
- // convert new lines to spaces
- .replace(/\n|\r\n?/g, ' ')
-
- // trim whitespace, brackets, strip comments
- .replace(brackets(/^[{ ]+|[ }]+$|\/\*.+?\*\//g), '')
-
- // is it an object literal? i.e. { key : value }
- return /^\s*[\w- "']+ *:/.test(s) ?
-
- // if object literal, return trueish keys
- // e.g.: { show: isOpen(), done: item.done } -> "show done"
- '[' +
-
- // extract key:val pairs, ignoring any nested objects
- extract(s,
-
- // name part: name:, "name":, 'name':, name :
- /["' ]*[\w- ]+["' ]*:/,
-
- // expression part: everything upto a comma followed by a name (see above) or end of line
- /,(?=["' ]*[\w- ]+["' ]*:)|}|$/
- ).map(function(pair) {
-
- // get key, val parts
- return pair.replace(/^[ "']*(.+?)[ "']*: *(.+?),? *$/, function(_, k, v) {
-
- // wrap all conditional parts to ignore errors
- return v.replace(/[^&|=!><]+/g, wrap) + '?"' + k + '":"",'
-
- })
-
- }).join('') +
-
- '].join(" ").trim()' :
-
- // if js expression, evaluate as javascript
- wrap(s, n)
-
- }
-
-
- // execute js w/o breaking on errors or undefined vars
-
- function wrap(s, nonull) {
- s = s.trim()
- return !s ? '' : '(function(v){try{v=' +
-
- // prefix vars (name => data.name)
- s.replace(reVars, function(s, _, v) { return v ? '(("' + v + OGLOB + v + ')' : s }) +
-
- // default to empty string for falsy values except zero
- '}catch(e){}return ' + (nonull === true ? '!v&&v!==0?"":v' : 'v') + '}).call(d)'
- }
-
-
- // split string by an array of substrings
-
- function split(str, substrings) {
- var parts = []
- substrings.map(function(sub, i) {
-
- // push matched expression and part before it
- i = str.indexOf(sub)
- parts.push(str.slice(0, i), sub)
- str = str.slice(i + sub.length)
- })
- if (str) parts.push(str)
-
- // push the remaining part
- return parts
- }
-
-
- // match strings between opening and closing regexp, skipping any inner/nested matches
-
- function extract(str, open, close) {
-
- var start,
- level = 0,
- matches = [],
- re = new RegExp('(' + open.source + ')|(' + close.source + ')', 'g')
-
- str.replace(re, function(_, open, close, pos) {
-
- // if outer inner bracket, mark position
- if (!level && open) start = pos
-
- // in(de)crease bracket level
- level += open ? 1 : -1
-
- // if outer closing bracket, grab the match
- if (!level && close != null) matches.push(str.slice(start, pos + close.length))
-
- })
-
- return matches
- }
-
- })()
-
- /*
- lib/browser/tag/mkdom.js
-
- Includes hacks needed for the Internet Explorer version 9 and bellow
-
- */
-// http://kangax.github.io/compat-table/es5/#ie8
-// http://codeplanet.io/dropping-ie8/
-
- var mkdom = (function (checkIE) {
-
- var rootEls = {
- 'tr': 'tbody',
- 'th': 'tr',
- 'td': 'tr',
- 'tbody': 'table',
- 'col': 'colgroup'
- },
- GENERIC = 'div'
-
- checkIE = checkIE && checkIE < 10
-
- // creates any dom element in a div, table, or colgroup container
- function _mkdom(html) {
-
- var match = html && html.match(/^\s*<([-\w]+)/),
- tagName = match && match[1].toLowerCase(),
- rootTag = rootEls[tagName] || GENERIC,
- el = mkEl(rootTag)
-
- el.stub = true
-
- if (checkIE && tagName && (match = tagName.match(SPECIAL_TAGS_REGEX)))
- ie9elem(el, html, tagName, !!match[1])
- else
- el.innerHTML = html
-
- return el
- }
-
- // creates tr, th, td, option, optgroup element for IE8-9
- /* istanbul ignore next */
- function ie9elem(el, html, tagName, select) {
-
- var div = mkEl(GENERIC),
- tag = select ? 'select>' : 'table>',
- child
-
- div.innerHTML = '<' + tag + html + '' + tag
-
- child = div.getElementsByTagName(tagName)[0]
- if (child)
- el.appendChild(child)
-
- }
- // end ie9elem()
-
- return _mkdom
-
- })(IE_VERSION)
-
-// { key, i in items} -> { key, i, items }
- function loopKeys(expr) {
- var b0 = brackets(0),
- els = expr.trim().slice(b0.length).match(/^\s*(\S+?)\s*(?:,\s*(\S+))?\s+in\s+(.+)$/)
- return els ? { key: els[1], pos: els[2], val: b0 + els[3] } : { val: expr }
- }
-
- function mkitem(expr, key, val) {
- var item = {}
- item[expr.key] = key
- if (expr.pos) item[expr.pos] = val
- return item
- }
-
-
- /* Beware: heavy stuff */
- function _each(dom, parent, expr) {
-
- remAttr(dom, 'each')
-
- var tagName = getTagName(dom),
- template = dom.outerHTML,
- hasImpl = !!tagImpl[tagName],
- impl = tagImpl[tagName] || {
- tmpl: template
- },
- root = dom.parentNode,
- placeholder = document.createComment('riot placeholder'),
- tags = [],
- child = getTag(dom),
- checksum
-
- root.insertBefore(placeholder, dom)
-
- expr = loopKeys(expr)
-
- // clean template code
- parent
- .one('premount', function () {
- if (root.stub) root = parent.root
- // remove the original DOM node
- dom.parentNode.removeChild(dom)
- })
- .on('update', function () {
- var items = tmpl(expr.val, parent)
-
- // object loop. any changes cause full redraw
- if (!isArray(items)) {
-
- checksum = items ? JSON.stringify(items) : ''
-
- items = !items ? [] :
- Object.keys(items).map(function (key) {
- return mkitem(expr, key, items[key])
- })
- }
-
- var frag = document.createDocumentFragment(),
- i = tags.length,
- j = items.length
-
- // unmount leftover items
- while (i > j) {
- tags[--i].unmount()
- tags.splice(i, 1)
- }
-
- for (i = 0; i < j; ++i) {
- var _item = !checksum && !!expr.key ? mkitem(expr, items[i], i) : items[i]
-
- if (!tags[i]) {
- // mount new
- tags[i] = new Tag(impl, {
- parent: parent,
- isLoop: true,
- hasImpl: hasImpl,
- root: SPECIAL_TAGS_REGEX.test(tagName) ? root : dom.cloneNode(),
- item: _item
- }, dom.innerHTML)
- tags[i]._item = _item
- tags[i].mount()
-
- frag.appendChild(tags[i].root)
- } else
- tags[i].update(_item)
-
- tags[i]._item = _item
-
- }
-
- root.insertBefore(frag, placeholder)
-
- if (child) parent.tags[tagName] = tags
-
- }).one('updated', function() {
- var keys = Object.keys(parent)// only set new values
- walk(root, function(node) {
- // only set element node and not isLoop
- if (node.nodeType == 1 && !node.isLoop && !node._looped) {
- node._visited = false // reset _visited for loop node
- node._looped = true // avoid set multiple each
- setNamed(node, parent, keys)
- }
- })
- })
-
- }
-
-
- function parseNamedElements(root, tag, childTags) {
-
- walk(root, function(dom) {
- if (dom.nodeType == 1) {
- dom.isLoop = dom.isLoop || (dom.parentNode && dom.parentNode.isLoop || dom.getAttribute('each')) ? 1 : 0
-
- // custom child tag
- var child = getTag(dom)
-
- if (child && !dom.isLoop) {
- childTags.push(initChildTag(child, dom, tag))
- }
-
- if (!dom.isLoop)
- setNamed(dom, tag, [])
- }
-
- })
-
- }
-
- function parseExpressions(root, tag, expressions) {
-
- function addExpr(dom, val, extra) {
- if (val.indexOf(brackets(0)) >= 0) {
- var expr = { dom: dom, expr: val }
- expressions.push(extend(expr, extra))
- }
- }
-
- walk(root, function(dom) {
- var type = dom.nodeType
-
- // text node
- if (type == 3 && dom.parentNode.tagName != 'STYLE') addExpr(dom, dom.nodeValue)
- if (type != 1) return
-
- /* element */
-
- // loop
- var attr = dom.getAttribute('each')
-
- if (attr) { _each(dom, tag, attr); return false }
-
- // attribute expressions
- each(dom.attributes, function(attr) {
- var name = attr.name,
- bool = name.split('__')[1]
-
- addExpr(dom, attr.value, { attr: bool || name, bool: bool })
- if (bool) { remAttr(dom, name); return false }
-
- })
-
- // skip custom tags
- if (getTag(dom)) return false
-
- })
-
- }
- function Tag(impl, conf, innerHTML) {
-
- var self = riot.observable(this),
- opts = inherit(conf.opts) || {},
- dom = mkdom(impl.tmpl),
- parent = conf.parent,
- isLoop = conf.isLoop,
- hasImpl = conf.hasImpl,
- item = cleanUpData(conf.item),
- expressions = [],
- childTags = [],
- root = conf.root,
- fn = impl.fn,
- tagName = root.tagName.toLowerCase(),
- attr = {},
- propsInSyncWithParent = []
-
- if (fn && root._tag) {
- root._tag.unmount(true)
- }
-
- // not yet mounted
- this.isMounted = false
- root.isLoop = isLoop
-
- // keep a reference to the tag just created
- // so we will be able to mount this tag multiple times
- root._tag = this
-
- // create a unique id to this tag
- // it could be handy to use it also to improve the virtual dom rendering speed
- this._id = __uid++
-
- extend(this, { parent: parent, root: root, opts: opts, tags: {} }, item)
-
- // grab attributes
- each(root.attributes, function(el) {
- var val = el.value
- // remember attributes with expressions only
- if (brackets(/{.*}/).test(val)) attr[el.name] = val
- })
-
- if (dom.innerHTML && !/^(select|optgroup|table|tbody|tr|col(?:group)?)$/.test(tagName))
- // replace all the yield tags with the tag inner html
- dom.innerHTML = replaceYield(dom.innerHTML, innerHTML)
-
- // options
- function updateOpts() {
- var ctx = hasImpl && isLoop ? self : parent || self
-
- // update opts from current DOM attributes
- each(root.attributes, function(el) {
- opts[el.name] = tmpl(el.value, ctx)
- })
- // recover those with expressions
- each(Object.keys(attr), function(name) {
- opts[name] = tmpl(attr[name], ctx)
- })
- }
-
- function normalizeData(data) {
- for (var key in item) {
- if (typeof self[key] !== T_UNDEF)
- self[key] = data[key]
- }
- }
-
- function inheritFromParent () {
- if (!self.parent || !isLoop) return
- each(Object.keys(self.parent), function(k) {
- // some properties must be always in sync with the parent tag
- var mustSync = !~RESERVED_WORDS_BLACKLIST.indexOf(k) && ~propsInSyncWithParent.indexOf(k)
- if (typeof self[k] === T_UNDEF || mustSync) {
- // track the property to keep in sync
- // so we can keep it updated
- if (!mustSync) propsInSyncWithParent.push(k)
- self[k] = self.parent[k]
- }
- })
- }
-
- this.update = function(data) {
- // make sure the data passed will not override
- // the component core methods
- data = cleanUpData(data)
- // inherit properties from the parent
- inheritFromParent()
- // normalize the tag properties in case an item object was initially passed
- if (data && typeof item === T_OBJECT) {
- normalizeData(data)
- item = data
- }
- extend(self, data)
- updateOpts()
- self.trigger('update', data)
- update(expressions, self)
- self.trigger('updated')
- }
-
- this.mixin = function() {
- each(arguments, function(mix) {
- mix = typeof mix === T_STRING ? riot.mixin(mix) : mix
- each(Object.keys(mix), function(key) {
- // bind methods to self
- if (key != 'init')
- self[key] = isFunction(mix[key]) ? mix[key].bind(self) : mix[key]
- })
- // init method will be called automatically
- if (mix.init) mix.init.bind(self)()
- })
- }
-
- this.mount = function() {
-
- updateOpts()
-
- // initialiation
- if (fn) fn.call(self, opts)
-
- // parse layout after init. fn may calculate args for nested custom tags
- parseExpressions(dom, self, expressions)
-
- // mount the child tags
- toggle(true)
-
- // update the root adding custom attributes coming from the compiler
- // it fixes also #1087
- if (impl.attrs || hasImpl) {
- walkAttributes(impl.attrs, function (k, v) { root.setAttribute(k, v) })
- parseExpressions(self.root, self, expressions)
- }
-
- if (!self.parent || isLoop) self.update(item)
-
- // internal use only, fixes #403
- self.trigger('premount')
-
- if (isLoop && !hasImpl) {
- // update the root attribute for the looped elements
- self.root = root = dom.firstChild
-
- } else {
- while (dom.firstChild) root.appendChild(dom.firstChild)
- if (root.stub) self.root = root = parent.root
- }
- // if it's not a child tag we can trigger its mount event
- if (!self.parent || self.parent.isMounted) {
- self.isMounted = true
- self.trigger('mount')
- }
- // otherwise we need to wait that the parent event gets triggered
- else self.parent.one('mount', function() {
- // avoid to trigger the `mount` event for the tags
- // not visible included in an if statement
- if (!isInStub(self.root)) {
- self.parent.isMounted = self.isMounted = true
- self.trigger('mount')
- }
- })
- }
-
-
- this.unmount = function(keepRootTag) {
- var el = root,
- p = el.parentNode,
- ptag
-
- if (p) {
-
- if (parent) {
- ptag = getImmediateCustomParentTag(parent)
- // remove this tag from the parent tags object
- // if there are multiple nested tags with same name..
- // remove this element form the array
- if (isArray(ptag.tags[tagName]))
- each(ptag.tags[tagName], function(tag, i) {
- if (tag._id == self._id)
- ptag.tags[tagName].splice(i, 1)
- })
- else
- // otherwise just delete the tag instance
- ptag.tags[tagName] = undefined
- }
-
- else
- while (el.firstChild) el.removeChild(el.firstChild)
-
- if (!keepRootTag)
- p.removeChild(el)
- else
- // the riot-tag attribute isn't needed anymore, remove it
- p.removeAttribute('riot-tag')
- }
-
-
- self.trigger('unmount')
- toggle()
- self.off('*')
- // somehow ie8 does not like `delete root._tag`
- root._tag = null
-
- }
-
- function toggle(isMount) {
-
- // mount/unmount children
- each(childTags, function(child) { child[isMount ? 'mount' : 'unmount']() })
-
- // listen/unlisten parent (events flow one way from parent to children)
- if (parent) {
- var evt = isMount ? 'on' : 'off'
-
- // the loop tags will be always in sync with the parent automatically
- if (isLoop)
- parent[evt]('unmount', self.unmount)
- else
- parent[evt]('update', self.update)[evt]('unmount', self.unmount)
- }
- }
-
- // named elements available for fn
- parseNamedElements(dom, this, childTags)
-
-
- }
-
- function setEventHandler(name, handler, dom, tag) {
-
- dom[name] = function(e) {
-
- var item = tag._item,
- ptag = tag.parent,
- el
-
- if (!item)
- while (ptag && !item) {
- item = ptag._item
- ptag = ptag.parent
- }
-
- // cross browser event fix
- e = e || window.event
-
- // ignore error on some browsers
- try {
- e.currentTarget = dom
- if (!e.target) e.target = e.srcElement
- if (!e.which) e.which = e.charCode || e.keyCode
- } catch (ignored) { /**/ }
-
- e.item = item
-
- // prevent default behaviour (by default)
- if (handler.call(tag, e) !== true && !/radio|check/.test(dom.type)) {
- if (e.preventDefault) e.preventDefault()
- e.returnValue = false
- }
-
- if (!e.preventUpdate) {
- el = item ? getImmediateCustomParentTag(ptag) : tag
- el.update()
- }
-
- }
-
- }
-
-// used by if- attribute
- function insertTo(root, node, before) {
- if (root) {
- root.insertBefore(before, node)
- root.removeChild(node)
- }
- }
-
- function update(expressions, tag) {
-
- each(expressions, function(expr, i) {
-
- var dom = expr.dom,
- attrName = expr.attr,
- value = tmpl(expr.expr, tag),
- parent = expr.dom.parentNode
-
- if (expr.bool)
- value = value ? attrName : false
- else if (value == null)
- value = ''
-
- // leave out riot- prefixes from strings inside textarea
- // fix #815: any value -> string
- if (parent && parent.tagName == 'TEXTAREA') value = ('' + value).replace(/riot-/g, '')
-
- // no change
- if (expr.value === value) return
- expr.value = value
-
- // text node
- if (!attrName) {
- dom.nodeValue = '' + value // #815 related
- return
- }
-
- // remove original attribute
- remAttr(dom, attrName)
- // event handler
- if (isFunction(value)) {
- setEventHandler(attrName, value, dom, tag)
-
- // if- conditional
- } else if (attrName == 'if') {
- var stub = expr.stub,
- add = function() { insertTo(stub.parentNode, stub, dom) },
- remove = function() { insertTo(dom.parentNode, dom, stub) }
-
- // add to DOM
- if (value) {
- if (stub) {
- add()
- dom.inStub = false
- // avoid to trigger the mount event if the tags is not visible yet
- // maybe we can optimize this avoiding to mount the tag at all
- if (!isInStub(dom)) {
- walk(dom, function(el) {
- if (el._tag && !el._tag.isMounted) el._tag.isMounted = !!el._tag.trigger('mount')
- })
- }
- }
- // remove from DOM
- } else {
- stub = expr.stub = stub || document.createTextNode('')
- // if the parentNode is defined we can easily replace the tag
- if (dom.parentNode)
- remove()
- else
- // otherwise we need to wait the updated event
- (tag.parent || tag).one('updated', remove)
-
- dom.inStub = true
- }
- // show / hide
- } else if (/^(show|hide)$/.test(attrName)) {
- if (attrName == 'hide') value = !value
- dom.style.display = value ? '' : 'none'
-
- // field value
- } else if (attrName == 'value') {
- dom.value = value
-
- //
- } else if (startsWith(attrName, RIOT_PREFIX) && attrName != RIOT_TAG) {
- if (value)
- dom.setAttribute(attrName.slice(RIOT_PREFIX.length), value)
-
- } else {
- if (expr.bool) {
- dom[attrName] = value
- if (!value) return
- }
-
- if (typeof value !== T_OBJECT) dom.setAttribute(attrName, value)
-
- }
-
- })
-
- }
- function each(els, fn) {
- for (var i = 0, len = (els || []).length, el; i < len; i++) {
- el = els[i]
- // return false -> remove current item during loop
- if (el != null && fn(el, i) === false) i--
- }
- return els
- }
-
- function isFunction(v) {
- return typeof v === T_FUNCTION || false // avoid IE problems
- }
-
- function remAttr(dom, name) {
- dom.removeAttribute(name)
- }
-
- function getTag(dom) {
- return dom.tagName && tagImpl[dom.getAttribute(RIOT_TAG) || dom.tagName.toLowerCase()]
- }
-
- function initChildTag(child, dom, parent) {
- var tag = new Tag(child, { root: dom, parent: parent }, dom.innerHTML),
- tagName = getTagName(dom),
- ptag = getImmediateCustomParentTag(parent),
- cachedTag
-
- // fix for the parent attribute in the looped elements
- tag.parent = ptag
-
- cachedTag = ptag.tags[tagName]
-
- // if there are multiple children tags having the same name
- if (cachedTag) {
- // if the parent tags property is not yet an array
- // create it adding the first cached tag
- if (!isArray(cachedTag))
- ptag.tags[tagName] = [cachedTag]
- // add the new nested tag to the array
- if (!~ptag.tags[tagName].indexOf(tag))
- ptag.tags[tagName].push(tag)
- } else {
- ptag.tags[tagName] = tag
- }
-
- // empty the child node once we got its template
- // to avoid that its children get compiled multiple times
- dom.innerHTML = ''
-
- return tag
- }
-
- function getImmediateCustomParentTag(tag) {
- var ptag = tag
- while (!getTag(ptag.root)) {
- if (!ptag.parent) break
- ptag = ptag.parent
- }
- return ptag
- }
-
- function getTagName(dom) {
- var child = getTag(dom),
- namedTag = dom.getAttribute('name'),
- tagName = namedTag && namedTag.indexOf(brackets(0)) < 0 ? namedTag : child ? child.name : dom.tagName.toLowerCase()
-
- return tagName
- }
-
- function extend(src) {
- var obj, args = arguments
- for (var i = 1; i < args.length; ++i) {
- if ((obj = args[i])) {
- for (var key in obj) { // eslint-disable-line guard-for-in
- src[key] = obj[key]
- }
- }
- }
- return src
- }
-
-// with this function we avoid that the current Tag methods get overridden
- function cleanUpData(data) {
- if (!(data instanceof Tag) && !(data && typeof data.trigger == T_FUNCTION)) return data
-
- var o = {}
- for (var key in data) {
- if (!~RESERVED_WORDS_BLACKLIST.indexOf(key))
- o[key] = data[key]
- }
- return o
- }
-
- function walk(dom, fn) {
- if (dom) {
- if (fn(dom) === false) return
- else {
- dom = dom.firstChild
-
- while (dom) {
- walk(dom, fn)
- dom = dom.nextSibling
- }
- }
- }
- }
-
-// minimize risk: only zero or one _space_ between attr & value
- function walkAttributes(html, fn) {
- var m,
- re = /([-\w]+) ?= ?(?:"([^"]*)|'([^']*)|({[^}]*}))/g
-
- while ((m = re.exec(html))) {
- fn(m[1].toLowerCase(), m[2] || m[3] || m[4])
- }
- }
-
- function isInStub(dom) {
- while (dom) {
- if (dom.inStub) return true
- dom = dom.parentNode
- }
- return false
- }
-
- function mkEl(name) {
- return document.createElement(name)
- }
-
- function replaceYield(tmpl, innerHTML) {
- return tmpl.replace(/<(yield)\/?>(<\/\1>)?/gi, innerHTML || '')
- }
-
- function $$(selector, ctx) {
- return (ctx || document).querySelectorAll(selector)
- }
-
- function $(selector, ctx) {
- return (ctx || document).querySelector(selector)
- }
-
- function inherit(parent) {
- function Child() {}
- Child.prototype = parent
- return new Child()
- }
-
- function setNamed(dom, parent, keys) {
- if (dom._visited) return
- var p,
- v = dom.getAttribute('id') || dom.getAttribute('name')
-
- if (v) {
- if (keys.indexOf(v) < 0) {
- p = parent[v]
- if (!p)
- parent[v] = dom
- else if (isArray(p))
- p.push(dom)
- else
- parent[v] = [p, dom]
- }
- dom._visited = true
- }
- }
-
-// faster String startsWith alternative
- function startsWith(src, str) {
- return src.slice(0, str.length) === str
- }
-
- /*
- Virtual dom is an array of custom tags on the document.
- Updates and unmounts propagate downwards from parent to children.
- */
-
- var virtualDom = [],
- tagImpl = {},
- styleNode
-
- function injectStyle(css) {
-
- if (riot.render) return // skip injection on the server
-
- if (!styleNode) {
- styleNode = mkEl('style')
- styleNode.setAttribute('type', 'text/css')
- }
-
- var head = document.head || document.getElementsByTagName('head')[0]
-
- if (styleNode.styleSheet)
- styleNode.styleSheet.cssText += css
- else
- styleNode.innerHTML += css
-
- if (!styleNode._rendered)
- if (styleNode.styleSheet) {
- document.body.appendChild(styleNode)
- } else {
- var rs = $('style[type=riot]')
- if (rs) {
- rs.parentNode.insertBefore(styleNode, rs)
- rs.parentNode.removeChild(rs)
- } else head.appendChild(styleNode)
-
- }
-
- styleNode._rendered = true
-
- }
-
- function mountTo(root, tagName, opts) {
- var tag = tagImpl[tagName],
- // cache the inner HTML to fix #855
- innerHTML = root._innerHTML = root._innerHTML || root.innerHTML
-
- // clear the inner html
- root.innerHTML = ''
-
- if (tag && root) tag = new Tag(tag, { root: root, opts: opts }, innerHTML)
-
- if (tag && tag.mount) {
- tag.mount()
- virtualDom.push(tag)
- return tag.on('unmount', function() {
- virtualDom.splice(virtualDom.indexOf(tag), 1)
- })
- }
-
- }
-
- riot.tag = function(name, html, css, attrs, fn) {
- if (isFunction(attrs)) {
- fn = attrs
- if (/^[\w\-]+\s?=/.test(css)) {
- attrs = css
- css = ''
- } else attrs = ''
- }
- if (css) {
- if (isFunction(css)) fn = css
- else injectStyle(css)
- }
- tagImpl[name] = { name: name, tmpl: html, attrs: attrs, fn: fn }
- return name
- }
-
- riot.mount = function(selector, tagName, opts) {
-
- var els,
- allTags,
- tags = []
-
- // helper functions
-
- function addRiotTags(arr) {
- var list = ''
- each(arr, function (e) {
- list += ', *[' + RIOT_TAG + '="' + e.trim() + '"]'
- })
- return list
- }
-
- function selectAllTags() {
- var keys = Object.keys(tagImpl)
- return keys + addRiotTags(keys)
- }
-
- function pushTags(root) {
- var last
- if (root.tagName) {
- if (tagName && (!(last = root.getAttribute(RIOT_TAG)) || last != tagName))
- root.setAttribute(RIOT_TAG, tagName)
-
- var tag = mountTo(root,
- tagName || root.getAttribute(RIOT_TAG) || root.tagName.toLowerCase(), opts)
-
- if (tag) tags.push(tag)
- }
- else if (root.length) {
- each(root, pushTags) // assume nodeList
- }
- }
-
- // ----- mount code -----
-
- if (typeof tagName === T_OBJECT) {
- opts = tagName
- tagName = 0
- }
-
- // crawl the DOM to find the tag
- if (typeof selector === T_STRING) {
- if (selector === '*')
- // select all the tags registered
- // and also the tags found with the riot-tag attribute set
- selector = allTags = selectAllTags()
- else
- // or just the ones named like the selector
- selector += addRiotTags(selector.split(','))
-
- els = $$(selector)
- }
- else
- // probably you have passed already a tag or a NodeList
- els = selector
-
- // select all the registered and mount them inside their root elements
- if (tagName === '*') {
- // get all custom tags
- tagName = allTags || selectAllTags()
- // if the root els it's just a single tag
- if (els.tagName)
- els = $$(tagName, els)
- else {
- // select all the children for all the different root elements
- var nodeList = []
- each(els, function (_el) {
- nodeList.push($$(tagName, _el))
- })
- els = nodeList
- }
- // get rid of the tagName
- tagName = 0
- }
-
- if (els.tagName)
- pushTags(els)
- else
- each(els, pushTags)
-
- return tags
- }
-
-// update everything
- riot.update = function() {
- return each(virtualDom, function(tag) {
- tag.update()
- })
- }
-
-// @deprecated
- riot.mountTo = riot.mount
-
- // share methods for other riot parts, e.g. compiler
- riot.util = { brackets: brackets, tmpl: tmpl }
-
- // support CommonJS, AMD & browser
- /* istanbul ignore next */
- if (typeof exports === T_OBJECT)
- module.exports = riot
- else if (typeof define === 'function' && define.amd)
- define(function() { return (window.riot = riot) })
- else
- window.riot = riot
-
-})(typeof window != 'undefined' ? window : void 0);
-/*
- * Utils 函数
- */
-var utils = {
- httpGet: function(url, params, callback, complete) {
- var xmlhttp = new XMLHttpRequest();
- var url = utils.concatParams(url, params);
- xmlhttp.open("GET", url, true);
- xmlhttp.send(null);
- xmlhttp.onreadystatechange = function() {
- if (xmlhttp.readyState === 4) {
- if (complete && typeof complete === 'function') {
- complete();
- }
- if (xmlhttp.status === 200) {
- var body = xmlhttp.responseText;
- try {
- if (typeof body === 'string') {
- var data = JSON.parse(body);
- }
- else {
- var data = body;
- }
- }
- catch(e) {
- alert('解析错误');
- }
- callback(data);
- }
- }
- }
- },
-
- httpPost: function(url, params, callback, complete) {
- var xmlhttp = new XMLHttpRequest();
- xmlhttp.open("POST", url, true);
- xmlhttp.setRequestHeader("Content-type", "application/json");
- xmlhttp.send(params);
- xmlhttp.onreadystatechange = function() {
- if (xmlhttp.readyState === 4) {
- if (complete && typeof complete === 'function') {
- complete();
- }
- if (xmlhttp.status === 200) {
- try {
- var data = JSON.parse(xmlhttp.responseText)
- }
- catch(e) {
- console.log('解析错误');
- }
- callback(data);
- }
- else {
- console.log('网络错误');
- }
- }
- };
- },
-
- jsonp: function (url, params, callback) {
- var now = Date.now();
- var script = document.createElement('script');
- var head = document.getElementsByTagName('head')[0];
- var url = utils.concatParams(url, params);
- if (!params.callback) {
- if (url.match(/\?/)) {
- var src = url + '&callback=jsonpCallback' + now;
- }
- else {
- var src = url + '?callback=jsonpCallback' + now;
- }
- var funcName = 'jsonpCallback' + now;
- }
- else {
- var src = url;
- var funcName = params.callback;
- }
- script.src = src;
- head.appendChild(script);
- window[funcName] = function(data) {
- if (typeof data === 'string') {
- try {
- data = JSON.parse(data);
- }
- catch(e) {}
- }
- callback(data);
- }
- script.onerror = function() {
- console.log('jsonp error');
- };
- script.onload = function() {
- head.removeChild(script);
- }
- },
-
- htmlEncode: function(value){
- var div = document.createElement('div');
- div.innerHTML = value;
- return div.innerText;
- },
-
- concatParams: function(url, params) {
- if (url.match(/\?/)) {
- var str = '&'
- }
- else {
- var str = '?'
- }
- for(i in params) {
- str = str + i + '=' + params[i] + '&';
- }
- str = str.replace(/&$/, '');
- return url + str;
- },
-
- setCookie: function(key, value, expires, path) {
- var exp = new Date();
- var path = path || '/';
- exp.setTime(exp.getTime() + expires);
- document.cookie = key + "=" + escape (value) + ";path=" + path + ";expires=" + exp.toGMTString();
- },
-
- transBytes: function(bytes) {
- var sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
- if (bytes == 0) return 'n/a';
- var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
- if (i == 0) return bytes + sizes[i];
- return (bytes / Math.pow(1024, i)).toFixed(1) + sizes[i];
- },
-
- transTimes: function(timeStamp) {
- var timeStamp = parseInt(timeStamp, 10);
- var time = new Date(timeStamp * 1000)
- var now = new Date().getTime()/1000;
- var dv = now - timeStamp;
- if ( dv < 86400) {
- return time.getHours() + ':' + time.getMinutes();
- }
- else if ( dv > 86400 && dv < 172800) {
- return '昨天';
- }
- else if ( dv > 172800) {
- var Y = (time.getFullYear() + '-').substring(2);
- var M = (time.getMonth()+1 < 10 ? '0' + (time.getMonth()+1) : time.getMonth()+1) + '-';
- var D = time.getDate() < 10 ? '0' + time.getDate() : time.getDate();
- return Y + M + D;
- }
- },
-
- hasClass: function (obj, cls) {
- return obj.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'));
- },
-
- addClass: function (obj, cls) {
- obj.className.trim();
- if (!this.hasClass(obj, cls)) obj.className += " " + cls;
- },
-
- removeClass: function (obj, cls) {
- if (utils.hasClass(obj, cls)) {
- var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)');
- obj.className = obj.className.replace(reg, ' ');
- }
- },
-
- toggleClass: function(obj, cls) {
- if (utils.hasClass(obj, cls)) {
- var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)');
- obj.className = obj.className.replace(reg, ' ');
- }
- else {
- obj.className += " " + cls;
- }
- },
-
- insertAfter: function(newElement, targetElement){
- var parent = targetElement.parentNode;
- if (parent.lastChild == targetElement) {
- parent.appendChild(newElement);
- }
- else {
- parent.insertBefore(newElement, targetElement.nextSibling);
- }
- },
-
- insertAfterText: function(newElement, targetElement) {
- var parent = targetElement.parentNode;
- if (parent.lastChild == targetElement) {
- parent.appendChild(newElement);
- }
- else {
- var next = targetElement.nextSibling;
- if (next.nodeType === 3) {
- next = next.nextSibling;
- }
- parent.insertBefore(newElement, next);
- }
- },
-
- isType: function (type) {
- return function (obj) {
- return toString.call(obj) === '[object ' + type + ']';
- }
- },
-
- makeArray: function () {
- return Array.prototype.concat(obj);
- },
-
- extend: function(src, obj) {
- for (var key in obj) {
- if (!src[key]) {
- src[key] = obj[key];
- }
- }
- },
-
- deepCopy: function (parent, child) {
- var defaultWrapper = (toString.call(parent) === '[object Array]') ? [] : {};
- var child = child || defaultWrapper;
- for (var i in parent) {
- if (toString.call(parent[i]) === '[object Object]') {
- child[i] = {}; //新建数组或者object来达到目的
- this.deepCopy(parent[i], child[i]);
- }
- else if (toString.call(parent[i]) === '[object Array]') {
- child[i] = []; //新建数组或者object来达到目的
- this.deepCopy(parent[i], child[i]);
- }
- else {
- child[i] = parent[i];
- }
- }
- return child;
- }
-
-};
-
-utils.extend(utils, {
- isArray: utils.isType('Array'),
- isObject: utils.isType('Object'),
- isFunction: utils.isType('Function'),
- isElement: function (obj) {
- return toString.call(obj).indexOf('Element') !== -1;
- },
-});
-
-utils.extend(utils, {
- jsLoader: (function () {
- var HEAD_NODE = document.head || document.getElementsByTagName('head')[0];
- var cache = {};
- var _cid = 0;
- var tasks = [];
- var isArray = utils.isArray;
- var isFunction = utils.isFunction;
- var makeArray = utils.makeArray;
- var DONE = 'done';
- var INPROCESS = 'inprocess';
- var REJECTED = 'rejected';
- var PENDING = 'pending';
- var processCache = {};
-
- /**
- * 产生客户端id
- * @return {Number} [description]
- */
- function cid() {
- return _cid++;
- }
-
- function isCSS(css) {
- return css.match(/\.css\??/);
- }
-
- /**
- * Script对象,储存需要加载的脚本的基本信息
- * @param {String} uri 地址
- */
- function Script(uri) {
- this.uri = uri;
- this.cid = cid();
- this.status = PENDING;
- }
-
- /**
- * 从缓存中获取需要的Script对象
- * @param {String} uri [description]
- * @return {Object} 需要的Script对象
- */
- Script.get = function (uri) {
- // 如果不存在于缓存中,创建一个新的Script对象
- return cache[uri] || (cache[uri] = new Script(uri));
- };
-
- /**
- * 当加载完成或失败时调用的处理函数
- * @param {Object} js Script对象
- * @return {[type]} [description]
- */
- Script.resolve = function (js) {
- var self = this;
- self.status++;
- if (js && js.status === REJECTED) {
- var error = Error('Source: ' + js.uri + ' load failed');
- reject(error);
- }
- if (self.status === self.task.length) {
- setTimeout(function () {
- self.callback && self.callback();
- self = null;
- resolve(tasks.shift());
- }, 7);
- }
- };
-
- /**
- * jsLoader
- * @param {[type]} js function or string or array
- * @param {Function} callback 加载完成后的回调
- * @return {Function}
- */
- function jsLoader(js, callback) {
- jsLoader.then(js, callback).start();
- return jsLoader;
- }
-
- /**
- * then方法用于向任务列表增加任务
- * @param {[type]} js function or string or array
- * @param {Function} callback [description]
- * @return {Function} [description]
- */
- jsLoader.then = function (js, callback) {
- if (!js) {
- return jsLoader;
- }
- if (!isArray(js)) {
- js = makeArray(js);
- }
- var resolver = {
- task: [],
- callback: callback,
- status: 0
- };
- for (var i = 0; i < js.length; i++) {
- resolver.task.push(getCache(js[i]));
- }
- tasks.push(resolver);
- // jsLoader.resolve();
- return jsLoader;
- };
-
- /**
- * [reject description]
- * @param {Object} e Object Error
- * @return {[type]} [description]
- */
- function reject(e) {
- throw e;
- }
-
- /**
- * 执行任务序列中的任务
- * @param {Object} resolver [description]
- * @return {[type]} [description]
- */
- function resolve(resolver) {
- if (!resolver) {
- if (!tasks.length) {
- return;
- }
- }
- for (var i = 0; i < resolver.task.length; i++) {
- var js = resolver.task[i];
- request(js, resolver);
- }
- }
-
- /**
- * 开始
- * @return {[type]} [description]
- */
- jsLoader.start = function () {
- resolve(tasks.shift());
- return jsLoader;
- }
-
- function loadStyles(script, resolver) {
- var node = document.createElement('link');
- node.type = 'text/css';
- node.rel = 'stylesheet';
- node.href = script.uri;
- HEAD_NODE.appendChild(node);
- node = null;
- script.status = DONE;
- Script.resolve.call(resolver);
- }
-
- /**
- * [request description]
- * @param {[type]} js [description]
- * @param {[type]} resolver [description]
- * @return {[type]} [description]
- */
- function request(js, resolver) {
- if (isFunction(js.uri)) {
- try {
- js.uri();
- js.status = DONE;
- Script.resolve.call(resolver);
- }
- catch (e) {
- js.status = REJECTED;
- Script.resolve.call(resolver);
- }
- return;
- }
- if (js.status === DONE) {
- Script.resolve.call(resolver);
- return;
- }
- if (isCSS(js.uri)) {
- loadStyles(js, resolver);
- return;
- }
- if (js.status === INPROCESS) {
- // 在loading过程中,标记遇到的resolver
- js.changeStatus = true;
- processCache[js.cid] = processCache[js.cid] || [];
- processCache[js.cid].push({js:js, resolver:resolver});
- return;
- }
- js.status = INPROCESS;
- var node = document.createElement('script');
- node.async = true;
- node.src = js.uri;
- node.onload = node.onerror = onloadResolve;
- HEAD_NODE.appendChild(node);
-
- function onloadResolve(evt) {
- if (evt.type === 'error') {
- js.status = REJECTED;
- }
- if (evt.type === 'load') {
- js.status = DONE;
- }
- Script.resolve.call(resolver, js);
- if (js.changeStatus) {
- // 如果加载完成,处理处在waiting状态下的任务
- js.changeStatus = false;
- for (var i = 0; i < processCache[js.cid].length; i++) {
- var tmp = processCache[js.cid][i];
- Script.resolve.call(tmp.resolver, tmp.js);
- }
- processCache[js.cid] = null;
- }
- node.onload = node.onerror = null;
- HEAD_NODE.removeChild(node);
- node = null;
- }
- }
-
- /**
- * 获取可能存在别名的Script对象
- * @param {String} uri [description]
- * @return {Object} Script Object
- */
- function getCache(uri) {
- var src = getAlias(uri);
- return src ? Script.get(src) : Script.get(uri);
- }
-
- /**
- * 获取真实地址
- * @param {String} str [description]
- * @return {[type]} [description]
- */
- function getAlias(str) {
- return jsLoader.alias[str];
- }
-
- jsLoader.alias = {};
-
- return jsLoader;
-
- })()
-});
-
-/*
- * 全局事件监控
- */
-var EventCtrl = EC = riot.observable();
-var iToolkit = itk = riot;
-riot.tag('itk-calendar', ' ⟨
⟪
{ month.text }
{ year.text }
⟩
⟫
', 'hide="{ !open }"', function(opts) {
-
-
-
- var self = this;
-
- self.i18n = {
- zh_cn: {
- weekArr: ['日','一','二','三','四','五','六'],
- monthArr: ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月']
- },
- en_us: {
- weekArr: ['Su','Mo','Tu','We','Th','Fr','Sa'],
- monthArr: ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
- }
- };
-
-
-
- var el = self.root;
-
- var config = self.opts.opts || self.opts || {};
-
-
- self.mapping = function (opts) {
- if (!utils.isObject(opts)) {
- throw new TypeError('Config is not a object!');
- return;
- }
- for (var i in opts) {
- self[i] = opts[i];
- }
- };
-
- self.mapping(config);
-
-
- self.initWeekList = function (language) {
- var list = self.i18n[language];
- if (list) {
- self.weekArr = list.weekArr;
- self.monthArr = list.monthArr;
- }
- else {
- if (!self.weekArr || !self.monthArr) {
- var list = self.i18n.en_us;
- self.weekArr = list.weekArr;
- self.monthArr = list.monthArr;
- }
- }
- };
-
- self.initWeekList(self.language);
-
- self.getDaysCount = function (year, month) {
- var ret = 0;
- switch (month) {
- case 1:
- case 3:
- case 5:
- case 7:
- case 8:
- case 10:
- case 12:
- case 0:
- case 13:
- ret = 31;
- break;
- case 4:
- case 6:
- case 9:
- case 11:
- ret = 30;
- break;
- case 2:
- ((year % 4 === 0 && year % 100 !== 0) || year % 400 === 0) ? ret = 29 : ret = 28;
- break;
- default:
- throw new Error('你算错了');
- break;
- }
- return ret;
- };
-
- self.drawDays = function (timeStamp) {
- var date;
- if (timeStamp) {
- date = new Date(timeStamp);
- }
- else {
- date = new Date();
- }
- var thisMonth = date.getMonth();
- var thisYear = date.getFullYear();
-
- self.month = {
- text: self.monthArr[thisMonth],
- val: thisMonth + 1
- };
-
- self.year = {
- text: thisYear,
- val: thisYear
- };
-
- thisMonth = thisMonth + 1;
-
- var thisMonthDays = self.getDaysCount(thisYear, thisMonth);
- var prevMonthDays = self.getDaysCount(thisYear, thisMonth - 1);
- var nextMonthDays = self.getDaysCount(thisYear, thisMonth + 1);
- date.setDate(1);
- var firstDay = date.getDay();
- date.setDate(thisMonthDays);
- var lastDay = date.getDay();
- var dayArr = [];
- dayArr = dayArr
- .concat((new Array(firstDay === 0 ? 1 : ((7 - firstDay) ^ 7) + 1).join(0).split('')).map(function (v, i) {
- return {
- year: '',
- month: '',
- day: prevMonthDays - i
- }
- }).reverse());
- dayArr = dayArr.concat((new Array(thisMonthDays + 1).join(0).split('')).map(function (v, i){
- return {
- year: thisYear,
- month: thisMonth,
- day: i + 1
- }
- }));
- dayArr = dayArr.concat((new Array(lastDay === 0 ? 7 : (6 - lastDay) + 1).join(0).split('')).map(function (v, i){
- return {
- year: '',
- month: '',
- day: i + 1
- }
- }));
- return dayArr;
- };
-
- self.initDays = function (timeStamp) {
- if (self.showToday) {
- var tmp_date = new Date();
- self.today = tmp_date.getDate();
- self.toMonth = tmp_date.getMonth() + 1;
- self.toYear = tmp_date.getFullYear();
- }
-
- if (self.defaultSelected) {
- var tmp_date = new Date();
- self.selectedDay = tmp_date.getDate();
- self.selectedMonth = tmp_date.getMonth() + 1;
- self.selectedYear = tmp_date.getFullYear();
- }
-
-
- self.dayArr = self.drawDays(timeStamp);
- self.update();
- };
-
- self.initDays(self.initTime);
-
- self.getNum = function (v) {
- return v > 10 ? v : '0' + v;
- }
-
- self.formatter = function (type) {
- var date = new Date(self.selectedYear, self.selectedMonth - 1, self.selectedDay, 0, 0, 0);
- var timeStamp = date.getTime();
- var ret;
- switch (type) {
- case 'unixTimeStamp':
- ret = self.getUnixTimeStamp(timeStamp);
- break;
- case 'timeStamp':
- ret = self.getTimeStamp(timeStamp);
- break;
- default:
- if (!type) {
- var type = 'yyyy/mm/dd';
- }
- ret = type.replace(/(yyyy|mm|dd|yy|m|d)/ig, function (v) {
- if (v === 'yyyy') {
- return self.selectedYear;
- }
- if (v === 'mm') {
- return self.getNum(self.selectedMonth);
- }
- if (v === 'dd') {
- return self.getNum(self.selectedDay);
- }
- if (v === 'yy') {
- return self.selectedYear.toString().substr(2, 4);
- }
- if (v === 'm') {
- return self.selectedMonth;
- }
- if (v === 'd') {
- return self.selectedDay;
- }
- });
- break;
- }
- return ret;
- };
-
-
- self.dayClicked = function (e) {
- self.selectedDay = e.item.day;
- self.selectedMonth = e.item.month;
- self.selectedYear = e.item.year;
- self.onSelect && self.onSelect(self.formatter, self.getYear(), self.getMonth(), self.getDay());
- self.update();
- };
-
- self.open = false;
-
- self.getAbsPoint = function (elm) {
- var x = elm.offsetLeft;
- var y = elm.offsetTop;
- while (elm = elm.offsetParent) {
- x += elm.offsetLeft;
- y += elm.offsetTop;
- }
- return {
- 'x': x,
- 'y': y
- };
- };
-
- self.location = function (e) {
- if (self.element) {
- var pos = self.getAbsPoint(self.element);
- self.root.style.position = 'absolute';
- self.root.style.top = pos.y + self.element.offsetHeight;
- self.root.style.left = pos.x;
- }
- };
-
- self.closeIt = function (e) {
- var className = e.target.className;
- if (
- e.target === self.element ||
- className &&
- className.indexOf('itk-calendar') !== -1 &&
- className !== 'itk-calendar-days'
- ) {
- return;
- }
- self.open = false;
- self.update();
- };
-
- self.openIt = function (e) {
- self.open = true;
- self.update();
- self.location(e);
- };
-
-
- self.unbindEvent = function () {
- if (self.element) {
- document.removeEventListener('click', self.closeIt, false);
- self.element.removeEventListener('click', self.openIt, false);
- }
- };
-
- self.on('mount', function () {
- if (self.element) {
- document.addEventListener('click', self.closeIt, false);
- self.element.addEventListener('click', self.openIt, false);
- }
- else {
- self.open = true;
- }
- self.update();
- });
-
- self.on('unmount', function () {
- self.unbindEvent();
- });
-
-
- self.getTimeStamp = function (timeStamp) {
- return timeStamp;
- };
-
-
- self.getUnixTimeStamp = function (timeStamp) {
- return Math.ceil(timeStamp / 1000).toString();
- };
-
-
- self.getYear = function () {
- return self.selectedYear;
- };
-
-
- self.getMonth = function () {
- return self.selectedMonth;
- };
-
-
- self.getDay = function () {
- return self.selectedDay;
- };
-
- self.nextYear = function () {
- var year = self.year.val + 1;
- self.dayArr = self.drawDays(new Date(year, self.month.val - 1, 1).getTime());
- self.update();
- };
-
- self.nextMonth = function () {
- var month = self.month.val - 1;
- var year = self.year.val;
- year = month === 11 ? year + 1 : year;
- month = month === 11 ? 0 : month + 1;
- var date = new Date(year, month, 1);
- self.dayArr = self.drawDays(date.getTime());
- self.update();
- };
-
- self.prevYear = function () {
- var year = self.year.val - 1;
- self.dayArr = self.drawDays(new Date(year, self.month.val - 1, 1).getTime());
- self.update();
- };
-
- self.prevMonth = function () {
- var month = self.month.val - 1;
- var year = self.year.val;
- year = month === 0 ? year - 1 : year;
- month = month === 0 ? 11 : month - 1;
- var date = new Date(year, month, 1);
- self.dayArr = self.drawDays(date.getTime());
- self.update();
- };
-
-});
-riot.tag('itk-center', '
', function(opts) {
- var self = this;
- var config = self.opts.opts || self.opts;
- self.default = false;
-
- self.on('mount', function() {
- var parentDom = self.root.parentNode;
- var parentPosition = window.getComputedStyle(parentDom, null).position;
- if (parentPosition === 'static') {
- parentDom.style.position = 'relative';
- }
-
- self.childDom = self.root.getElementsByClassName('itk-loading')[0];
-
- if (self.childDom.innerHTML.trim()) {
- self.default = false;
- self.update();
- }
-
- var cellHeight = parseInt(window.getComputedStyle(self.childDom, null).height.replace('px', ''), 10);
- self.root.style.marginTop = '-' + cellHeight/2 + 'px';
-
- });
-
- self.root.show = function(){
- if (self.childDom) {
- self.childDom.style.display = 'block';
- }
- }
-
- self.root.hide = function(){
- if (self.childDom) {
- self.childDom.style.display = 'none';
- }
- }
-
-});
-riot.tag('date-picker', '', function(opts) {
- var self = this;
- var EL = self.root;
- var config = self.opts.opts || self.opts;
-
- var js = document.scripts;
-
- var path = '';
-
- var jsPath = '';
-
- if (!config.path) {
- for (var i = 0; i < js.length; i++) {
- if (!js[i].src) {
- continue;
- }
- if (/iToolkit_pc.min.js|iToolkit_pc.js/.test(js[i].src)) {
- jsPath = js[i].src.replace(/iToolkit_pc.min.js|iToolkit_pc.js/, '');
- break;
- }
- }
- path = jsPath + 'plugins/laydate/';
- }
- else {
- path = config.path;
- }
-
- var theme = config.theme ? config.theme : 'default';
-
- utils.jsLoader([
- path + 'laydate.min.js',
- path + '/need/' + 'laydate.css',
- path + '/skins/' + theme + '/laydate.css'
- ], function () {
- for (var i = 0; i < EL.children.length; i++) {
- var child = EL.children[i];
- if (child.attributes['pTrigger']) {
- self.pTrigger = child;
- }
- if (child.attributes['media']) {
- self.media = child;
- }
- }
- self.resolve();
- self.update();
- });
-
- this.resolve = function() {
- if (self.pTrigger || self.media) {
- if (self.pTrigger === self.media) {
- config.elem = config.pTrigger = self.media;
- }
- if (typeof self.pTrigger === 'undefined') {
- config.elem = self.media;
- }
- if (
- self.pTrigger
- && self.media
- && (self.pTrigger !== self.media)
- ) {
- config.pTrigger = self.pTrigger;
- config.elem = self.media;
- }
- if (self.pTrigger && !self.media) {
- config.elem = self.pTrigger;
- config.justChoose = true;
- }
- }
- else {
- throw 'media and pTrigger property was not found in the element';
- }
-
- if (config.pTrigger) {
- config.pTrigger.onclick = function (e) {
- laydate(config);
- }
- return;
- }
- laydate(config);
- }.bind(this);
-
-});
-
-riot.tag('itk-div', '', function(opts) {
- var self = this;
- var config = self.opts.opts || self.opts;
- var EL = self.root;
-
- for (i in config) {
- self[i] = config[i];
- }
-
-
- self.getData = function(params) {
- var params = params || {};
- if (EL.getAttribute('data-get')) {
- var method = 'httpGet';
- }
- else if (EL.getAttribute('data-jsonp')) {
- var method = 'jsonp';
- }
-
- utils[method](self.superDivUrl, params, function(data) {
- for (i in data) {
- self.data = {};
- self.data[i] = data[i];
- }
- self.update();
- });
- }
-
- self.on('mount', function() {
- EL.style.display = 'block';
- self.superDivUrl = EL.getAttribute('data-get') || EL.getAttribute('data-jsonp');
- if (self.superDivUrl) {
- self.getData(config.params);
- }
- })
-
-
- self.loadData = EL.loadData = function(newData, colName){
- colName = colName || 'data';
- self[colName] = newData
- self.update();
- }
-
- self.reload = EL.reload = function() {
- if (self.superDivUrl) {
- self.getData(config.params);
- }
- else {
- self.update();
- }
- }
-
-});
-riot.tag('itk-editor', '', function(opts) {
- var self = this;
- var EL = self.root;
- var config = self.opts.opts || self.opts;
- var js = document.scripts;
- var path = '';
- var jsPath = '';
- var type = config.type || 'standard';
-
- if (!config.path) {
- for (var i = 0; i < js.length; i++) {
- if (!js[i].src) {
- continue;
- }
- if (/iToolkit_pc.min.js|iToolkit_pc.js/.test(js[i].src)) {
- jsPath = js[i].src.replace(/iToolkit_pc.min.js|iToolkit_pc.js/, '');
- break;
- }
- }
- path = jsPath + 'plugins/ckeditor/';
- }
- else {
- path = config.path;
- }
-
- self.on('mount', function() {
- var textarea = EL.getElementsByTagName('textarea')[0];
- var id = EL.getAttribute('id');
- textarea.setAttribute('name', EL.getAttribute('name'));
- textarea.setAttribute('id', EL.getAttribute('id'));
- EL.removeAttribute('id');
-
- utils.jsLoader([
- path + type + '/ckeditor.js',
-
-
- ], function () {
- CKEDITOR.replace( id, {
- image_previewText: '',
- filebrowserImageUploadUrl: "admin/UserArticleFileUpload.do"
- });
- self.update();
- });
- })
-
-
-
-
-});
-riot.tag('itk-form', '', function(opts) {
- var self = this;
- var EL = self.root;
- var config = self.opts.opts || self.opts;
- var keyWords = [
- 'insertTip',
- 'ajaxSubmit',
- 'submit',
- 'removeTips',
- 'insertTip',
- 'removeTip',
- 'loadData',
- 'getData',
- 'setData'
- ]; //保留字,不被覆盖
-
- var checkList = [
- 'allowEmpty',
- 'allowempty',
- 'max',
- 'min',
- 'valid',
- 'vr'
- ];
-
- var NUMBER_REGEXP = {
- NON_NEGATIVE_INT: /^0$|^-[1-9]\d*$/, //非负整数(正整数 + 0)
- POSITIVE_INT: /^[1-9]\d*$/, //正整数
- NON_POSITIVE_INT: /^[1-9]\d*$|^0$/, //非正整数(负整数 + 0)
- NEGATIVE_INT: /^-[1-9]\d*$/, //负整数
- INT: /^-?[1-9]\d*$|^0$/, //整数
- NON_NEGATIVE_FLOAT: /^(\d)(\.\d+)?$|^([1-9]\d*)(\.\d+)?$|^0$/, //非负浮点数(正浮点数 + 0)
- POSITIVE_FLOAT: /^(\d)(\.\d+)?$|^([1-9]\d*)(\.\d+)?$/, //正浮点数
- NON_POSITIVE_FLOAT: /^(-\d)(\.\d+)?$|^(-[1-9]\d*)(\.\d+)?$|^0$/,//非正浮点数(负浮点数 + 0)
- NEGATIVE_FLOAT: /^(-\d)(\.\d+)?$|^(-[1-9]\d*)(\.\d+)?$/, //负浮点数
- FLOAT: /^(-?\d)(\.\d+)?$|^(-?[1-9]\d*)(\.\d+)?$|^0$/ //浮点数
- };
-
- self.presentWarning = '必填';
- self.emailWarning = '邮箱格式错误';
- self.mobileWarning = '手机格式错误';
- self.urlWarning = '网址格式错误';
- self.successTips = config.successTipsText || '通过';
- self.regexpWarning = '字段不符合验证规则';
- self.numWarning = '数字格式错误';
-
- self.passClass = config.passClass || 'valid-pass';
- self.failedClass = config.failedClass || 'valid-failed';
-
-
- self.comparator = function (type) {
- return {
- handler: function (validation, attrs) {
- switch (type) {
- case 'number':
- return self.numComparator(validation, attrs);
- case 'string':
- default:
- return self.strCompatator(validation, attrs);
- }
- }
- };
- };
-
-
- self.strCompatator = function(validation, attrs) {
- var min = parseInt(attrs.min, 10);
- var max = parseInt(attrs.max, 10);
- var nMin = isNaN(min);
- var nMax = isNaN(max);
- var len = attrs.value.length;
- if (!nMin && !nMax) {
- if (len > max || len < min) {
- validation.msg.push(self.bpWarning(min, max));
- }
- }
- else {
- if (!nMin && len < min) {
- validation.msg.push(self.minWarning(min));
- }
- if (!nMax && len > max) {
- validation.msg.push(self.maxWarning(max));
- }
- }
- return validation;
- };
-
-
- self.numComparator = function(validation, attrs) {
- var min = parseInt(attrs.min, 10);
- var max = parseInt(attrs.max, 10);
- var nMin = isNaN(min);
- var nMax = isNaN(max);
- var value = +attrs.value;
- if (!nMin && !nMax) {
- if (value > max || value < min) {
- validation.msg.push(self.numBpWarning(min, max));
- }
- }
- else {
- if (!nMin && value < min) {
- validation.msg.push(self.minNumWarning(min));
- }
- if (!nMax && value > max) {
- validation.msg.push(self.maxNumWarning(max));
- }
- }
- return validation;
- };
-
- self.one('mount', function() {
- EL.style.display = 'block';
- if (config.realTime && config.valid) {
- var elems = self.root.getElementsByTagName('form')[0].elements;
- for (var i = 0, len = elems.length; i < len; i ++) {
- var type = elems[i].type;
- if (type !== 'submit' || type !== 'button') {
- elems[i].addEventListener('input', valueOnChange, false);
- elems[i].addEventListener('change', valueOnChange, false);
- }
- }
- }
- });
-
-
- function valueOnChange(e) {
- doCheck([], this);
- }
-
- function isType(obj) {
- return Object.prototype.toString.call(obj).match(/\ (.*)\]/)[1];
- }
-
- function dif(obj) {
- var constructor = isType(obj);
- if (constructor === 'Null'
- || constructor === 'Undefined'
- || constructor === 'Function'
- ) {
- return obj;
- }
- return new window[constructor](obj);
- }
-
- EL.loadData = function(newData, colName){
- if (utils.isObject(newData)) {
- for(var i in newData) {
- newData[i] = dif(newData[i]);
- }
- }
- else {
- newData = dif(newData);
- }
- colName = colName || 'data';
- self[colName] = newData;
- self.update();
- };
-
- EL.setData = function(newData, name){
- self.data[name] = dif(newData);
- self.update();
- };
-
- self.checkExistKey = function(obj, key, value) {
- if (obj.hasOwnProperty(key)) {
- if (utils.isArray(obj[key])) {
- obj[key].push(value);
- }
- else {
- var arr = [];
- arr.push(obj[key]);
- arr.push(value)
- obj[key] = arr;
- }
- }
- else {
- obj[key] = value;
- }
- }
-
- self.getData = EL.getData = function(){
- var elems = self.root.getElementsByTagName('form')[0].elements;
- var params = {};
- for (var i = 0; i < elems.length; i++) {
- if (elems[i].name) {
- var value;
- if (elems[i].tagName === "SELECT") {
- var options = elems[i].options;
- for (var j = 0; j < options.length; j++) {
- if (options[j].selected) {
- value = options[j].value;
- self.checkExistKey(params, elems[i].name, encodeURIComponent(value));
- }
- }
- }
- else if (elems[i].type === "checkbox" || elems[i].type === "radio"){
- if (elems[i].checked) {
- value = elems[i].value;
- self.checkExistKey(params, elems[i].name, encodeURIComponent(value));
- }
- }
- else {
- value = elems[i].value;
- self.checkExistKey(params, elems[i].name, encodeURIComponent(value));
- }
- }
- }
- return params;
- }
-
-
-
- self.submitingText = config.submitingText || '提交中...';
- if (config.valid === undefined) {
- config.valid = true;
- }
-
- self.maxWarning = config.maxWarning || function(n) {
- return '不得超过' + n + '个字符';
- }
- self.minWarning = config.minWarning || function(n) {
- return '不得小于' + n + '个字符';
- }
-
- self.bpWarning = config.bpWarning || function (min, max) {
- return '只允许' + min + '-' + max + '个字符';
- }
-
- self.minNumWarning = config.minNumWarning || function (n) {
- return '不得小于' + n;
- }
- self.maxNumWarning = config.maxNumWarning || function (n) {
- return '不得大于' + n;
- }
- self.numBpWarning = config.numBpWarning || function (min, max) {
- return '输入数字应在' + min + '-' + max + '之间';
- }
-
-
- self.removeTips = EL.removeTips = function() {
- var root = self.root;
- var elems = root.getElementsByTagName('form')[0].elements;
- var tips = root.getElementsByClassName('tip-container');
- if (tips && tips.length) {
- del();
- }
-
- function del() {
- for (i = 0; i < tips.length; i++) {
- tips[i].parentNode.removeChild(tips[i]);
- if (tips.length) {
- del();
- }
- }
- }
-
- for (var i = 0; i < elems.length; i++) {
- utils.removeClass(elems[i], self.passClass);
- utils.removeClass(elems[i], self.failedClass);
- }
- }
-
-
-
- self.removeTipNode = function(dom) {
- var tip = dom.nextElementSibling;
- if (tip && tip.className.match(/tip-container/)) {
- dom.parentNode.removeChild(tip);
- }
- };
- self.removeTip = EL.removeTip = function(dom){
- self.removeTipNode(dom);
- utils.removeClass(dom, self.passClass);
- utils.removeClass(dom, self.failedClass);
- };
-
- self.insertTip = EL.insertTip = function(dom, message, className){
- self.removeTipNode(dom);
- var tipContainer = document.createElement('span');
- tipContainer.className = className;
- tipContainer.innerHTML = message;
- utils.insertAfterText(tipContainer, dom);
- };
-
- self.onValidRefuse = EL.onValidRefuse = config.onValidRefuse || function(dom, errorTips) {
- self.insertTip(dom, errorTips, 'tip-container');
- utils.removeClass(dom, self.passClass);
- utils.addClass(dom, self.failedClass);
- };
-
- self.onValidPass = EL.onValidPass = config.onValidPass || function(dom, successTips) {
- self.insertTip(dom, successTips, 'tip-container success');
- utils.removeClass(dom, self.failedClass);
- utils.addClass(dom, self.passClass);
- };
-
-
- self.ajaxSubmit = function(elems, url) {
- var params = '';
- for (var i = 0; i < elems.length; i++) {
- if (elems[i].name) {
- var value;
- if (elems[i].tagName === "SELECT") {
- var options = elems[i].options;
- for (var j = 0; j < options.length; j++) {
- if (options[j].selected) {
- value = options[j].value;
- params += elems[i].name + "=" + encodeURIComponent(value) + "&";
- }
- }
- }
- else if (elems[i].type === "checkbox" || elems[i].type === "radio"){
- if (elems[i].checked) {
- value = elems[i].value;
- params += elems[i].name + "=" + encodeURIComponent(value) + "&";
- }
- }
- else {
- value = elems[i].value;
- params += elems[i].name + "=" + encodeURIComponent(value) + "&";
- }
- }
- if (elems[i].type === "submit") {
- var submitbtn = elems[i];
- var attr = submitbtn.tagName === 'BUTTON'
- ? 'innerHTML'
- : 'value';
- var submitingText = submitbtn[attr];
- submitbtn.disabled = 'disabled';
- submitbtn[attr] = self.submitingText;
- }
- }
- var xmlhttp = new XMLHttpRequest();
- xmlhttp.open("POST", url, true);
- xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
- xmlhttp.send(params);
- xmlhttp.onreadystatechange = function() {
- if (xmlhttp.readyState === 4) {
- self.removeTips();
- submitbtn[attr] = submitingText;
- submitbtn.disabled = false;
- if (config.complete && typeof config.complete === 'function') {
- config.complete();
- }
- if (xmlhttp.status === 200) {
- try {
- var result = JSON.parse(xmlhttp.responseText);
- config.callback && config.callback(result);
- EC.trigger('submit_success', result);
- }catch(e){
- throw new Error(e.message);
- }
- }
- else {
- config.errCallback && config.errCallback(params);
- EC.trigger('submit_error', params);
- }
- }
- };
- }
-
-
- this.submit = function(e) {
- var validArr = [];
- var elems = self.root.getElementsByTagName('form')[0].elements;
- var action = self.action || self.root.getAttribute('action');
- var url = action;
-
- if (config.valid) {
- for (var i = 0; i < elems.length; i++) {
- doCheck(validArr, elems[i]);
- }
- }
-
- if (!validArr.length) {
- try {
- config.beforeSubmit && config.beforeSubmit(validArr);
- }
- catch (e) {
- validArr.push(e);
- }
- }
-
- if (!validArr.length) {
- if (config.normalSubmit) {
- self.root.firstChild.setAttribute('action', action);
- return true;
- }
- else {
- e.preventDefault();
- self.ajaxSubmit(elems, url);
- }
- }
- else {
- return false;
- }
- }.bind(this);
-
- function getCheckParam(elem) {
- var elem = elem;
- var attributes = elem.attributes;
- var ret = {};
- for (var i = 0; i < attributes.length; i++) {
- var attr = attributes[i];
- ret[attr.name] = attr.value;
- }
- ret.value = elem.value;
- return ret;
- }
-
- function isNeedCheck(attrs) {
- for (var i = 0; i < checkList.length; i++) {
- if (attrs[checkList[i]]) {
- return true;
- }
- }
- return false;
- }
-
-
- self.Validation = function(validArr, name, dom) {
- this.msg = [];
- this.validTip = function() {
- if (this.msg.length) {
- self.onValidRefuse(dom, this.msg[0]);
- validArr.push(name)
- }
- else {
- if (config.forbidTips) {
- self.removeTip(dom);
- }
- else {
- self.onValidPass(dom, self.successTips);
- }
- }
- }
- };
-
-
- self.rulesConfig = {
- email: {
- regexp: /^([a-zA-Z0-9_\-\.])+\@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/,
- msg: self.emailWarning
- },
- present: {
- regexp: /\S+/,
- msg: self.presentWarning
- },
- url: {
- regexp: /((http|ftp|https|file):\/\/([\w\-]+\.)+[\w\-]+(\/[\w\u4e00-\u9fa5\-\.\/?\@\%\!\&=\+\~\:\#\;\,]*)?)/,
- msg: self.urlWarning
- },
- mobile: {
- regexp:/^1[3|4|5|8][0-9]\d{4,8}$/,
- msg: self.mobileWarning
- }
- };
-
- self.valid = function(rule, validation, attrs) {
- if (self.rules[rule]) {
- var judgeResult = self.rules[rule](attrs);
- if (judgeResult === true) {
- self.comparator('string').handler(validation, attrs);
- }
- else {
- validation.msg.push(judgeResult);
- }
- return validation;
- }
- };
-
-
- self.validNumRange = function(validation, attrs) {
- var reg = NUMBER_REGEXP[attrs.valid.toUpperCase()];
- if (!reg.test(attrs.value)) {
- validation.msg.push(self.numWarning);
- }
- else {
- self.comparator('number').handler(validation, attrs);
- }
- return validation;
- };
-
- self.validUnion = function (validation, validArr, elem, attrs) {
- if (attrs.vr) {
- var arr = attrs.vr.split('::');
- var method = arr[0];
- var params = arr[1] ? arr[1].split(',') : undefined;
- var flag = false;
- try {
- flag = iToolkit[method].apply(elem, params);
- }
- catch (e) {
- flag = false;
- throw e;
- }
- if (!flag) {
- validation.msg.push('');
- }
- }
- return validation;
- };
-
- self.validEmpty = function (validation, attrs) {
- if (attrs.value === '') {
- validation.msg.push(self.presentWarning);
- }
- return validation;
- };
-
-
- self.on('mount', function() {
- self.init();
- });
-
- self.init = function() {
- for (i in config) {
- if (keyWords.indexOf(i) < 0) {
- if (self.hasOwnProperty(i)) {
- self[i] = utils.deepCopy(config[i], self[i]);
- }
- else {
- self[i] = config[i];
- }
- }
- }
- self.data = config.data;
- self.rules = {};
- for (ruleConfig in self.rulesConfig) {
- (function(ruleConfig) {
- self.rules[ruleConfig] = function(attrs) {
- if (attrs.value.match(self.rulesConfig[ruleConfig].regexp)) {
- return true;
- }
- else {
- return self.rulesConfig[ruleConfig].msg;
- }
- }
- })(ruleConfig);
- }
-
- };
-
-
-
- function doCheck(validArr, elem) {
- var dom = elem;
- var attrs = getCheckParam(elem);
- if (!isNeedCheck(attrs)) {
- return;
- }
- var validation = new self.Validation(validArr, attrs.name, dom);
- if (attrs.name) {
- if ((attrs.allowEmpty || attrs.allowempty) && attrs.value === '') {
- self.onValidPass(dom, self.successTips);
- return;
- }
- self.validEmpty(validation, attrs);
- if (attrs.valid) {
- if (self.rules[attrs.valid]) {
- self.valid(attrs.valid, validation, attrs);
- }
- else if (NUMBER_REGEXP[attrs.valid.toUpperCase()]) {
- self.validNumRange(validation, attrs);
- }
- }
- else if (!attrs.valid) {
- if (attrs.min || attrs.max){
- self.comparator('string').handler(validation, attrs);
- }
- }
- }
- if (!validArr.length) {
- self.validUnion(validation, validArr, dom, attrs);
- }
- validation.validTip();
- }
-
-});
-riot.tag('itk-modal', '', function(opts) {
-
- var self = this;
- var config = self.opts.opts || self.opts;
- var EL = self.root;
- for (i in config) {
- self[i] = config[i];
- }
- self.width = config.width || 600;
- self.height = config.height || 'auto';
-
- self.on('mount', function() {
- var container = self.root.querySelector('.itk-modal-container');
- var head = self.root.querySelector('.itk-modal-title');
- var headHeight = parseInt(window.getComputedStyle(head, null).height.replace('px', ''));
- if (config.height) {
- container.style.height = (self.height - headHeight - 2) + 'px';
- }
-
- })
-
- this.close = function(e) {
- self.root.style.display = 'none';
- self.onClose && self.onClose();
- }.bind(this);
-
- if (document.querySelector("[modal-open-target='" + self.root.id + "']")) {
- document.querySelector("[modal-open-target='" + self.root.id + "']").onclick = function() {
- self.root.style.display = 'block';
- self.onOpen && self.onOpen();
- }
- }
-
- self.root.open = function() {
- self.root.style.display = 'block';
- self.onOpen && self.onOpen();
- }
-
- self.root.close = function() {
- self.root.style.display = 'none';
- self.onClose && self.onClose();
- }
-
- self.root.loadData = function(newData, colName){
- colName = colName || 'data';
- self[colName] = newData;
- self.update();
- }
-
-
-
-
-});
-riot.tag('itk-paginate', '', function(opts) {
- var self = this;
- var EL = self.root;
- var config = self.opts.opts || self.opts;
- self.showTip = 'none';
- self.count = config.count || 0;
- self.pagesize = config.pagesize || 20;
- self.pageCount = config.pageCount || Math.ceil(self.count/self.pagesize) || 1;
- self.currentPage = config.currentPage || 1;
- self.url = config.url || '';
- self.showNumber = config.showNumber || 5;
-
- self.redirect = config.redirect || true;
- self.showPageCount = config.showPageCount || true;
- self.showItemCount = config.showItemCount || true;
- self.needInit = config.needInit || false;
-
- self.updateCurrentPage = function () {
- if (self.currentPage > Math.ceil(self.showNumber/2) && self.pageCount > self.showNumber) {
- self.pages = [];
- if (self.pageCount - self.currentPage > 2) {
- var origin = self.currentPage - Math.ceil(self.showNumber/2);
- var last = self.currentPage + Math.floor(self.showNumber/2);
- }
- else {
- var last = self.pageCount;
- var origin = self.pageCount - self.showNumber;
- }
- for (i = origin; i < last; i++) {
- self.pages.push({page: i + 1});
- self.update();
- }
- }
- else if (self.currentPage < (Math.ceil(self.showNumber/2) + 1) && self.pageCount > self.showNumber){
- self.pages = [];
- for (i = 0; i < self.showNumber; i++) {
- self.pages.push({page: i + 1});
- }
- self.pages.push({page: '...'});
- }
- };
- EL.addCount = function (num) {
- var count = self.count + num;
- var oldPageCount = self.pageCount;
- count < 0
- ? self.count = 0
- : self.count = count;
-
- self.pageCount = Math.ceil(self.count/self.pagesize) || 1;
- self.currentPage = (
- self.currentPage > self.pageCount
- ? self.pageCount
- : self.currentPage
- );
-
- if (self.pageCount <= self.showNumber) {
- self.pages = [];
- for (var i = 0; i < self.pageCount; i++) {
- self.pages.push({page: i + 1});
- }
- }
-
- if (
-
- self.needInit
-
- || (self.pageCount < oldPageCount && self.currentPage <= self.pageCount)
- ) {
- config.callback(self.currentPage);
- }
-
- self.pageChange(self.currentPage)
- self.update();
- };
-
- self.pages = [];
-
- if (self.pageCount < (self.showNumber + 1)) {
- for (i = 0; i < self.pageCount; i++) {
- self.pages.push({page: i + 1});
- }
- }
- else {
- for (i = 0; i < self.showNumber; i++) {
- self.pages.push({page: i + 1});
- }
- self.pages.push({page: '...'});
- }
-
- if (self.needInit) {
- config.callback(self.currentPage);
- }
- self.updateCurrentPage();
- self.update();
-
- this.goFirst = function(e) {
- self.pageChange(1);
- }.bind(this);
-
- this.goPrev = function(e) {
- if (self.currentPage > 1) {
- self.pageChange(self.currentPage - 1);
- }
- }.bind(this);
-
- this.goNext = function(e) {
- if (self.currentPage < self.pageCount) {
- self.pageChange(self.currentPage + 1);
- }
- }.bind(this);
-
- this.goLast = function(e) {
- self.pageChange(self.pageCount);
- }.bind(this);
-
- this.redirect = function(e) {
- var index = parseInt(self.page.value, 10);
- if (
- index &&
- index < (self.pageCount + 1) &&
- index > 0
- ) {
- self.pageChange(parseInt(index, 10));
- }
- else {
- self.tipsLeft = self.page.offsetLeft;
- self.tipsTop = self.page.offsetTop + self.page.offsetHeight + 8;
- self.showTip = 'block';
- setTimeout(function () {
- self.showTip = 'none';
- self.update();
- }, 1500)
- self.update();
- }
- }.bind(this);
-
- this.changePage = function(e) {
- var page = e.item.page
- if (typeof(page) === 'string') {
- return false;
- }
- else {
- self.pageChange(page);
- }
- }.bind(this);
-
- self.pageChange = function(page) {
- if (self.currentPage != page) {
- self.currentPage = page;
- config.callback(page);
- }
- self.updateCurrentPage();
- };
-
-
-});
-riot.tag('itk-select', ' ', function(opts) {
- var self = this;
- var config = self.opts.opts || self.opts;
- self.gotOptions = false;
- self.chooseOnce = true;
-
- self.init = self.root.init = function() {
- self.gotOptions = false;
- self.update();
- };
-
-
- self.realData = [];
- self.root.exportData = self.realData;
-
- self.initData = self.root.initData = function() {
- if (self.root.querySelector('select')) {
- var options = self.root.querySelector('select').querySelectorAll('option');
- var mutiple = self.root.querySelector('select').hasAttribute('mutiple');
- if (mutiple) {
- self.mutiple = true;
- }
- else {
- self.mutiple = false;
- self.noSearch = true;
- }
- }
- if (options && options.length && !self.gotOptions) {
- self.options = options;
- self.searchInput = self.root.querySelector('.itk-select-search');
- self.optionsWrap = self.root.querySelector('.itk-options-container');
- self.realData = [];
- for (i = 0; i < options.length; i++) {
- self.realData.push({
- name: options[i].innerHTML,
- value: options[i].getAttribute('value'),
- selected: options[i].getAttribute('selected'),
- index: i
- });
- }
- self.searchInput.onfocus = function () {
- self.optionsWrap.style.display = 'block';
- };
-
- self.searchInput.onblur = function () {
- self.optionsWrap.style.display = 'none';
- self.searchInput.value = '';
- self.resetSelectOpt();
- };
-
- if (self.noSearch) {
- self.searchInput.style.width = '0px';
- }
- self.gotOptions = true;
- self.update();
- }
- };
-
-
- self.on('update', function() {
- setTimeout(function() {
- self.initData();
- }, 0)
-
- });
-
-
-
- self.on('mount', function() {
- if (config) {
- for (var i in config) {
- self[i] = config[i];
- }
- self.update();
- }
- });
-
- self.filter = function(e) {
- self.resetSelectOpt();
- var v = e.target.value;
- e.target.style.width = (0.9 * v.length + 1) + 'em';
- var match;
- for (i = 0; i < self.realData.length; i++) {
- if (!self.realData[i].name.match(v)) {
- self.realData[i].hide = true;
- }
- else {
- self.realData[i].hide = false;
- match = true;
- }
- }
- self.noResult = !match;
- };
-
- self.toggle = function(e) {
- if (self.mutiple) {
- if (e.item.selected) {
- e.item.selected = false;
- self.options[e.item.index].selected = false;
- }
- else {
- e.item.selected = true;
- self.options[e.item.index].selected = true;
- }
- }
- else {
- for (i = 0; i < self.realData.length; i++) {
- self.realData[i].selected = false;
- self.options[i].selected = false;
- }
- e.item.selected = true;
- self.options[e.item.index].selected = true;
- }
- self.update();
- if (self.chooseOnce) {
- self.searchInput.blur();
- }
- };
-
- self.cancel = function(e) {
- e.stopPropagation();
- e.item.selected = false;
- self.options[e.item.index].selected = false;
- self.update();
- };
-
- self.showOptions = function(e) {
- if (self.searchInput && self.searchInput !== document.activeElement) {
- self.searchInput.focus();
- }
- else {
- self.searchInput.blur();
- }
- };
-
-
- self.keyboardHandle = function(e) {
- var searchInput = e.target;
- searchInput.options = self.root.querySelectorAll('.itk-options');
- if (searchInput.seletedIndex === undefined ){
- searchInput.seletedIndex = -1;
- }
-
- var keyCode = e.keyCode;
- if (keyCode === 37 || keyCode === 38){
- self.clearSelectedOpt(searchInput);
- searchInput.seletedIndex--;
- if (searchInput.seletedIndex < 0){
- searchInput.seletedIndex = searchInput.options.length - 1;
- }
- self.setSelectedOpt(searchInput);
- }
- else if (keyCode === 39 || keyCode === 40){
- self.clearSelectedOpt(searchInput);
- searchInput.seletedIndex++;
- if (searchInput.seletedIndex >= searchInput.options.length){
- searchInput.seletedIndex = 0;
- }
- self.setSelectedOpt(searchInput);
- }
- else if (keyCode === 13){
- self.chooseByKeyboard(searchInput);
- }
- else if (keyCode === 27){
- self.searchInput.blur();
- }
- };
-
- self.chooseByKeyboard = function(target){
- var e = document.createEvent("MouseEvents");
- var dom = target.options[target.seletedIndex];
- e.initEvent("mousedown", true, true);
- if (dom) {
- dom.dispatchEvent(e);
- }
- };
-
- self.clearSelectedOpt = function(target){
- if (target.options) {
- var dom = target.options[target.seletedIndex];
- if (target.seletedIndex >= 0 && dom) {
- dom.style.background = "";
- dom.scrollIntoView();
- }
- }
- };
-
- self.resetSelectOpt = function() {
- self.clearSelectedOpt(self.searchInput);
- self.searchInput.seletedIndex = -1;
- };
-
- self.setSelectedOpt = function(target){
- var dom = target.options[target.seletedIndex];
- if (dom) {
- dom.style.background = "#eff3f8";
- dom.scrollIntoView();
- }
- };
-
-});
-
-
-riot.tag('itk-slide', ' ', function(opts) {
-
- var self = this;
- var EL = self.root;
- var config = self.opts.opts || self.opts;
- var js = document.scripts;
- var path = '';
- var jsPath = '';
-
-
- for (var i = 0; i < js.length; i++) {
- if (!js[i].src) {
- continue;
- }
- if (/iToolkit_pc.min.js|iToolkit_pc.js/.test(js[i].src)) {
- jsPath = js[i].src.replace(/iToolkit_pc.min.js|iToolkit_pc.js/, '');
- break;
- }
- }
-
- path = jsPath + 'plugins/';
-
- if (typeof jQuery == 'undefined') {
- (function () {
- utils.jsLoader([
- path + 'jquery/jquery-1.12.0.min.js',
- ], function () {
-
- jQuery(document).ready(function ($) {
- utils.jsLoader([
- path + 'slick/slick.css',
- path + 'slick/slick-theme.css',
- path + 'slick/slick.js',
- ], function () {
- $(document).ready(function () {
- $(EL).slick(config);
- });
- });
- });
- });
- })();
- } else {
- jQuery(document).ready(function ($) {
- utils.jsLoader([
- path + 'slick/slick.css',
- path + 'slick/slick-theme.css',
- path + 'slick/slick.js'
- ], function () {
- $(document).ready(function () {
- $(EL).slick(config);
- });
- });
- });
- }
-
- self.on('mount', function() {
- self.root.style.display = 'block';
- })
-
-});
-riot.tag('itk-table', '', function(opts) {
- var self = this;
- var config = self.opts.opts || self.opts;
- var EL = self.root;
-
- self.init = function() {
- EL.style.display = 'block';
- for (i in config) {
- if (!self[i]) {
- self[i] = config[i];
- }
- }
- self.originData = utils.deepCopy(self.data);
- self.update();
- };
-
-
- self.on('mount', function() {
- self.init();
- });
-
-
- self.compare = function(a, b) {
- if (a[self.orderkeyName] > b[self.orderkeyName]) {
- return 1;
- }
- else if (a[self.orderkeyName] === b[self.orderkeyName]) {
- return 0;
- }
- else {
- return -1;
- }
- }
-
- self.clearOrder = function() {
- self.ordered = false;
- self.reversed = false;
- }
-
-
- self.loadData = EL.loadData = function(data) {
- self.data = data;
- self.originData = utils.deepCopy(data);
- self.update();
- return self.data;
- };
-
-
- self.exportData = EL.exportData = function() {
- return self.data;
- }
-
-
- self.reset = EL.reset = function() {
- self.data = utils.deepCopy(self.originData);
- self.update();
- };
-
-
- self.orderBy = function(col) {
- return function() {
- self.orderkeyName = col;
- if (self.ordered !== col) {
- if (self.reversed !== col) {
- self.data = self.data.sort(self.compare)
- }
- else {
- self.data = self.data.reverse();
- }
- self.ordered = col;
- self.reversed = false;
- self.update()
- }
- return self.data;
- }
- };
-
- EL.orderBy = function(col) {
- self.orderBy(col)();
- };
-
-
- self.reverseBy = function(col) {
- return function() {
- self.orderkeyName = col;
- if (self.reversed !== col) {
- if (self.ordered !== col) {
- self.data = self.data.sort(self.compare);
- self.data = self.data.reverse();
- }
- else {
- self.data = self.data.reverse();
- }
- self.ordered = false;
- self.reversed = col;
- self.update()
- }
- return self.data;
- }
- };
-
- EL.reverseBy = function(col) {
- self.reverseBy(col)();
- };
-
- self.toggleBy = function(col) {
- if (self.ordered === col) {
- return self.reverseBy(col);
- }
- else {
- return self.orderBy(col);
- }
- };
-
- EL.toggleBy = function(col) {
- if (self.ordered === col) {
- EL.reverseBy(col);
- }
- else {
- EL.orderBy(col);
- }
- };
-
-
-
- self.append = function(rows) {
- return function() {
- self.clearOrder();
- if (utils.isObject(rows)) {
- self.data.push(rows);
- }
- else if (utils.isArray(rows)) {
- self.data = self.data.concat(rows);
- }
- self.update();
- }
- };
-
- EL.append = function(rows) {
- self.append(rows)();
- };
-
-
- self.prepend = function(rows) {
- return function() {
- self.clearOrder();
- if (utils.isObject(rows)) {
- self.data.unshift(rows);
- }
- else if (utils.isArray(rows)) {
- self.data = rows.concat(self.data);
- }
- self.update();
- }
- };
- EL.prepend = function(rows) {
- self.prepend(rows)();
- };
-
-
- self.deleteBy = function(col, value) {
- return function() {
- if (col && value) {
- self.clearOrder();
- for (var i = 0 ; i < self.data.length; i++) {
- if (self.data[i][col] === value) {
- self.data.splice(i, 1);
- i = i - 1;
- }
- }
- self.update();
- }
- };
- }
-
- EL.deleteBy = function (col, value) {
- self.deleteBy(col, value)();
- }
-
-
-
-});
-riot.tag('itk-tree-item', ' { item.name }
', function(opts) {
-
- var self = this;
-
-
- self.selectchildren = function(item, bool) {
- var selectChildItem = function(item) {
- if (item && item.children) {
- for(var i = 0; i < item.children.length; i++) {
- item.children[i].selected = bool;
- selectChildItem(item.children[i]);
- }
- }
- };
- selectChildItem(item, bool);
- self.parent.treeroot.update();
- };
-
-
- self.cancelParent = function(item) {
- var cancelParentSelect = function(item) {
- if (item && item.pnode) {
- item.pnode.selected = false;
- cancelParentSelect(item.pnode);
- }
- };
- cancelParentSelect(item);
- self.parent.treeroot.update();
- };
-
-
- this.checkHandle = function(e) {
- var config = self.parent.rootConfig
- var checkCb = config.onCheck;
- var uncheckCb = config.onUnCheck;
- if (self.item.selected) {
- self.item.selected = false;
- uncheckCb && uncheckCb(self.item, e.target);
-
- if (config.link) {
- self.selectchildren(self.item, false);
- self.cancelParent(self.item);
- }
- }
- else if (!self.item.selected) {
- self.item.selected = true;
- checkCb && checkCb(self.item, e.target);
- if (config.link) {
- self.selectchildren(self.item, true);
- }
- }
- }.bind(this);
-
-
- this.toggle = function(e) {
- if (self.item.opened === true) {
- self.item.opened = false;
- }
- else {
- self.item.opened = true;
- }
- self.parent.treeroot.update();
- }.bind(this);
-
-
- this.leftClick = function(e) {
- var config = self.parent.rootConfig;
- if (config.folder && config.children) {
- if (self.item.opened === true) {
- self.item.opened = false;
- }
- else {
- self.item.opened = true;
- }
- }
- else {
- var leftClick = config.onLeftClick;
- if (leftClick) {
- leftClick(self.item, e.target);
- }
- }
- }.bind(this);
-
-
-});
-
-riot.tag('itk-tree', '', function(opts) {
- var self = this;
- self.config = self.opts.opts || self.opts;
-
-
- self.dataHandle = function(data, idName, pidName) {
- var data = data || []
- var id = idName || 'id';
- var pid = pidName || 'pid';
-
- var dataMap = {};
- data.forEach(function(node) {
- if (self.config.name) {
- node.name = node[self.config.name];
- }
- dataMap[node[id]] = node;
- });
-
- var tree = [];
- data.forEach(function(node) {
- var parent = dataMap[node[pid]];
- if (parent) {
- if (!parent.children) {
- parent.children = [];
- }
- node.pnode = parent;
- parent.children.push(node);
- }
- else {
- tree.push(node);
- }
- });
-
- var countLevel = function(tree, level) {
- var level = level + 1;
- tree.forEach(function(item) {
- item.level = level - 1;
-
- if (item.level < (self.config.openLevel + 1)) {
- item.opened = true;
- }
- if (item.children) {
- countLevel(item.children, level);
- }
- })
- };
- countLevel(tree, 1);
- return tree;
-
- };
-
-
- if (!self.parent || self.parent.root.tagName !== 'ITK-TREE') {
- if (self.config.handleData) {
- var tree = self.dataHandle(self.config.data);
- self.data = tree;
- }
- self.rootConfig = self.config;
- self.treeroot = self;
- }
- else {
- self.data = self.config.data;
- self.rootConfig = self.parent.rootConfig || self.parent.parent.rootConfig;
- self.treeroot = self.parent.treeroot || self.parent.parent.treeroot;
- }
- self.treeroot.update();
-
-
-
- this.countPadding = function(level) {
- var padding = self.rootConfig.padding || 20;
- return (level - 1) * padding + 'px';
- }.bind(this);
-
-
-});
-riot.tag('itk-uploader', '上传
', function(opts) {
- var self = this;
- var EL = self.root;
- var config = self.opts.opts || self.opts;
-
- var randomNumber = function (min, max) {
- return Math.floor(min + Math.random() * (max - min));
- };
- self['uploadBtn'].id = randomNumber(10000, 99999);
-
- var js = document.scripts;
- var jsPath = '';
- for (var i = 0; i < js.length; i++) {
- if (!js[i].src) {
- continue;
- }
- if (/iToolkit_pc.min.js|iToolkit_pc.js/.test(js[i].src)) {
- jsPath = js[i].src.replace(/iToolkit_pc.min.js|iToolkit_pc.js/, '');
- break;
- }
- }
- path = jsPath + 'plugins/uploader/';
- var sourceArr = [
- path + 'SimpleAjaxUploader.min.js',
- ];
-
- utils.jsLoader(sourceArr, function () {
-
- var btn = document.getElementById(self['uploadBtn'].id);
-
- console.log(btn);
-
- var json = {};
- json.button = btn;
-
- json.url = config.url;
- json.name = config.name ? config.name : "";
- json.multipart = config.multipart ? config.multipart : true;
- json.responseType = config.responseType ? config.responseType : "";
- json.startXHR = config.startXHR ? config.startXHR : null;
- json.onSubmit = config.onSubmit ? config.onSubmit : null;
- json.onComplete = config.onComplete ? config.onComplete : null;
- json.onError = config.onError ? config.onError : null;
-
-
- var uploader = new ss.SimpleUpload(json);
- });
-
-
-});
diff --git a/build/iToolkit_pc.min.js b/build/iToolkit_pc.min.js
deleted file mode 100644
index 2f73470..0000000
--- a/build/iToolkit_pc.min.js
+++ /dev/null
@@ -1,8 +0,0 @@
-/**
- * iToolkit v1.0.0
- * Revised in 2016-02-16 010:35:06
- * Released under the ISC License.
- */
-
-!function(e,t){"use strict";function n(e){var t=q(0),n=e.trim().slice(t.length).match(/^\s*(\S+?)\s*(?:,\s*(\S+))?\s+in\s+(.+)$/);return n?{key:n[1],pos:n[2],val:t+n[3]}:{val:e}}function i(e,t,n){var i={};return i[e.key]=t,e.pos&&(i[e.pos]=n),i}function r(e,t,r){f(e,"each");var a,o=v(e),u=e.outerHTML,l=!!K[o],c=K[o]||{tmpl:u},d=e.parentNode,p=document.createComment("riot placeholder"),g=[],h=m(e);d.insertBefore(p,e),r=n(r),t.one("premount",function(){d.stub&&(d=t.root),e.parentNode.removeChild(e)}).on("update",function(){var n=Y(r.val,t);U(n)||(a=n?JSON.stringify(n):"",n=n?Object.keys(n).map(function(e){return i(r,e,n[e])}):[]);for(var u=document.createDocumentFragment(),f=g.length,m=n.length;f>m;)g[--f].unmount(),g.splice(f,1);for(f=0;m>f;++f){var v=!a&&r.key?i(r,n[f],f):n[f];g[f]?g[f].update(v):(g[f]=new s(c,{parent:t,isLoop:!0,hasImpl:l,root:$.test(o)?d:e.cloneNode(),item:v},e.innerHTML),g[f]._item=v,g[f].mount(),u.appendChild(g[f].root)),g[f]._item=v}d.insertBefore(u,p),h&&(t.tags[o]=g)}).one("updated",function(){var e=Object.keys(t);k(d,function(n){1!=n.nodeType||n.isLoop||n._looped||(n._visited=!1,n._looped=!0,A(n,t,e))})})}function a(e,t,n){k(e,function(e){if(1==e.nodeType){e.isLoop=e.isLoop||e.parentNode&&e.parentNode.isLoop||e.getAttribute("each")?1:0;var i=m(e);i&&!e.isLoop&&n.push(g(i,e,t)),e.isLoop||A(e,t,[])}})}function o(e,t,n){function i(e,t,i){if(t.indexOf(q(0))>=0){var r={dom:e,expr:t};n.push(y(r,i))}}k(e,function(e){var n=e.nodeType;if(3==n&&"STYLE"!=e.parentNode.tagName&&i(e,e.nodeValue),1==n){var a=e.getAttribute("each");return a?(r(e,t,a),!1):(d(e.attributes,function(t){var n=t.name,r=n.split("__")[1];return i(e,t.value,{attr:r||n,bool:r}),r?(f(e,n),!1):void 0}),m(e)?!1:void 0)}})}function s(e,n,i){function r(){var e=w&&k?f:v||f;d(E.attributes,function(t){m[t.name]=Y(t.value,e)}),d(Object.keys(M),function(t){m[t]=Y(M[t],e)})}function s(e){for(var t in N)typeof f[t]!==H&&(f[t]=e[t])}function u(){f.parent&&k&&d(Object.keys(f.parent),function(e){var t=!~R.indexOf(e)&&~_.indexOf(e);(typeof f[e]===H||t)&&(t||_.push(e),f[e]=f.parent[e])})}function l(e){if(d(A,function(t){t[e?"mount":"unmount"]()}),v){var t=e?"on":"off";k?v[t]("unmount",f.unmount):v[t]("update",f.update)[t]("unmount",f.unmount)}}var f=O.observable(this),m=S(n.opts)||{},g=z(e.tmpl),v=n.parent,k=n.isLoop,w=n.hasImpl,N=b(n.item),D=[],A=[],E=n.root,j=e.fn,I=E.tagName.toLowerCase(),M={},_=[];j&&E._tag&&E._tag.unmount(!0),this.isMounted=!1,E.isLoop=k,E._tag=this,this._id=L++,y(this,{parent:v,root:E,opts:m,tags:{}},N),d(E.attributes,function(e){var t=e.value;q(/{.*}/).test(t)&&(M[e.name]=t)}),g.innerHTML&&!/^(select|optgroup|table|tbody|tr|col(?:group)?)$/.test(I)&&(g.innerHTML=x(g.innerHTML,i)),this.update=function(e){e=b(e),u(),e&&typeof N===B&&(s(e),N=e),y(f,e),r(),f.trigger("update",e),c(D,f),f.trigger("updated")},this.mixin=function(){d(arguments,function(e){e=typeof e===P?O.mixin(e):e,d(Object.keys(e),function(t){"init"!=t&&(f[t]=p(e[t])?e[t].bind(f):e[t])}),e.init&&e.init.bind(f)()})},this.mount=function(){if(r(),j&&j.call(f,m),o(g,f,D),l(!0),(e.attrs||w)&&(C(e.attrs,function(e,t){E.setAttribute(e,t)}),o(f.root,f,D)),(!f.parent||k)&&f.update(N),f.trigger("premount"),k&&!w)f.root=E=g.firstChild;else{for(;g.firstChild;)E.appendChild(g.firstChild);E.stub&&(f.root=E=v.root)}!f.parent||f.parent.isMounted?(f.isMounted=!0,f.trigger("mount")):f.parent.one("mount",function(){T(f.root)||(f.parent.isMounted=f.isMounted=!0,f.trigger("mount"))})},this.unmount=function(e){var n,i=E,r=i.parentNode;if(r){if(v)n=h(v),U(n.tags[I])?d(n.tags[I],function(e,t){e._id==f._id&&n.tags[I].splice(t,1)}):n.tags[I]=t;else for(;i.firstChild;)i.removeChild(i.firstChild);e?r.removeAttribute("riot-tag"):r.removeChild(i)}f.trigger("unmount"),l(),f.off("*"),E._tag=null},a(g,this,A)}function u(t,n,i,r){i[t]=function(t){var a,o=r._item,s=r.parent;if(!o)for(;s&&!o;)o=s._item,s=s.parent;t=t||e.event;try{t.currentTarget=i,t.target||(t.target=t.srcElement),t.which||(t.which=t.charCode||t.keyCode)}catch(u){}t.item=o,n.call(r,t)===!0||/radio|check/.test(i.type)||(t.preventDefault&&t.preventDefault(),t.returnValue=!1),t.preventUpdate||(a=o?h(s):r,a.update())}}function l(e,t,n){e&&(e.insertBefore(n,t),e.removeChild(t))}function c(e,t){d(e,function(e,n){var i=e.dom,r=e.attr,a=Y(e.expr,t),o=e.dom.parentNode;if(e.bool?a=a?r:!1:null==a&&(a=""),o&&"TEXTAREA"==o.tagName&&(a=(""+a).replace(/riot-/g,"")),e.value!==a){if(e.value=a,!r)return void(i.nodeValue=""+a);if(f(i,r),p(a))u(r,a,i,t);else if("if"==r){var s=e.stub,c=function(){l(s.parentNode,s,i)},d=function(){l(i.parentNode,i,s)};a?s&&(c(),i.inStub=!1,T(i)||k(i,function(e){e._tag&&!e._tag.isMounted&&(e._tag.isMounted=!!e._tag.trigger("mount"))})):(s=e.stub=s||document.createTextNode(""),i.parentNode?d():(t.parent||t).one("updated",d),i.inStub=!0)}else if(/^(show|hide)$/.test(r))"hide"==r&&(a=!a),i.style.display=a?"":"none";else if("value"==r)i.value=a;else if(E(r,M)&&r!=_)a&&i.setAttribute(r.slice(M.length),a);else{if(e.bool&&(i[r]=a,!a))return;typeof a!==B&&i.setAttribute(r,a)}}})}function d(e,t){for(var n,i=0,r=(e||[]).length;r>i;i++)n=e[i],null!=n&&t(n,i)===!1&&i--;return e}function p(e){return typeof e===W||!1}function f(e,t){e.removeAttribute(t)}function m(e){return e.tagName&&K[e.getAttribute(_)||e.tagName.toLowerCase()]}function g(e,t,n){var i,r=new s(e,{root:t,parent:n},t.innerHTML),a=v(t),o=h(n);return r.parent=o,i=o.tags[a],i?(U(i)||(o.tags[a]=[i]),~o.tags[a].indexOf(r)||o.tags[a].push(r)):o.tags[a]=r,t.innerHTML="",r}function h(e){for(var t=e;!m(t.root)&&t.parent;)t=t.parent;return t}function v(e){var t=m(e),n=e.getAttribute("name"),i=n&&n.indexOf(q(0))<0?n:t?t.name:e.tagName.toLowerCase();return i}function y(e){for(var t,n=arguments,i=1;i(<\/\1>)?/gi,t||"")}function N(e,t){return(t||document).querySelectorAll(e)}function D(e,t){return(t||document).querySelector(e)}function S(e){function t(){}return t.prototype=e,new t}function A(e,t,n){if(!e._visited){var i,r=e.getAttribute("id")||e.getAttribute("name");r&&(n.indexOf(r)<0&&(i=t[r],i?U(i)?i.push(e):t[r]=[i,e]:t[r]=e),e._visited=!0)}}function E(e,t){return e.slice(0,t.length)===t}function j(e){if(!O.render){V||(V=w("style"),V.setAttribute("type","text/css"));var t=document.head||document.getElementsByTagName("head")[0];if(V.styleSheet?V.styleSheet.cssText+=e:V.innerHTML+=e,!V._rendered)if(V.styleSheet)document.body.appendChild(V);else{var n=D("style[type=riot]");n?(n.parentNode.insertBefore(V,n),n.parentNode.removeChild(n)):t.appendChild(V)}V._rendered=!0}}function I(e,t,n){var i=K[t],r=e._innerHTML=e._innerHTML||e.innerHTML;return e.innerHTML="",i&&e&&(i=new s(i,{root:e,opts:n},r)),i&&i.mount?(i.mount(),G.push(i),i.on("unmount",function(){G.splice(G.indexOf(i),1)})):void 0}var O={version:"v2.2.4",settings:{}},L=0,M="riot-",_=M+"tag",P="string",B="object",H="undefined",W="function",$=/^(?:opt(ion|group)|tbody|col|t[rhd])$/,R=["_item","_id","update","root","mount","unmount","mixin","isMounted","isLoop","tags","parent","opts","trigger","on","off","one"],F=0|(e&&e.document||{}).documentMode,U=Array.isArray;O.observable=function(e){e=e||{};var t={},n=0;return e.on=function(i,r){return p(r)&&(typeof r.id===H&&(r._id=n++),i.replace(/\S+/g,function(e,n){(t[e]=t[e]||[]).push(r),r.typed=n>0})),e},e.off=function(n,i){return"*"==n?t={}:n.replace(/\S+/g,function(e){if(i)for(var n,r=t[e],a=0;n=r&&r[a];++a)n._id==i._id&&r.splice(a--,1);else t[e]=[]}),e},e.one=function(t,n){function i(){e.off(t,i),n.apply(e,arguments)}return e.on(t,i)},e.trigger=function(n){for(var i,r=[].slice.call(arguments,1),a=t[n]||[],o=0;i=a[o];++o)i.busy||(i.busy=1,i.apply(e,i.typed?[n].concat(r):r),a[o]!==i&&o--,i.busy=0);return t.all&&"all"!=n&&e.trigger.apply(e,["all",n].concat(r)),e},e},O.mixin=function(){var e={};return function(t,n){return n?void(e[t]=n):e[t]}}(),function(e,t,n){function i(){return s.href.split("#")[1]||""}function r(e){return e.split("/")}function a(e){e.type&&(e=i()),e!=o&&(u.trigger.apply(null,["H"].concat(r(e))),o=e)}if(n){var o,s=n.location,u=e.observable(),l=!1,c=e.route=function(e){e[0]?(s.hash=e,a(e)):u.on("H",e)};c.exec=function(e){e.apply(null,r(i()))},c.parser=function(e){r=e},c.stop=function(){l&&(n.removeEventListener?n.removeEventListener(t,a,!1):n.detachEvent("on"+t,a),u.off("*"),l=!1)},c.start=function(){l||(n.addEventListener?n.addEventListener(t,a,!1):n.attachEvent("on"+t,a),l=!0)},c.start()}}(O,"hashchange",e);var V,q=function(e){var t,n,i,r=/[{}]/g;return function(a){var o=O.settings.brackets||e;return t!==o&&(t=o,i=o.split(" "),n=i.map(function(e){return e.replace(/(?=.)/g,"\\")})),a instanceof RegExp?o===e?a:new RegExp(a.source.replace(r,function(e){return n[~~("}"===e)]}),a.global?"g":""):i[a]}}("{ }"),Y=function(){function t(e,t){return e.indexOf(q(0))<0?(e=e.replace(/\n|\r\n?/g,"\n"),function(){return e}):(e=e.replace(q(/\\{/g),"").replace(q(/\\}/g),""),t=r(e,a(e,q(/{/),q(/}/))),e=2!==t.length||t[0]?"["+t.map(function(e,t){return t%2?n(e,!0):'"'+e.replace(/\n|\r\n?/g,"\\n").replace(/"/g,'\\"')+'"'}).join(",")+'].join("")':n(t[1]),new Function("d","return "+e.replace(/\uFFF0/g,q(0)).replace(/\uFFF1/g,q(1))+";"))}function n(e,t){return e=e.replace(/\n|\r\n?/g," ").replace(q(/^[{ ]+|[ }]+$|\/\*.+?\*\//g),""),/^\s*[\w- "']+ *:/.test(e)?"["+a(e,/["' ]*[\w- ]+["' ]*:/,/,(?=["' ]*[\w- ]+["' ]*:)|}|$/).map(function(e){return e.replace(/^[ "']*(.+?)[ "']*: *(.+?),? *$/,function(e,t,n){return n.replace(/[^&|=!><]+/g,i)+'?"'+t+'":"",'})}).join("")+'].join(" ").trim()':i(e,t)}function i(e,t){return e=e.trim(),e?"(function(v){try{v="+e.replace(u,function(e,t,n){return n?'(("'+n+s+n+")":e})+"}catch(e){}return "+(t===!0?'!v&&v!==0?"":v':"v")+"}).call(d)":""}function r(e,t){var n=[];return t.map(function(t,i){i=e.indexOf(t),n.push(e.slice(0,i),t),e=e.slice(i+t.length)}),e&&n.push(e),n}function a(e,t,n){var i,r=0,a=[],o=new RegExp("("+t.source+")|("+n.source+")","g");return e.replace(o,function(t,n,o,s){!r&&n&&(i=s),r+=n?1:-1,r||null==o||a.push(e.slice(i,s+o.length))}),a}var o={},s='"in d?d:'+(e?"window).":"global)."),u=/(['"\/])(?:[^\\]*?|\\.|.)*?\1|\.\w*|\w*:|\b(?:(?:new|typeof|in|instanceof) |(?:this|true|false|null|undefined)\b|function\s*\()|([A-Za-z_$]\w*)/g;return function(e,n){return e&&(o[e]||(o[e]=t(e)))(n)}}(),z=function(e){function t(t){var a=t&&t.match(/^\s*<([-\w]+)/),o=a&&a[1].toLowerCase(),s=i[o]||r,u=w(s);return u.stub=!0,e&&o&&(a=o.match($))?n(u,t,o,!!a[1]):u.innerHTML=t,u}function n(e,t,n,i){var a,o=w(r),s=i?"select>":"table>";o.innerHTML="<"+s+t+""+s,a=o.getElementsByTagName(n)[0],a&&e.appendChild(a)}var i={tr:"tbody",th:"tr",td:"tr",tbody:"table",col:"colgroup"},r="div";return e=e&&10>e,t}(F),G=[],K={};O.tag=function(e,t,n,i,r){return p(i)&&(r=i,/^[\w\-]+\s?=/.test(n)?(i=n,n=""):i=""),n&&(p(n)?r=n:j(n)),K[e]={name:e,tmpl:t,attrs:i,fn:r},e},O.mount=function(e,t,n){function i(e){var t="";return d(e,function(e){t+=", *["+_+'="'+e.trim()+'"]'}),t}function r(){var e=Object.keys(K);return e+i(e)}function a(e){var i;if(e.tagName){!t||(i=e.getAttribute(_))&&i==t||e.setAttribute(_,t);var r=I(e,t||e.getAttribute(_)||e.tagName.toLowerCase(),n);r&&u.push(r)}else e.length&&d(e,a)}var o,s,u=[];if(typeof t===B&&(n=t,t=0),typeof e===P?("*"===e?e=s=r():e+=i(e.split(",")),o=N(e)):o=e,"*"===t){if(t=s||r(),o.tagName)o=N(t,o);else{var l=[];d(o,function(e){l.push(N(t,e))}),o=l}t=0}return o.tagName?a(o):d(o,a),u},O.update=function(){return d(G,function(e){e.update()})},O.mountTo=O.mount,O.util={brackets:q,tmpl:Y},typeof exports===B?module.exports=O:"function"==typeof define&&define.amd?define(function(){return e.riot=O}):e.riot=O}("undefined"!=typeof window?window:void 0);var utils={httpGet:function(e,t,n,i){var r=new XMLHttpRequest,e=utils.concatParams(e,t);r.open("GET",e,!0),r.send(null),r.onreadystatechange=function(){if(4===r.readyState&&(i&&"function"==typeof i&&i(),200===r.status)){var e=r.responseText;try{if("string"==typeof e)var t=JSON.parse(e);else var t=e}catch(a){alert("解析错误")}n(t)}}},httpPost:function(e,t,n,i){var r=new XMLHttpRequest;r.open("POST",e,!0),r.setRequestHeader("Content-type","application/json"),r.send(t),r.onreadystatechange=function(){if(4===r.readyState)if(i&&"function"==typeof i&&i(),200===r.status){try{var e=JSON.parse(r.responseText)}catch(t){console.log("解析错误")}n(e)}else console.log("网络错误")}},jsonp:function(e,t,n){var i=Date.now(),r=document.createElement("script"),a=document.getElementsByTagName("head")[0],e=utils.concatParams(e,t);if(t.callback)var o=e,s=t.callback;else{if(e.match(/\?/))var o=e+"&callback=jsonpCallback"+i;else var o=e+"?callback=jsonpCallback"+i;var s="jsonpCallback"+i}r.src=o,a.appendChild(r),window[s]=function(e){if("string"==typeof e)try{e=JSON.parse(e)}catch(t){}n(e)},r.onerror=function(){console.log("jsonp error")},r.onload=function(){a.removeChild(r)}},htmlEncode:function(e){var t=document.createElement("div");return t.innerHTML=e,t.innerText},concatParams:function(e,t){if(e.match(/\?/))var n="&";else var n="?";for(i in t)n=n+i+"="+t[i]+"&";return n=n.replace(/&$/,""),e+n},setCookie:function(e,t,n,i){var r=new Date,i=i||"/";r.setTime(r.getTime()+n),document.cookie=e+"="+escape(t)+";path="+i+";expires="+r.toGMTString()},transBytes:function(e){var t=["B","KB","MB","GB","TB"];if(0==e)return"n/a";var n=parseInt(Math.floor(Math.log(e)/Math.log(1024)));return 0==n?e+t[n]:(e/Math.pow(1024,n)).toFixed(1)+t[n]},transTimes:function(e){var e=parseInt(e,10),t=new Date(1e3*e),n=(new Date).getTime()/1e3,i=n-e;if(86400>i)return t.getHours()+":"+t.getMinutes();if(i>86400&&172800>i)return"昨天";if(i>172800){var r=(t.getFullYear()+"-").substring(2),a=(t.getMonth()+1<10?"0"+(t.getMonth()+1):t.getMonth()+1)+"-",o=t.getDate()<10?"0"+t.getDate():t.getDate();return r+a+o}},hasClass:function(e,t){return e.className.match(new RegExp("(\\s|^)"+t+"(\\s|$)"))},addClass:function(e,t){e.className.trim(),this.hasClass(e,t)||(e.className+=" "+t)},removeClass:function(e,t){if(utils.hasClass(e,t)){var n=new RegExp("(\\s|^)"+t+"(\\s|$)");e.className=e.className.replace(n," ")}},toggleClass:function(e,t){if(utils.hasClass(e,t)){var n=new RegExp("(\\s|^)"+t+"(\\s|$)");e.className=e.className.replace(n," ")}else e.className+=" "+t},insertAfter:function(e,t){var n=t.parentNode;n.lastChild==t?n.appendChild(e):n.insertBefore(e,t.nextSibling)},insertAfterText:function(e,t){var n=t.parentNode;if(n.lastChild==t)n.appendChild(e);else{var i=t.nextSibling;3===i.nodeType&&(i=i.nextSibling),n.insertBefore(e,i)}},isType:function(e){return function(t){return toString.call(t)==="[object "+e+"]"}},makeArray:function(){return Array.prototype.concat(obj)},extend:function(e,t){for(var n in t)e[n]||(e[n]=t[n])},deepCopy:function(e,t){var n="[object Array]"===toString.call(e)?[]:{},t=t||n;for(var i in e)"[object Object]"===toString.call(e[i])?(t[i]={},this.deepCopy(e[i],t[i])):"[object Array]"===toString.call(e[i])?(t[i]=[],this.deepCopy(e[i],t[i])):t[i]=e[i];return t}};utils.extend(utils,{isArray:utils.isType("Array"),isObject:utils.isType("Object"),isFunction:utils.isType("Function"),isElement:function(e){return-1!==toString.call(e).indexOf("Element")}}),utils.extend(utils,{jsLoader:function(){function e(){return p++}function t(e){return e.match(/\.css\??/)}function n(t){this.uri=t,this.cid=e(),this.status=k}function i(e,t){return i.then(e,t).start(),i}function r(e){throw e}function a(e){if(e||f.length)for(var t=0;t ⟨
⟪
{ month.text }
{ year.text }
⟩
⟫
','hide="{ !open }"',function(e){var t=this;t.i18n={zh_cn:{weekArr:["日","一","二","三","四","五","六"],monthArr:["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"]},en_us:{weekArr:["Su","Mo","Tu","We","Th","Fr","Sa"],monthArr:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]}};var n=(t.root,t.opts.opts||t.opts||{});t.mapping=function(e){if(!utils.isObject(e))throw new TypeError("Config is not a object!");for(var n in e)t[n]=e[n]},t.mapping(n),t.initWeekList=function(e){var n=t.i18n[e];if(n)t.weekArr=n.weekArr,t.monthArr=n.monthArr;else if(!t.weekArr||!t.monthArr){var n=t.i18n.en_us;t.weekArr=n.weekArr,t.monthArr=n.monthArr}},t.initWeekList(t.language),t.getDaysCount=function(e,t){var n=0;switch(t){case 1:case 3:case 5:case 7:case 8:case 10:case 12:case 0:case 13:n=31;break;case 4:case 6:case 9:case 11:n=30;break;case 2:n=e%4===0&&e%100!==0||e%400===0?29:28;break;default:throw new Error("你算错了")}return n},t.drawDays=function(e){var n;n=e?new Date(e):new Date;var i=n.getMonth(),r=n.getFullYear();t.month={text:t.monthArr[i],val:i+1},t.year={text:r,val:r},i+=1;var a=t.getDaysCount(r,i),o=t.getDaysCount(r,i-1);t.getDaysCount(r,i+1);n.setDate(1);var s=n.getDay();n.setDate(a);var u=n.getDay(),l=[];return l=l.concat(new Array(0===s?1:(7-s^7)+1).join(0).split("").map(function(e,t){return{year:"",month:"",day:o-t}}).reverse()),l=l.concat(new Array(a+1).join(0).split("").map(function(e,t){return{year:r,month:i,day:t+1}})),l=l.concat(new Array(0===u?7:6-u+1).join(0).split("").map(function(e,t){return{year:"",month:"",day:t+1}}))},t.initDays=function(e){if(t.showToday){var n=new Date;t.today=n.getDate(),t.toMonth=n.getMonth()+1,t.toYear=n.getFullYear()}if(t.defaultSelected){var n=new Date;t.selectedDay=n.getDate(),t.selectedMonth=n.getMonth()+1,t.selectedYear=n.getFullYear()}t.dayArr=t.drawDays(e),t.update()},t.initDays(t.initTime),t.getNum=function(e){return e>10?e:"0"+e},t.formatter=function(e){var n,i=new Date(t.selectedYear,t.selectedMonth-1,t.selectedDay,0,0,0),r=i.getTime();switch(e){case"unixTimeStamp":n=t.getUnixTimeStamp(r);break;case"timeStamp":n=t.getTimeStamp(r);break;default:if(!e)var e="yyyy/mm/dd";n=e.replace(/(yyyy|mm|dd|yy|m|d)/gi,function(e){return"yyyy"===e?t.selectedYear:"mm"===e?t.getNum(t.selectedMonth):"dd"===e?t.getNum(t.selectedDay):"yy"===e?t.selectedYear.toString().substr(2,4):"m"===e?t.selectedMonth:"d"===e?t.selectedDay:void 0})}return n},t.dayClicked=function(e){t.selectedDay=e.item.day,t.selectedMonth=e.item.month,t.selectedYear=e.item.year,t.onSelect&&t.onSelect(t.formatter,t.getYear(),t.getMonth(),t.getDay()),t.update()},t.open=!1,t.getAbsPoint=function(e){for(var t=e.offsetLeft,n=e.offsetTop;e=e.offsetParent;)t+=e.offsetLeft,n+=e.offsetTop;return{x:t,y:n}},t.location=function(e){if(t.element){var n=t.getAbsPoint(t.element);t.root.style.position="absolute",t.root.style.top=n.y+t.element.offsetHeight,t.root.style.left=n.x}},t.closeIt=function(e){var n=e.target.className;e.target===t.element||n&&-1!==n.indexOf("itk-calendar")&&"itk-calendar-days"!==n||(t.open=!1,t.update())},t.openIt=function(e){t.open=!0,t.update(),t.location(e)},t.unbindEvent=function(){t.element&&(document.removeEventListener("click",t.closeIt,!1),t.element.removeEventListener("click",t.openIt,!1))},t.on("mount",function(){t.element?(document.addEventListener("click",t.closeIt,!1),t.element.addEventListener("click",t.openIt,!1)):t.open=!0,t.update()}),t.on("unmount",function(){t.unbindEvent()}),t.getTimeStamp=function(e){return e},t.getUnixTimeStamp=function(e){return Math.ceil(e/1e3).toString()},t.getYear=function(){return t.selectedYear},t.getMonth=function(){return t.selectedMonth},t.getDay=function(){return t.selectedDay},t.nextYear=function(){var e=t.year.val+1;t.dayArr=t.drawDays(new Date(e,t.month.val-1,1).getTime()),t.update()},t.nextMonth=function(){var e=t.month.val-1,n=t.year.val;n=11===e?n+1:n,e=11===e?0:e+1;var i=new Date(n,e,1);t.dayArr=t.drawDays(i.getTime()),t.update()},t.prevYear=function(){var e=t.year.val-1;t.dayArr=t.drawDays(new Date(e,t.month.val-1,1).getTime()),t.update()},t.prevMonth=function(){var e=t.month.val-1,n=t.year.val;n=0===e?n-1:n,e=0===e?11:e-1;var i=new Date(n,e,1);t.dayArr=t.drawDays(i.getTime()),t.update()}}),riot.tag("itk-center",'
',function(e){var t=this;t.opts.opts||t.opts;t["default"]=!1,t.on("mount",function(){var e=t.root.parentNode,n=window.getComputedStyle(e,null).position;"static"===n&&(e.style.position="relative"),t.childDom=t.root.getElementsByClassName("itk-loading")[0],t.childDom.innerHTML.trim()&&(t["default"]=!1,t.update());var i=parseInt(window.getComputedStyle(t.childDom,null).height.replace("px",""),10);t.root.style.marginTop="-"+i/2+"px"}),t.root.show=function(){t.childDom&&(t.childDom.style.display="block")},t.root.hide=function(){t.childDom&&(t.childDom.style.display="none")}}),riot.tag("date-picker","",function(e){var t=this,n=t.root,i=t.opts.opts||t.opts,r=document.scripts,a="",o="";if(i.path)a=i.path;else{for(var s=0;s",function(e){var t=this,n=t.opts.opts||t.opts,r=t.root;for(i in n)t[i]=n[i];t.getData=function(e){var e=e||{};if(r.getAttribute("data-get"))var n="httpGet";else if(r.getAttribute("data-jsonp"))var n="jsonp";utils[n](t.superDivUrl,e,function(e){for(i in e)t.data={},t.data[i]=e[i];t.update()})},t.on("mount",function(){r.style.display="block",t.superDivUrl=r.getAttribute("data-get")||r.getAttribute("data-jsonp"),t.superDivUrl&&t.getData(n.params)}),t.loadData=r.loadData=function(e,n){n=n||"data",t[n]=e,t.update()},t.reload=r.reload=function(){t.superDivUrl?t.getData(n.params):t.update()}}),riot.tag("itk-editor",'',function(e){var t=this,n=t.root,i=t.opts.opts||t.opts,r=document.scripts,a="",o="",s=i.type||"standard";if(i.path)a=i.path;else{for(var u=0;u ',function(e){function t(e){s([],this)}function n(e){return Object.prototype.toString.call(e).match(/\ (.*)\]/)[1]}function r(e){var t=n(e);return"Null"===t||"Undefined"===t||"Function"===t?e:new window[t](e)}function a(e){for(var e=e,t=e.attributes,n={},i=0;io&&e.msg.push(u.minWarning(n)),!a&&o>i&&e.msg.push(u.maxWarning(i))):(o>i||n>o)&&e.msg.push(u.bpWarning(n,i)),e},u.numComparator=function(e,t){var n=parseInt(t.min,10),i=parseInt(t.max,10),r=isNaN(n),a=isNaN(i),o=+t.value;return r||a?(!r&&n>o&&e.msg.push(u.minNumWarning(n)),!a&&o>i&&e.msg.push(u.maxNumWarning(i))):(o>i||n>o)&&e.msg.push(u.numBpWarning(n,i)),e},u.one("mount",function(){if(l.style.display="block",c.realTime&&c.valid)for(var e=u.root.getElementsByTagName("form")[0].elements,n=0,i=e.length;i>n;n++){var r=e[n].type;("submit"!==r||"button"!==r)&&(e[n].addEventListener("input",t,!1),e[n].addEventListener("change",t,!1))}}),l.loadData=function(e,t){if(utils.isObject(e))for(var n in e)e[n]=r(e[n]);else e=r(e);t=t||"data",u[t]=e,u.update()},l.setData=function(e,t){u.data[t]=r(e),u.update()},u.checkExistKey=function(e,t,n){if(e.hasOwnProperty(t))if(utils.isArray(e[t]))e[t].push(n);else{var i=[];i.push(e[t]),i.push(n),e[t]=i}else e[t]=n},u.getData=l.getData=function(){for(var e=u.root.getElementsByTagName("form")[0].elements,t={},n=0;n
',function(e){var t=this,n=t.opts.opts||t.opts;t.root;for(i in n)t[i]=n[i];t.width=n.width||600,t.height=n.height||"auto",t.on("mount",function(){var e=t.root.querySelector(".itk-modal-container"),i=t.root.querySelector(".itk-modal-title"),r=parseInt(window.getComputedStyle(i,null).height.replace("px",""));n.height&&(e.style.height=t.height-r-2+"px")}),this.close=function(e){t.root.style.display="none",t.onClose&&t.onClose()}.bind(this),document.querySelector("[modal-open-target='"+t.root.id+"']")&&(document.querySelector("[modal-open-target='"+t.root.id+"']").onclick=function(){t.root.style.display="block",t.onOpen&&t.onOpen()}),t.root.open=function(){t.root.style.display="block",t.onOpen&&t.onOpen()},t.root.close=function(){t.root.style.display="none",t.onClose&&t.onClose()},t.root.loadData=function(e,n){n=n||"data",t[n]=e,t.update()}}),riot.tag("itk-paginate",'',function(e){var t=this,n=t.root,r=t.opts.opts||t.opts;if(t.showTip="none",t.count=r.count||0,t.pagesize=r.pagesize||20,t.pageCount=r.pageCount||Math.ceil(t.count/t.pagesize)||1,t.currentPage=r.currentPage||1,t.url=r.url||"",t.showNumber=r.showNumber||5,t.redirect=r.redirect||!0,t.showPageCount=r.showPageCount||!0,t.showItemCount=r.showItemCount||!0,t.needInit=r.needInit||!1,t.updateCurrentPage=function(){if(t.currentPage>Math.ceil(t.showNumber/2)&&t.pageCount>t.showNumber){if(t.pages=[],t.pageCount-t.currentPage>2)var e=t.currentPage-Math.ceil(t.showNumber/2),n=t.currentPage+Math.floor(t.showNumber/2);else var n=t.pageCount,e=t.pageCount-t.showNumber;for(i=e;it.showNumber){for(t.pages=[],i=0;in?t.count=0:t.count=n,t.pageCount=Math.ceil(t.count/t.pagesize)||1,t.currentPage=t.currentPage>t.pageCount?t.pageCount:t.currentPage,t.pageCount<=t.showNumber){t.pages=[];for(var a=0;a1&&t.pageChange(t.currentPage-1)}.bind(this),this.goNext=function(e){t.currentPage0?t.pageChange(parseInt(n,10)):(t.tipsLeft=t.page.offsetLeft,t.tipsTop=t.page.offsetTop+t.page.offsetHeight+8,t.showTip="block",setTimeout(function(){t.showTip="none",t.update()},1500),t.update())}.bind(this),this.changePage=function(e){var n=e.item.page;return"string"==typeof n?!1:void t.pageChange(n)}.bind(this),t.pageChange=function(e){t.currentPage!=e&&(t.currentPage=e,r.callback(e)),t.updateCurrentPage()}}),riot.tag("itk-select",' ',function(e){var t=this,n=t.opts.opts||t.opts;t.gotOptions=!1,t.chooseOnce=!0,t.init=t.root.init=function(){t.gotOptions=!1,t.update()},t.realData=[],t.root.exportData=t.realData,t.initData=t.root.initData=function(){if(t.root.querySelector("select")){var e=t.root.querySelector("select").querySelectorAll("option"),n=t.root.querySelector("select").hasAttribute("mutiple");n?t.mutiple=!0:(t.mutiple=!1,t.noSearch=!0)}if(e&&e.length&&!t.gotOptions){for(t.options=e,t.searchInput=t.root.querySelector(".itk-select-search"),t.optionsWrap=t.root.querySelector(".itk-options-container"),t.realData=[],i=0;i=n.options.length&&(n.seletedIndex=0),t.setSelectedOpt(n)):13===i?t.chooseByKeyboard(n):27===i&&t.searchInput.blur()},t.chooseByKeyboard=function(e){var t=document.createEvent("MouseEvents"),n=e.options[e.seletedIndex];t.initEvent("mousedown",!0,!0),n&&n.dispatchEvent(t)},t.clearSelectedOpt=function(e){if(e.options){var t=e.options[e.seletedIndex];e.seletedIndex>=0&&t&&(t.style.background="",t.scrollIntoView())}},t.resetSelectOpt=function(){t.clearSelectedOpt(t.searchInput),t.searchInput.seletedIndex=-1},t.setSelectedOpt=function(e){var t=e.options[e.seletedIndex];t&&(t.style.background="#eff3f8",t.scrollIntoView())}}),riot.tag("itk-slide"," ",function(e){for(var t=this,n=t.root,i=t.opts.opts||t.opts,r=document.scripts,a="",o="",s=0;s",function(e){var t=this,n=t.opts.opts||t.opts,r=t.root;t.init=function(){r.style.display="block";for(i in n)t[i]||(t[i]=n[i]);t.originData=utils.deepCopy(t.data),t.update()},t.on("mount",function(){t.init()}),t.compare=function(e,n){return e[t.orderkeyName]>n[t.orderkeyName]?1:e[t.orderkeyName]===n[t.orderkeyName]?0:-1},t.clearOrder=function(){t.ordered=!1,t.reversed=!1},t.loadData=r.loadData=function(e){return t.data=e,t.originData=utils.deepCopy(e),t.update(),t.data},t.exportData=r.exportData=function(){return t.data},t.reset=r.reset=function(){t.data=utils.deepCopy(t.originData),t.update()},t.orderBy=function(e){return function(){return t.orderkeyName=e,t.ordered!==e&&(t.reversed!==e?t.data=t.data.sort(t.compare):t.data=t.data.reverse(),t.ordered=e,t.reversed=!1,t.update()),t.data}},r.orderBy=function(e){t.orderBy(e)()},t.reverseBy=function(e){return function(){return t.orderkeyName=e,t.reversed!==e&&(t.ordered!==e?(t.data=t.data.sort(t.compare),t.data=t.data.reverse()):t.data=t.data.reverse(),t.ordered=!1,t.reversed=e,t.update()),t.data}},r.reverseBy=function(e){t.reverseBy(e)()},t.toggleBy=function(e){return t.ordered===e?t.reverseBy(e):t.orderBy(e)},r.toggleBy=function(e){t.ordered===e?r.reverseBy(e):r.orderBy(e)},t.append=function(e){return function(){t.clearOrder(),utils.isObject(e)?t.data.push(e):utils.isArray(e)&&(t.data=t.data.concat(e)),t.update()}},r.append=function(e){t.append(e)()},t.prepend=function(e){return function(){t.clearOrder(),utils.isObject(e)?t.data.unshift(e):utils.isArray(e)&&(t.data=e.concat(t.data)),t.update()}},r.prepend=function(e){t.prepend(e)()},t.deleteBy=function(e,n){return function(){if(e&&n){t.clearOrder();for(var i=0;i { item.name }
',function(e){var t=this;t.selectchildren=function(e,n){var i=function(e){if(e&&e.children)for(var t=0;t ',function(e){var t=this;if(t.config=t.opts.opts||t.opts,t.dataHandle=function(e,n,i){var e=e||[],r=n||"id",a=i||"pid",o={};e.forEach(function(e){t.config.name&&(e.name=e[t.config.name]),o[e[r]]=e});var s=[];e.forEach(function(e){var t=o[e[a]];t?(t.children||(t.children=[]),e.pnode=t,t.children.push(e)):s.push(e)});var u=function(e,n){var n=n+1;e.forEach(function(e){e.level=n-1,e.level上传',function(e){var t=this,n=(t.root,t.opts.opts||t.opts),i=function(e,t){return Math.floor(e+Math.random()*(t-e))};t.uploadBtn.id=i(1e4,99999);for(var r=document.scripts,a="",o=0;o