Optimize RegExp code by using 'test' instead of 'match'. b=145373, fix by neil@parkwaycc.co.uk, r=cmanske, sr=alecf
git-svn-id: svn://10.0.0.236/trunk@127179 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
b7d0d489ec
commit
8b0254a1fa
@ -117,7 +117,7 @@ function InitDialog()
|
||||
{
|
||||
// Get image from document
|
||||
gBackgroundImage = GetHTMLOrCSSStyleValue(globalElement, backgroundStr, cssBackgroundImageStr);
|
||||
if (gBackgroundImage.match( /url\((.*)\)/ ))
|
||||
if (/url\((.*)\)/.test( gBackgroundImage ))
|
||||
gBackgroundImage = RegExp.$1;
|
||||
|
||||
gDialog.BackgroundImageInput.value = gBackgroundImage;
|
||||
|
||||
@ -150,7 +150,7 @@ function onAccept()
|
||||
{
|
||||
var tagContent = TrimString(str.slice(start+1, end));
|
||||
|
||||
if ( tagContent.match(/^ol|^ul|^dl/) )
|
||||
if ( /^ol|^ul|^dl/.test(tagContent) )
|
||||
{
|
||||
// Replace list tag with <BR> to start new row
|
||||
// at begining of second or greater list tag
|
||||
@ -161,7 +161,7 @@ function onAccept()
|
||||
// Reset for list item separation into cells
|
||||
listItemSeparator = "";
|
||||
}
|
||||
else if ( tagContent.match(/^li|^dt|^dd/) )
|
||||
else if ( /^li|^dt|^dd/.test(tagContent) )
|
||||
{
|
||||
// Start a new row if this is first item after the ending the last list
|
||||
if (endList)
|
||||
@ -178,8 +178,8 @@ function onAccept()
|
||||
else
|
||||
{
|
||||
// Find end tags
|
||||
endList = tagContent.match(/^\/ol|^\/ul|^\/dl/);
|
||||
if ( endList || tagContent.match(/^\/li|^\/dt|^\/dd/) )
|
||||
endList = /^\/ol|^\/ul|^\/dl/.test(tagContent);
|
||||
if ( endList || /^\/li|^\/dt|^\/dd/.test(tagContent) )
|
||||
{
|
||||
// Strip out tag
|
||||
str = str.slice(0, start) + str.slice(end+1);
|
||||
|
||||
@ -336,16 +336,6 @@ function LimitStringLength(elementID, length)
|
||||
editField.value = stringIn.slice(0,length);
|
||||
}
|
||||
|
||||
function StripPxUnit(value)
|
||||
{
|
||||
var pxIndex = value.search(/px/);
|
||||
if (pxIndex > 0) {
|
||||
// Strip out the unit
|
||||
value = value.substr(0, pxIndex);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function InitPixelOrPercentMenulist(elementForAtt, elementInDoc, attribute, menulistID, defaultIndex)
|
||||
{
|
||||
if (!defaultIndex) defaultIndex = gPixel;
|
||||
@ -371,23 +361,20 @@ function InitPixelOrPercentMenulist(elementForAtt, elementInDoc, attribute, menu
|
||||
if (size && size.length > 0)
|
||||
{
|
||||
// Search for a "%" or "px"
|
||||
var percentIndex = size.search(/%/);
|
||||
var pxIndex = size.search(/px/);
|
||||
if (percentIndex > 0)
|
||||
if (/%/.test(size))
|
||||
{
|
||||
// Strip out the %
|
||||
size = size.substr(0, percentIndex);
|
||||
size = RegExp.leftContext;
|
||||
if (percentItem)
|
||||
menulist.selectedItem = percentItem;
|
||||
}
|
||||
else if (pxIndex > 0)
|
||||
else
|
||||
{
|
||||
// Strip out the %
|
||||
size = size.substr(0, pxIndex);
|
||||
if (/px/.test(size))
|
||||
// Strip out the px
|
||||
size = RegExp.leftContext;
|
||||
menulist.selectedItem = pixelItem;
|
||||
}
|
||||
else
|
||||
menulist.selectedItem = pixelItem;
|
||||
}
|
||||
else
|
||||
menulist.selectedIndex = defaultIndex;
|
||||
|
||||
@ -74,7 +74,9 @@ function InitDialog()
|
||||
// Just to be confusing, "size" is used instead of height because it does
|
||||
// not accept % values, only pixels
|
||||
var height = GetHTMLOrCSSStyleValue(globalElement, "size", "height")
|
||||
height = StripPxUnit(height);
|
||||
if (/px/.test(height)) {
|
||||
height = RegExp.leftContext;
|
||||
}
|
||||
if(!height) {
|
||||
height = 2; //Default value
|
||||
}
|
||||
@ -124,16 +126,15 @@ function onSaveDefault()
|
||||
}
|
||||
prefs.setIntPref("editor.hrule.align", alignInt);
|
||||
|
||||
var percentIndex = width.search(/%/);
|
||||
var percent;
|
||||
var widthInt;
|
||||
var heightInt;
|
||||
|
||||
if (width)
|
||||
{
|
||||
if (percentIndex > 0) {
|
||||
if (/%/.test(width)) {
|
||||
percent = true;
|
||||
widthInt = Number(width.substr(0, percentIndex));
|
||||
widthInt = Number(RegExp.leftContext);
|
||||
} else {
|
||||
percent = false;
|
||||
widthInt = Number(width);
|
||||
|
||||
@ -139,11 +139,10 @@ function InitImage()
|
||||
|
||||
// dialog.border.value = globalElement.getAttribute("border");
|
||||
var bv = GetHTMLOrCSSStyleValue(globalElement, "border", "border-top-width");
|
||||
var pxIndex = bv.search(/px/);
|
||||
if (pxIndex > 0)
|
||||
if (/px/.test(bv))
|
||||
{
|
||||
// Strip out the px
|
||||
bv = bv.substr(0, pxIndex);
|
||||
bv = RegExp.leftContext;
|
||||
}
|
||||
else if (bv == "thin")
|
||||
{
|
||||
|
||||
@ -57,7 +57,7 @@ function Startup()
|
||||
|
||||
editorShell.SelectElement(labelElement);
|
||||
gDialog.labelText.value = GetSelectionAsText();
|
||||
if (labelElement.innerHTML.match(/</))
|
||||
if (/</.test(labelElement.innerHTML))
|
||||
{
|
||||
gDialog.editText.checked = false;
|
||||
gDialog.editText.disabled = false;
|
||||
|
||||
@ -183,10 +183,9 @@ function onReplace()
|
||||
{
|
||||
if (selArray[i] != specArray[i])
|
||||
{
|
||||
if ( selArray[i][0].search(/\s/) == -1 ||
|
||||
specArray[i][0].search(/\s/) == -1)
|
||||
if ( /\S/.test(selArray[i][0]) || /\S/.test(specArray[i][0]) )
|
||||
{
|
||||
// lowercase \s, not a space chunk -- match fails
|
||||
// not a space chunk -- match fails
|
||||
matches = false;
|
||||
break;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user