|
38 | 38 | *
|
39 | 39 | * @type string
|
40 | 40 | **/
|
41 |
| - Mobilebone.VERSION = '2.4.1'; |
| 41 | + Mobilebone.VERSION = '2.4.2'; |
42 | 42 |
|
43 | 43 | /**
|
44 | 44 | * Whether catch attribute of href from element with tag 'a'
|
|
274 | 274 | }
|
275 | 275 |
|
276 | 276 | // delete page with same id when options.remove !== false
|
277 |
| - var pageid = options.id || pageInto.id; |
| 277 | + var pageid = options.id || pageInto.id, hashid = options.id || pageInto.id; |
| 278 | + if (options.id && options.reload == "root") { |
| 279 | + pageid = pageid.split("?")[0]; |
| 280 | + } |
278 | 281 |
|
279 | 282 | if (options.remove !== false && store[pageid] && store[pageid] != pageInto && store[pageid].parentElement) {
|
280 | 283 | store[pageid].parentElement.removeChild(store[pageid]);
|
|
336 | 339 | });
|
337 | 340 |
|
338 | 341 | // history
|
339 |
| - var url_push = pageid, url_push_replaced = ''; |
| 342 | + // hashid should a full url address |
| 343 | + // different with pageid |
| 344 | + // add on 2.4.2 |
| 345 | + var url_push = hashid, url_push_replaced = ''; |
340 | 346 | if (url_push && /^#/.test(url_push) == false) {
|
341 | 347 | url_push = "#" + url_push;
|
342 | 348 | }
|
|
383 | 389 | params: string|object. ajax params. - Optional
|
384 | 390 | * @returns string
|
385 | 391 | * @example Mobilebone.getCleanUrl(elementOfA);
|
| 392 | + Mobilebone.getCleanUrl(elementOfForm); |
386 | 393 | Mobilebone.getCleanUrl(elementOfA, '', "a=1&b=2");
|
387 | 394 | Mobilebone.getCleanUrl(null, "xxx.html");
|
388 | 395 | Mobilebone.getCleanUrl(null, "xxx.html?a=1&b=2");
|
|
393 | 400 | if (trigger) {
|
394 | 401 | if (trigger.nodeType == 1) {
|
395 | 402 | // form element
|
396 |
| - if (trigger.action) return trigger.getAttribute("action"); |
397 |
| - // a element |
398 |
| - href = trigger.getAttribute("href"); |
399 |
| - formdata = trigger.getAttribute("data-formdata") || trigger.getAttribute("data-data"); |
| 403 | + if (trigger.action) { |
| 404 | + href = trigger.getAttribute("action"); |
| 405 | + // add on v2.4.1 |
| 406 | + if (trigger.method && trigger.method.toUpperCase() == "POST") { |
| 407 | + return href; |
| 408 | + } else if (window.$ && $.fn && $.fn.serialize) { |
| 409 | + // use jquery serialize() |
| 410 | + formdata = $(trigger).serialize(); |
| 411 | + } else { |
| 412 | + formdata = {}; |
| 413 | + // simple serialize from Mobilebone |
| 414 | + slice.call(trigger.querySelectorAll("input,select,textarea")).forEach(function(control) { |
| 415 | + if (control.name && !control.disabled) { |
| 416 | + var val = control.value.trim(), name = control.name; |
| 417 | + if (/^radio|checkbox/i.test(control.type)) { |
| 418 | + if (control.checked) { |
| 419 | + if (formdata[name]) { |
| 420 | + formdata[name].push(val); |
| 421 | + } else { |
| 422 | + formdata[name] = [val]; |
| 423 | + } |
| 424 | + } |
| 425 | + } else { |
| 426 | + formdata[name] = [val]; |
| 427 | + } |
| 428 | + } |
| 429 | + }); |
| 430 | + } |
| 431 | + } else { |
| 432 | + // a element |
| 433 | + href = trigger.getAttribute("href"); |
| 434 | + formdata = trigger.getAttribute("data-formdata") || trigger.getAttribute("data-data"); |
| 435 | + } |
400 | 436 | } else if (trigger.url) {
|
401 | 437 | href = trigger.url;
|
402 | 438 | formdata = trigger.data;
|
|
407 | 443 |
|
408 | 444 | // get formdata
|
409 | 445 | formdata = formdata || params || "";
|
410 |
| - |
| 446 | + |
411 | 447 | if (typeof formdata == "object") {
|
412 | 448 | var arr_data = [];
|
413 |
| - for (key in params) { |
414 |
| - arr_data.push(key + "=" + encodeURIComponent(params[key])); |
| 449 | + for (key in formdata) { |
| 450 | + if (!formdata[key].forEach) { |
| 451 | + formdata[key] = [formdata[key]]; |
| 452 | + } |
| 453 | + formdata[key].forEach(function(keyValue) { |
| 454 | + arr_data.push(key + "=" + encodeURIComponent(keyValue)); |
| 455 | + }); |
| 456 | + |
415 | 457 | }
|
416 | 458 | if (arr_data.length > 0) {
|
417 | 459 | formdata = arr_data.join("&");
|
|
526 | 568 | // do transition
|
527 | 569 | optionsTransition.response = response || dom_or_html;
|
528 | 570 | optionsTransition.id = this.getCleanUrl(element_or_options) || create_page.id || ("unique" + Date.now());
|
| 571 | + |
529 | 572 | if (is_root == true) {
|
530 |
| - optionsTransition.id = optionsTransition.id.split("?")[0]; |
| 573 | + optionsTransition.reload = "root"; |
531 | 574 | }
|
532 | 575 | // 'if' statement below added on v2.0.0
|
533 | 576 | if (typeof options == "object") {
|
|
622 | 665 | }
|
623 | 666 | }
|
624 | 667 | }
|
625 |
| - |
| 668 | + |
| 669 | + // ajax的url地址 |
626 | 670 | params.url = this.getCleanUrl(trigger_or_options, params.url);
|
627 | 671 | params.target = trigger_or_options;
|
628 | 672 |
|
|
672 | 716 | ele_mask.style.visibility = "visible";
|
673 | 717 |
|
674 | 718 | // ajax request
|
675 |
| - var xhr = new XMLHttpRequest(); |
| 719 | + var xhr = new XMLHttpRequest(); |
676 | 720 | xhr.open(params.type || "GET", params.url + (/\?/.test(params.url)? "&" : "?") + "r=" + Date.now(), params.async, params.username, params.password);
|
677 | 721 | xhr.timeout = params.timeout;
|
678 | 722 |
|
|
756 | 800 | var ajax = form.getAttribute("data-ajax");
|
757 | 801 | if (ajax == "false" || (this.captureForm == false && ajax != "true")) return;
|
758 | 802 |
|
| 803 | + // All form no cache |
| 804 | + if (form.getAttribute("data-reload") === null) { |
| 805 | + form.setAttribute("data-reload", "root"); |
| 806 | + } |
| 807 | + |
759 | 808 | form.addEventListener("submit", function(event) {
|
760 | 809 | // prevent detect
|
761 | 810 | var attrPrevent = this.getAttribute("data-preventdefault");
|
|
0 commit comments