Skip to content

Commit 9aa79cf

Browse files
author
zhangxinxu
committed
v2.8.1 publish
1 parent 92788a5 commit 9aa79cf

29 files changed

+627
-297
lines changed

dist/mobilebone.css

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,16 @@ html, body, .page {
2828
}
2929

3030
/* mask layer when ajax sending... */
31+
[data-mask] {
32+
position: relative;
33+
}
3134
.mask {
3235
height: 100%; width: 100%;
3336
background-color: rgba(255,255,255,.35);
3437
position: absolute; left: 0; top: 0;
3538
z-index: 9;
3639
}
37-
.loading {
40+
s.loading {
3841
width: 16px; height: 16px;
3942
border-radius: 100%;
4043
border: 2px solid;

dist/mobilebone.esm.js

Lines changed: 60 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**!
22
* @author @copyright zhangxinxu(.com)
33
* @since 2014-09-26
4-
* @description mobilebone.js(v2.8.0) - bone of switch for mobile web app - https://github.com/zhangxinxu/mobilebone
4+
* @description mobilebone.js(v2.8.1) - bone of switch for mobile web app - https://github.com/zhangxinxu/mobilebone
55
* @license MIT
66
**/
77

@@ -31,7 +31,7 @@ const Mobilebone = (function(root, Mobilebone) {
3131
*
3232
* @type string
3333
**/
34-
Mobilebone.VERSION = "2.8.0";
34+
Mobilebone.VERSION = "2.8.1";
3535

3636
/**
3737
* Whether auto init Mobilebone
@@ -552,17 +552,17 @@ const Mobilebone = (function(root, Mobilebone) {
552552
Mobilebone.getCleanUrl = function(trigger, url, params) {
553553
var href = "", formdata = "", cleanUrl = "";
554554
if (trigger) {
555-
if (trigger.nodeType == 1) {
556-
// form element
557-
if (trigger.action) {
558-
href = trigger.getAttribute("action");
559-
// add on v2.4.1
560-
if (trigger.method && trigger.method.toUpperCase() == "POST") {
561-
return href;
562-
} else if (window.$ && $.fn && $.fn.serialize) {
555+
if (trigger.nodeType == 1) {
556+
// form element
557+
if (trigger.action) {
558+
href = trigger.getAttribute("action");
559+
// add on v2.4.1
560+
if (trigger.method && trigger.method.toUpperCase() == "POST") {
561+
return href;
562+
} else if (window.$ && $.fn && $.fn.serialize) {
563563
// use jquery serialize()
564564
formdata = $(trigger).serialize();
565-
} else {
565+
} else {
566566
formdata = {};
567567
// simple serialize from Mobilebone
568568
slice.call(trigger.querySelectorAll("input,select,textarea")).forEach(function(control) {
@@ -581,10 +581,13 @@ const Mobilebone = (function(root, Mobilebone) {
581581
}
582582
}
583583
});
584-
}
585-
} else {
584+
}
585+
} else {
586586
// a element
587587
href = trigger.getAttribute("href");
588+
if (/^javascript/.test(href)) {
589+
href = '';
590+
}
588591
formdata = trigger.getAttribute("data-formdata") || trigger.getAttribute("data-params") || "";
589592
// v2.6.1 for #107
590593
// remember container when refresh
@@ -593,11 +596,11 @@ const Mobilebone = (function(root, Mobilebone) {
593596
var queryContainer = strContainer + "=" + attrContainer;
594597
formdata = formdata ? formdata + "&" + queryContainer : queryContainer;
595598
}
596-
}
597-
} else if (trigger.url) {
598-
href = trigger.url;
599-
formdata = trigger.data;
600-
}
599+
}
600+
} else if (trigger.url) {
601+
href = trigger.url;
602+
formdata = trigger.data;
603+
}
601604
}
602605

603606
if (!(href = href || url)) {
@@ -626,7 +629,7 @@ const Mobilebone = (function(root, Mobilebone) {
626629
}
627630

628631
// get url of root
629-
cleanUrl = href.split("#")[0].replace(/&+$/, "");
632+
cleanUrl = href.split("#")[0].replace(/&+$/, "").replace(/^\.\/+/, "");
630633

631634
if (cleanUrl.slice(-1) == "?") {
632635
cleanUrl = cleanUrl.split("?")[0];
@@ -1012,7 +1015,7 @@ const Mobilebone = (function(root, Mobilebone) {
10121015
if (eleMask == null) {
10131016
eleMask = document.createElement("div");
10141017
eleMask.className = classMask;
1015-
eleMask.innerHTML = '<i class="loading"></i>';
1018+
eleMask.innerHTML = '<s class="loading"></s>';
10161019
if (typeof attrMask == "string") {
10171020
eleOrObj.appendChild(eleMask);
10181021
} else {
@@ -1067,26 +1070,22 @@ const Mobilebone = (function(root, Mobilebone) {
10671070
Mobilebone.createPage(response, eleOrObj, params);
10681071
}
10691072
params.success.call(params, response, xhr.status);
1070-
1071-
params.complete.call(params, xhr, xhr.status);
1072-
1073-
// hide loading
1074-
eleMask.style.display = "none";
1075-
if (this.hideLoading) {
1076-
this.hideLoading();
1077-
}
1078-
}
1073+
};
10791074

10801075
xhr.onerror = function(e) {
10811076
params.message = "Illegal request address or an unexpected network error!";
10821077
params.error.call(params, xhr, xhr.status);
1078+
};
1079+
1080+
xhr.onloadend = function () {
10831081
// hide loading
10841082
eleMask.style.display = "none";
10851083
if (this.hideLoading) {
10861084
this.hideLoading();
10871085
}
1086+
10881087
params.complete.call(params, xhr, xhr.status);
1089-
}
1088+
};
10901089

10911090
xhr.ontimeout = function() {
10921091
params.message = "The request timeout!";
@@ -1147,12 +1146,18 @@ const Mobilebone = (function(root, Mobilebone) {
11471146
*
11481147
**/
11491148
Mobilebone.isBack = function(pageIn, pageOut) {
1150-
// back or forword, according to the order of two pages
1149+
// back or forwards, according to the order of two pages
11511150
if (history.tempBack == true) {
11521151
// backwords
11531152
history.tempBack = null;
11541153
return true;
11551154
}
1155+
1156+
if (history.tempGo == true) {
1157+
// forwards
1158+
history.tempGo = null;
1159+
return false;
1160+
}
11561161
// 2.7.5 return true -> false
11571162
if (typeof pageIn == "undefined") {
11581163
return false;
@@ -1269,24 +1274,9 @@ const Mobilebone = (function(root, Mobilebone) {
12691274
};
12701275

12711276
/**
1272-
* If 'a' element has href, slide auto when tapping~
1277+
* If 'a' element has href, slide auto when clicked
12731278
**/
12741279
Mobilebone.handleTapEvent = function(event) {
1275-
/**
1276-
// iscroll(set tap: true) may cause twice tap problem
1277-
// which is none of Mobilebone's business
1278-
// However, you can let code below go to avoid twice tap in Mobilebone
1279-
// but the tap event bind out of Mobilebone also has bug
1280-
// so my advice is that:
1281-
// 1. use Date.now to judge as Mobilebone did;
1282-
// or
1283-
// 2. keep this code in the form of comment and fixed bug outside
1284-
if (store.timerTap && Date.now() - store.timerTap < 100) {
1285-
event.preventDefault();
1286-
return false;
1287-
}
1288-
store.timerTap = Date.now();
1289-
*/
12901280
var target = null;
12911281
// you can pass target as params directly
12921282
if (event && event.nodeType == 1) {
@@ -1300,7 +1290,7 @@ const Mobilebone = (function(root, Mobilebone) {
13001290
return;
13011291
}
13021292

1303-
// 此时的链接地址
1293+
// current href
13041294
var href = target.href;
13051295

13061296
// the page that current actived
@@ -1353,11 +1343,19 @@ const Mobilebone = (function(root, Mobilebone) {
13531343
var capture = (Mobilebone.captureLink == true);
13541344
// get rel
13551345
var rel = target.getAttribute("data-rel");
1346+
if (!rel) {
1347+
rel = 'auto';
1348+
}
13561349
// if back
13571350
var back = false;
13581351
if (rel == "back") {
13591352
back = true;
13601353
}
1354+
// if go
1355+
var go;
1356+
if (rel == "go") {
1357+
go = true;
1358+
}
13611359

13621360
// if external link
13631361
var external = (rel == "external");
@@ -1381,7 +1379,7 @@ const Mobilebone = (function(root, Mobilebone) {
13811379
return;
13821380
}
13831381
if (/^javascript/.test(href)) {
1384-
if (back == false) {
1382+
if (back == false && !go) {
13851383
return;
13861384
}
13871385
} else {
@@ -1398,6 +1396,11 @@ const Mobilebone = (function(root, Mobilebone) {
13981396
var hashTargetPage = href.split("#")[1];
13991397
var idTargetPage = hashTargetPage.split("?")[0];
14001398
var queryTargetPage = hashTargetPage.split("?")[1];
1399+
var paramTargetPage = target.getAttribute('data-formdata') || target.getAttribute('data-params');
1400+
if (paramTargetPage) {
1401+
queryTargetPage = queryTargetPage + '&' + paramTargetPage;
1402+
}
1403+
14011404
// add on v2.7.4
14021405
options.query = _queryToObject(queryTargetPage);
14031406
options.id = hashTargetPage;
@@ -1410,7 +1413,7 @@ const Mobilebone = (function(root, Mobilebone) {
14101413
if (eleTargetPage) {
14111414
var lastShip = store.lastShip;
14121415

1413-
if (lastShip && eleTargetPage == lastShip[1] && selfPage == lastShip[0]) {
1416+
if (lastShip && eleTargetPage == lastShip[1] && selfPage == lastShip[0] && !go) {
14141417
// back
14151418
history.tempBack = true;
14161419
history.back();
@@ -1420,8 +1423,13 @@ const Mobilebone = (function(root, Mobilebone) {
14201423
}
14211424
} else if (/^javascript/.test(href)) {
14221425
// back
1423-
history.tempBack = true;
1424-
history.back();
1426+
if (back) {
1427+
history.tempBack = true;
1428+
history.back();
1429+
} else if (go) {
1430+
history.tempGo = true;
1431+
history.go(1);
1432+
}
14251433
} else if (target.getAttribute("data-ajax") != "false") {
14261434
event.preventDefault();
14271435
// get a clean ajax url as page id

0 commit comments

Comments
 (0)