1
+ /**********************************************************************
2
+ Generates a random placeholder image for a speaker
3
+
4
+ css: css class for <img> element
5
+ name: identifier for the speaker that gets hashed
6
+ path: the path to the image with a # for the image. # gets replaced
7
+ alt: alt text for the image
8
+ num: total number of placeholder image options for modulo
9
+ ***********************************************************************/
10
+
11
+ function placeholderImage ( css , name , path , alt , num ) {
12
+ const hashCode = function ( str ) {
13
+ if ( Array . prototype . reduce ) {
14
+ return str . split ( "" ) . reduce ( function ( a , b ) { a = ( ( a << 5 ) - a ) + b . charCodeAt ( 0 ) ; return a & a } , 0 ) ;
15
+ } else {
16
+ var hash = 0 , i , chr , len ;
17
+ if ( str . length == 0 ) return hash ;
18
+ for ( i = 0 , len = str . length ; i < len ; i ++ ) {
19
+ chr = str . charCodeAt ( i ) ;
20
+ hash = ( ( hash << 5 ) - hash ) + chr ;
21
+ hash |= 0 ; // Convert to 32bit integer
22
+ }
23
+ return hash ;
24
+ }
25
+ } ;
26
+
27
+ var output = '<img ' ;
28
+ output += 'class="' + css + '" ' ;
29
+ output += 'alt="' + alt + '" ' ;
30
+ output += 'src="' + path . replace ( '#' , Math . abs ( hashCode ( name ) ) % 10 ) + '" ' ;
31
+ output = output . trim ( ) + '>' ;
32
+ document . write ( output ) ;
33
+ }
0 commit comments