|
From: <ch...@us...> - 2007-03-08 12:04:27
|
Revision: 9101
http://zaf.svn.sourceforge.net/zaf/?rev=9101&view=rev
Author: charlvn
Date: 2007-03-08 04:04:25 -0800 (Thu, 08 Mar 2007)
Log Message:
-----------
Cleaned Up JavaScript in Template
Modified Paths:
--------------
trunk/web/template/index.php
trunk/web/template/scripts/general.js
Added Paths:
-----------
trunk/web/template/scripts/3rdparty.js
Modified: trunk/web/template/index.php
===================================================================
--- trunk/web/template/index.php 2007-03-08 11:42:46 UTC (rev 9100)
+++ trunk/web/template/index.php 2007-03-08 12:04:25 UTC (rev 9101)
@@ -5,6 +5,7 @@
<link rel="stylesheet" type="text/css" href="/templates/translate/stylesheets/index.css" />
<link rel="alternate" type="application/rss+xml" title="Development Blog Entries" href="/blogs/dev/feed/" />
<link rel="alternate" type="application/rss+xml" title="Development Blog Comments" href="/blogs/dev/comments/feed/" />
+ <script type="text/javascript" src="/templates/translate/scripts/3rdparty.js"></script>
<script type="text/javascript" src="/templates/translate/scripts/general.js"></script>
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script>
<script type="text/javascript">
@@ -29,4 +30,4 @@
<div id="footer"><?php mosLoadModules("footer", -1); ?></div>
</div>
</body>
-</html>
\ No newline at end of file
+</html>
Added: trunk/web/template/scripts/3rdparty.js
===================================================================
--- trunk/web/template/scripts/3rdparty.js (rev 0)
+++ trunk/web/template/scripts/3rdparty.js 2007-03-08 12:04:25 UTC (rev 9101)
@@ -0,0 +1,47 @@
+/* === General Third-Party Library Functions === */
+
+// http://www.robertnyman.com/2005/11/07/the-ultimate-getelementsbyclassname/
+function getElementsByClassName(oElm, strTagName, oClassNames){
+ var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
+ var arrReturnElements = new Array();
+ var arrRegExpClassNames = new Array();
+ if(typeof oClassNames == "object"){
+ for(var i=0; i<oClassNames.length; i++){
+ arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames[i].replace(/\-/g, "\\-") + "(\\s|$)"));
+ }
+ }
+ else{
+ arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames.replace(/\-/g, "\\-") + "(\\s|$)"));
+ }
+ var oElement;
+ var bMatchesAll;
+ for(var j=0; j<arrElements.length; j++){
+ oElement = arrElements[j];
+ bMatchesAll = true;
+ for(var k=0; k<arrRegExpClassNames.length; k++){
+ if(!arrRegExpClassNames[k].test(oElement.className)){
+ bMatchesAll = false;
+ break;
+ }
+ }
+ if(bMatchesAll){
+ arrReturnElements.push(oElement);
+ }
+ }
+ return (arrReturnElements)
+}
+
+// http://simonwillison.net/2004/May/26/addLoadEvent/
+function addLoadEvent(func) {
+ var oldonload = window.onload;
+ if (typeof window.onload != 'function') {
+ window.onload = func;
+ } else {
+ window.onload = function() {
+ if (oldonload) {
+ oldonload();
+ }
+ func();
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/web/template/scripts/general.js
===================================================================
--- trunk/web/template/scripts/general.js 2007-03-08 11:42:46 UTC (rev 9100)
+++ trunk/web/template/scripts/general.js 2007-03-08 12:04:25 UTC (rev 9101)
@@ -1,82 +1,61 @@
-/* === General Functions === */
+/**
+ * General scripts for use on Translate.org.za
+ * Author: Charl van Niekerk <ch...@us...>
+ * Last Updated: 2007-03-08
+ * Copyright: 2007 Translate.org.za
+ * Licence: GNU/GPL - http://www.gnu.org/copyleft/gpl.html
+ */
-function getElementsByClassName(oElm, strTagName, oClassNames){
- var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
- var arrReturnElements = new Array();
- var arrRegExpClassNames = new Array();
- if(typeof oClassNames == "object"){
- for(var i=0; i<oClassNames.length; i++){
- arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames[i].replace(/\-/g, "\\-") + "(\\s|$)"));
- }
- }
- else{
- arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames.replace(/\-/g, "\\-") + "(\\s|$)"));
- }
- var oElement;
- var bMatchesAll;
- for(var j=0; j<arrElements.length; j++){
- oElement = arrElements[j];
- bMatchesAll = true;
- for(var k=0; k<arrRegExpClassNames.length; k++){
- if(!arrRegExpClassNames[k].test(oElement.className)){
- bMatchesAll = false;
- break;
- }
- }
- if(bMatchesAll){
- arrReturnElements.push(oElement);
- }
- }
- return (arrReturnElements)
-}
-
-function addLoadEvent(func) {
- var oldonload = window.onload;
- if (typeof window.onload != 'function') {
- window.onload = func;
- } else {
- window.onload = function() {
- if (oldonload) {
- oldonload();
- }
- func();
- }
- }
-}
-
/* === Ghost Text === */
-function ghosttextInit() {
- var e = getElementsByClassName(document, "input", "ghosttext");
-
- for (var i = 0; i < e.length; i++) {
- e[i].onfocus = ghosttextOnfocus;
- e[i].onblur = ghosttextOnblur;
- e[i].setAttribute("title", e[i].value);
- }
-}
-
+/**
+ * Event handler for onfocus on ghost text elements
+ */
function ghosttextOnfocus(e) {
- if (window && window.event && window.event.srcElement) {
+ // Get source element
+ if (window && window.event && window.event.srcElement) { // For IE
e = window.event.srcElement;
- } else {
+ } else { // For Firefox
e = e.currentTarget;
}
+
+ // If the value is the default, clear it
if (e.value == e.getAttribute("title")) {
e.value = "";
}
}
+/**
+ * Event handler for onblur on ghost text elements
+ */
function ghosttextOnblur(e) {
- if (window && window.event && window.event.srcElement) {
+ // Get source element
+ if (window && window.event && window.event.srcElement) { // For IE
e = window.event.srcElement;
- } else {
+ } else { // For Firefox
e = e.currentTarget;
}
+
+ // If the value is empty, fill it with default
if (e.value == "") {
e.value = e.getAttribute("title");
}
}
+
+/**
+ * Initialise the ghost text system by adding events to the elements with class "ghosttext"
+ */
+function ghosttextInit() {
+ // Get input elements tagged with class name "ghosttext"
+ var e = getElementsByClassName(document, "input", "ghosttext");
-/* === Set onload events === */
-addLoadEvent(ghosttextInit);
+ // Add event handlers to elements and back up default value in "title" attribute
+ for (var i = 0; i < e.length; i++) {
+ e[i].onfocus = ghosttextOnfocus;
+ e[i].onblur = ghosttextOnblur;
+ e[i].setAttribute("title", e[i].value);
+ }
+}
+
+// Add ghost text initialisation function to onload scripts
+addLoadEvent(ghosttextInit);
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|