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 | newPageFunction.created.apply(assign(newPageFunction, {
|
24 | $el: entryDom,
|
25 | activePage: window.ozzx.activePage,
|
26 | domList: window.ozzx.domList
|
27 | }))
|
28 |
|
29 | for (var key in newPageFunction.template) {
|
30 | var templateScript = newPageFunction.template[key]
|
31 | if (templateScript.created) {
|
32 |
|
33 | templateScript.created.apply(assign(newPageFunction.template[key], {
|
34 | $el: entryDom,
|
35 | activePage: window.ozzx.activePage,
|
36 | domList: window.ozzx.domList
|
37 | }))
|
38 | }
|
39 | }
|
40 | }
|
41 |
|
42 |
|
43 | function pgNameHandler (dom) {
|
44 |
|
45 | for (var i = 0; i < dom.children.length; i++) {
|
46 | var tempDom = dom.children[i]
|
47 |
|
48 |
|
49 | var pgName = tempDom.attributes['@name']
|
50 | if (pgName) {
|
51 |
|
52 | window.ozzx.domList[pgName.textContent] = tempDom
|
53 | }
|
54 |
|
55 | var clickFunc = tempDom.attributes['@click']
|
56 |
|
57 | if (clickFunc) {
|
58 | tempDom.onclick = function() {
|
59 | var clickFor = this.attributes['@click'].textContent
|
60 |
|
61 | var newPageFunction = window.ozzx.script[window.ozzx.activePage]
|
62 |
|
63 |
|
64 |
|
65 | var templateName = this.attributes['template']
|
66 |
|
67 | if (templateName) {
|
68 | newPageFunction = newPageFunction.template[templateName.textContent]
|
69 | }
|
70 |
|
71 |
|
72 | var parameterArr = []
|
73 | var parameterList = clickFor.match(/[^\(\)]+(?=\))/g)
|
74 | if (parameterList && parameterList.length > 0) {
|
75 |
|
76 | parameterArr = parameterList[0].split(',')
|
77 | clickFor = clickFor.replace('(' + parameterList + ')', '')
|
78 | }
|
79 |
|
80 |
|
81 | if (newPageFunction.methods[clickFor]) {
|
82 |
|
83 |
|
84 | newPageFunction.methods[clickFor].apply({
|
85 | $el: tempDom,
|
86 | activePage: window.ozzx.activePage,
|
87 | domList: window.ozzx.domList,
|
88 | data: newPageFunction.data,
|
89 | methods: newPageFunction.methods
|
90 | }, parameterArr)
|
91 | }
|
92 | }
|
93 | }
|
94 |
|
95 | if (tempDom.children.length > 0) {
|
96 | pgNameHandler(tempDom)
|
97 | }
|
98 | }
|
99 | } |
\ | No newline at end of file |