Ticket #8282: 0010-patch-with-String-extractStyles-String-insertStyle.patch
| File 0010-patch-with-String-extractStyles-String-insertStyle.patch, 2.0 kB (added by kangax, 8 months ago) |
|---|
-
a/src/prototype.js
old new 22 22 }, 23 23 24 24 ScriptFragment: '<script[^>]*>([\\S\\s]*?)<\/script>', 25 StyleFragment: '<style[^>]*>([\u0001-\uFFFF]*?)<\/style>', 25 26 JSONFilter: /^\/\*-secure-([\s\S]*)\*\/\s*$/, 26 27 27 28 emptyFunction: function() { }, -
a/src/string.js
old new 71 71 }); 72 72 }, 73 73 74 extractStyles: function() { 75 var matchAll = new RegExp(Prototype.StyleFragment, 'img'); 76 var matchOne = new RegExp(Prototype.StyleFragment, 'im'); 77 return (this.match(matchAll) || []).map(function(styleTag) { 78 return (styleTag.match(matchOne) || ['', ''])[1]; 79 }); 80 }, 81 82 insertStyle: function() { 83 var style = document.createElement('style'); 84 var head = document.getElementsByTagName('head')[0]; 85 86 style.setAttribute('type', 'text/css'); 87 88 if (style.styleSheet) { 89 if (!style.styleSheet.disabled) 90 style.styleSheet.cssText = this; 91 } 92 else { 93 var text = document.createTextNode(this); 94 style.appendChild(text); 95 } 96 97 head.appendChild(style); 98 return this; 99 }, 100 74 101 evalScripts: function() { 75 102 return this.extractScripts().map(function(script) { return eval(script) }); 76 103 }, 104 105 applyStyles: function() { 106 return this.extractStyles().invoke('insertStyle'); 107 }, 77 108 78 109 escapeHTML: function() { 79 110 var self = arguments.callee;