zeroclickinfo-goodies/share/goodie/js_minify/js_minify.js

53 lines
1.6 KiB
JavaScript
Raw Normal View History

2016-07-04 15:51:31 -07:00
DDH.js_minify = DDH.js_minify || {};
"use strict";
2016-07-04 15:51:31 -07:00
DDH.js_minify.build = function(ops) {
2016-07-04 15:51:31 -07:00
var shown = false;
2016-07-04 16:29:18 -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'),
$minifyButton = $dom.find('.js_minify__action'),
$input = $dom.find('#js_minify__input'),
$output = $dom.find('#js_minify__output');
$main.toggleClass('c-base');
// hide output textarea by default
$output.css('display', 'none');
DDG.require(prettydiff, function() {
// Add click handler for the minify button
2016-07-06 03:25:58 -07:00
$minifyButton.click(function() {
// 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);
// hide output textarea by default
$output.css('display', 'inline');
// Add the output to output textarea field
$output.val(output);
2016-07-06 03:25:58 -07:00
});
})
}
};
};