|
6 | 6 | define(["require", "exports"], factory); |
7 | 7 | } |
8 | 8 | else { |
9 | | - var IosAlertView = factory(); |
10 | | - if(typeof window !== 'undefined'){ |
11 | | - window.IosAlertView = IosAlertView; |
| 9 | + if(typeof window !== 'undefined' && window.Vue){ |
| 10 | + window.Vue.use(factory()); |
12 | 11 | } |
13 | 12 | } |
14 | 13 | })(function (require, exports) { |
|
63 | 62 | }; |
64 | 63 | }; |
65 | 64 |
|
66 | | - var IosAlertViewComponent = Vue.extend({ |
67 | | - template: template, |
68 | | - data: function () { |
69 | | - return { |
70 | | - value: '', |
71 | | - showModal: false |
72 | | - }; |
73 | | - }, |
74 | | - props: [ |
75 | | - 'title', |
76 | | - 'text', |
77 | | - 'input', |
78 | | - 'placeholder', |
79 | | - 'onClick', |
80 | | - 'remindDuration', |
81 | | - 'buttons' |
82 | | - ], |
83 | | - methods: { |
84 | | - activate: function(){ |
85 | | - var self = this; |
86 | | - |
87 | | - self._deferred = defer(); |
88 | | - |
89 | | - self.showModal = true; |
90 | | - |
91 | | - // no buttons, remind (ANIMATION_TIME + remindDuration) time, then auto remove |
92 | | - if(!self.buttons || !self.buttons.length){ |
93 | | - setTimeout(function(){ |
94 | | - self.showModal = false; |
95 | | - self._deferred.resolve(); |
96 | | - }, ANIMATION_TIME + self.remindDuration); |
97 | | - } |
98 | | - |
99 | | - return self._deferred.promise; |
100 | | - }, |
101 | | - onClick: function (button, index) { |
102 | | - var cbkData = { |
103 | | - index: index, |
104 | | - button: button, |
105 | | - value: this.value |
| 65 | + return function(Vue, globalOptions){ |
| 66 | + var IosAlertViewComponent = Vue.extend({ |
| 67 | + template: template, |
| 68 | + data: function () { |
| 69 | + return { |
| 70 | + value: '', |
| 71 | + showModal: false |
106 | 72 | }; |
107 | | - |
108 | | - if (typeof button.onClick === 'function') { |
109 | | - button.onClick(cbkData); |
110 | | - } |
111 | | - |
112 | | - this._deferred.resolve(cbkData); |
113 | | - this.showModal = false; |
114 | 73 | }, |
115 | | - afterLeave: function () { |
116 | | - this.$destroy(); |
| 74 | + props: [ |
| 75 | + 'title', |
| 76 | + 'text', |
| 77 | + 'input', |
| 78 | + 'placeholder', |
| 79 | + 'onClick', |
| 80 | + 'remindDuration', |
| 81 | + 'buttons' |
| 82 | + ], |
| 83 | + methods: { |
| 84 | + activate: function(){ |
| 85 | + var self = this; |
| 86 | + |
| 87 | + self._deferred = defer(); |
| 88 | + |
| 89 | + self.showModal = true; |
| 90 | + |
| 91 | + // no buttons, remind (ANIMATION_TIME + remindDuration) time, then auto remove |
| 92 | + if(!self.buttons || !self.buttons.length){ |
| 93 | + setTimeout(function(){ |
| 94 | + self.showModal = false; |
| 95 | + self._deferred.resolve(); |
| 96 | + }, ANIMATION_TIME + self.remindDuration); |
| 97 | + } |
| 98 | + |
| 99 | + return self._deferred.promise; |
| 100 | + }, |
| 101 | + onClick: function (button, index) { |
| 102 | + var cbkData = { |
| 103 | + index: index, |
| 104 | + button: button, |
| 105 | + value: this.value |
| 106 | + }; |
| 107 | + |
| 108 | + if (typeof button.onClick === 'function') { |
| 109 | + button.onClick(cbkData); |
| 110 | + } |
| 111 | + |
| 112 | + this._deferred.resolve(cbkData); |
| 113 | + this.showModal = false; |
| 114 | + }, |
| 115 | + afterLeave: function () { |
| 116 | + this.$destroy(); |
| 117 | + } |
117 | 118 | } |
118 | | - } |
119 | | - }); |
120 | | - |
121 | | - function getPropsData(options){ |
122 | | - options = options || {}; |
| 119 | + }); |
123 | 120 |
|
124 | | - var propsData = Vue.util.extend({}, defaults); |
| 121 | + function getPropsData(options){ |
| 122 | + options = options || {}; |
125 | 123 |
|
126 | | - if (typeof options === 'string') { |
127 | | - propsData[defaults.defaultOption] = options; |
128 | | - } else { |
129 | | - propsData = Vue.util.extend(propsData, options); |
130 | | - } |
| 124 | + var propsData = Vue.util.extend({}, defaults); |
131 | 125 |
|
132 | | - return propsData; |
133 | | - } |
| 126 | + if (typeof options === 'string') { |
| 127 | + propsData[defaults.defaultOption] = options; |
| 128 | + } else { |
| 129 | + propsData = Vue.util.extend(propsData, options); |
| 130 | + } |
134 | 131 |
|
135 | | - function IosAlertView(options) { |
136 | | - var propsData = getPropsData(options); |
| 132 | + return propsData; |
| 133 | + } |
137 | 134 |
|
138 | | - var instance = new IosAlertViewComponent({propsData: propsData}); |
| 135 | + function IosAlertView(options) { |
| 136 | + var propsData = getPropsData(options); |
139 | 137 |
|
140 | | - var mount = document.createElement('div'); |
141 | | - mount.id = 'ios-alert-view-' + Date.now(); |
142 | | - document.body.appendChild(mount); |
| 138 | + var instance = new IosAlertViewComponent({propsData: propsData}); |
143 | 139 |
|
144 | | - instance.$mount(mount); |
| 140 | + var mount = document.createElement('div'); |
| 141 | + mount.id = 'ios-alert-view-' + Date.now(); |
| 142 | + document.body.appendChild(mount); |
145 | 143 |
|
146 | | - return instance.activate(); |
147 | | - } |
| 144 | + instance.$mount(mount); |
148 | 145 |
|
149 | | - IosAlertView.install = function (Vue, globalOptions) { |
| 146 | + return instance.activate(); |
| 147 | + } |
150 | 148 |
|
151 | 149 | globalOptions = globalOptions || {}; |
152 | 150 |
|
153 | 151 | if (typeof globalOptions !== 'object') { |
154 | | - throw 'Expect Object options'; |
| 152 | + throw new Error('Expect Object options'); |
155 | 153 | } |
156 | 154 |
|
157 | 155 | // override defaults |
|
228 | 226 | var propsData = getPropsData(options); |
229 | 227 | return IosAlertView(propsData); |
230 | 228 | }; |
231 | | - }; |
232 | | - |
233 | | - if(typeof window !== 'undefined' && window.Vue){ |
234 | | - window.Vue.use(IosAlertView); |
235 | 229 | } |
236 | | - |
237 | | - return IosAlertView; |
238 | 230 | }); |
239 | 231 |
|
0 commit comments