📄 aform.js
字号:
/*
==========================================================================
Module: AForm.js
==========================================================================
Pre-canned functions to map the user interface into JavaScripts.
==========================================================================
The Software, including this file, is subject to the End User License
Agreement.
Copyright (c) 1998, Adobe Systems Incorporated, All Rights Reserved.
==========================================================================
*/
// The following code "exports" any strings in the list into the current scope.
var esStrsToExport =["IDS_GREATER_THAN", "IDS_GT_AND_LT", "IDS_LESS_THAN", "IDS_INVALID_MONTH",
"IDS_INVALID_DATE", "IDS_INVALID_VALUE", "IDS_AM", "IDS_PM", "IDS_MONTH_INFO",
"IDS_STARTUP_CONSOLE_MSG"];
for(var n = 0; n < esStrsToExport.length; n++)
eval(esStrsToExport[n] + " = " + app.getString("EScript", esStrsToExport[n]).toSource());
console.println(IDS_STARTUP_CONSOLE_MSG);
RE_NUMBER_ENTRY_DOT_SEP = new Array(
"[+-]?\\d*\\.?\\d*"
);
RE_NUMBER_COMMIT_DOT_SEP = new Array(
"[+-]?\\d+(\\.\\d+)?", /* -1.0 or -1 */
"[+-]?\\.\\d+", /* -.1 */
"[+-]?\\d+\\." /* -1. */
);
RE_NUMBER_ENTRY_COMMA_SEP = new Array(
"[+-]?\\d*,?\\d*"
);
RE_NUMBER_COMMIT_COMMA_SEP = new Array(
"[+-]?\\d+([.,]\\d+)?", /* -1,0 or -1 */
"[+-]?[.,]\\d+", /* -,1 */
"[+-]?\\d+[.,]" /* -1, */
);
RE_ZIP_ENTRY = new Array(
"\\d{0,5}"
);
RE_ZIP_COMMIT = new Array(
"\\d{5}"
);
RE_ZIP4_ENTRY = new Array(
"\\d{0,5}(\\.|[- ])?\\d{0,4}"
);
RE_ZIP4_COMMIT = new Array(
"\\d{5}(\\.|[- ])?\\d{4}"
);
RE_PHONE_ENTRY = new Array(
"\\d{0,3}(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}", /* 555-1234 or 408 555-1234 */
"\\(\\d{0,3}", /* (408 */
"\\(\\d{0,3}\\)(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}", /* (408) 555-1234 */
/* (allow the addition of parens as an afterthought) */
"\\(\\d{0,3}(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}", /* (408 555-1234 */
"\\d{0,3}\\)(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}", /* 408) 555-1234 */
"011(\\.|[- \\d])*" /* international */
);
RE_PHONE_COMMIT = new Array(
"\\d{3}(\\.|[- ])?\\d{4}", /* 555-1234 */
"\\d{3}(\\.|[- ])?\\d{3}(\\.|[- ])?\\d{4}", /* 408 555-1234 */
"\\(\\d{3}\\)(\\.|[- ])?\\d{3}(\\.|[- ])?\\d{4}", /* (408) 555-1234 */
"011(\\.|[- \\d])*" /* international */
);
RE_SSN_ENTRY = new Array(
"\\d{0,3}(\\.|[- ])?\\d{0,2}(\\.|[- ])?\\d{0,4}"
);
RE_SSN_COMMIT = new Array(
"\\d{3}(\\.|[- ])?\\d{2}(\\.|[- ])?\\d{4}"
);
/* Function definitions for the color object. */
function ColorConvert(oColor, cColorspace)
{ // Converts a color to a specific colorspace.
var oOut = oColor;
switch (cColorspace) {
case "G":
// Note that conversion to the DeviceGray colorspace is lossy in the same
// way that a color signal on a B/W TV is lossy.
if (oColor[0] == "RGB")
oOut = new Array("G", 0.3 * oColor[1] + 0.59 * oColor[2] + 0.11 * oColor[3]);
else if (oColor[0] == "CMYK")
oOut = new Array("G", 1.0 - Math.min(1.0,
0.3 * oColor[1] + 0.59 * oColor[2] + 0.11 * oColor[3] + oColor[4]));
break;
case "RGB":
if (oColor[0] == "G")
oOut = new Array("RGB", oColor[1], oColor[1], oColor[1]);
else if (oColor[0] == "CMYK")
oOut = new Array("RGB", 1.0 - Math.min(1.0, oColor[1] + oColor[4]),
1.0 - Math.min(1.0, oColor[2] + oColor[4]),
1.0 - Math.min(1.0, oColor[3] + oColor[4]));
break;
case "CMYK":
if (oColor[0] == "G")
oOut = new Array("CMYK", 0, 0, 0, 1.0 - oColor[1]);
else if (oColor[0] == "RGB")
oOut = new Array("CMYK", 1.0 - oColor[1], 1.0 - oColor[2], 1.0 - oColor[3], 0);
break;
}
return oOut;
}
function ColorEqual(c1, c2)
{ // Compare two colors.
/* The gray colorspace conversion is lossy so we avoid if possible. */
if (c1[0] == "G")
c1 = color.convert(c1, c2[0]);
else
c2 = color.convert(c2, c1[0]);
/* Colorspace must be equal. */
if (c1[0] != c2[0]) {
return false;
}
/* Compare the individual components. */
var nComponents = 0;
switch (c1[0]) {
case "G":
nComponents = 1;
break;
case "RGB":
nComponents = 3;
break;
case "CMYK":
nComponents = 4;
break;
}
for (var i = 1; i <= nComponents; i++) {
if (c1[i] != c2[i]) {
return false;
}
}
return true;
}
/* ==== Convenience Objects ==== */
/* Stock color definitions for ease of use. */
color = new Object();
color.equal = ColorEqual;
color.convert = ColorConvert;
color.transparent = new Array("T");
color.black = new Array("G", 0);
color.white = new Array("G", 1);
color.dkGray = new Array("G", 0.25);
color.gray = new Array("G", 0.5);
color.ltGray = new Array("G", 0.75);
color.red = new Array("RGB", 1, 0, 0);
color.green = new Array("RGB", 0, 1, 0);
color.blue = new Array("RGB", 0, 0, 1);
color.cyan = new Array("CMYK", 1, 0, 0, 0);
color.magenta = new Array("CMYK", 0, 1, 0, 0);
color.yellow = new Array("CMYK", 0, 0, 1, 0);
/* Font definitions for ease of use */
font = new Object();
font.Times = "Times-Roman";
font.TimesB = "Times-Bold";
font.TimesI = "Times-Italic";
font.TimesBI = "Times-BoldItalic";
font.Helv = "Helvetica";
font.HelvB = "Helvetica-Bold";
font.HelvI = "Helvetica-Oblique";
font.HelvBI = "Helvetica-BoldOblique";
font.Cour = "Courier";
font.CourB = "Courier-Bold";
font.CourI = "Courier-Oblique";
font.CourBI = "Courier-BoldOblique";
font.Symbol = "Symbol";
font.ZapfD = "ZapfDingbats";
font.KaGo = "HeiseiKakuGo-W5-UniJIS-UCS2-H";
font.KaMi = "HeiseiMin-W3-UniJIS-UCS2-H";
/* Border style definitions for ease of use */
border = new Object();
border.s = "solid";
border.d = "dashed";
border.b = "beveled";
border.i = "inset";
border.u = "underline";
/* Radio/Check button style definitions for ease of use */
style = new Object();
style.ch = "check";
style.cr = "cross";
style.di = "diamond";
style.ci = "circle";
style.st = "star";
style.sq = "square";
/* highlight modes of on a push button */
highlight = new Object();
highlight.n = "none";
highlight.i = "invert";
highlight.p = "push";
highlight.o = "outline";
/* zoom types for a document */
zoomtype = new Object();
zoomtype.none = "NoVary";
zoomtype.fitW = "FitWidth";
zoomtype.fitH = "FitHeight";
zoomtype.fitP = "FitPage";
zoomtype.fitV = "FitVisibleWidth";
zoomtype.pref = "Preferred";
/* Cursor behavior in full screen mode. */
cursor = new Object();
cursor.visible = 0;
cursor.hidden = 1;
cursor.delay = 2;
/* Transition definitions. */
trans = new Object();
trans.blindsH = "BlindsHorizontal";
trans.blindsV = "BlindsVertical";
trans.boxI = "BoxIn";
trans.boxO = "BoxOut";
trans.dissolve = "Dissolve";
trans.glitterD = "GlitterDown";
trans.glitterR = "GlitterRight";
trans.glitterRD = "GlitterRightDown";
trans.random = "Random";
trans.replace = "Replace";
trans.splitHI = "SplitHorizontalIn";
trans.splitHO = "SplitHorizontalOut";
trans.splitVI = "SplitVerticalIn";
trans.splitVO = "SplitVerticalOut";
trans.wipeD = "WipeDown";
trans.wipeL = "WipeLeft";
trans.wipeR = "WipeRight";
trans.wipeU = "WipeUp";
/* Icon/Text placement. */
position = new Object();
position.textOnly = 0;
position.iconOnly = 1;
position.iconTextV = 2;
position.textIconV = 3;
position.iconTextH = 4;
position.textIconH = 5;
position.overlay = 6;
/* When does icon scale. */
scaleWhen = new Object();
scaleWhen.always = 0;
scaleWhen.never = 1;
scaleWhen.tooBig = 2;
scaleWhen.tooSmall = 3;
/* How does icon scale. */
scaleHow = new Object();
scaleHow.proportional = 0;
scaleHow.anamorphic = 1;
/* Field display. */
display = new Object();
display.visible = 0;
display.hidden = 1;
display.noPrint = 2;
display.noView = 3;
/* ==== Functions ==== */
/* these may be used a lot -- they are language independent */
AFDigitsRegExp = new RegExp();
AFDigitsRegExp.compile("\\d+");
AFPMRegExp = new RegExp();
AFPMRegExp.compile(IDS_PM, "i");
AFAMRegExp = new RegExp();
AFAMRegExp.compile(IDS_AM, "i");
AFTimeLongRegExp = new RegExp();
AFTimeLongRegExp.compile("\\d{1,2}:\\d{1,2}:\\d{1,2}");
AFTimeShortRegExp = new RegExp();
AFTimeShortRegExp.compile("\\d{1,2}:\\d{1,2}");
function AFBuildRegExps(array)
/* Takes an array of strings and turns it into an array of compiled regular
* expressions -- is used for the definitions that follow */
{
var retVal = new Array();
retVal.length = array.length;
for(var it = 0; it < array.length; it++)
{
retVal[it] = new RegExp();
retVal[it].compile(array[it], "i");
}
return retVal;
}
/* these may be used a lot -- they are NOT language independent and are
* derived from the localizable (RE_xxx) stuff above */
AFNumberDotSepEntryRegExp = AFBuildRegExps(RE_NUMBER_ENTRY_DOT_SEP);
AFNumberDotSepCommitRegExp = AFBuildRegExps(RE_NUMBER_COMMIT_DOT_SEP);
AFNumberCommaSepEntryRegExp = AFBuildRegExps(RE_NUMBER_ENTRY_COMMA_SEP);
AFNumberCommaSepCommitRegExp = AFBuildRegExps(RE_NUMBER_COMMIT_COMMA_SEP);
AFZipEntryRegExp = AFBuildRegExps(RE_ZIP_ENTRY);
AFZipCommitRegExp = AFBuildRegExps(RE_ZIP_COMMIT);
AFZip4EntryRegExp = AFBuildRegExps(RE_ZIP4_ENTRY);
AFZip4CommitRegExp = AFBuildRegExps(RE_ZIP4_COMMIT);
AFPhoneEntryRegExp = AFBuildRegExps(RE_PHONE_ENTRY);
AFPhoneCommitRegExp = AFBuildRegExps(RE_PHONE_COMMIT);
AFSSNEntryRegExp = AFBuildRegExps(RE_SSN_ENTRY);
AFSSNCommitRegExp = AFBuildRegExps(RE_SSN_COMMIT);
AFMonthsRegExp = AFBuildRegExps(IDS_MONTH_INFO.split(/\[\d+\]/));
function AFExactMatch(rePatterns, sString)
{ /* match a string against an array of RegExps */
var it;
if(!rePatterns.length && rePatterns.test(sString) && RegExp.lastMatch == sString)
return true;
for(it = 0; it < rePatterns.length; it++)
if(rePatterns[it].test(sString) && RegExp.lastMatch == sString)
return it + 1;
return 0;
}
function AFExtractNums(string)
{ /* returns an array of numbers that it managed to extract from the given
* string or null on failure */
var nums = new Array();
if (string.charAt(0) == '.' || string.charAt(0) == ',')
string = "0" + string;
while(AFDigitsRegExp.test(string)) {
nums.length++;
nums[nums.length - 1] = RegExp.lastMatch;
string = RegExp.rightContext;
}
if(nums.length >= 1) return nums;
return null;
}
function AFMakeNumber(string)
{ /* attempts to make a number out of a string that may not use '.' as the
* seperator; it expects that the number is fairly well-behaved other than
* possibly having a non-JavaScript friendly separator */
var type = typeof string;
if (type == "number")
return string;
if (type != "string")
return null;
var array = AFExtractNums(string);
if(array)
{
var joined = array.join(".");
if (string.indexOf("-.") >= 0)
joined = "0." + joined;
return joined * (string.indexOf("-") >= 0 ? -1.0 : 1.0);
}
else
return null;
}
function AFExtractRegExp(rePattern, string)
{ /* attempts to match the pattern given against the string given; on
* success, returns an array containing (at index 0) the initial
* string with the matched text removed and (at index 1) the matched
* text; on failure, returns null */
var retVal = new Array();
if(rePattern.test(string))
{
retVal.length = 2;
retVal[0] = RegExp.leftContext + RegExp.rightContext;
retVal[1] = RegExp.lastMatch;
return retVal;
}
return null;
}
function AFMakeArrayFromList(string)
{
var type = typeof string;
if(type == "string")
{
var reSep = new RegExp();
reSep.compile(",[ ]?");
return string.split(reSep);
}
return string;
}
function AFExtractTime(string)
{ /* attempts to extract a WELL FORMED time from a string; returned
* is an array in the same vein as AFExtractRegExp or null on
* failure. a WELL FORMED time looks like 12:23:56pm */
var pm = "";
var info;
info = AFExtractRegExp(AFPMRegExp, string);
if(info)
{
pm = info[1];
string = info[0];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -