Skip to content

Commit eb535c8

Browse files
committed
Merge pull request #8 from zhangxinxu/develop
Develop
2 parents ce6597b + 298ef9a commit eb535c8

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/mobilebone.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,19 @@
166166
}
167167
if (pageInto != null && pageInto.classList) {
168168
// for title change
169-
var title = params_in.title, header = document.querySelector("h1");
169+
var title = params_in.title,
170+
header = document.querySelector("h1"),
171+
first_page = document.querySelector("." + this.classPage);
170172
// do title change
171173
if (title) {
172174
document.title = title;
173175
if (header) {
174176
header.innerHTML = title;
175177
header.title = title;
176178
}
179+
} else if (first_page == pageInto && !pageOut && document.title) {
180+
// set data-title for first visibie page
181+
pageInto.setAttribute("data-title", document.title);
177182
}
178183

179184
// delete page with same id
@@ -357,18 +362,21 @@
357362
options = options || {};
358363
// get current page(will be out) according to 'page_or_child'
359364
var current_page = document.querySelector(".in." + this.classPage);
360-
365+
// get page-title from element_or_options or options
366+
var page_title;
361367
if (element_or_options) {
362368
if (element_or_options.nodeType == 1) {
363369
// legal elements
364370
if (element_or_options.classList.contains(this.classPage)) {
365371
current_page = element_or_options;
366372
} else if (element_or_options.href) {
367373
current_page = this.getPage(element_or_options);
374+
page_title = element_or_options.getAttribute("data-title") || options.title;
368375
}
369376
response = options.response;
370377
} else {
371378
response = element_or_options.response || options.response;
379+
page_title = element_or_options.title || options.title;
372380
}
373381
}
374382

@@ -381,11 +389,19 @@
381389
} else {
382390
create.appendChild(dom_or_html);
383391
}
392+
var create_title = create.getElementsByTagName("title")[0];
384393
// get the page element
385394
if (!(create_page = create.querySelector("." + this.classPage))) {
386395
create.className = "page out";
396+
if (typeof page_title == "string") create.setAttribute("data-title", page_title);
387397
create_page = create;
388-
}
398+
} else {
399+
if (create_title) {
400+
create_page.setAttribute("data-title", create_title.innerText);
401+
} else if (typeof page_title == "string") {
402+
create_page.setAttribute("data-title", page_title);
403+
}
404+
}
389405
// insert create page as a last-child
390406
document.body.appendChild(create_page);
391407

@@ -489,6 +505,8 @@
489505
}
490506
// get url
491507
params.url = this.getCleanUrl(null, params.url, params.data);
508+
// here params.title will become page title;
509+
params.title = trigger_or_options.title;
492510
} else {
493511
return;
494512
}

test/ajax-html/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<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>
2020
</ul>
2121
<ul>
22-
<li><a href="ajax-without-page.html">点击加载-返回不含page, 自动创建page</a></li>
22+
<li><a href="ajax-without-page.html" data-title="纯a标签元素返回页面">点击加载-返回不含page, 自动创建page</a></li>
2323
</ul>
2424
<ul>
2525
<li><a href="../index.html" data-ajax="false">&laquo; 返回测试引导首页</a></li>

0 commit comments

Comments
 (0)