Archive for the 'Coldfusion' Category

1328 Part V (Yahoo web hosting) . Putting JavaScript to Work

Saturday, January 5th, 2008

1328 Part V . Putting JavaScript to Work while (i < cLen) { var j = i + labelLen if (mycookie.substring(i,j) == label) { var cEnd = mycookie.indexOf( ; ,j) if (cEnd == -1) { cEnd = mycookie.length } return unescape(mycookie.substring(j,cEnd)) } i++ } return } A global variable is used to act as a speedy intermediary between the actual browser cookie and the functions here that need to access cookie data. The setCurrState() function contains a construction that you don t see much in this book, but is quite valid. Notice the three-piece assignment statement. Evaluation of this statement works from right to left. The rightmost expression concatenates a cookie label and the value passed in as a parameter to the function. Note, too, that the value is passed through the escape() function to properly URL-encode the data for the sake of data integrity (so that spaces and odd punctuation don t mess up the mechanism). The concatenated value is assigned to the document.cookie property. With the value safely dropped into the cookie (it may be just one of several name/value pairs for this domain), the value of the document.cookie property (which includes all name/value pairs for the domain) is assigned to the mycookie global variable. Retrieving information from the cookie still requires a bit of parsing to be on the safe side. If other cookie writing were to come from the current server path, more than one cookie would be available to the current document. Parsing the entire cookie for just the portion that corresponds to the currState labeled cookie ensures that the script gets only the data previously saved to that label. In an earlier version of this code, the frequent access to the document.cookie property inside the while loop of getCurrState() wasn t a problem until the sluggish cookie reading performance of NN4 got in the way. Adapting the code to use the global variable for the repetitive parsing of the cookie value rescued the day. The focal point The toggle() function, which is pivotal in this outline scheme, receives as a parameter the index number of the db array element whose content the user just clicked. The purpose of this function is to grab a copy of the current outline state from the cookie, alter the binary representation of the clicked item, and feed the revised binary number back to the cookie (where it governs the display of the outline after the document reloads): // **function that updates persistent storage of state** // toggles an outline mother entry, storing new value in the cookie function toggle(n) { var newString = var currState = getCurrState()
You want to have a cheap webhost for your apache application, then check apache web hosting services.

1327Chapter 52 .Application: Outline-Style (Database web hosting) Table of Contents property

Friday, January 4th, 2008

1327Chapter 52 .Application: Outline-Style Table of Contents property in the brackets, you instruct JavaScript to walk the ladder upward from zero. If you move things around the outline, however, don t forget to adjust the indentation levels if they are affected by the content changes. The bottom of the array creation section marks the end of the code that you need to modify after you deploy the outliner. The rest of the JavaScript code works silently for you, but if you intend to perform further customizations to the outliner, understanding how it all works will help. On to the constructor function for the dbRecord entries: This function is the classic JavaScript way to build a custom object (see Chapter 41): // object constructor for each outline entry // (see object-building calls, below) function dbRecord(mother,display,URL,indent,statusMsg){ this.mother = mother // is this item a parent? this.display = display // text to display this.URL = URL // link tied to text; no link for empty string this.indent = indent // how deeply nested? this.statusMsg = statusMsg // descriptive text for status bar return this } To preload all the images into the browser s image cache, you create new Image objects for each and assign the filenames to their srcproperties. Notice that these statements are not in functions, but rather execute as the page loads: // pre-load all images into cache var fillerImg = new Image(1,1) fillerImg.src = filler.gif var collapsedImg = new Image(widgetWidth,widgetHeight) collapsedImg.src = collapsedWidget var expandedImg = new Image(widgetWidth,widgetHeight) expandedImg.src = expandedWidget var endpointImg = new Image(widgetWidth,widgetHeight) endpointImg.src = endpointWidget Cookie storage To preserve the binary digit string between redraws of the outline, this script must save the string to a place that won t be overwritten or emptied during the document reload. The document.cookie fills that requirement nicely. Excerpting and adapting parts of Bill Dortch s cookie functions (see Chapter 18), this script simplifies the writing of a cookie that disappears when the user quits the browser: // ** functions that get and set persistent cookie data ** // set cookie data var mycookie = document.cookie function setCurrState(setting) { mycookie = document.cookie = currState= + escape(setting) } // retrieve cookie data function getCurrState() { var label = currState= var labelLen = label.length var cLen = mycookie.length var i = 0
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.

1326 Part V . Putting JavaScript to Work (Ecommerce web host)

Friday, January 4th, 2008

1326 Part V . Putting JavaScript to Work custom objects. The dbRecordarray (defined in the following listing) helps populate the db array with specifics provided in the comma-delimited statements here: // Create array object containing outline content and attributes. // To adapt outline for your use, modify this table. // Start the array with [1], and continue without gaps to your last item. // The order of the five parameters: // 1. Boolean (true or false) whether _next_ item is indented. // 2. String to display in outline entry (including tags). // 3. URL of link for outline entry; Use empty string ( ) for no link // 4. Integer of indentation level (0 is leftmost margin level) // 5. String for status line onMouseOver (apostrophes require \ ) var db = new Array() db[db.length] = new dbRecord(true, Peas , ,0, ) db[db.length] = new dbRecord(false, Boiled , foods.htm#boiled , 1, Mmm, boiled peas… ) db[db.length] = new dbRecord(true, Canned , foods.htm#canned , 1, Check out canned peas… ) db[db.length] = new dbRecord(false, Alaska , foods.htm#alaska , 2, Alaska\ s finest… ) db[db.length] = new dbRecord(false, Low-Sodium , foods.htm#losodium , 2, A healthy treat… ) db[db.length] = new dbRecord(true, Pickles , ,0, ) db[db.length] = new dbRecord(true, Cucumber , foods.htm#cucumber , 1, What\ s new in cukes… ) db[db.length] = new dbRecord(false, Dill , foods.htm#dill , 2, Pucker up… ) db[db.length] = new dbRecord(false, Fresh , foods.htm#fresh , 2, You\ d prefer stale? ) db[db.length] = new dbRecord(false, Sour , foods.htm#sour , 2, For sweeties… ) // add more records to complete your outline // ** END AUTHOR-ADJUSTABLE SPECIFICATIONS **// Each record consists of five items. The first item is a Boolean value, which denotes whether the item is a mother item (that is, the next item in the list is nested one level deeper). The HTML that displays in the outline comes next. This text can be multiple-word strings, or any HTML that you like (some users have assigned tags to show pictures instead of text). For the third item, you can insert any valid URL, whether it be to a separate site, an anchor in another document (as shown here), or even a javascript:URL to execute another function. If you don t want an entry in the outline to be a link just plain, flat text leave this third item as an empty string, as I do here for the topmost items in both categories. The fourth item is a number representing how many nested levels the item has. And finally, the last item is a string containing the text that appears in the statusbar when the user rolls the mouse over the item in the outline. Because of a quirk in the way the statusbar responds to quoted characters, any string literal character (normally preceded with a backslash) requires two backslashes (one to alert the browser of the other). Be sure to keep the items for the db array in the same top-to-bottom order as you d expect to see in a fully expanded outline. Notice that the index values of the array are automatically inserted for you: The length property of an array is always one more than the highest index. By inserting references to the db.length
We recommend high quality webhost to host and run your jsp application: christian web host services.

1325Chapter 52 .Application: Outline-Style Table of Contents To (Web server version)

Thursday, January 3rd, 2008

1325Chapter 52 .Application: Outline-Style Table of Contents To help me visualize the inner workings of these scripts, I developed a convention that calls any item with nested items beneath it a mother. Any nested item is that mother s daughter. A daughter can also be a mother if it has an item nested beneath it. You see how this plays out in the code shortly. The food outline document starts out simply enough, with the standard opening of a JavaScript script. The first specification set apart for easy modification is the size of the indentation level in pixels. Food Selection Outline To gain a better understanding of how the script assembles the HTML for this part of the table, start by looking at the colSpacervariable. This variable contains a table cell definition that must span all but the rightmost two columns. Thus, the
Please visit Domain Name Hosting services for high quality webhost to host and run your jsp applications.