1
- var loudlinks = ( function ( ) {
2
-
1
+ var loudlinks = ( function ( document ) {
2
+
3
3
// Create audio element and make it awesome
4
4
var generateAudioElement = ( function ( ) {
5
5
var audioPlayer = document . createElement ( 'audio' ) ; // create the audio element
6
+ var source1 = document . createElement ( 'source' ) ; // creating a source element
7
+ var source2 = document . createElement ( 'source' ) ;
8
+
6
9
audioPlayer . id = 'loudLinksAudioPlayer' ; // give the audio element the proper id
7
10
audioPlayer . preload = true ; // audio element preload attribute
8
11
9
- var source1 = document . createElement ( 'source' ) ; // creating a source element
10
- var source2 = document . createElement ( 'source' ) ;
11
12
source1 . id = 'mp3Source' ;
12
13
source2 . id = 'oggSource' ;
13
14
@@ -42,6 +43,7 @@ var loudlinks = (function(){
42
43
var audioSrc = element . getAttribute ( 'data-src' ) ; // getting the sound name from the data-src Attribute
43
44
var soundMp3Link = mp3Location + audioSrc + '.mp3' ; // settnig the mp3 sound in a variable
44
45
var soundOggLink = oggLocation + audioSrc + '.ogg' ; // settnig the ogg sound in a variable
46
+
45
47
mp3Source . setAttribute ( 'src' , soundMp3Link ) ; // putting the mp3 sound link in the src Attribute of <source>
46
48
oggSource . setAttribute ( 'src' , soundOggLink ) ; // putting the mp3 sound link in the src Attribute of <source>
47
49
@@ -56,6 +58,7 @@ var loudlinks = (function(){
56
58
// checking if the data-src Attribute isn't empty
57
59
checkAttribute = function ( element ) {
58
60
var audioSrc = element . getAttribute ( 'data-src' ) ; // getting the sound name from the data-src Attribute
61
+
59
62
if ( audioSrc ) {
60
63
return true ;
61
64
} else {
@@ -106,20 +109,25 @@ var loudlinks = (function(){
106
109
107
110
// Go crazy! Scan all the links and see if they have the 'data-src' Attribute and do the events
108
111
runTrackers = function ( ) {
109
- for ( var i = 0 ; i < LoudLinksHover . length ; i ++ ) { // Hover
112
+ var i ;
113
+ var loudLinksHoverLength = LoudLinksHover . length ;
114
+ var loudLinksClickLength = LoudLinksClick . length ;
115
+
116
+ for ( i = 0 ; i < loudLinksHoverLength ; i ++ ) { // Hover
110
117
trackHover ( LoudLinksHover [ i ] ) ;
111
118
}
112
- for ( var i = 0 ; i < LoudLinksClick . length ; i ++ ) { // Click
119
+
120
+ for ( i = 0 ; i < loudLinksClickLength ; i ++ ) { // Click
113
121
trackClick ( LoudLinksClick [ i ] ) ;
114
122
}
115
123
}
116
124
117
125
// Check if the browser supports audio then get crazy!
118
- if ( checkAudioSupport ( ) ) {
126
+ if ( checkAudioSupport ( ) ) {
119
127
console . log ( 'Audio works like a charm 👍' ) ;
120
128
runTrackers ( ) ;
121
129
} else {
122
130
console . log ( 'Oh man 😩! \nI\'m sorry but your browsers doesn\'t support awesomeness.' )
123
131
}
124
132
125
- } ) ( ) ;
133
+ } ) ( document ) ;
0 commit comments