forked from expressjs/serve-index
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes expressjs#8 - Separate javascript and css from directory.html t…
…o be compliant with content security policy
- Loading branch information
Showing
3 changed files
with
119 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
function $(id){ | ||
var el = 'string' == typeof id | ||
? document.getElementById(id) | ||
: id; | ||
|
||
el.on = function(event, fn){ | ||
if ('content loaded' == event) { | ||
event = window.attachEvent ? "load" : "DOMContentLoaded"; | ||
} | ||
el.addEventListener | ||
? el.addEventListener(event, fn, false) | ||
: el.attachEvent("on" + event, fn); | ||
}; | ||
|
||
el.all = function(selector){ | ||
return $(el.querySelectorAll(selector)); | ||
}; | ||
|
||
el.each = function(fn){ | ||
for (var i = 0, len = el.length; i < len; ++i) { | ||
fn($(el[i]), i); | ||
} | ||
}; | ||
|
||
el.getClasses = function(){ | ||
return this.getAttribute('class').split(/\s+/); | ||
}; | ||
|
||
el.addClass = function(name){ | ||
var classes = this.getAttribute('class'); | ||
el.setAttribute('class', classes | ||
? classes + ' ' + name | ||
: name); | ||
}; | ||
|
||
el.removeClass = function(name){ | ||
var classes = this.getClasses().filter(function(curr){ | ||
return curr != name; | ||
}); | ||
this.setAttribute('class', classes.join(' ')); | ||
}; | ||
|
||
return el; | ||
} | ||
|
||
function search() { | ||
var str = $('search').value | ||
, links = $('files').all('a'); | ||
|
||
links.each(function(link){ | ||
var text = link.textContent; | ||
|
||
if ('..' == text) return; | ||
if (str.length && ~text.indexOf(str)) { | ||
link.addClass('highlight'); | ||
} else { | ||
link.removeClass('highlight'); | ||
} | ||
}); | ||
} | ||
|
||
$(window).on('content loaded', function(){ | ||
$('search').on('keyup', search); | ||
}); |