Skip to content

Commit 2aeaed4

Browse files
author
zhangxinxu
committed
fix a bug cause by data-preventdefault
fix a bug by data-preventdefault that may cause no out element;
1 parent 1f54aba commit 2aeaed4

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

src/mobilebone.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,20 @@
209209
var preventOut = params_out.preventdefault, isPreventOut = false;
210210
if (typeof preventOut == "string") preventOut = params_out.root[preventOut];
211211
if (typeof preventOut == "function") isPreventOut = preventOut.call(params_out.root, pageInto, pageOut, options);
212-
212+
}
213+
if (pageInto != null && pageInto.classList) {
214+
// weather prevent transition
215+
var preventInto = params_in.preventdefault, isPreventInto = false;
216+
if (typeof preventInto == "string") preventInto = params_in.root[preventInto];
217+
if (typeof preventInto == "function") isPreventInto = preventInto.call(params_in.root, pageInto, pageOut, options);
218+
// if pageinto stopped, stop all
219+
if (isPreventInto == true) {
220+
// only run here and nothing more
221+
return this;
222+
}
223+
}
224+
225+
if (pageOut != null && pageOut.classList) {
213226
// do transition if there are no 'prevent'
214227
if (isPreventOut != true) {
215228
pageOut.classList.add("out");
@@ -223,15 +236,7 @@
223236
if (typeof fallback == "function") fallback.call(params_out.root, pageInto, pageOut, options);
224237
}
225238
}
226-
if (pageInto != null && pageInto.classList) {
227-
// weather prevent transition
228-
var preventInto = params_in.preventdefault;
229-
if (typeof preventInto == "string") preventInto = params_in.root[preventInto];
230-
if (typeof preventInto == "function" && preventInto.call(params_in.root, pageInto, pageOut, options) == true) {
231-
// only run here and nothing more
232-
return this;
233-
}
234-
239+
if (pageInto != null && pageInto.classList) {
235240
// for title change
236241
var title = params_in.title,
237242
header = document.querySelector("h1"),

test/form-submit/index.html

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<div id="pageHome" class="page out">
2222
<ul>
2323
<li class="pl10">
24-
<form method="get" action="search.html" data-validate="validate">
24+
<form method="get" action="search.html">
2525
<input type="search" class="search mr10" required><input type="submit" class="submit" value="搜索">
2626
</form>
2727
</li>
@@ -35,10 +35,5 @@
3535
</div>
3636

3737
<script src="../../src/mobilebone.js"></script>
38-
<script>
39-
var validate = function() {
40-
41-
};
42-
</script>
4338
</body>
4439
</html>

test/prevent-default/index.html

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,14 @@
8383
}
8484
};
8585

86-
var otherPageIfGithub = function() {
87-
if (/rawgit/i.test(location.href)) {
86+
var otherPageIfGithub = function(elein) {
87+
if (elein.id == "searchResult" && /rawgit/i.test(location.href)) {
8888
Mobilebone.ajax({
89-
url: "other.html"
89+
url: "other.html",
90+
success: function() {
91+
var result = document.getElementById("searchResult");
92+
if (result) result.parentNode.removeChild(result);
93+
}
9094
});
9195
return true;
9296
}

0 commit comments

Comments
 (0)