Skip to content
This repository was archived by the owner on May 15, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.markdown
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## Recursive Reloadr

This version of reloadr looks at directories recursively, so you can just supply "*.ext" to Reloadr, and it will refresh regardless of deep-nested directory structures.
It also adds localStorage support for enabling/disabling Reloadr.

# Reloadr

## The Problem
Expand Down Expand Up @@ -51,4 +56,4 @@ All options are, um, optional, but Reloadr won't actually *do* anything if you d

This is kind of a quick and dirty hack. I'd like to add some features to make usage easier, but still keep it simple. Here are some ideas:

- Scan the document's HEAD to find CSS and JS urls to poll.
- Scan the document's HEAD to find CSS and JS urls to poll.
7 changes: 6 additions & 1 deletion reloadr.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@ TO USE: include reloadr.js and tell it what to check:
]);
*/


var Reloadr = {
options: {
frequency: 2000,
client: [],
server: [],
path: '/reloadr.php'
path: '/reloadr.php',
},
req: new XMLHttpRequest(),
disable: function(){ localStorage.setItem("reloadrDisabled", "true"); },
enable: function(){ localStorage.setItem("reloadrDisabled", "false"); },
timeout: null,
watch: function(options) { this.go.call(this, options); },
go: function(options) {
Expand All @@ -49,6 +52,8 @@ var Reloadr = {
}, this.options.frequency);
},
ajax: function(url, callback) {
if (localStorage.getItem("reloadrDisabled")==="true") return;

this.req.open("GET", url, false);
this.req.setRequestHeader('If-Modified-Since', window._Reloadr_LoadTime.toUTCString());
this.req.send(null);
Expand Down
21 changes: 11 additions & 10 deletions reloadr.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<?php

$filename_lists = array_map('glob', explode(',', $_SERVER['QUERY_STRING']));

$filename_lists = array_map('glob_recursive', explode(',', $_SERVER['QUERY_STRING']));
$files = array();

foreach( $filename_lists as $filename_list )
$files = array_merge($files, $filename_list);

foreach ( $files as &$file )
$file = filemtime($file);

foreach( $filename_lists as $filename_list ) $files = array_merge($files, $filename_list);
foreach ( $files as &$file ) $file = filemtime($file);
header('Last-Modified: '. date('r', @max($files)));

function glob_recursive($pattern, $flags = 0) {
$files = glob($pattern, $flags);
foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) {
$files = array_merge($files, glob_recursive($dir.'/'.basename($pattern), $flags));
}
return $files;
}
?>