UNPKG

2.53 kBtext/coffeescriptView Raw
1### istanbul ignore next ###
2import * as CSS from 'quickcss'
3### istanbul ignore next ###
4import * as extend from 'smart-extend'
5import './parts/allowedOptions'
6import './parts/helpers'
7import './parts/checks'
8import './parts/element'
9import './parts/window'
10import './parts/mediaQuery'
11
12QuickDom = ()->
13 args = new Array(arguments.length)
14 args[i] = arg for arg,i in arguments
15 prevCount = QuickElement.count
16 element = QuickDom.create(args)
17 element._postCreation() if element and element._postCreation and QuickElement.count isnt prevCount
18 return element
19
20QuickDom.create = (args)-> switch
21 when IS.array(args[0])
22 return QuickDom(args[0]...)
23
24 when IS.template(args[0])
25 return args[0].spawn()
26
27 when IS.quickDomEl(args[0])
28 return if args[1] then args[0].updateOptions(args[1]) else args[0]
29
30 when IS.domNode(args[0]) or IS.domDoc(args[0])
31 if args[0]._quickElement
32 return args[0]._quickElement
33
34 type = args[0].nodeName.toLowerCase().replace('#', '')
35 options = args[1] or {}
36 options.existing = args[0]
37 return new QuickElement(type, options)
38
39 when args[0] is window
40 return QuickWindow
41
42 when IS.string(args[0])
43 type = args[0].toLowerCase()
44 if type is 'text'
45 options = if IS.object(args[1]) then args[1] else {text:args[1] or ''}
46 else
47 options = if IS.object(args[1]) then args[1] else {}
48
49 element = new QuickElement(type, options)
50 if args.length > 2
51 children = new Array(argsLength = args.length); i = 1;
52 children[i+1] = args[i] while ++i < argsLength
53
54 for child in children
55 child = QuickDom.text(child) if IS.string(child)
56 child = QuickDom(child...) if IS.array(child)
57 element.append(child) if IS.quickDomEl(child)
58
59 return element
60
61 when args[0] and (IS.domNode(args[0][0]) or IS.domDoc(args[0][0]))
62 return QuickDom(args[0][0])
63
64
65QuickDom.template = (tree)->
66 new QuickTemplate(tree, true)
67
68
69QuickDom.html = (innerHTML)->
70 container = document.createElement('div')
71 container.innerHTML = innerHTML
72 children = Array::slice.call container.childNodes
73
74 return QuickDom.batch(children)
75
76QuickDom.query = (target)->
77 QuickDom(document).query(target)
78
79QuickDom.queryAll = (target)->
80 QuickDom(document).queryAll(target)
81
82QuickDom.isTemplate = (target)->
83 IS.template(target)
84
85QuickDom.isQuickEl = (target)->
86 IS.quickDomEl(target)
87
88QuickDom.isEl = (target)->
89 IS.domEl(target)
90
91
92
93
94import './parts/batch'
95import './parts/template'
96import './parts/shortcuts'
97QuickDom.version = import '../package.json $ version'
98QuickDom.CSS = CSS
99module.exports = QuickDom
100
101
102