Skip to content

Commit 866aced

Browse files
committed
Merge pull request #34 from zhangxinxu/develop
Develop
2 parents cc297f5 + 4e31cad commit 866aced

File tree

5 files changed

+29
-16
lines changed

5 files changed

+29
-16
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mobilebone",
3-
"version": "2.0.2",
3+
"version": "2.1.0",
44
"description": "Bone main for mobile web APP with a sigle page mode.",
55
"main": "src/mobilebone.js",
66
"directories": {

src/mobilebone.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
*
4141
* @type string
4242
**/
43-
Mobilebone.VERSION = '2.0.2';
43+
Mobilebone.VERSION = '2.1.0';
4444

4545
/**
4646
* Whether catch attribute of href from element with tag 'a'
@@ -248,9 +248,9 @@
248248
var onpagefirstinto = params_in.onpagefirstinto;
249249
if (!store[pageid]) {
250250
if (typeof onpagefirstinto == "string" && params_in.root[onpagefirstinto]) {
251-
params_in.root[onpagefirstinto](pageInto, pageOut, options.response);
251+
params_in.root[onpagefirstinto](pageInto, pageOut, options);
252252
} else if (typeof onpagefirstinto == "function") {
253-
onpagefirstinto(pageInto, pageOut, options.response);
253+
onpagefirstinto(pageInto, pageOut, options);
254254
}
255255
// capture form submit
256256
slice.call(pageInto.querySelectorAll("form")).forEach(function(form) {
@@ -275,11 +275,11 @@
275275
// bind animation events
276276
if (typeof animition == "string" && params_in.root[animition]) {
277277
pageInto.addEventListener(animateEventName, function() {
278-
params_in.root[animition](this, this.classList.contains("in")? "into": "out");
278+
params_in.root[animition](this, this.classList.contains("in")? "into": "out", options);
279279
});
280280
} else if (typeof animition == "function") {
281281
pageInto.addEventListener(animateEventName, function() {
282-
animition(this, this.classList.contains("in")? "into": "out");
282+
animition(this, this.classList.contains("in")? "into": "out", options);
283283
});
284284
}
285285
}
@@ -304,7 +304,7 @@
304304
var callback = params_in.callback;
305305

306306
if (typeof callback == "string") callback = params_in.root[callback];
307-
if (typeof callback == "function") callback.call(params_in.root, pageInto, pageOut, options.response);
307+
if (typeof callback == "function") callback.call(params_in.root, pageInto, pageOut, options);
308308
}
309309
};
310310

@@ -455,6 +455,9 @@
455455
if (typeof options.remove != "undefined") {
456456
optionsTransition.remove = options.remove;
457457
}
458+
if (typeof options.target != "undefined") {
459+
optionsTransition.target = options.target;
460+
}
458461
}
459462
this.transition(create_page, current_page, optionsTransition);
460463
};
@@ -534,6 +537,7 @@
534537
}
535538

536539
params.url = this.getCleanUrl(trigger_or_options, params.url);
540+
params.target = trigger_or_options;
537541

538542
var tagName = trigger_or_options.tagName.toLowerCase();
539543
if (tagName == "form") {
@@ -727,8 +731,7 @@
727731
if (hasInited == true) return 'Don\'t repeat initialization!';
728732
var hash = location.hash.replace("#&", "#"), ele_in = null;
729733
if (hash == "" || hash == "#") {
730-
store._initPage = document.querySelector("." + this.classPage);
731-
this.transition(store._initPage);
734+
this.transition(document.querySelector("." + this.classPage));
732735
} else if (isSimple.test(hash) == true && (ele_in = document.querySelector(hash)) && ele_in.classList.contains(this.classPage)) { // 'ele_in' must be a page element
733736
this.transition(ele_in);
734737
} else {
@@ -832,7 +835,9 @@
832835
if (back == false && rel == "auto") {
833836
back = Mobilebone.isBack(eleTargetPage, self_page);
834837
}
835-
if (eleTargetPage) Mobilebone.transition(eleTargetPage, self_page, back);
838+
if (eleTargetPage) Mobilebone.transition(eleTargetPage, self_page, back, {
839+
target: target
840+
});
836841
event.preventDefault();
837842
} else if (/^javascript/.test(href)) {
838843
// back
@@ -849,6 +854,7 @@
849854
back = Mobilebone.isBack(store[clean_url], self_page);
850855
}
851856
Mobilebone.transition(store[clean_url], self_page, back, {
857+
target: target,
852858
id: clean_url
853859
});
854860
} else {
@@ -912,9 +918,9 @@
912918
window.addEventListener("popstate", function() {
913919
var hash = location.hash.replace("#&", "").replace("#", ""), page_in = null;
914920
if (hash == "") {
915-
// if no hash, get init page as 'page_in'
916-
page_in = store._initPage;
917-
if (!page_in) return;
921+
// if no hash, get first page as 'page_in'
922+
page_in = document.querySelector("." + Mobilebone.classPage);
923+
if (page_in.id) return;
918924
} else {
919925
page_in = store[hash];
920926
}

test/ajax-html/ajax-page.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
</head>
66

77
<body>
8-
<div class="page out"><a href="#pageHome" data-rel="back">返回</a></div>
8+
<div class="page out" data-callback="optionsTest"><a href="#pageHome" data-rel="back">返回</a></div>
99
</body>
1010
</html>

test/ajax-html/index.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,12 @@
3030
</div>
3131

3232
<script src="../../src/mobilebone.js"></script>
33+
<script>
34+
var optionsTest = function(elein, eleout, options) {
35+
// ajax过场回调options参数测试
36+
// console.log("点击的元素是:" + (options.target && options.target.outerHTML));
37+
// console.log("请求内容是:" + options.response);
38+
};
39+
</script>
3340
</body>
3441
</html>

test/callback/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ <h2>主页</h2>
5858
callback: function() {
5959
console.log(this.status.into = "回调执行!this对应的是Fun!");
6060
},
61-
home: function(pageInto, pageOut, response) {
61+
home: function(pageInto, pageOut, options) {
6262
pageInto.querySelector("p").innerHTML += "首次载入时间是:" + this.time() + "<br>";
6363
},
64-
start: function(page, into_or_out) {
64+
start: function(page, into_or_out, options) {
6565
page.querySelector("p").innerHTML += "页面即将进行"+ this.status[into_or_out] +"动画,时间是:" + this.time() + "<br>";
6666
},
6767
end: function(page, into_or_out) {

0 commit comments

Comments
 (0)