From c4e7e7dda04620eacb098a49debe98e1ae75d52b Mon Sep 17 00:00:00 2001 From: RubyLouvre Date: Wed, 20 Aug 2014 18:09:35 +0800 Subject: [PATCH] fix quote BUG --- avalon.js | 4 ++-- avalon.min.js | 4 ++-- mobile.js | 18 ++++++++++-------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/avalon.js b/avalon.js index 2e7231502..28728e4ef 100644 --- a/avalon.js +++ b/avalon.js @@ -2335,8 +2335,8 @@ '"': '\\"', '\\': '\\\\' }; - var quote = window.JSON && JSON.stringify || function() { - return '"' + this.replace(/[\\\"\x00-\x1f]/g, function(a) { + var quote = window.JSON && JSON.stringify || function(str) { + return '"' + str.replace(/[\\\"\x00-\x1f]/g, function(a) { var c = meta[a]; return typeof c === 'string' ? c : '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4); diff --git a/avalon.min.js b/avalon.min.js index 42b94d0e6..70db3ebbf 100644 --- a/avalon.min.js +++ b/avalon.min.js @@ -67,8 +67,8 @@ if(d=d.element){var l=[b].concat(g);if("up"===c)t?Ea(d,"dataavailable",l):(h=doc [];na(b,d)};var Rb=J("AREA,BASE,BASEFONT,BR,COL,COMMAND,EMBED,HR,IMG,INPUT,LINK,META,PARAM,SOURCE,TRACK,WBR,NOSCRIPT,SCRIPT,STYLE,TEXTAREA"),Pb=t?15:50,lb=/ms-(\w+)-?(.*)/,mb={"if":10,repeat:90,widget:110,each:1400,"with":1500,duplex:2E3,on:3E3},Qb=J("animationend,blur,change,input,click,dblclick,focus,keydown,keypress,keyup,mousedown,mouseenter,mouseleave,mousemove,mouseout,mouseover,mouseup,scroll,submit");if(!"1"[0])var Na=Aa(512),Hc=/\s+(ms-[^=\s]+)(?:=("[^"]*"|'[^']*'|[^\s>]+))?/g,Ic=/^['"]/, Jc=/<\w+\b(?:(["'])[^"]*?(\1)|[^>])*>/i,Kc=/&/g,kb=function(b){b=b.outerHTML;if(".avalonHide{ display: none!important }"),H.firstChild);var Sc=/(?:[\s\S]+?)<\/noscript>/img,Tc=/([\s\S]+?)<\/noscript>/im,Pa=function(){return new (r.XMLHttpRequest||ActiveXObject)("Microsoft.XMLHTTP")},da=function(b,c,d){if(b=b.getAttribute(c)){c=0;for(var e;e=d[c++];)if(e.hasOwnProperty(b)&&"function"===typeof e[b])return e[b]}},Qa=avalon.templateCache= {},aa=q.createElement("div");aa.innerHTML="a";try{aa.contains(aa.firstChild),avalon.contains=function(b,c){return b.contains(c)}}catch(ed){avalon.contains=Ya}var Ca=avalon.bindingExecutors={attr:function(b,c,d){var e=d.type,f=d.param;if("css"===e)avalon(c).css(f,b);else if("attr"===e)(d=!1===b||null===b||void 0===b)?c.removeAttribute(f):t?d||c.setAttribute(f,b):(f=Db[f]||f,d?c.removeAttribute(f):c[f]=b);else if("include"===e&&b){var g=d.vmodels,h=da(c,"data-include-rendered",g),k=da(c,"data-include-loaded", g),l=function(b){k&&(b=k.apply(c,[b].concat(g)));avalon.innerHTML(c,b);wa(c,g);h&&gb(c,function(){h.call(c)})};if("src"===d.param)if(Qa[b])l(Qa[b]);else{var m=Pa();m.onreadystatechange=function(){if(4===m.readyState){var c=m.status;if(200<=c&&300>c||304===c||1223===c)l(Qa[b]=m.responseText)}};m.open("GET",b,!0);"withCredentials"in m&&(m.withCredentials=!0);m.setRequestHeader("X-Requested-With","XMLHttpRequest");m.send(null)}else{var n=b&&1==b.nodeType?b:q.getElementById(b);if(n){if("NOSCRIPT"===n.tagName&& diff --git a/mobile.js b/mobile.js index a655191be..d9344fbb2 100644 --- a/mobile.js +++ b/mobile.js @@ -35,15 +35,17 @@ void function() { clickEvent.markFastClick = "司徒正美"; element.dispatchEvent(clickEvent) }, - focus: function(targetElement) { - if (this.canFocus(targetElement)) { - var length; - // Issue #160: on iOS 7, some input elements (e.g. date datetime) throw a vague TypeError on setSelectionRange. These elements don't have an integer value for the selectionStart and selectionEnd properties, but unfortunately that can't be used for detection because accessing the properties also throws a TypeError. Just check the type instead. Filed as Apple bug #15122724. - if (isIOS && targetElement.setSelectionRange && targetElement.type.indexOf("date") !== 0 && targetElement.type !== 'time') { - length = targetElement.value.length - targetElement.setSelectionRange(length, length) + focus: function(target) { + if (this.canFocus(target)) { + //https://github.com/RubyLouvre/avalon/issues/254 + var value = target.value + target.value = value + if (isIOS && target.setSelectionRange && target.type.indexOf("date") !== 0 && target.type !== 'time') { + // iOS 7, date datetime等控件直接对selectionStart,selectionEnd赋值会抛错 + var n = value.length + target.setSelectionRange(n, n) } else { - targetElement.focus() + target.focus() } } },