Skip to content

Commit 4178270

Browse files
author
zhangxinxu
committed
svg title fix
svg title fix
1 parent 2af8a8c commit 4178270

File tree

5 files changed

+40
-23
lines changed

5 files changed

+40
-23
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.5.5",
3+
"version": "2.5.6",
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: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
*
4747
* @type string
4848
**/
49-
Mobilebone.VERSION = '2.5.5';
49+
Mobilebone.VERSION = '2.5.6';
5050

5151
/**
5252
* Whether catch attribute of href from element with tag 'a'
@@ -625,18 +625,20 @@
625625
}
626626

627627
var create_title = create.getElementsByTagName("title")[0];
628+
628629
// get the page element
629630
if (!(create_page = create.querySelector("." + classPage))) {
631+
// if there no .page, create as create_page
630632
create.className = classPage + " out";
631-
if (typeof page_title == "string") create.setAttribute("data-title", page_title);
632633
create_page = create;
633-
} else {
634-
if (create_title) {
635-
create_page.setAttribute("data-title", create_title.innerText);
636-
} else if (typeof page_title == "string") {
637-
create_page.setAttribute("data-title", page_title);
638-
}
639634
}
635+
// set and store title
636+
if (typeof page_title == "string") {
637+
create_page.setAttribute("data-title", page_title);
638+
} else if (create_title && create_title.innerText) { // the judge behind '&&' for issues #144
639+
create_page.setAttribute("data-title", create_title.innerText);
640+
}
641+
640642
// insert create page as a last-child
641643
(container || document.body).appendChild(create_page);
642644

@@ -881,7 +883,7 @@
881883
Mobilebone.submit = function(form) {
882884
if (!form || typeof form.action != "string") return;
883885
var ajax = form.getAttribute("data-ajax");
884-
if (ajax == "false" || (this.captureForm == false && ajax != "true")) return;
886+
if (ajax == "false" || (Mobilebone.captureForm == false && ajax != "true")) return;
885887

886888
form.addEventListener("submit", function(event) {
887889
// prevent detect
@@ -970,17 +972,11 @@
970972
}
971973

972974
// Initialization link-catch events.
973-
var eventName = "click", $ = root.$ || root.jQuery || root.Zepto;
974-
if ($ && $.fn && $.fn.tap && ('ontouchstart' in window == true)) eventName = "tap";
975-
976-
if ($ && $.fn && $.fn.on) {
975+
var $ = root.$ || root.jQuery || root.Zepto;
976+
if ($ && $.fn && $.fn.tap && ('ontouchstart' in window == true)) {
977977
// for some unknown 'tap' plugin
978-
$(document).on(eventName, this.handleTapEvent);
979-
} else {
980-
document.addEventListener(eventName, this.handleTapEvent);
981-
}
982-
983-
if (eventName == "tap") {
978+
$(document).tap(this.handleTapEvent);
979+
984980
// zepto tap event.preventDefault can't prevent default click-events
985981
document.addEventListener("click", function(event) {
986982
var target = event.target;
@@ -993,11 +989,14 @@
993989
if (target.getAttribute("data-rel") == "external"
994990
|| ajax == "false"
995991
|| (href.replace("://", "").split("/")[0] !== location.href.replace("://", "").split("/")[0] && ajax != "true")
996-
|| (this.captureLink == false && ajax != "true")
992+
|| (Mobilebone.captureLink == false && ajax != "true")
997993
) return;
998994
event.preventDefault();
999995
});
996+
} else {
997+
document.addEventListener("click", this.handleTapEvent);
1000998
}
999+
10011000
// Important:
10021001
// In ios7+, swipe the edge of page will navigate Safari
10031002
// that will trigger 'popstate' events and the page will transition twice

test/ajax-html/ajax-without-page.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@
55
</head>
66
77
<body>-->
8+
<!--<title>普通标题,应该显示</title>-->
89
<a href="#pageHome" data-rel="back">返回(请求返回内容就是个a标签)</a>
10+
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" x="0" y="0"
11+
width="200" height="200" viewBox="0 0 200 200">
12+
<title>SVG标题-应该不显示</title>
13+
<g>
14+
<path fill-rule="evenodd" clip-rule="evenodd" d="M191,14H7c-4.418,0-8,3.582-8,8v156c0,4.418,3.582,8,8,8h184c4.418,0,8-3.582,8-8
15+
V22C199,17.582,195.418,14,191,14z M191,178H7v-3.032l37.486-34.723l22.306,20.81l65.297-70.1L191,148.898V178z M191,139.513
16+
l-58.87-57.519l-65.612,69.67l-22.1-20.902L7,165.384V22h184V139.513z"/>
17+
<path fill-rule="evenodd" clip-rule="evenodd" d="M57.5,94c14.36,0,26-11.641,26-26c0-14.36-11.64-26-26-26
18+
c-14.359,0-26,11.641-26,26C31.5,82.359,43.141,94,57.5,94z M57.5,50c9.942,0,18.001,8.059,18.001,18c0,9.941-8.059,18-18.001,18
19+
c-9.941,0-18-8.059-18-18C39.5,58.059,47.559,50,57.5,50z"/>
20+
</g>
21+
</svg>
22+
923
<!--</body>
1024
</html>-->

test/ajax-html/index.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
<li><a href="ajax-page.html?a=1&b=" class="follow" data-reload data-formdata="c=1&d=1" data-mask="true">点击加载(data-formdata测试)-跟随loading</a></li>
2121
</ul>
2222
<ul>
23-
<li><a href="ajax-without-page.html" data-title="纯a标签元素返回页面">点击加载-返回不含page, 自动创建page</a></li>
23+
<li><a href="ajax-without-page.html" data-title="纯a标签元素返回页面" data-reload>点击加载-返回不含page, 自动创建page</a></li>
24+
<li><a href="ajax-without-page.html" data-reload>svg中title测试</a></li>
2425
</ul>
2526
<ul>
2627
<li><a href="root-reload.php?id=1" data-ajax="true">根地址不缓存1</a></li>
@@ -46,6 +47,9 @@
4647
<!--<script src="../base-slide/zepto.js"></script>
4748
<script src="../base-slide/frozen.js"></script>-->
4849
<script>
50+
// store title
51+
document.getElementById("pageHome").setAttribute("data-title", document.title);
52+
4953
var optionsTest = function(elein, eleout, options) {
5054
// ajax过场回调options参数测试
5155
// console.log("点击的元素是:" + (options.target && options.target.outerHTML));

test/complex/js/wechat.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Mobilebone.onpagefirstinto = function(pageinto) {
1313
var weChatScroll = new IScroll(pageinto.querySelector(".content"), {
1414
tap: true
1515
});
16-
/Android/i.test(navigator.userAgent) && pageinto.addEventListener('tap', Mobilebone.handleTapEvent, false);
16+
// /Android/i.test(navigator.userAgent) && pageinto.addEventListener('tap', Mobilebone.handleTapEvent, false);
1717
};
1818

1919
Mobilebone.callback = function(pageinto, pageout) {

0 commit comments

Comments
 (0)