2016-07-04 15:51:31 -07:00
|
|
|
|
DDH.js_minify = DDH.js_minify || {};
|
|
|
|
|
|
2016-07-05 15:41:51 -07:00
|
|
|
|
"use strict";
|
2016-07-04 15:51:31 -07:00
|
|
|
|
|
2016-07-05 15:41:51 -07:00
|
|
|
|
DDH.js_minify.build = function(ops) {
|
2016-07-04 15:51:31 -07:00
|
|
|
|
|
2016-07-05 15:41:51 -07:00
|
|
|
|
var shown = false;
|
2016-07-04 16:29:18 -07:00
|
|
|
|
|
2016-07-05 15:41:51 -07:00
|
|
|
|
return {
|
|
|
|
|
onShow: function() {
|
|
|
|
|
// make sure this function is run only once, the first time
|
|
|
|
|
// the IA is shown otherwise things will get initialized more than once
|
|
|
|
|
if (shown)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// set the flag to true so it doesn't get run again
|
|
|
|
|
shown = true;
|
|
|
|
|
|
|
|
|
|
var $dom = $('#zci-js_minify'),
|
2016-07-05 16:10:53 -07:00
|
|
|
|
$main = $dom.find('.zci__main'),
|
2016-07-06 04:33:55 -07:00
|
|
|
|
$minifyButton = $dom.find('.js_minify__action'),
|
|
|
|
|
$input = $dom.find('#js_minify__input'),
|
|
|
|
|
$output = $dom.find('#js_minify__output');
|
2016-07-05 15:41:51 -07:00
|
|
|
|
|
|
|
|
|
$main.toggleClass('c-base');
|
|
|
|
|
|
2016-07-06 05:29:55 -07:00
|
|
|
|
// hide output textarea by default
|
|
|
|
|
$output.css('display', 'none');
|
|
|
|
|
|
2016-07-09 03:56:10 -07:00
|
|
|
|
DDG.require(‘prettydiff’, function() {
|
2016-07-06 04:33:55 -07:00
|
|
|
|
// Add click handler for the minify button
|
2016-07-06 03:25:58 -07:00
|
|
|
|
$minifyButton.click(function() {
|
2016-07-06 04:33:55 -07:00
|
|
|
|
// Set config options for minify operation
|
|
|
|
|
var args = {
|
|
|
|
|
mode: "minify",
|
|
|
|
|
lang: "javascript",
|
|
|
|
|
source: $input.val()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Operate using the prettydiff function provided by the library
|
|
|
|
|
var output = prettydiff(args);
|
|
|
|
|
|
2016-07-06 05:29:55 -07:00
|
|
|
|
// hide output textarea by default
|
|
|
|
|
$output.css('display', 'inline');
|
|
|
|
|
|
2016-07-06 04:33:55 -07:00
|
|
|
|
// Add the output to output textarea field
|
|
|
|
|
$output.val(output);
|
2016-07-06 03:25:58 -07:00
|
|
|
|
});
|
|
|
|
|
})
|
2016-07-05 15:41:51 -07:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|