1
0
mirror of https://github.com/mrclay/minify.git synced 2025-08-21 13:21:59 +02:00

crude builder app for generating URIs quickly

This commit is contained in:
Steve Clay
2008-09-03 05:13:52 +00:00
parent e31e9299a5
commit 7b9fcb4dd6
4 changed files with 121 additions and 0 deletions

24
min/builder/index.html Normal file
View File

@@ -0,0 +1,24 @@
<!doctype html>
<head>
<title>Minify URI Builder</title>
<style type="text/css">
#sources {margin:0; padding:0;}
#sources li {margin:0 0 0 40px}
#add {margin:5px 0 1em 40px}
li span {margin:0 3px}
</style>
</head>
<h1>Minify URI Builder</h1>
<ol id=sources></ol>
<div id=add><a href='#'>Add file +</a></div>
<p><button id=update>Update</button></p>
<table style="display:none">
<tr><th>URI</th><td><a id=uriA target="_blank">/min</a> <small>(opens in new window)</small></td></tr>
<tr><th>HTML</th><td><input id=uriHtml type=text size=80 readonly></td></tr>
</table>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
<script type="text/javascript" src="index.js"></script>

79
min/builder/index.js Normal file
View File

@@ -0,0 +1,79 @@
// @todo update test links when reordering, app instructions
var MUB = {
_uid : 0
,newLi : function () {
return '<li id="li' + MUB._uid + '">http://' + location.host + '<span>/</span><input type=text size=20>'
+ ' <button title="Remove">x</button> <button title="Include Earlier">&uarr;</button>'
+ ' <button title="Include Later">&darr;</button> <a href=# target="_blank" '
+ 'title="Open this URL in a new window">test link</a></li>';
}
,addLi : function () {
$('#sources').append(MUB.newLi());
var li = $('#li' + MUB._uid)[0];
$('button[title=Remove]', li).click(function () {
$(li).remove();
});
$('button[title$=Earlier]', li).click(function () {
$(li).prev('li').find('input').each(function () {
// this = previous li input
var tmp = this.value;
this.value = $('input', li).val();
$('input', li).val(tmp);
});
});
$('button[title$=Later]', li).click(function () {
$(li).next('li').find('input').each(function () {
// this = next li input
var tmp = this.value;
this.value = $('input', li).val();
$('input', li).val(tmp);
});
});
$('input', li).keyup(function () {
$('a', li)[0].href = '/' + this.value;
});
++MUB._uid;
}
,update : function () {
var sources = []
,ext = false
,fail = false;
$('#sources input').each(function () {
if (! fail && this.value && (m = this.value.match(/\.(css|js)$/))) {
var thisExt = m[1];
if (ext === false)
ext = thisExt;
else if (thisExt !== ext) {
fail = true;
return alert('extensions must match!');
}
if (-1 != $.inArray(this.value, sources)) {
fail = true;
return alert('duplicate file!');
}
sources.push(this.value);
}
});
if (fail || ! sources.length)
return;
var uri = '/min/?f=' + sources.join(',')
,uriH = uri.replace(/</, '&lt;').replace(/>/, '&gt;').replace(/&/, '&amp;');
$('#uriA').html(uriH)[0].href = uri;
$('#uriHtml').val(
ext === 'js'
? '<script type="text/javascript" src="' + uriH + '"></script>'
: '<link type="text/css" rel="stylesheet" href="' + uriH + '" />'
);
$('table').show();
}
,init : function () {
$('#add a').click(MUB.addLi);
$('#uriHtml').click(function () {
this.select();
}).focus(function () {
this.select();
});
$('#update').click(MUB.update);
}
};
window.onload = MUB.init;

View File

@@ -5,6 +5,13 @@
*/ */
/**
* Forward empty requests to URI Builder app. After initial setup this
* should be set to false.
**/
$min_forwardToBuilder = true;
/** /**
* For best performance, specify your temp directory here. * For best performance, specify your temp directory here.
* Otherwise Minify will have to load extra code to guess. * Otherwise Minify will have to load extra code to guess.

View File

@@ -69,4 +69,15 @@ if (isset($_GET['g'])) {
$_GET['files'] = $min_base . str_replace(',', ',' . $min_base, $_GET['f']); $_GET['files'] = $min_base . str_replace(',', ',' . $min_base, $_GET['f']);
Minify::serve('Version1', $min_serveOptions); Minify::serve('Version1', $min_serveOptions);
} elseif ($min_forwardToBuilder) {
header('Location: builder/');
exit();
} else {
header("HTTP/1.0 404 Not Found");
exit();
} }