7 checkRewrite : function () {
8 var testUri = location.pathname.replace(/\/[^\/]*$/, '/rewriteTest.js').substr(1);
10 $('#minRewriteFailed')[0].className = 'topNote';
13 url : '../f=' + testUri + '&' + (new Date()).getTime(),
14 success : function (data) {
16 MUB._minRoot = '/min/';
17 $('span.minRoot').html('/min/');
25 * Get markup for new source LI element
28 return '<li id="li' + MUB._uid + '">http://' + location.host + '/<input type=text size=20>' +
29 ' <button title="Remove">x</button> <button title="Include Earlier">↑</button>' +
30 ' <button title="Include Later">↓</button> <span></span></li>';
33 * Add new empty source LI and attach handlers to buttons
36 $('#sources').append(MUB.newLi());
37 var li = $('#li' + MUB._uid)[0];
38 $('button[title=Remove]', li).click(function () {
40 var hadValue = !!$('input', li)[0].value;
43 $('button[title$=Earlier]', li).click(function () {
44 $(li).prev('li').find('input').each(function () {
46 // this = previous li input
48 this.value = $('input', li).val();
49 $('input', li).val(tmp);
50 MUB.updateAllTestLinks();
53 $('button[title$=Later]', li).click(function () {
54 $(li).next('li').find('input').each(function () {
56 // this = next li input
58 this.value = $('input', li).val();
59 $('input', li).val(tmp);
60 MUB.updateAllTestLinks();
66 * In the context of a source LI element, this will analyze the URI in
67 * the INPUT and check the URL on the site.
69 liUpdateTestLink : function () { // call in context of li element
70 if (! $('input', this)[0].value)
73 $('span', this).html('');
74 var url = location.protocol + '//' + location.host + '/' +
75 $('input', this)[0].value.replace(/^\//, '');
78 complete : function (xhr, stat) {
79 if ('success' === stat)
80 $('span', li).html('✓');
82 $('span', li).html('<button><b>404! </b> recheck</button>')
83 .find('button').click(function () {
84 MUB.liUpdateTestLink.call(li);
92 * Check all source URLs
94 updateAllTestLinks : function () {
95 $('#sources li').each(MUB.liUpdateTestLink);
98 * In a given array of strings, find the character they all have at
100 * @param Array arr array of strings
101 * @param Number pos index to check
102 * @return mixed a common char or '' if any do not match
104 getCommonCharAtPos : function (arr, pos) {
107 c = arr[0].charAt(pos);
108 if (c === '' || l === 1)
110 for (i = 1; i < l; ++i)
111 if (arr[i].charAt(pos) !== c)
116 * Get the shortest URI to minify the set of source files
117 * @param Array sources URIs
119 getBestUri : function (sources) {
124 c = MUB.getCommonCharAtPos(sources, pos);
131 base = base.replace(/[^\/]+$/, '');
132 var uri = MUB._minRoot + 'f=' + sources.join(',');
133 if (base.charAt(base.length - 1) === '/') {
134 // we have a base dir!
135 var basedSources = sources,
138 for (i = 0; i < l; ++i) {
139 basedSources[i] = sources[i].substr(base.length);
141 base = base.substr(0, base.length - 1);
142 var bUri = MUB._minRoot + 'b=' + base + '&f=' + basedSources.join(',');
143 //window.console && console.log([uri, bUri]);
144 uri = uri.length < bUri.length ? uri : bUri;
149 * Create the Minify URI for the sources
151 update : function () {
152 MUB.updateAllTestLinks();
157 $('#sources input').each(function () {
159 if (! fail && this.value && (m = this.value.match(/\.(css|js)$/))) {
163 else if (thisExt !== ext) {
165 return alert('extensions must match!');
167 this.value = this.value.replace(/^\//, '');
168 if (-1 !== $.inArray(this.value, sources)) {
170 return alert('duplicate file!');
172 sources.push(this.value);
175 if (fail || ! sources.length)
177 $('#groupConfig').val(" 'keyName' => array('//" + sources.join("', '//") + "'),");
178 var uri = MUB.getBestUri(sources),
179 uriH = uri.replace(/</, '<').replace(/>/, '>').replace(/&/, '&');
180 $('#uriA').html(uriH)[0].href = uri;
182 markup = '<script type="text/javascript" src="' + uriH + '"></script>';
184 markup = '<link type="text/css" rel="stylesheet" href="' + uriH + '" />';
186 $('#uriHtml').val(markup);
187 $('#results').show();
190 * Handler for the "Add file +" button
192 addButtonClick : function () {
193 $('#results').hide();
195 MUB.updateAllTestLinks();
196 $('#update').show().click(MUB.update);
197 $('#sources li:last input')[0].focus();
203 $('#jsDidntLoad').remove();
205 $('#sources').html('');
206 $('#add button').click(MUB.addButtonClick);
207 // make easier to copy text out of
208 $('#uriHtml, #groupConfig, #symlinkOpt').click(function () {
210 }).focus(function () {
213 $('a.ext').attr({target:'_blank'});
215 // make links out of URIs from bookmarklet
217 var i = 0, found = location.hash.substr(1).split(','), l = found.length;
218 $('#bmUris').html('<p><strong>Found by bookmarklet:</strong> /</p>');
219 var $p = $('#bmUris p');
221 $p.append($('<a href=#></a>').text(found[i])[0]);
226 $('#bmUris a').click(function () {
227 MUB.addButtonClick();
228 $('#sources li:last input').val(this.innerHTML);
229 MUB.liUpdateTestLink.call($('#sources li:last')[0]);
230 $('#results').hide();
232 }).attr({title:'Add file +'});
234 // setup bookmarklet 1
236 url : '../?f=' + location.pathname.replace(/\/[^\/]*$/, '/bm.js').substr(1),
237 success : function (code) {
238 $('#bm')[0].href = code
239 .replace('%BUILDER_URL%', location.href)
240 .replace(/\n/g, ' ');
244 if ($.browser.msie) {
245 $('#getBm p:last').append(' Sorry, not supported in MSIE!');
247 MUB.addButtonClick();
249 // setup bookmarklet 2
251 url : '../?f=' + location.pathname.replace(/\/[^\/]*$/, '/bm2.js').substr(1),
252 success : function (code) {
253 $('#bm2')[0].href = code.replace(/\n/g, ' ');