Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Web Design & Development > PHP/MySQL/Scripting

JavaScript Usage in the GoLive Environment

This chapter discusses JavaScript and ECMAScript/ExtendScript concepts and usage in GoLive. Topics covered include JavaScript objects in the GoLive environment, the scope of variables and functions, and delays and timeouts.
This chapter is from the book

This chapter discusses JavaScript and ECMAScript/ExtendScript concepts and usage in GoLive, including:

  • JavaScript Objects in the GoLive Environment
  • Scope of Variables and Functions
  • Handling Events
  • Sharing Data
  • Delays and Timeouts

JavaScript Objects in the GoLive Environment

GoLive provides access to data and objects in a way that JavaScript programmers will find familiar. Those new to JavaScript will discover that the GoLive environment usually provides multiple ways to access data and objects. This section describes various ways an extension’s JavaScript code can access data and objects in the GoLive environment.

Objects, elements, and properties

GoLive JavaScript objects can represent parts of a document, or GoLive components:

  • When GoLive loads a markup document, it generates objects to represent the markup tree of a document. Collectively, the objects that represent portions of the markup document are known as markup objects. Markup objects can represent HTML markup elements (as defined by a tag and its attributes), and also comments, text blocks, and other types of markup such as entities or CDATA sections.
  • When GoLive loads an extension definition file (that is, the Main.html file for your extension), it creates JavaScript objects to represent the GoLive components you define, such as windows, UI controls, and menu items. For example, a <jsxdialog> element in your extension definition results in a window Object (page 313).

There are various ways to obtain a reference to a JavaScript object, depending on the object’s type.

  • You can retrieve most component objects by name from global properties, such as the menus and dialogs collections.
  • Objects that represent HTML page content are available from the markup tree; you get the root object from the document Object (page 138) for the page (document.documentElement), and that object’s properties and methods allow you to navigate the tree.
  • GoLive passes relevant objects as event-object property values to event-handling functions.

For information on retrieving a particular object, see that object’s description in the GoLive CS2 SDK Programmer’s Reference.

Accessing attribute values

The attributes of an element (whether it is a document markup element or an element in your extension definition) appear as the properties of the corresponding JavaScript object. For example, the name attribute of the element becomes the name property of the object. Access to JavaScript properties is case-sensitive; that is, the Thing attribute creates the Thing property, not the thing property. When writing JavaScript code, observe case accordingly.

JavaScript uses the symbol undefined to indicate a null state. When a property exists, but no value has been explicitly set, that property has a value of undefined. If a property has never been defined, its state (rather than its value) is undefined. To test whether a property exists in JavaScript, you must test the state (not the value), by checking whether the name has a defined type; for example:

// correct test
if (typeof (myProperty) != undefined)
// do something

Do not use the following test. This tests the property’s value, rather than its state, and results in a run-time error if the property does not exist:

// incorrect test
if (myProperty != undefined)
// if myProperty does not exist, an error occurs

When you must test a property’s value with a case-sensitive comparison, you can use the toLowerCase method of the JavaScript String object. For example, this tests an element object’s tagName property, disregarding the value’s case:

if (currElt.tagName.toLowerCase()) ==
(tagToGet.toLowerCase())

For element Objects (page 156), attributes are also represented by objects, which are themselves nodes in the markup tree. Use an element object’s getAttributeNode and setAttributeNode functions (page 157) to access the attribute object, rather than accessing the attribute directly by name, as a property of the element object. By using these methods, you avoid potential problems with referencing names that contain special characters, such as hyphens.

Naming objects and attributes

The value of an element’s name attribute must follow JavaScript naming conventions. If more than one element or object uses the same name, the results of name-based object retrieval are unpredictable, so you must take care to ensure that your names are unique. One way to do this is to use a unique prefix or postfix in all of your extension’s names. For example, the following element definitions begin the value of each element’s name attribute with the letters ADBE.

<jsxmenubar> // opens definition of all menus
  <jsxmenu name="Hello" title="Hello, GoLive!"> //Hello menu
   <jsxitem name="This" title="Do Something"> // menu item
   <jsxitem name="That" title="Do Something Else" > menu item
  </jsxmenu> // closes definition of Hello menu
</jsxmenubar> // closes definition of all menus

When the SDK loads an extension containing these elements, it creates a menu object that appears in the JavaScript global menus collection. You can use the name to retrieve this menu from the collection:

var myMenu = menubar["ADBEHello"];

JavaScript object collections

The SDK makes commonly used objects available as the elements of array-like structures that all extensions can access. GoLive updates the contents of these structures dynamically as these objects are created and deleted.

The SDK implements many of these structures as collection Objects (page 72). This is like an array that provides access to its elements by name or index; however, collections are not actually arrays; not every collection provides numeric access to its elements, as an array object does.

Each of these global properties contains a collection object that GoLive updates dynamically:

Using the global object arrays

These examples use the menus array to illustrate how you retrieve objects from global arrays. These arraya provide access to all of the menus and menu items added to GoLive by extensions. Most of the arrays work the same way; exceptions are noted in the Programmer’s Reference, Part 2 of this book.

The following JavaScript defines a menu Sample, with one item, MyItem. The SDK creates a menu object named sample and a menuitem object named item1:

<jsxmenu name="sample" title="Sample" ...>
   <jsxitem name="item1" title="MyItem" ...>
</jsxmenu>

The following retrieves the Sample menu from the menuCollection object in the menubar global variable, and stores the retrieved menu object in the sampleMenu variable:

var sampleMenu = menubar["sample"]

In this case, “Sample” is the title of the menu, as displayed to the user, while “sample” is the name of the menu object, which you use to access it programmatically.

The following retrieves the menu item by name from the collection in the items property the sample menu:

menubar["sample"].items["item1"]

Alternatively, you can retrieve the menu item directly, using its name as a property name of the sample menu:

menubar["sample"].item1

GoLive also makes each menu available as a JavaScript object in the global namespace. Thus, the following simple line of JavaScript retrieves the menu item from the sample menu.

sample.item1

Many collections can be accessed by numeric index as well as by name. For example, if item1 is the first menu item:

menubar["sample"].items[0] // 0-based index of first item

This is only reliable for the items, not for menus; because other extensions can also add menus, you cannot rely on the order. Some collections, like the controls collection, do not support numeric access at all. Most of the time, an object’s unique name property provides the most reliable way to retrieve it.

Comparing objects

To ascertain an object’s identity, you can compare the value of its name property to a known string, or you can compare object references directly. For example, you can test the name of a menu item in any of the following ways:

if (item.name == "item1") // compare object name to known
string value
if (item == menubar["sample"].items["item1"]) // compare
objects
if (item == sample.item1) // another object comparison
example

Updating references to objects

GoLive generates objects to represent the markup tree of a document when it loads that document. It regenerates these objects if the document changes; this is know as reparsing the document. If you save a reference to an object that GoLive generated as the result of interpreting a markup tag, you must update that reference any time the document containing the tag changes. For details, see the full version of the Programmer’s Guide on the product CD.

Peachpit Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from Peachpit and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about Peachpit products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites; develop new products and services; conduct educational research; and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email ask@peachpit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by Adobe Press. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.peachpit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020