|
38 | 38 | *
|
39 | 39 | * @type string
|
40 | 40 | **/
|
41 |
| - Mobilebone.VERSION = '1.1.3'; |
| 41 | + Mobilebone.VERSION = '1.1.4'; |
42 | 42 |
|
43 | 43 | /**
|
44 | 44 | * Whether bind events when dom ready
|
|
76 | 76 | Mobilebone.rootTransition = root;
|
77 | 77 |
|
78 | 78 | /**
|
79 |
| - * className for mark page element |
| 79 | + * Whether merge(vs cover) global callback and local callback |
| 80 | + * |
| 81 | + * @type boolean |
| 82 | + **/ |
| 83 | + Mobilebone.mergeCallback = true; |
| 84 | + |
| 85 | + /** |
| 86 | + * for mark page element |
80 | 87 | *
|
81 | 88 | * @type string
|
82 | 89 | **/
|
|
133 | 140 | onpagefirstinto: this.onpagefirstinto,
|
134 | 141 | animationstart: this.animationstart,
|
135 | 142 | animationend: this.animationend,
|
| 143 | + fallback: this.fallback, |
136 | 144 | callback: this.callback
|
137 | 145 | }, params = function(element) {
|
138 | 146 | if (!element || !element.getAttribute) return {};
|
|
141 | 149 |
|
142 | 150 | // rules as follow:
|
143 | 151 | // data-* > data-params > options > defaults
|
144 |
| - ["title", "root", "form", "onpagefirstinto", "callback", "animationstart", "animationend"].forEach(function(key) { |
| 152 | + ["title", "root", "form"].forEach(function(key) { |
| 153 | + |
145 | 154 | _params[key] = element.getAttribute("data-" + key) || _dataparams[key] || options[key] || defaults[key];
|
146 | 155 | });
|
147 | 156 |
|
148 | 157 | if (typeof _params.root == "string") {
|
149 | 158 | _params.root = Mobilebone.getFunction(_params.root);
|
150 | 159 | }
|
151 | 160 |
|
| 161 | + ["onpagefirstinto", "callback", "fallback", "animationstart", "animationend"].forEach(function(key) { |
| 162 | + if (Mobilebone.mergeCallback == true && typeof defaults[key] == "function") { |
| 163 | + // merge global callback |
| 164 | + var local_function_key = element.getAttribute("data-" + key) || _dataparams[key]; |
| 165 | + if (typeof _params.root[local_function_key] == "function") { |
| 166 | + _params[key] = function() { |
| 167 | + defaults[key].apply(null, arguments); |
| 168 | + _params.root[local_function_key].apply(null, arguments); |
| 169 | + } |
| 170 | + } else if (typeof options[key] == "function") { |
| 171 | + _params[key] = function() { |
| 172 | + defaults[key].apply(null, arguments); |
| 173 | + options[key].apply(null, arguments); |
| 174 | + } |
| 175 | + } else { |
| 176 | + _params[key] = defaults[key]; |
| 177 | + } |
| 178 | + } else { |
| 179 | + // replace global callback |
| 180 | + _params[key] = element.getAttribute("data-" + key) || _dataparams[key] || options[key] || defaults[key]; |
| 181 | + } |
| 182 | + }); |
| 183 | + |
| 184 | + |
152 | 185 | return _params;
|
153 | 186 | };
|
154 | 187 |
|
|
162 | 195 | pageOut.classList.remove("in");
|
163 | 196 | // if reverse direction
|
164 | 197 | pageOut.classList[back? "add": "remove"]("reverse");
|
165 |
| - |
| 198 | + // do fallback every time |
| 199 | + var fallback = params_out.fallback; |
| 200 | + if (typeof fallback == "string") fallback = params_out.root[fallback]; |
| 201 | + if (typeof fallback == "function") fallback(pageInto, pageOut, options.response); |
166 | 202 | }
|
167 | 203 | if (pageInto != null && pageInto.classList) {
|
168 | 204 | // for title change
|
|
0 commit comments