1- <!DOCTYPE html>
2- < html lang ="en ">
3- < head >
4- < meta charset ="utf-8 ">
5- < title > Subtle Pattern Demo</ title >
6- < style >
7- body , html { padding : 0 ;margin : 0 ;height : 100% ; }
8- body { background : # ccc none repeat 0 0 ; }
9- form { padding : 10px ;text-align : center;background : # FFF ;border-bottom : 1px solid # 000 ; }
10- </ style >
11- </ head >
12- < body >
13- < form >
14- < select id ="image ">
15- < option selected > Downloading Pattern Names...</ option >
16- </ select >
17- </ form >
18-
19- < script src ="http://code.jquery.com/jquery.min.js "> </ script >
20- < script >
21- $ ( document ) . ready ( function ( ) {
22-
23- var pattern_selector = $ ( '#image' )
24- body_tag = $ ( 'body' ) ;
25-
26- // make an ajax request to find all the file names
27- $ . getJSON ( 'https://api.github.com/repos/subtlepatterns/SubtlePatterns/contents?callback=?' , function ( files ) {
28- // http://baylorrae.com/prevent-dom-reflow/
29- var items = document . createDocumentFragment ( ) ,
30- item , file ;
31-
32- // loop through all files in the repo
33- for ( var i = 0 , len = files . data . length ; i < len ; i ++ ) {
34- file = files . data [ i ] ;
35-
36- // skip over non image files
37- if ( / \. ( p n g | j p g | j p e g ) $ / . test ( file [ "path" ] ) == false ) {
38- continue ;
39- }
40-
41- // create the option tag and use the raw image url
42- item = $ ( '<option />' , {
43- value : file [ "_links" ] [ "html" ] . replace ( 'blob' , 'raw' ) ,
44- text : file [ "path" ]
45- } ) [ 0 ] ;
46-
47- items . appendChild ( item ) ;
48- }
49-
50- // update the dropdown menu
51- pattern_selector . find ( 'option' ) . remove ( ) ;
52- pattern_selector . append ( items ) ;
53- pattern_selector . change ( ) ;
54- } ) ;
55-
56- // bind an event to change the body background image
57- pattern_selector . change ( function ( ) {
58- body_tag . css ( 'background-image' , 'url(' + this . value + ')' ) ;
59- } ) ;
60-
61- } ) ;
62- </ script >
63- </ body >
1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="utf-8 ">
5+ < title > Subtle Pattern Demo</ title >
6+ < style >
7+ body , html { padding : 0 ;margin : 0 ;height : 100% ; }
8+ body { background : # ccc none repeat 0 0 ; }
9+ form { padding : 10px ;text-align : center;background : # FFF ;border-bottom : 1px solid # 000 ; }
10+ </ style >
11+ </ head >
12+ < body >
13+ < form >
14+ < select id ="image ">
15+ < option selected > Downloading Pattern Names...</ option >
16+ </ select >
17+ </ form >
18+
19+ < script src ="http://code.jquery.com/jquery.min.js "> </ script >
20+ < script >
21+ $ ( document ) . ready ( function ( ) {
22+
23+ var pattern_selector = $ ( '#image' )
24+ body_tag = $ ( 'body' ) ;
25+
26+ // make an ajax request to find all the file names
27+ $ . getJSON ( 'https://api.github.com/repos/subtlepatterns/SubtlePatterns/contents?callback=?' , function ( files ) {
28+ // http://baylorrae.com/prevent-dom-reflow/
29+ var items = document . createDocumentFragment ( ) ,
30+ item , file ;
31+
32+ // loop through all files in the repo
33+ for ( var i = 0 , len = files . data . length ; i < len ; i ++ ) {
34+ file = files . data [ i ] ;
35+
36+ // skip over non image files
37+ if ( / \. ( p n g | j p g | j p e g ) $ / . test ( file [ "path" ] ) == false ) {
38+ continue ;
39+ }
40+
41+ // create the option tag and use the raw image url
42+ item = $ ( '<option />' , {
43+ value : file [ "_links" ] [ "html" ] . replace ( 'blob' , 'raw' ) ,
44+ text : file [ "path" ]
45+ } ) [ 0 ] ;
46+
47+ items . appendChild ( item ) ;
48+ }
49+
50+ // update the dropdown menu
51+ pattern_selector . find ( 'option' ) . remove ( ) ;
52+ pattern_selector . append ( items ) ;
53+ pattern_selector . change ( ) ;
54+ } ) ;
55+
56+ // bind an event to change the body background image
57+ pattern_selector . change ( function ( ) {
58+ body_tag . css ( 'background-image' , 'url(' + this . value + ')' ) ;
59+ } ) ;
60+
61+ } ) ;
62+ </ script >
63+ </ body >
6464</ html >
0 commit comments