git-svn-id: svn://euphorik.ch/pompage@45 02bbb61a-6d21-0410-aba0-cb053bdfd66a
[pompage.git] / doc / webdeveloper / common / array.js
1 // Returns true if the array contains the element
2 function webdeveloper_contains(array, element)
3 {
4 // If the array and element are set
5 if(array && element)
6 {
7 try
8 {
9 // If the element does not exist in the array
10 if(array.indexOf(element) == -1)
11 {
12 return false;
13 }
14 else
15 {
16 return true;
17 }
18 }
19 catch(exception)
20 {
21 var arrayLength = array.length;
22
23 // Loop through the array
24 for(var i = 0; i < arrayLength; i++)
25 {
26 // If the element is found
27 if(array[i] == element)
28 {
29 return true;
30 }
31 }
32 }
33 }
34
35 return false;
36 }
37
38 // Returns true if the array contains media with the given URL
39 function webdeveloper_mediaArrayContains(array, url)
40 {
41 // If the array and url are set
42 if(array && url)
43 {
44 var arrayLength = array.length;
45
46 // Loop through the array
47 for(var i = 0; i < arrayLength; i++)
48 {
49 // If media with the given URL is found
50 if(array[i].src == url)
51 {
52 return true;
53 }
54 }
55 }
56
57 return false;
58 }