mirror of
https://github.com/mrclay/minify.git
synced 2025-08-20 21:02:30 +02:00
Fixed JSHint errors in _index.js
This commit is contained in:
@@ -2,37 +2,37 @@
|
||||
* Minify URI Builder
|
||||
*/
|
||||
var MUB = {
|
||||
_uid : 0
|
||||
,_minRoot : '/min/?'
|
||||
,checkRewrite : function () {
|
||||
_uid : 0,
|
||||
_minRoot : '/min/?',
|
||||
checkRewrite : function () {
|
||||
var testUri = location.pathname.replace(/\/[^\/]*$/, '/rewriteTest.js').substr(1);
|
||||
function fail() {
|
||||
$('#minRewriteFailed')[0].className = 'topNote';
|
||||
};
|
||||
}
|
||||
$.ajax({
|
||||
url : '../f=' + testUri + '&' + (new Date()).getTime()
|
||||
,success : function (data) {
|
||||
url : '../f=' + testUri + '&' + (new Date()).getTime(),
|
||||
success : function (data) {
|
||||
if (data === '1') {
|
||||
MUB._minRoot = '/min/';
|
||||
$('span.minRoot').html('/min/');
|
||||
} else
|
||||
fail();
|
||||
}
|
||||
,error : fail
|
||||
},
|
||||
error : fail
|
||||
});
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Get markup for new source LI element
|
||||
*/
|
||||
,newLi : function () {
|
||||
return '<li id="li' + MUB._uid + '">http://' + location.host + '/<input type=text size=20>'
|
||||
+ ' <button title="Remove">x</button> <button title="Include Earlier">↑</button>'
|
||||
+ ' <button title="Include Later">↓</button> <span></span></li>';
|
||||
}
|
||||
newLi : function () {
|
||||
return '<li id="li' + MUB._uid + '">http://' + location.host + '/<input type=text size=20>' +
|
||||
' <button title="Remove">x</button> <button title="Include Earlier">↑</button>' +
|
||||
' <button title="Include Later">↓</button> <span></span></li>';
|
||||
},
|
||||
/**
|
||||
* Add new empty source LI and attach handlers to buttons
|
||||
*/
|
||||
,addLi : function () {
|
||||
addLi : function () {
|
||||
$('#sources').append(MUB.newLi());
|
||||
var li = $('#li' + MUB._uid)[0];
|
||||
$('button[title=Remove]', li).click(function () {
|
||||
@@ -61,22 +61,22 @@ var MUB = {
|
||||
});
|
||||
});
|
||||
++MUB._uid;
|
||||
}
|
||||
},
|
||||
/**
|
||||
* In the context of a source LI element, this will analyze the URI in
|
||||
* the INPUT and check the URL on the site.
|
||||
*/
|
||||
,liUpdateTestLink : function () { // call in context of li element
|
||||
liUpdateTestLink : function () { // call in context of li element
|
||||
if (! $('input', this)[0].value)
|
||||
return;
|
||||
var li = this;
|
||||
$('span', this).html('');
|
||||
var url = 'http://' + location.host + '/'
|
||||
+ $('input', this)[0].value.replace(/^\//, '');
|
||||
var url = 'http://' + location.host + '/' +
|
||||
$('input', this)[0].value.replace(/^\//, '');
|
||||
$.ajax({
|
||||
url : url
|
||||
,complete : function (xhr, stat) {
|
||||
if ('success' == stat)
|
||||
url : url,
|
||||
complete : function (xhr, stat) {
|
||||
if ('success' === stat)
|
||||
$('span', li).html('✓');
|
||||
else {
|
||||
$('span', li).html('<button><b>404! </b> recheck</button>')
|
||||
@@ -84,16 +84,16 @@ var MUB = {
|
||||
MUB.liUpdateTestLink.call(li);
|
||||
});
|
||||
}
|
||||
}
|
||||
,dataType : 'text'
|
||||
},
|
||||
dataType : 'text'
|
||||
});
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Check all source URLs
|
||||
*/
|
||||
,updateAllTestLinks : function () {
|
||||
updateAllTestLinks : function () {
|
||||
$('#sources li').each(MUB.liUpdateTestLink);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* In a given array of strings, find the character they all have at
|
||||
* a particular index
|
||||
@@ -101,25 +101,25 @@ var MUB = {
|
||||
* @param Number pos index to check
|
||||
* @return mixed a common char or '' if any do not match
|
||||
*/
|
||||
,getCommonCharAtPos : function (arr, pos) {
|
||||
var i
|
||||
,l = arr.length
|
||||
,c = arr[0].charAt(pos);
|
||||
getCommonCharAtPos : function (arr, pos) {
|
||||
var i,
|
||||
l = arr.length,
|
||||
c = arr[0].charAt(pos);
|
||||
if (c === '' || l === 1)
|
||||
return c;
|
||||
for (i = 1; i < l; ++i)
|
||||
if (arr[i].charAt(pos) !== c)
|
||||
return '';
|
||||
return c;
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Get the shortest URI to minify the set of source files
|
||||
* @param Array sources URIs
|
||||
*/
|
||||
,getBestUri : function (sources) {
|
||||
var pos = 0
|
||||
,base = ''
|
||||
,c;
|
||||
getBestUri : function (sources) {
|
||||
var pos = 0,
|
||||
base = '',
|
||||
c;
|
||||
while (true) {
|
||||
c = MUB.getCommonCharAtPos(sources, pos);
|
||||
if (c === '')
|
||||
@@ -132,29 +132,28 @@ var MUB = {
|
||||
var uri = MUB._minRoot + 'f=' + sources.join(',');
|
||||
if (base.charAt(base.length - 1) === '/') {
|
||||
// we have a base dir!
|
||||
var basedSources = sources
|
||||
,i
|
||||
,l = sources.length;
|
||||
var basedSources = sources,
|
||||
i,
|
||||
l = sources.length;
|
||||
for (i = 0; i < l; ++i) {
|
||||
basedSources[i] = sources[i].substr(base.length);
|
||||
}
|
||||
base = base.substr(0, base.length - 1);
|
||||
var bUri = MUB._minRoot + 'b=' + base + '&f=' + basedSources.join(',');
|
||||
//window.console && console.log([uri, bUri]);
|
||||
uri = uri.length < bUri.length
|
||||
? uri
|
||||
: bUri;
|
||||
uri = uri.length < bUri.length ? uri : bUri;
|
||||
}
|
||||
return uri;
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Create the Minify URI for the sources
|
||||
*/
|
||||
,update : function () {
|
||||
update : function () {
|
||||
MUB.updateAllTestLinks();
|
||||
var sources = []
|
||||
,ext = false
|
||||
,fail = false;
|
||||
var sources = [],
|
||||
ext = false,
|
||||
fail = false,
|
||||
markup;
|
||||
$('#sources input').each(function () {
|
||||
var m, val;
|
||||
if (! fail && this.value && (m = this.value.match(/\.(css|js)$/))) {
|
||||
@@ -166,7 +165,7 @@ var MUB = {
|
||||
return alert('extensions must match!');
|
||||
}
|
||||
this.value = this.value.replace(/^\//, '');
|
||||
if (-1 != $.inArray(this.value, sources)) {
|
||||
if (-1 !== $.inArray(this.value, sources)) {
|
||||
fail = true;
|
||||
return alert('duplicate file!');
|
||||
}
|
||||
@@ -176,30 +175,31 @@ var MUB = {
|
||||
if (fail || ! sources.length)
|
||||
return;
|
||||
$('#groupConfig').val(" 'keyName' => array('//" + sources.join("', '//") + "'),");
|
||||
var uri = MUB.getBestUri(sources)
|
||||
,uriH = uri.replace(/</, '<').replace(/>/, '>').replace(/&/, '&');
|
||||
var uri = MUB.getBestUri(sources),
|
||||
uriH = uri.replace(/</, '<').replace(/>/, '>').replace(/&/, '&');
|
||||
$('#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 + '" />'
|
||||
);
|
||||
$('#results').show();
|
||||
if (ext === 'js') {
|
||||
markup = '<script type="text/javascript" src="' + uriH + '"></script>';
|
||||
} else {
|
||||
markup = '<link type="text/css" rel="stylesheet" href="' + uriH + '" />';
|
||||
}
|
||||
$('#uriHtml').val(markup);
|
||||
$('#results').show();
|
||||
},
|
||||
/**
|
||||
* Handler for the "Add file +" button
|
||||
*/
|
||||
,addButtonClick : function () {
|
||||
addButtonClick : function () {
|
||||
$('#results').hide();
|
||||
MUB.addLi();
|
||||
MUB.updateAllTestLinks();
|
||||
$('#update').show().click(MUB.update);
|
||||
$('#sources li:last input')[0].focus();
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Runs on DOMready
|
||||
*/
|
||||
,init : function () {
|
||||
init : function () {
|
||||
$('#jsDidntLoad').remove();
|
||||
$('#app').show();
|
||||
$('#sources').html('');
|
||||
@@ -214,13 +214,13 @@ var MUB = {
|
||||
if (location.hash) {
|
||||
// make links out of URIs from bookmarklet
|
||||
$('#getBm').hide();
|
||||
$('#bmUris').html('<p><strong>Found by bookmarklet:</strong> /<a href=#>'
|
||||
+ location.hash.substr(1).split(',').join('</a> | /<a href=#>')
|
||||
+ '</a></p>'
|
||||
$('#bmUris').html('<p><strong>Found by bookmarklet:</strong> /<a href=#>' +
|
||||
location.hash.substr(1).split(',').join('</a> | /<a href=#>') +
|
||||
'</a></p>'
|
||||
);
|
||||
$('#bmUris a').click(function () {
|
||||
MUB.addButtonClick();
|
||||
$('#sources li:last input').val(this.innerHTML)
|
||||
$('#sources li:last input').val(this.innerHTML);
|
||||
MUB.liUpdateTestLink.call($('#sources li:last')[0]);
|
||||
$('#results').hide();
|
||||
return false;
|
||||
@@ -228,24 +228,26 @@ var MUB = {
|
||||
} else {
|
||||
// setup bookmarklet 1
|
||||
$.ajax({
|
||||
url : '../?f=' + location.pathname.replace(/\/[^\/]*$/, '/bm.js').substr(1)
|
||||
,success : function (code) {
|
||||
url : '../?f=' + location.pathname.replace(/\/[^\/]*$/, '/bm.js').substr(1),
|
||||
success : function (code) {
|
||||
$('#bm')[0].href = code
|
||||
.replace('%BUILDER_URL%', location.href)
|
||||
.replace(/\n/g, ' ');
|
||||
}
|
||||
,dataType : 'text'
|
||||
},
|
||||
dataType : 'text'
|
||||
});
|
||||
$.browser.msie && $('#getBm p:last').append(' Sorry, not supported in MSIE!');
|
||||
if ($.browser.msie) {
|
||||
$('#getBm p:last').append(' Sorry, not supported in MSIE!');
|
||||
}
|
||||
MUB.addButtonClick();
|
||||
}
|
||||
// setup bookmarklet 2
|
||||
$.ajax({
|
||||
url : '../?f=' + location.pathname.replace(/\/[^\/]*$/, '/bm2.js').substr(1)
|
||||
,success : function (code) {
|
||||
url : '../?f=' + location.pathname.replace(/\/[^\/]*$/, '/bm2.js').substr(1),
|
||||
success : function (code) {
|
||||
$('#bm2')[0].href = code.replace(/\n/g, ' ');
|
||||
}
|
||||
,dataType : 'text'
|
||||
},
|
||||
dataType : 'text'
|
||||
});
|
||||
MUB.checkRewrite();
|
||||
}
|
||||
|
Reference in New Issue
Block a user