git-svn-id: svn://euphorik.ch/pompage@45 02bbb61a-6d21-0410-aba0-cb053bdfd66a
[pompage.git] / doc / webdeveloper / common / array.js
diff --git a/doc/webdeveloper/common/array.js b/doc/webdeveloper/common/array.js
new file mode 100644 (file)
index 0000000..a70ad6d
--- /dev/null
@@ -0,0 +1,58 @@
+// Returns true if the array contains the element
+function webdeveloper_contains(array, element)
+{
+    // If the array and element are set
+    if(array && element)
+    {
+        try
+        {
+            // If the element does not exist in the array
+            if(array.indexOf(element) == -1)
+            {
+                return false;
+            }
+            else
+            {
+                return true;
+            }
+        }
+        catch(exception)
+        {
+            var arrayLength = array.length;
+
+            // Loop through the array
+            for(var i = 0; i < arrayLength; i++)
+            {
+                // If the element is found
+                if(array[i] == element)
+                {
+                    return true;
+                }
+            }
+        }
+    }
+
+    return false;
+}
+
+// Returns true if the array contains media with the given URL
+function webdeveloper_mediaArrayContains(array, url)
+{
+    // If the array and url are set
+    if(array && url)
+    {
+        var arrayLength = array.length;
+
+        // Loop through the array
+        for(var i = 0; i < arrayLength; i++)
+        {
+            // If media with the given URL is found
+            if(array[i].src == url)
+            {
+                return true;
+            }
+        }
+    }
+
+    return false;
+}