|
2 | 2 | * mobilebone.js
|
3 | 3 | * by zhangxinxu(.com) 2014-09-26
|
4 | 4 | * https://github.com/zhangxinxu/mobilebone
|
5 |
| - * bone of slide for mobile web app |
| 5 | + * bone of switch for mobile web app |
6 | 6 | **/
|
7 | 7 |
|
8 | 8 | (function(root, factory) {
|
|
138 | 138 |
|
139 | 139 | // do callback when come in first time
|
140 | 140 | var onpagefirstinto = params_in.onpagefirstinto;
|
141 |
| - if (typeof onpagefirstinto == "string") onpagefirstinto = params_in.root[onpagefirstinto]; |
142 |
| - if (!store[pageid] && typeof onpagefirstinto == "function") { |
143 |
| - onpagefirstinto(pageInto, pageOut, options.response); |
| 141 | + if (!store[pageid]) { |
| 142 | + if (typeof onpagefirstinto == "string" && params_in.root[onpagefirstinto]) { |
| 143 | + params_in.root[onpagefirstinto](pageInto, pageOut, options.response); |
| 144 | + } else if (typeof onpagefirstinto == "function") { |
| 145 | + onpagefirstinto(pageInto, pageOut, options.response); |
| 146 | + } |
144 | 147 | }
|
145 | 148 |
|
146 | 149 | // do callback when animation start/end
|
|
150 | 153 | return matchs.toUpperCase();
|
151 | 154 | });
|
152 | 155 |
|
153 |
| - if (typeof animition == "string") animition = params_in.root[animition]; |
154 |
| - |
155 |
| - if (!store[pageid] && typeof animition == "function") { |
156 |
| - pageInto.addEventListener(isWebkit? webkitkey: animationkey, function() { |
157 |
| - animition(this, this.classList.contains("in")? "into": "out"); |
158 |
| - }); |
159 |
| - } |
| 156 | + if (!store[pageid]) { |
| 157 | + if (typeof animition == "string" && params_in.root[animition]) { |
| 158 | + pageInto.addEventListener(isWebkit? webkitkey: animationkey, function() { |
| 159 | + params_in.root[animition](this, this.classList.contains("in")? "into": "out"); |
| 160 | + }); |
| 161 | + } else if (typeof animition == "function") { |
| 162 | + pageInto.addEventListener(isWebkit? webkitkey: animationkey, function() { |
| 163 | + animition(this, this.classList.contains("in")? "into": "out"); |
| 164 | + }); |
| 165 | + } |
| 166 | + } |
160 | 167 | });
|
161 | 168 |
|
162 | 169 | // history
|
|
388 | 395 | params.response = response;
|
389 | 396 | Mobilebone.createPage(Mobilebone.jsonHandle(response), trigger_or_options, params);
|
390 | 397 | } catch (e) {
|
391 |
| - params.message = "JSON解析出现错误:" + e.message; |
| 398 | + params.message = "JSON parse error:" + e.message; |
392 | 399 | params.error.call(params, xhr, xhr.status);
|
393 | 400 | }
|
394 | 401 | } else if (params.dataType == "unknown") {
|
|
409 | 416 | }
|
410 | 417 | params.success.call(params, response, xhr.status);
|
411 | 418 | } else {
|
| 419 | + params.message = "The status code exception!"; |
412 | 420 | params.error.call(params, xhr, xhr.status);
|
413 | 421 | }
|
414 | 422 |
|
|
417 | 425 | // hide loading
|
418 | 426 | ele_mask.style.display = "none";
|
419 | 427 | }
|
| 428 | + |
| 429 | + xhr.onerror = function(e) { |
| 430 | + params.message = "Illegal request!"; |
| 431 | + params.error.call(params, xhr, xhr.status); |
| 432 | + // hide loading |
| 433 | + ele_mask.style.display = "none"; |
| 434 | + } |
420 | 435 | xhr.send(null);
|
421 | 436 | };
|
422 | 437 |
|
|
468 | 483 | Mobilebone.handleTapEvent = function(event) {
|
469 | 484 | // get target and href
|
470 | 485 | var target = event.target || event.touches[0], href = target.href;
|
| 486 | + |
471 | 487 | if (!href && (target = target.getParentElementByTag("a"))) {
|
472 | 488 | href = target.href;
|
473 | 489 | }
|
|
531 | 547 | Mobilebone.ajax(target);
|
532 | 548 | }
|
533 | 549 | event.preventDefault();
|
534 |
| - } |
| 550 | + } else { |
| 551 | + // console.log('pass thought'); |
| 552 | + } |
535 | 553 | };
|
536 | 554 |
|
537 | 555 |
|
|
0 commit comments