Changeset 592588
- Timestamp:
- 08/30/2012 07:31:28 PM (14 years ago)
- Location:
- css-refresh-automatically/trunk
- Files:
-
- 3 edited
-
css-refresh.js (modified) (1 diff)
-
css-refresh.php (modified) (2 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
css-refresh-automatically/trunk/css-refresh.js
r588032 r592588 1 1 /* 2 2 3 * CSSrefresh v1.0.1 4 3 5 * 6 4 7 * Copyright (c) 2012 Fred Heusschen 8 5 9 * www.frebsite.nl 10 6 11 * 12 7 13 * Dual licensed under the MIT and GPL licenses. 14 8 15 * http://en.wikipedia.org/wiki/MIT_License 16 9 17 * http://en.wikipedia.org/wiki/GNU_General_Public_License 18 10 19 */ 11 20 21 22 12 23 (function() { 13 24 25 26 14 27 var phpjs = { 15 28 29 30 16 31 array_filter: function( arr, func ) 17 { 32 33 { 34 18 35 var retObj = {}; 36 19 37 for ( var k in arr ) 20 { 38 39 { 40 21 41 if ( func( arr[ k ] ) ) 22 { 42 43 { 44 23 45 retObj[ k ] = arr[ k ]; 24 } 25 } 46 47 } 48 49 } 50 26 51 return retObj; 52 27 53 }, 54 28 55 filemtime: function( file ) 29 { 56 57 { 58 30 59 var headers = this.get_headers( file, 1 ); 60 31 61 return ( headers && headers[ 'Last-Modified' ] && Date.parse( headers[ 'Last-Modified' ] ) / 1000 ) || false; 62 32 63 }, 64 33 65 get_headers: function( url, format ) 66 34 67 { 68 35 69 var req = window.ActiveXObject ? new ActiveXObject( 'Microsoft.XMLHTTP' ) : new XMLHttpRequest(); 70 36 71 if ( !req ) 37 { 72 73 { 74 38 75 throw new Error('XMLHttpRequest not supported.'); 39 } 76 77 } 78 79 40 80 41 81 var tmp, headers, pair, i, j = 0; 42 82 83 84 43 85 try 44 { 86 87 { 88 45 89 req.open( 'HEAD', url, false ); 90 46 91 req.send( null ); 92 47 93 if ( req.readyState < 3 ) 48 { 94 95 { 96 49 97 return false; 50 } 98 99 } 100 51 101 tmp = req.getAllResponseHeaders(); 102 52 103 tmp = tmp.split( '\n' ); 104 53 105 tmp = this.array_filter( tmp, function ( value ) 54 { 106 107 { 108 55 109 return value.toString().substring( 1 ) !== ''; 110 56 111 }); 112 57 113 headers = format ? {} : []; 114 58 115 116 59 117 for ( i in tmp ) 60 { 118 119 { 120 61 121 if ( format ) 122 62 123 { 124 63 125 pair = tmp[ i ].toString().split( ':' ); 126 64 127 headers[ pair.splice( 0, 1 ) ] = pair.join( ':' ).substring( 1 ); 128 65 129 } 130 66 131 else 132 67 133 { 134 68 135 headers[ j++ ] = tmp[ i ]; 136 69 137 } 70 } 138 139 } 140 71 141 142 72 143 return headers; 73 } 144 145 } 146 74 147 catch ( err ) 75 { 148 149 { 150 76 151 return false; 77 } 152 153 } 154 78 155 } 156 79 157 }; 80 158 159 160 81 161 var cssRefresh = function() { 82 162 163 164 83 165 this.reloadFile = function( links ) 84 { 166 167 { 168 85 169 for ( var a = 0, l = links.length; a < l; a++ ) 86 { 170 171 { 172 87 173 var link = links[ a ], 174 88 175 newTime = phpjs.filemtime( this.getRandom( link.href ) ); 89 176 177 178 90 179 // has been checked before 180 91 181 if ( link.last ) 92 { 182 183 { 184 93 185 // has been changed 186 94 187 if ( link.last != newTime ) 188 95 189 { 190 96 191 // reload 192 97 193 link.elem.setAttribute( 'href', this.getRandom( this.getHref( link.elem ) ) ); 194 98 195 } 99 } 196 197 } 198 199 100 200 101 201 // set last time checked 202 102 203 link.last = newTime; 103 } 204 205 } 206 104 207 setTimeout( function() 105 { 208 209 { 210 106 211 this.reloadFile( links ); 212 107 213 }, 1000 ); 214 108 215 }; 109 216 217 218 110 219 this.getHref = function( f ) 111 { 220 221 { 222 112 223 return f.getAttribute( 'href' ).split( '?' )[ 0 ]; 224 113 225 }; 226 114 227 this.getRandom = function( f ) 115 { 228 229 { 230 116 231 return f + '?x=' + Math.random(); 232 117 233 }; 118 234 119 235 236 237 238 120 239 var files = document.getElementsByTagName( 'link' ), 240 121 241 links = []; 122 242 243 244 123 245 for ( var a = 0, l = files.length; a < l; a++ ) 246 124 247 { 248 125 249 var elem = files[ a ], 250 126 251 rel = elem.rel; 252 127 253 if ( typeof rel != 'string' || rel.length == 0 || rel == 'stylesheet' ) 128 { 254 255 { 256 129 257 links.push({ 258 130 259 'elem' : elem, 260 131 261 'href' : this.getHref( elem ), 262 132 263 'last' : false 264 133 265 }); 134 } 266 267 } 268 135 269 } 270 136 271 this.reloadFile( links ); 272 137 273 }; 138 274 139 275 276 277 278 140 279 cssRefresh(); 141 280 281 282 142 283 })(); -
css-refresh-automatically/trunk/css-refresh.php
r588942 r592588 16 16 function loadcssrefresh() { 17 17 18 wp_enqueue_script( 'css_refresh', plugins_url('/css-refresh-automatically/css-refresh.js' )); 18 if ( ! is_admin() ) { 19 20 wp_enqueue_script( 'css_refresh', plugins_url('/css-refresh-automatically/css-refresh.js' )); 21 22 } 19 23 20 24 } … … 27 31 function loadcssfile() { 28 32 29 wp_register_style('stylesheet', get_ template_directory_uri() . '/style.css');33 wp_register_style('stylesheet', get_stylesheet_uri()); 30 34 wp_enqueue_style('stylesheet'); 31 35 -
css-refresh-automatically/trunk/readme.txt
r588942 r592588 13 13 == Description == 14 14 15 Eliminate the need to constantly refresh your website everytime you make a change to your CSS file. Let CSS Refresh do the heavy lifting automatically 15 Eliminate the need to constantly refresh your website everytime you make a change to your CSS file. Let CSS Refresh do the heavy lifting - automatically. 16 17 CSS Refresh will now add your template CSS file automatically. 16 18 17 19 == Installation == … … 31 33 == Changelog == 32 34 35 = 2.1 = 36 37 * This version removes the refresh mechanism from the admin section as it wasn't needed. 38 * Append the stylesheet based on the template file CSS 39 40 = 2.0 = 41 42 * Out of Beta 43 33 44 == Upgrade Notice == 45
Note: See TracChangeset
for help on using the changeset viewer.