elements containing that content's hit-or-miss status to reflect the new numbers. * * Pre-conditions: * The following arguments are expected: * contentTypeId REQUIRED The numeric content type of the content. * contentId REQUIRED The Id of the content. * hits REQUIRED The number of positive ratings earned. * misses REQUIRED The number of negative ratings earned. * rating REQUIRED The overall derived (i.e. calculated) rating earned. * isHit REQUIRED True if the content is a hit, false if it is a miss. * message REQUIRED A message to display to the user. Can be empty. * Additionally, the HTML id properties of the
tags holding the ratings must be as follows: * The id must consist of a set of key-value pairs, with each key separated from its value * by a colon (":"). The pairs are separated from each other by a hyphen ("-"). The pairs * should be as follows: * 1: rating:hitOrMiss * 2: type:hit or type:miss or type:rating or type:message * 3: contentTypeId:43 (value for example only) * 4: contentId:23862 (value for example only) * 5: hash:1 (value for example only) * The "hash" key is an alphanumeric suffix to allow for uniqueness, since HTML does not * allow identical ID properties on different elements in the same document. * Example HTML snippet for content with 34 misses: * Misses:
34
* * Post-conditions: * Updates any onscreen displays of the given content's numeric hit-or-miss status. * * Libraries: * html_element_search.js * * Log: * Randall Betta 11/07/2006 * - Creation * */ function updateHitOrMissDisplays(contentTypeId, contentId, hits, misses, rating, isHit, message) { // HTML elements with nodeValues of numeric hit or miss counts, or rating totals. var hitElts; var missElts; var ratingElts; var hitGraphicElts; var missGraphicElts; // Regexes that describe the IDs of HTML elements to change. var hitEltRegex = 'rating\:hitOrMiss\-type\:hit\-contentTypeId\:' + contentTypeId + '\-contentId\:' + contentId + '\-hash\:([A-Za-z0-9])*'; var hitGraphicRegex = 'rating\:hitOrMiss\-type\:hitGraphic\-contentTypeId\:' + contentTypeId + '\-contentId\:' + contentId + '\-hash\:([A-Za-z0-9])*'; var missEltRegex = 'rating\:hitOrMiss\-type\:miss\-contentTypeId\:' + contentTypeId + '\-contentId\:' + contentId + '\-hash\:([A-Za-z0-9])*'; var missGraphicRegex = 'rating\:hitOrMiss\-type\:missGraphic\-contentTypeId\:' + contentTypeId + '\-contentId\:' + contentId + '\-hash\:([A-Za-z0-9])*'; var ratingEltRegex = 'rating\:hitOrMiss\-type\:rating\-contentTypeId\:' + contentTypeId + '\-contentId\:' + contentId + '\-hash\:([A-Za-z0-9])*'; // Counters and temporary variables. var eltIndex; var elt; // Obtain separate arrays of all
elements containing hit, miss, // and rating numbers, as well as messages to be displayed. hitElts = getRelatedElements('div', hitEltRegex, true, true); missElts = getRelatedElements('div', missEltRegex, true, true); ratingElts = getRelatedElements('div', ratingEltRegex, true, true); hitGraphicElts = getRelatedElements('div', hitGraphicRegex, true, true); missGraphicElts = getRelatedElements('div', missGraphicRegex, true, true); // Update the numeric hit displays. for (eltIndex = hitElts.length - 1; eltIndex >= 0; eltIndex--) { // For: HTML hit elements. // Store current hit element. elt = hitElts[eltIndex]; // Update its contents. try { if (elt.firstChild) { elt.firstChild.nodeValue = hits; } else { elt.appendChild(document.createTextNode(hits)); } } catch (exc) { ; } // Silently fail on a JavaScript permissions error. } // End for: iteration through HTML hit elements. // Update the numeric miss displays. for (eltIndex = missElts.length - 1; eltIndex >= 0; eltIndex--) { // For: HTML miss elements. // Store current miss element. elt = missElts[eltIndex]; // Update its contents. try { if (elt.firstChild) { elt.firstChild.nodeValue = misses; } else { elt.appendChild(document.createTextNode(misses)); } } catch (exc) { ; } // Silently fail on a JavaScript permissions error. } // End for: iteration through HTML miss elements. // Update the numeric rating displays. for (eltIndex = ratingElts.length - 1; eltIndex >= 0; eltIndex--) { // For: HTML rating elements. // Store current rating element. elt = ratingElts[eltIndex]; // Update its contents. try { if (elt.firstChild) { elt.firstChild.nodeValue = rating; } else { elt.appendChild(document.createTextNode(rating)); } } catch (exc) { ; } // Silently fail on a JavaScript permissions error. } // End for: iteration through HTML miss elements. // Update the graphical hit displays. for (eltIndex = hitGraphicElts.length - 1; eltIndex >= 0; eltIndex--) { // For: hit graphic elements. // Store current hit graphic element. elt = hitGraphicElts[eltIndex]; // Update its visibility. try { elt.style.display = (isHit == 1) ? 'block' : 'none'; } catch (exc) { ; } // Silently fail on a JavaScript permissions error. } // End for: iteration through hit graphic elements. // Update the graphical miss displays. for (eltIndex = missGraphicElts.length - 1; eltIndex >= 0; eltIndex--) { // For: miss graphic elements. // Store current miss graphic element. elt = missGraphicElts[eltIndex]; // Update its visibility. try { elt.style.display = (isHit != 1) ? 'block' : 'none'; } catch (exc) { ; } // Silently fail on a JavaScript permissions error. } // End for: iteration through miss graphic elements. // Update the message displays. message = (message) ? message : ''; displayRatingMessages (contentTypeId, contentId, message); return; } // End function: updateHitOrMissDisplays /* * Name: * displayRatingMessages * * Description: * Displays a message to the user regarding rating a given piece of content. * * Pre-conditions: * The following arguments are expected: * contentTypeId REQUIRED The numeric content type of the content. * contentId REQUIRED The Id of the content. * message REQUIRED A message to display to the user. Can be empty. * * Post-conditions: * Updates any onscreen displays of the given content's rating messages. * * Libraries: * html_element_search.js * * Log: * Randall Betta 11/14/2006 * - Creation * */ function displayRatingMessages(contentTypeId, contentId, message) { // HTML elements with text nodes to store the message. var messageElts; var messageEltId; // Regexes that describe the IDs of HTML elements to change. var messageEltRegex = 'rating\:hitOrMiss\-type\:message\-contentTypeId\:' + contentTypeId + '\-contentId\:' + contentId + '\-hash\:([A-Za-z0-9])*'; // Counters and temporary variables. var eltIndex; var elt; // Obtain separate arrays of all
elements containing messages to be displayed. messageElts = getRelatedElements('div', messageEltRegex, true, true); // Update the message displays. message = (message) ? message : ''; for (eltIndex = messageElts.length - 1; eltIndex >= 0; eltIndex--) { // For: HTML message elements. // Store current rating element. elt = messageElts[eltIndex]; // Update its contents. try { if (elt.firstChild) { elt.firstChild.nodeValue = message; } else { elt.appendChild(document.createTextNode(message)); } messageEltId = elt.id; document.getElementById(messageEltId).style.display = 'block'; window.setTimeout("document.getElementById('" + messageEltId + "').style.display = 'none';", 3000); } catch (exc) { ; } // Silently fail on a JavaScript permissions error. } // End for: iteration through HTML message elements. return messageElts; } // End function: displayRatingMessages