Plugin Directory

Changeset 592588


Ignore:
Timestamp:
08/30/2012 07:31:28 PM (14 years ago)
Author:
uniquewebdevelopment
Message:
 
Location:
css-refresh-automatically/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • css-refresh-automatically/trunk/css-refresh.js

    r588032 r592588  
    11/* 
     2
    23 *  CSSrefresh v1.0.1
     4
    35 * 
     6
    47 *  Copyright (c) 2012 Fred Heusschen
     8
    59 *  www.frebsite.nl
     10
    611 *
     12
    713 *  Dual licensed under the MIT and GPL licenses.
     14
    815 *  http://en.wikipedia.org/wiki/MIT_License
     16
    917 *  http://en.wikipedia.org/wiki/GNU_General_Public_License
     18
    1019 */
    1120
     21
     22
    1223(function() {
    1324
     25
     26
    1427    var phpjs = {
    1528
     29
     30
    1631        array_filter: function( arr, func )
    17         {
     32
     33        {
     34
    1835            var retObj = {};
     36
    1937            for ( var k in arr )
    20             {
     38
     39            {
     40
    2141                if ( func( arr[ k ] ) )
    22                 {
     42
     43                {
     44
    2345                    retObj[ k ] = arr[ k ];
    24                 }
    25             }
     46
     47                }
     48
     49            }
     50
    2651            return retObj;
     52
    2753        },
     54
    2855        filemtime: function( file )
    29         {
     56
     57        {
     58
    3059            var headers = this.get_headers( file, 1 );
     60
    3161            return ( headers && headers[ 'Last-Modified' ] && Date.parse( headers[ 'Last-Modified' ] ) / 1000 ) || false;
     62
    3263        },
     64
    3365        get_headers: function( url, format )
     66
    3467        {
     68
    3569            var req = window.ActiveXObject ? new ActiveXObject( 'Microsoft.XMLHTTP' ) : new XMLHttpRequest();
     70
    3671            if ( !req )
    37             {
     72
     73            {
     74
    3875                throw new Error('XMLHttpRequest not supported.');
    39             }
     76
     77            }
     78
     79
    4080
    4181            var tmp, headers, pair, i, j = 0;
    4282
     83
     84
    4385            try
    44             {
     86
     87            {
     88
    4589                req.open( 'HEAD', url, false );
     90
    4691                req.send( null );
     92
    4793                if ( req.readyState < 3 )
    48                 {
     94
     95                {
     96
    4997                    return false;
    50                 }
     98
     99                }
     100
    51101                tmp = req.getAllResponseHeaders();
     102
    52103                tmp = tmp.split( '\n' );
     104
    53105                tmp = this.array_filter( tmp, function ( value )
    54                 {
     106
     107                {
     108
    55109                    return value.toString().substring( 1 ) !== '';
     110
    56111                });
     112
    57113                headers = format ? {} : [];
     114
    58115   
     116
    59117                for ( i in tmp )
    60                 {
     118
     119                {
     120
    61121                    if ( format )
     122
    62123                    {
     124
    63125                        pair = tmp[ i ].toString().split( ':' );
     126
    64127                        headers[ pair.splice( 0, 1 ) ] = pair.join( ':' ).substring( 1 );
     128
    65129                    }
     130
    66131                    else
     132
    67133                    {
     134
    68135                        headers[ j++ ] = tmp[ i ];
     136
    69137                    }
    70                 }
     138
     139                }
     140
    71141   
     142
    72143                return headers;
    73             }
     144
     145            }
     146
    74147            catch ( err )
    75             {
     148
     149            {
     150
    76151                return false;
    77             }
     152
     153            }
     154
    78155        }
     156
    79157    };
    80158
     159
     160
    81161    var cssRefresh = function() {
    82162
     163
     164
    83165        this.reloadFile = function( links )
    84         {
     166
     167        {
     168
    85169            for ( var a = 0, l = links.length; a < l; a++ )
    86             {
     170
     171            {
     172
    87173                var link = links[ a ],
     174
    88175                    newTime = phpjs.filemtime( this.getRandom( link.href ) );
    89176
     177
     178
    90179                //  has been checked before
     180
    91181                if ( link.last )
    92                 {
     182
     183                {
     184
    93185                    //  has been changed
     186
    94187                    if ( link.last != newTime )
     188
    95189                    {
     190
    96191                        //  reload
     192
    97193                        link.elem.setAttribute( 'href', this.getRandom( this.getHref( link.elem ) ) );
     194
    98195                    }
    99                 }
     196
     197                }
     198
     199
    100200
    101201                //  set last time checked
     202
    102203                link.last = newTime;
    103             }
     204
     205            }
     206
    104207            setTimeout( function()
    105             {
     208
     209            {
     210
    106211                this.reloadFile( links );
     212
    107213            }, 1000 );
     214
    108215        };
    109216
     217
     218
    110219        this.getHref = function( f )
    111         {
     220
     221        {
     222
    112223            return f.getAttribute( 'href' ).split( '?' )[ 0 ];
     224
    113225        };
     226
    114227        this.getRandom = function( f )
    115         {
     228
     229        {
     230
    116231            return f + '?x=' + Math.random();
     232
    117233        };
    118234
    119235
     236
     237
     238
    120239        var files = document.getElementsByTagName( 'link' ),
     240
    121241            links = [];
    122242
     243
     244
    123245        for ( var a = 0, l = files.length; a < l; a++ )
     246
    124247        {           
     248
    125249            var elem = files[ a ],
     250
    126251                rel = elem.rel;
     252
    127253            if ( typeof rel != 'string' || rel.length == 0 || rel == 'stylesheet' )
    128             {
     254
     255            {
     256
    129257                links.push({
     258
    130259                    'elem' : elem,
     260
    131261                    'href' : this.getHref( elem ),
     262
    132263                    'last' : false
     264
    133265                });
    134             }
     266
     267            }
     268
    135269        }
     270
    136271        this.reloadFile( links );
     272
    137273    };
    138274
    139275
     276
     277
     278
    140279    cssRefresh();
    141280
     281
     282
    142283})();
  • css-refresh-automatically/trunk/css-refresh.php

    r588942 r592588  
    1616function loadcssrefresh() {
    1717   
    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    }
    1923   
    2024}   
     
    2731function loadcssfile() {
    2832
    29 wp_register_style('stylesheet', get_template_directory_uri() . '/style.css');
     33wp_register_style('stylesheet', get_stylesheet_uri());
    3034wp_enqueue_style('stylesheet');
    3135
  • css-refresh-automatically/trunk/readme.txt

    r588942 r592588  
    1313== Description ==
    1414
    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
     15Eliminate 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
     17CSS Refresh will now add your template CSS file automatically.
    1618
    1719== Installation ==
     
    3133== Changelog ==
    3234
     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
    3344== Upgrade Notice ==
     45
Note: See TracChangeset for help on using the changeset viewer.