diff options
| author | Misko Hevery | 2011-02-03 16:35:51 -0800 | 
|---|---|---|
| committer | Misko Hevery | 2011-02-04 13:44:22 -0800 | 
| commit | 46d690ff0188836688811dda9af1b99c44750c48 (patch) | |
| tree | f2253031ba3c8574ec93f03a18bb9fb2667aef51 /src | |
| parent | 882f412d578e4f01394847fa5fde21b6b4096de2 (diff) | |
| download | angular.js-46d690ff0188836688811dda9af1b99c44750c48.tar.bz2 | |
smarter normalization of value on option, and htmlParser fixes
Diffstat (limited to 'src')
| -rw-r--r-- | src/Angular.js | 2 | ||||
| -rw-r--r-- | src/markups.js | 33 | ||||
| -rw-r--r-- | src/sanitizer.js | 35 | 
3 files changed, 35 insertions, 35 deletions
| diff --git a/src/Angular.js b/src/Angular.js index de2de30d..aea1dd3f 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -719,7 +719,7 @@ function elementError(element, type, error) {      element[0]['$NG_ERROR'] = error;      if (error) {        element.addClass(type); -      element.attr(type, error); +      element.attr(type, error.message || error);      } else {        element.removeClass(type);        element.removeAttr(type); diff --git a/src/markups.js b/src/markups.js index 0aa7170e..89cc0d05 100644 --- a/src/markups.js +++ b/src/markups.js @@ -57,21 +57,26 @@ angularTextMarkup('{{}}', function(text, textNode, parentElement) {    }  }); -// TODO: this should be widget not a markup -angularTextMarkup('OPTION', function(text, textNode, parentElement){ -  if (nodeName_(parentElement) == "OPTION") { -    var select = jqLite('<select>'); -    select.append(parentElement.clone()); -    htmlParser(select.html(), { -      start: function(tag, attrs) { -        if (isUndefined(attrs.value)) { -          parentElement.attr('value', text); +/** + * This tries to normalize the behavior of value attribute across browsers. If value attribute is + * not specified, then specify it to be that of the text. + */ +angularTextMarkup('option', function(text, textNode, parentElement){ +  if (lowercase(nodeName_(parentElement)) == 'option') { +    if (msie <= 7) { +      // In IE7 The issue is that there is no way to see if the value was specified hence +      // we have to resort to parsing HTML; +      htmlParser(parentElement[0].outerHTML, { +        start: function(tag, attrs) { +          if (isUndefined(attrs.value)) { +            parentElement.attr('value', text); +          }          } -      }, -      chars: noop, -      end: noop, -      comment: noop -    }); +      }); +    } else if (parentElement[0].getAttribute('value') == null) { +      // jQuery does normalization on 'value' so we have to bypass it. +      parentElement.attr('value', text); +    }    }  }); diff --git a/src/sanitizer.js b/src/sanitizer.js index 8f4b87a6..7bd26455 100644 --- a/src/sanitizer.js +++ b/src/sanitizer.js @@ -42,15 +42,12 @@ var closeSelfElements = makeMap("colgroup,dd,dt,li,p,td,tfoot,th,thead,tr");  var specialElements = makeMap("script,style");  var validElements = extend({}, emptyElements, blockElements, inlineElements, closeSelfElements); -//see: http://www.w3.org/TR/html4/index/attributes.html -//Attributes that have their values filled in disabled="disabled" -var fillAttrs = makeMap("compact,ismap,nohref,nowrap");  //Attributes that have href and hence need to be sanitized  var uriAttrs = makeMap("background,href,longdesc,src,usemap"); -var validAttrs = extend({}, fillAttrs, uriAttrs, makeMap( +var validAttrs = extend({}, uriAttrs, makeMap(      'abbr,align,alt,axis,bgcolor,border,cellpadding,cellspacing,class,clear,'+ -    'color,cols,colspan,coords,dir,face,headers,height,hreflang,hspace,'+ -    'lang,language,rel,rev,rows,rowspan,rules,'+ +    'color,cols,colspan,compact,coords,dir,face,headers,height,hreflang,hspace,'+ +    'ismap,lang,language,nohref,nowrap,rel,rev,rows,rowspan,rules,'+      'scope,scrolling,shape,span,start,summary,target,title,type,'+      'valign,value,vspace,width')); @@ -81,8 +78,7 @@ function htmlParser( html, handler ) {          index = html.indexOf("-->");          if ( index >= 0 ) { -          if ( handler.comment ) -            handler.comment( html.substring( 4, index ) ); +          if (handler.comment) handler.comment( html.substring( 4, index ) );            html = html.substring( index + 3 );            chars = false;          } @@ -114,7 +110,7 @@ function htmlParser( html, handler ) {          var text = index < 0 ? html : html.substring( 0, index );          html = index < 0 ? "" : html.substring( index ); -        handler.chars( decodeEntities(text) ); +        if (handler.chars) handler.chars( decodeEntities(text) );        }      } else { @@ -123,7 +119,7 @@ function htmlParser( html, handler ) {            replace(COMMENT_REGEXP, "$1").            replace(CDATA_REGEXP, "$1"); -        handler.chars( decodeEntities(text) ); +        if (handler.chars) handler.chars( decodeEntities(text) );          return "";        }); @@ -159,16 +155,15 @@ function htmlParser( html, handler ) {      var attrs = {}; -    rest.replace(ATTR_REGEXP, function(match, name) { -      var value = arguments[2] ? arguments[2] : -        arguments[3] ? arguments[3] : -        arguments[4] ? arguments[4] : -        fillAttrs[name] ? name : ""; +    rest.replace(ATTR_REGEXP, function(match, name, doubleQuotedValue, singleQoutedValue, unqoutedValue) { +      var value = doubleQuotedValue +        || singleQoutedValue +        || unqoutedValue +        || ''; -      attrs[name] = decodeEntities(value); //value.replace(/(^|[^\\])"/g, '$1\\\"') //" +      attrs[name] = decodeEntities(value);      }); - -    handler.start( tagName, attrs, unary ); +    if (handler.start) handler.start( tagName, attrs, unary );    }    function parseEndTag( tag, tagName ) { @@ -183,7 +178,7 @@ function htmlParser( html, handler ) {      if ( pos >= 0 ) {        // Close all the open elements, up the stack        for ( i = stack.length - 1; i >= pos; i-- ) -        handler.end( stack[ i ] ); +        if (handler.end) handler.end( stack[ i ] );        // Remove the open elements from the stack        stack.length = pos; @@ -210,7 +205,7 @@ function makeMap(str){  var hiddenPre=document.createElement("pre");  function decodeEntities(value) {    hiddenPre.innerHTML=value.replace(/</g,"<"); -  return hiddenPre.innerText || hiddenPre.textContent; +  return hiddenPre.innerText || hiddenPre.textContent || '';  }  /** | 
