1 |
|
2 | import * as CSS from 'quickcss'
|
3 |
|
4 | import * as extend from 'smart-extend'
|
5 | import './parts/allowedOptions'
|
6 | import './parts/helpers'
|
7 | import './parts/checks'
|
8 | import './parts/element'
|
9 | import './parts/window'
|
10 | import './parts/mediaQuery'
|
11 |
|
12 | QuickDom = ()->
|
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 |
|
20 | QuickDom.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 |
|
65 | QuickDom.template = (tree)->
|
66 | new QuickTemplate(tree, true)
|
67 |
|
68 |
|
69 | QuickDom.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 |
|
76 | QuickDom.query = (target)->
|
77 | QuickDom(document).query(target)
|
78 |
|
79 | QuickDom.queryAll = (target)->
|
80 | QuickDom(document).queryAll(target)
|
81 |
|
82 | QuickDom.isTemplate = (target)->
|
83 | IS.template(target)
|
84 |
|
85 | QuickDom.isQuickEl = (target)->
|
86 | IS.quickDomEl(target)
|
87 |
|
88 | QuickDom.isEl = (target)->
|
89 | IS.domEl(target)
|
90 |
|
91 |
|
92 |
|
93 |
|
94 | import './parts/batch'
|
95 | import './parts/template'
|
96 | import './parts/shortcuts'
|
97 | QuickDom.version = import '../package.json $ version'
|
98 | QuickDom.CSS = CSS
|
99 | module.exports = QuickDom
|
100 |
|
101 |
|
102 |
|