1 |
|
2 | function assign(a, b) {
|
3 | var newObj = {}
|
4 | for (var key in a){
|
5 | newObj[key] = a[key]
|
6 | }
|
7 | for (var key in b){
|
8 | newObj[key] = b[key]
|
9 | }
|
10 | return newObj
|
11 | }
|
12 |
|
13 |
|
14 | function runPageFunction (pageName, entryDom) {
|
15 |
|
16 | window.ozzx.domList = {}
|
17 | pgNameHandler(entryDom)
|
18 |
|
19 |
|
20 | var newPageFunction = window.ozzx.script[pageName]
|
21 | if (!newPageFunction) return
|
22 |
|
23 |
|
24 | if (newPageFunction.created) {
|
25 |
|
26 | newPageFunction.created.apply(assign(newPageFunction, {
|
27 | $el: entryDom,
|
28 | data: newPageFunction.data,
|
29 | activePage: window.ozzx.activePage,
|
30 | domList: window.ozzx.domList
|
31 | }))
|
32 | }
|
33 |
|
34 |
|
35 | for (var key in newPageFunction.template) {
|
36 | var templateScript = newPageFunction.template[key]
|
37 | if (templateScript.created) {
|
38 |
|
39 |
|
40 | var domList = entryDom.getElementsByClassName('ox-' + key)
|
41 | if (domList.length !== 1){
|
42 | console.error('我就说会有问题吧!')
|
43 | console.log(domList)
|
44 | }
|
45 |
|
46 | templateScript.created.apply(assign(newPageFunction.template[key], {
|
47 | $el: domList[0].children[0],
|
48 | data: templateScript.data,
|
49 | activePage: window.ozzx.activePage,
|
50 | domList: window.ozzx.domList
|
51 | }))
|
52 | }
|
53 | }
|
54 | }
|
55 |
|
56 |
|
57 | function pgNameHandler (dom) {
|
58 |
|
59 | for (var i = 0; i < dom.children.length; i++) {
|
60 | var tempDom = dom.children[i]
|
61 |
|
62 |
|
63 | var pgName = tempDom.attributes['@name']
|
64 | if (pgName) {
|
65 |
|
66 |
|
67 | tempDom.hide = function () {
|
68 | this.style.display = 'none'
|
69 | }
|
70 | window.ozzx.domList[pgName.textContent] = tempDom
|
71 | }
|
72 |
|
73 | var clickFunc = tempDom.attributes['@click']
|
74 |
|
75 | if (clickFunc) {
|
76 |
|
77 | tempDom.onclick = function() {
|
78 | var clickFor = this.attributes['@click'].textContent
|
79 |
|
80 | var newPageFunction = window.ozzx.script[window.ozzx.activePage]
|
81 |
|
82 |
|
83 | var templateName = this.attributes['template']
|
84 |
|
85 | if (templateName) {
|
86 | newPageFunction = newPageFunction.template[templateName.textContent]
|
87 | }
|
88 |
|
89 |
|
90 | var parameterArr = []
|
91 | var parameterList = clickFor.match(/[^\(\)]+(?=\))/g)
|
92 |
|
93 | if (parameterList && parameterList.length > 0) {
|
94 |
|
95 | parameterArr = parameterList[0].split(',')
|
96 |
|
97 |
|
98 | for (var i = 0; i < parameterArr.length; i++) {
|
99 | var parameterValue = parameterArr[i].replace(/(^\s*)|(\s*$)/g, "")
|
100 |
|
101 |
|
102 |
|
103 | if (parameterValue.charAt(0) === '"' && parameterValue.charAt(parameterValue.length - 1) === '"') {
|
104 | parameterArr[i] = parameterValue.substring(1, parameterValue.length - 1)
|
105 | }
|
106 | if (parameterValue.charAt(0) === "'" && parameterValue.charAt(parameterValue.length - 1) === "'") {
|
107 | parameterArr[i] = parameterValue.substring(1, parameterValue.length - 1)
|
108 | }
|
109 |
|
110 | }
|
111 | clickFor = clickFor.replace('(' + parameterList + ')', '')
|
112 | }
|
113 |
|
114 |
|
115 | if (newPageFunction[clickFor]) {
|
116 |
|
117 |
|
118 |
|
119 | newPageFunction.$el = this
|
120 | newPageFunction.domList = window.ozzx.domList
|
121 | newPageFunction[clickFor].apply(newPageFunction, parameterArr)
|
122 | }
|
123 | }
|
124 | }
|
125 |
|
126 | if (tempDom.children.length > 0) {
|
127 | pgNameHandler(tempDom)
|
128 | }
|
129 | }
|
130 | } |
\ | No newline at end of file |