|
166 | 166 | }
|
167 | 167 | if (pageInto != null && pageInto.classList) {
|
168 | 168 | // 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); |
170 | 172 | // do title change
|
171 | 173 | if (title) {
|
172 | 174 | document.title = title;
|
173 | 175 | if (header) {
|
174 | 176 | header.innerHTML = title;
|
175 | 177 | header.title = title;
|
176 | 178 | }
|
| 179 | + } else if (first_page == pageInto && !pageOut && document.title) { |
| 180 | + // set data-title for first visibie page |
| 181 | + pageInto.setAttribute("data-title", document.title); |
177 | 182 | }
|
178 | 183 |
|
179 | 184 | // delete page with same id
|
|
357 | 362 | options = options || {};
|
358 | 363 | // get current page(will be out) according to 'page_or_child'
|
359 | 364 | var current_page = document.querySelector(".in." + this.classPage);
|
360 |
| - |
| 365 | + // get page-title from element_or_options or options |
| 366 | + var page_title; |
361 | 367 | if (element_or_options) {
|
362 | 368 | if (element_or_options.nodeType == 1) {
|
363 | 369 | // legal elements
|
364 | 370 | if (element_or_options.classList.contains(this.classPage)) {
|
365 | 371 | current_page = element_or_options;
|
366 | 372 | } else if (element_or_options.href) {
|
367 | 373 | current_page = this.getPage(element_or_options);
|
| 374 | + page_title = element_or_options.getAttribute("data-title") || options.title; |
368 | 375 | }
|
369 | 376 | response = options.response;
|
370 | 377 | } else {
|
371 | 378 | response = element_or_options.response || options.response;
|
| 379 | + page_title = element_or_options.title || options.title; |
372 | 380 | }
|
373 | 381 | }
|
374 | 382 |
|
|
381 | 389 | } else {
|
382 | 390 | create.appendChild(dom_or_html);
|
383 | 391 | }
|
| 392 | + var create_title = create.getElementsByTagName("title")[0]; |
384 | 393 | // get the page element
|
385 | 394 | if (!(create_page = create.querySelector("." + this.classPage))) {
|
386 | 395 | create.className = "page out";
|
| 396 | + if (typeof page_title == "string") create.setAttribute("data-title", page_title); |
387 | 397 | 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 | + } |
389 | 405 | // insert create page as a last-child
|
390 | 406 | document.body.appendChild(create_page);
|
391 | 407 |
|
|
489 | 505 | }
|
490 | 506 | // get url
|
491 | 507 | params.url = this.getCleanUrl(null, params.url, params.data);
|
| 508 | + // here params.title will become page title; |
| 509 | + params.title = trigger_or_options.title; |
492 | 510 | } else {
|
493 | 511 | return;
|
494 | 512 | }
|
|
0 commit comments