Merge remote-tracking branch 'upstream/master' into feature_filter

This commit is contained in:
Mike Schwörer 2016-12-21 20:17:53 +01:00
commit f44171c005
No known key found for this signature in database
GPG key ID: D3C7172E0A70F8CF
22 changed files with 9087 additions and 131 deletions

View file

@ -82,6 +82,7 @@ const Categories = [
"XOR Brute Force",
"Vigenère Encode",
"Vigenère Decode",
"Substitute",
"Derive PBKDF2 key",
"Derive EVP key",
]
@ -190,6 +191,8 @@ const Categories = [
"Extract file paths",
"Extract dates",
"Regular expression",
"XPath expression",
"CSS selector",
]
},
{
@ -242,6 +245,8 @@ const Categories = [
"SQL Minify",
"CSS Beautify",
"CSS Minify",
"XPath expression",
"CSS selector",
"Strip HTML tags",
"Diff",
]

View file

@ -1961,6 +1961,42 @@ const OperationConfig = {
},
]
},
"XPath expression": {
description: "Extract information from an XML document with an XPath query",
run: Code.run_xpath,
input_type: "string",
output_type: "string",
args: [
{
name: "XPath",
type: "string",
value: Code.XPATH_INITIAL
},
{
name: "Result delimiter",
type: "binary_short_string",
value: Code.XPATH_DELIMITER
}
]
},
"CSS selector": {
description: "Extract information from an HTML document with a CSS selector",
run: Code.run_css_query,
input_type: "string",
output_type: "string",
args: [
{
name: "CSS selector",
type: "string",
value: Code.CSS_SELECTOR_INITIAL
},
{
name: "Delimiter",
type: "binary_short_string",
value: Code.CSS_QUERY_DELIMITER
},
]
},
"From UNIX Timestamp": {
description: "Converts a UNIX timestamp to a datetime string.<br><br>e.g. <code>978346800</code> becomes <code>Mon 1 January 2001 11:00:00 UTC</code>",
run: DateTime.run_from_unix_timestamp,
@ -2850,5 +2886,23 @@ const OperationConfig = {
input_type: "string",
output_type: "string",
args: []
},
"Substitute": {
description: "A substitution cipher allowing you to specify bytes to replace with other byte values. This can be used to create Caesar ciphers but is more powerful as any byte value can be substituted, not just letters, and the substitution values need not be in order.<br><br>Enter the bytes you want to replace in the Plaintext field and the bytes to replace them with in the Ciphertext field.<br><br>Non-printable bytes can be specified using string escape notation. For example, a line feed character can be written as either <code>\\n</code> or <code>\\x0a</code>.<br><br>Byte ranges can be specified using a hyphen. For example, the sequence <code>0123456789</code> can be written as <code>0-9</code>.",
run: Cipher.run_substitute,
input_type: "byte_array",
output_type: "byte_array",
args: [
{
name: "Plaintext",
type: "binary_string",
value: Cipher.SUBS_PLAINTEXT
},
{
name: "Ciphertext",
type: "binary_string",
value: Cipher.SUBS_CIPHERTEXT
}
]
}
};

View file

@ -1,6 +1,6 @@
/** @license
========================================================================
Split.js v1.0.7
Split.js v1.1.1
Copyright (c) 2015 Nathan Cahill
Permission is hereby granted, free of charge, to any person obtaining a copy
@ -22,17 +22,43 @@
THE SOFTWARE.
*/
// The programming goals of Split.js are to deliver readable, understandable and
// maintainable code, while at the same time manually optimizing for tiny minified file size,
// browser compatibility without additional requirements, graceful fallback (IE8 is supported)
// and very few assumptions about the user's page layout.
//
// Make sure all browsers handle this JS library correctly with ES5.
// More information here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode
'use strict';
// A wrapper function that does a couple things:
//
// 1. Doesn't pollute the global namespace. This is important for a library.
// 2. Allows us to mount the library in different module systems, as well as
// directly in the browser.
(function() {
// Save the global `this` for use later. In this case, since the library only
// runs in the browser, it will refer to `window`. Also, figure out if we're in IE8
// or not. IE8 will still render correctly, but will be static instead of draggable.
//
// Save a couple long function names that are used frequently.
// This optimization saves around 400 bytes.
var global = this
, isIE8 = global.attachEvent && !global[addEventListener]
, document = global.document
, addEventListener = 'addEventListener'
, removeEventListener = 'removeEventListener'
, getBoundingClientRect = 'getBoundingClientRect'
, isIE8 = global.attachEvent && !global[addEventListener]
, document = global.document
// This library only needs two helper functions:
//
// The first determines which prefixes of CSS calc we need.
// We only need to do this once on startup, when this anonymous function is called.
//
// Tests -webkit, -moz and -o prefixes. Modified from StackOverflow:
// http://stackoverflow.com/questions/16625140/js-feature-detection-to-detect-the-usage-of-webkit-calc-over-calc/16625167#16625167
, calc = (function () {
var el
, prefixes = ["", "-webkit-", "-moz-", "-o-"]
@ -46,6 +72,10 @@ var global = this
}
}
})()
// The second helper function allows elements and string selectors to be used
// interchangeably. In either case an element is returned. This allows us to
// do `Split(elem1, elem2)` as well as `Split('#id1', '#id2')`.
, elementOrSelector = function (el) {
if (typeof el === 'string' || el instanceof String) {
return document.querySelector(el)
@ -54,6 +84,38 @@ var global = this
}
}
// The main function to initialize a split. Split.js thinks about each pair
// of elements as an independant pair. Dragging the gutter between two elements
// only changes the dimensions of elements in that pair. This is key to understanding
// how the following functions operate, since each function is bound to a pair.
//
// A pair object is shaped like this:
//
// {
// a: DOM element,
// b: DOM element,
// aMin: Number,
// bMin: Number,
// dragging: Boolean,
// parent: DOM element,
// isFirst: Boolean,
// isLast: Boolean,
// direction: 'horizontal' | 'vertical'
// }
//
// The basic sequence:
//
// 1. Set defaults to something sane. `options` doesn't have to be passed at all.
// 2. Initialize a bunch of strings based on the direction we're splitting.
// A lot of the behavior in the rest of the library is paramatized down to
// rely on CSS strings and classes.
// 3. Define the dragging helper functions, and a few helpers to go with them.
// 4. Define a few more functions that "balance" the entire split instance.
// Split.js tries it's best to cope with min sizes that don't add up.
// 5. Loop through the elements while pairing them off. Every pair gets an
// `pair` object, a gutter, and special isFirst/isLast properties.
// 6. Actually size the pair elements, insert gutters and attach event listeners.
// 7. Balance all of the pairs to accomodate min sizes as best as possible.
, Split = function (ids, options) {
var dimension
, i
@ -65,8 +127,9 @@ var global = this
, paddingB
, pairs = []
// Set defaults
// 1. Set defaults to something sane. `options` doesn't have to be passed at all,
// so create an options object if none exists. Pixel values 10, 100 and 30 are
// arbitrary but feel natural.
options = typeof options !== 'undefined' ? options : {}
if (typeof options.gutterSize === 'undefined') options.gutterSize = 10
@ -74,6 +137,9 @@ var global = this
if (typeof options.snapOffset === 'undefined') options.snapOffset = 30
if (typeof options.direction === 'undefined') options.direction = 'horizontal'
// 2. Initialize a bunch of strings based on the direction we're splitting.
// A lot of the behavior in the rest of the library is paramatized down to
// rely on CSS strings and classes.
if (options.direction == 'horizontal') {
dimension = 'width'
clientDimension = 'clientWidth'
@ -94,25 +160,43 @@ var global = this
if (!options.cursor) options.cursor = 'ns-resize'
}
// Event listeners for drag events, bound to a pair object.
// Calculate the pair's position and size when dragging starts.
// Prevent selection on start and re-enable it when done.
// 3. Define the dragging helper functions, and a few helpers to go with them.
// Each helper is bound to a pair object that contains it's metadata. This
// also makes it easy to store references to listeners that that will be
// added and removed.
//
// Even though there are no other functions contained in them, aliasing
// this to self saves 50 bytes or so since it's used so frequently.
//
// The pair object saves metadata like dragging state, position and
// event listener references.
//
// startDragging calls `calculateSizes` to store the inital size in the pair object.
// It also adds event listeners for mouse/touch events,
// and prevents selection while dragging so avoid the selecting text.
var startDragging = function (e) {
// Alias frequently used variables to save space. 200 bytes.
var self = this
, a = self.a
, b = self.b
// Call the onDragStart callback.
if (!self.dragging && options.onDragStart) {
options.onDragStart()
}
// Don't actually drag the element. We emulate that in the drag function.
e.preventDefault()
// Set the dragging property of the pair object.
self.dragging = true
// Create two event listeners bound to the same pair object and store
// them in the pair object.
self.move = drag.bind(self)
self.stop = stopDragging.bind(self)
// All the binding. `window` gets the stop events in case we drag out of the elements.
global[addEventListener]('mouseup', self.stop)
global[addEventListener]('touchend', self.stop)
global[addEventListener]('touchcancel', self.stop)
@ -120,10 +204,11 @@ var global = this
self.parent[addEventListener]('mousemove', self.move)
self.parent[addEventListener]('touchmove', self.move)
a[addEventListener]('selectstart', preventSelection)
a[addEventListener]('dragstart', preventSelection)
b[addEventListener]('selectstart', preventSelection)
b[addEventListener]('dragstart', preventSelection)
// Disable selection. Disable!
a[addEventListener]('selectstart', noop)
a[addEventListener]('dragstart', noop)
b[addEventListener]('selectstart', noop)
b[addEventListener]('dragstart', noop)
a.style.userSelect = 'none'
a.style.webkitUserSelect = 'none'
@ -135,11 +220,16 @@ var global = this
b.style.MozUserSelect = 'none'
b.style.pointerEvents = 'none'
// Set the cursor, both on the gutter and the parent element.
// Doing only a, b and gutter causes flickering.
self.gutter.style.cursor = options.cursor
self.parent.style.cursor = options.cursor
// Cache the initial sizes of the pair.
calculateSizes.call(self)
}
// stopDragging is very similar to startDragging in reverse.
, stopDragging = function () {
var self = this
, a = self.a
@ -151,6 +241,7 @@ var global = this
self.dragging = false
// Remove the stored event listeners. This is why we store them.
global[removeEventListener]('mouseup', self.stop)
global[removeEventListener]('touchend', self.stop)
global[removeEventListener]('touchcancel', self.stop)
@ -158,13 +249,15 @@ var global = this
self.parent[removeEventListener]('mousemove', self.move)
self.parent[removeEventListener]('touchmove', self.move)
// Delete them once they are removed. I think this makes a difference
// in memory usage with a lot of splits on one page. But I don't know for sure.
delete self.stop
delete self.move
a[removeEventListener]('selectstart', preventSelection)
a[removeEventListener]('dragstart', preventSelection)
b[removeEventListener]('selectstart', preventSelection)
b[removeEventListener]('dragstart', preventSelection)
a[removeEventListener]('selectstart', noop)
a[removeEventListener]('dragstart', noop)
b[removeEventListener]('selectstart', noop)
b[removeEventListener]('dragstart', noop)
a.style.userSelect = ''
a.style.webkitUserSelect = ''
@ -179,36 +272,70 @@ var global = this
self.gutter.style.cursor = ''
self.parent.style.cursor = ''
}
// drag, where all the magic happens. The logic is really quite simple:
//
// 1. Ignore if the pair is not dragging.
// 2. Get the offset of the event.
// 3. Snap offset to min if within snappable range (within min + snapOffset).
// 4. Actually adjust each element in the pair to offset.
//
// ---------------------------------------------------------------------
// | | <- this.aMin || this.bMin -> | |
// | | | <- this.snapOffset || this.snapOffset -> | | |
// | | | || | | |
// | | | || | | |
// ---------------------------------------------------------------------
// | <- this.start this.size -> |
, drag = function (e) {
var offset
if (!this.dragging) return
// Get the relative position of the event from the first side of the
// pair.
// Get the offset of the event from the first side of the
// pair `this.start`. Supports touch events, but not multitouch, so only the first
// finger `touches[0]` is counted.
if ('touches' in e) {
offset = e.touches[0][clientAxis] - this.start
} else {
offset = e[clientAxis] - this.start
}
// If within snapOffset of min or max, set offset to min or max
if (offset <= this.aMin + options.snapOffset) {
offset = this.aMin
} else if (offset >= this.size - this.bMin - options.snapOffset) {
offset = this.size - this.bMin
// If within snapOffset of min or max, set offset to min or max.
// snapOffset buffers aMin and bMin, so logic is opposite for both.
// Include the appropriate gutter sizes to prevent overflows.
if (offset <= this.aMin + options.snapOffset + this.aGutterSize) {
offset = this.aMin + this.aGutterSize
} else if (offset >= this.size - (this.bMin + options.snapOffset + this.bGutterSize)) {
offset = this.size - (this.bMin + this.bGutterSize)
}
// Actually adjust the size.
adjust.call(this, offset)
// Call the drag callback continously. Don't do anything too intensive
// in this callback.
if (options.onDrag) {
options.onDrag()
}
}
// Cache some important sizes when drag starts, so we don't have to do that
// continously:
//
// `size`: The total size of the pair. First element + second element + first gutter + second gutter.
// `percentage`: The percentage between 0-100 that the pair occupies in the parent.
// `start`: The leading side of the first element.
//
// ------------------------------------------------ - - - - - - - - - - -
// | aGutterSize -> ||| | |
// | ||| | |
// | ||| | |
// | ||| <- bGutterSize | |
// ------------------------------------------------ - - - - - - - - - - -
// | <- start size -> | parentSize -> |
, calculateSizes = function () {
// Calculate the pairs size, and percentage of the parent size
// Figure out the parent size minus padding.
var computedStyle = global.getComputedStyle(this.parent)
, parentSize = this.parent[clientDimension] - parseFloat(computedStyle[paddingA]) - parseFloat(computedStyle[paddingB])
@ -216,13 +343,21 @@ var global = this
this.percentage = Math.min(this.size / parentSize * 100, 100)
this.start = this.a[getBoundingClientRect]()[position]
}
, adjust = function (offset) {
// A size is the same as offset. B size is total size - A size.
// Both sizes are calculated from the initial parent percentage.
// Actually adjust the size of elements `a` and `b` to `offset` while dragging.
// calc is used to allow calc(percentage + gutterpx) on the whole split instance,
// which allows the viewport to be resized without additional logic.
// Element a's size is the same as offset. b's size is total size - a size.
// Both sizes are calculated from the initial parent percentage, then the gutter size is subtracted.
, adjust = function (offset) {
this.a.style[dimension] = calc + '(' + (offset / this.size * this.percentage) + '% - ' + this.aGutterSize + 'px)'
this.b.style[dimension] = calc + '(' + (this.percentage - (offset / this.size * this.percentage)) + '% - ' + this.bGutterSize + 'px)'
}
// 4. Define a few more functions that "balance" the entire split instance.
// Split.js tries it's best to cope with min sizes that don't add up.
// At some point this should go away since it breaks out of the calc(% - px) model.
// Maybe it's a user error if you pass uncomputable minSizes.
, fitMin = function () {
var self = this
, a = self.a
@ -260,9 +395,31 @@ var global = this
fitMinReverse.call(pairs[i])
}
}
, preventSelection = function () { return false }
, setElementSize = function (el, size, gutterSize) {
// Split.js allows setting sizes via numbers (ideally), or if you must,
// by string, like '300px'. This is less than ideal, because it breaks
// the fluid layout that `calc(% - px)` provides. You're on your own if you do that,
// make sure you calculate the gutter size by hand.
if (typeof size !== 'string' && !(size instanceof String)) {
if (!isIE8) {
size = calc + '(' + size + '% - ' + gutterSize + 'px)'
} else {
size = options.sizes[i] + '%'
}
}
el.style[dimension] = size
}
// No-op function to prevent default. Used to prevent selection.
, noop = function () { return false }
// All DOM elements in the split should have a common parent. We can grab
// the first elements parent and hope users read the docs because the
// behavior will be whacky otherwise.
, parent = elementOrSelector(ids[0]).parentNode
// Set default options.sizes to equal percentages of the parent element.
if (!options.sizes) {
var percent = 100 / ids.length
@ -273,6 +430,8 @@ var global = this
}
}
// Standardize minSize to an array if it isn't already. This allows minSize
// to be passed as a number.
if (!Array.isArray(options.minSize)) {
var minSizes = []
@ -283,15 +442,34 @@ var global = this
options.minSize = minSizes
}
// 5. Loop through the elements while pairing them off. Every pair gets a
// `pair` object, a gutter, and isFirst/isLast properties.
//
// Basic logic:
//
// - Starting with the second element `i > 0`, create `pair` objects with
// `a = ids[i - 1]` and `b = ids[i]`
// - Set gutter sizes based on the _pair_ being first/last. The first and last
// pair have gutterSize / 2, since they only have one half gutter, and not two.
// - Create gutter elements and add event listeners.
// - Set the size of the elements, minus the gutter sizes.
//
// -----------------------------------------------------------------------
// | i=0 | i=1 | i=2 | i=3 |
// | | isFirst | | isLast |
// | pair 0 pair 1 pair 2 |
// | | | | |
// -----------------------------------------------------------------------
for (i = 0; i < ids.length; i++) {
var el = elementOrSelector(ids[i])
, isFirst = (i == 1)
, isLast = (i == ids.length - 1)
, size
, isFirstPair = (i == 1)
, isLastPair = (i == ids.length - 1)
, size = options.sizes[i]
, gutterSize = options.gutterSize
, pair
if (i > 0) {
// Create the pair object with it's metadata.
pair = {
a: elementOrSelector(ids[i - 1]),
b: el,
@ -299,27 +477,31 @@ var global = this
bMin: options.minSize[i],
dragging: false,
parent: parent,
isFirst: isFirst,
isLast: isLast,
isFirst: isFirstPair,
isLast: isLastPair,
direction: options.direction
}
// For first and last pairs, first and last gutter width is half.
pair.aGutterSize = options.gutterSize
pair.bGutterSize = options.gutterSize
if (isFirst) {
if (isFirstPair) {
pair.aGutterSize = options.gutterSize / 2
}
if (isLast) {
if (isLastPair) {
pair.bGutterSize = options.gutterSize / 2
}
}
// Determine the size of the current element. IE8 is supported by
// staticly assigning sizes without draggable gutters. Assigns a string
// to `size`.
//
// IE9 and above
if (!isIE8) {
// Create gutter elements for each pair.
if (i > 0) {
var gutter = document.createElement('div')
@ -334,35 +516,62 @@ var global = this
pair.gutter = gutter
}
// Half-size gutters for first and last elements.
if (i === 0 || i == ids.length - 1) {
gutterSize = options.gutterSize / 2
}
if (typeof options.sizes[i] === 'string' || options.sizes[i] instanceof String) {
size = options.sizes[i]
} else {
size = calc + '(' + options.sizes[i] + '% - ' + gutterSize + 'px)'
}
// IE8 and below
} else {
if (typeof options.sizes[i] === 'string' || options.sizes[i] instanceof String) {
size = options.sizes[i]
} else {
size = options.sizes[i] + '%'
}
}
el.style[dimension] = size
// Set the element size to our determined size.
setElementSize(el, size, gutterSize)
// After the first iteration, and we have a pair object, append it to the
// list of pairs.
if (i > 0) {
pairs.push(pair)
}
}
// Balance the pairs to try to accomodate min sizes.
balancePairs(pairs)
return {
setSizes: function (sizes) {
for (var i = 0; i < sizes.length; i++) {
if (i > 0) {
var pair = pairs[i - 1]
setElementSize(pair.a, sizes[i - 1], pair.aGutterSize)
setElementSize(pair.b, sizes[i], pair.bGutterSize)
}
}
},
collapse: function (i) {
var pair
if (i === pairs.length) {
pair = pairs[i - 1]
calculateSizes.call(pair)
adjust.call(pair, pair.size - pair.bGutterSize)
} else {
pair = pairs[i]
calculateSizes.call(pair)
adjust.call(pair, pair.aGutterSize)
}
},
destroy: function () {
for (var i = 0; i < pairs.length; i++) {
pairs[i].parent.removeChild(pairs[i].gutter)
pairs[i].a.style[dimension] = ''
pairs[i].b.style[dimension] = ''
}
}
}
}
// Play nicely with module systems, and the browser too if you include it raw.
if (typeof exports !== 'undefined') {
if (typeof module !== 'undefined' && module.exports) {
exports = module.exports = Split
@ -372,4 +581,5 @@ if (typeof exports !== 'undefined') {
global.Split = Split
}
// Call our wrapper function with the current global. In this case, `window`.
}).call(window);

8466
src/js/lib/xpath.js Executable file

File diff suppressed because it is too large Load diff

View file

@ -475,6 +475,43 @@ var Cipher = {
return output;
},
/**
* @constant
* @default
*/
SUBS_PLAINTEXT: "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
/**
* @constant
* @default
*/
SUBS_CIPHERTEXT: "XYZABCDEFGHIJKLMNOPQRSTUVW",
/**
* Substitute operation.
*
* @param {byte_array} input
* @param {Object[]} args
* @returns {byte_array}
*/
run_substitute: function (input, args) {
var plaintext = Utils.str_to_byte_array(Utils.expand_alph_range(args[0]).join()),
ciphertext = Utils.str_to_byte_array(Utils.expand_alph_range(args[1]).join()),
output = [],
index = -1;
if (plaintext.length !== ciphertext.length) {
output = Utils.str_to_byte_array("Warning: Plaintext and Ciphertext lengths differ\n\n");
}
for (var i = 0; i < input.length; i++) {
index = plaintext.indexOf(input[i]);
output.push(index > -1 && index < ciphertext.length ? ciphertext[index] : input[i]);
}
return output;
},
};

View file

@ -1,4 +1,4 @@
/* globals prettyPrintOne, vkbeautify */
/* globals prettyPrintOne, vkbeautify, xpath */
/**
* Code operations.
@ -304,4 +304,119 @@ var Code = {
}
},
/**
* @constant
* @default
*/
XPATH_INITIAL: "",
/**
* @constant
* @default
*/
XPATH_DELIMITER: "\\n",
/**
* XPath expression operation.
*
* @author Mikescher (https://github.com/Mikescher | https://mikescher.com)
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run_xpath:function(input, args) {
const query = args[0],
delimiter = args[1];
var xml;
try {
xml = $.parseXML(input);
} catch (err) {
return "Invalid input XML.";
}
var result;
try {
result = xpath.evaluate(xml, query);
} catch (err) {
return "Invalid XPath. Details:\n" + err.message;
}
const serializer = new XMLSerializer();
const node_to_string = function(node) {
switch (node.nodeType) {
case Node.ELEMENT_NODE: return serializer.serializeToString(node);
case Node.ATTRIBUTE_NODE: return node.value;
case Node.COMMENT_NODE: return node.data;
case Node.DOCUMENT_NODE: return serializer.serializeToString(node);
default: throw new Error("Unknown Node Type: " + node.nodeType);
}
};
return Object.keys(result).map(function(key) {
return result[key];
}).slice(0, -1) // all values except last (length)
.map(node_to_string)
.join(delimiter);
},
/**
* @constant
* @default
*/
CSS_SELECTOR_INITIAL: "",
/**
* @constant
* @default
*/
CSS_QUERY_DELIMITER: "\\n",
/**
* CSS selector operation.
*
* @author Mikescher (https://github.com/Mikescher | https://mikescher.com)
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run_css_query: function(input, args) {
const query = args[0],
delimiter = args[1];
var html;
try {
html = $.parseHTML(input);
} catch (err) {
return "Invalid input HTML.";
}
var result;
try {
result = $(html).find(query);
} catch (err) {
return "Invalid CSS Selector. Details:\n" + err.message;
}
const node_to_string = function(node) {
switch (node.nodeType) {
case Node.ELEMENT_NODE: return node.outerHTML;
case Node.ATTRIBUTE_NODE: return node.value;
case Node.COMMENT_NODE: return node.data;
case Node.TEXT_NODE: return node.wholeText;
case Node.DOCUMENT_NODE: return node.outerHTML;
default: throw new Error("Unknown Node Type: " + node.nodeType);
}
};
return Array.apply(null, Array(result.length))
.map(function(_, i) {
return result[i];
})
.map(node_to_string)
.join(delimiter);
},
};

View file

@ -10,7 +10,7 @@
var Extract = {
/**
* Runs search operations across the input data using refular expressions.
* Runs search operations across the input data using regular expressions.
*
* @private
* @param {string} input
@ -293,5 +293,5 @@ var Extract = {
output += Extract.run_dates(input, []);
return output;
},
};

View file

@ -205,14 +205,17 @@ HTMLApp.prototype.populate_operations_list = function() {
* Sets up the adjustable splitter to allow the user to resize areas of the page.
*/
HTMLApp.prototype.initialise_splitter = function() {
Split(["#operations", "#recipe", "#IO"], {
this.column_splitter = Split(["#operations", "#recipe", "#IO"], {
sizes: [20, 30, 50],
minSize: [240, 325, 500],
minSize: [240, 325, 440],
gutterSize: 4,
onDrag: this.manager.controls.adjust_width.bind(this.manager.controls)
onDrag: function() {
this.manager.controls.adjust_width();
this.manager.output.adjust_width();
}.bind(this)
});
Split(["#input", "#output"], {
this.io_splitter = Split(["#input", "#output"], {
direction: "vertical",
gutterSize: 4,
});
@ -463,13 +466,11 @@ HTMLApp.prototype.set_recipe_config = function(recipe_config) {
* Resets the splitter positions to default.
*/
HTMLApp.prototype.reset_layout = function() {
document.getElementById("operations").style.width = "calc(20% - 2px)";
document.getElementById("recipe").style.width = "calc(30% - 4px)";
document.getElementById("IO").style.width = "calc(50% - 2px)";
document.getElementById("input").style.height = "calc(50% - 2px)";
document.getElementById("output").style.height = "calc(50% - 2px)";
this.column_splitter.setSizes([20, 30, 50]);
this.io_splitter.setSizes([50, 50]);
this.manager.controls.adjust_width();
this.manager.output.adjust_width();
};

View file

@ -125,6 +125,7 @@ Manager.prototype.initialise_event_listeners = function() {
document.getElementById("save-to-file").addEventListener("click", this.output.save_click.bind(this.output));
document.getElementById("switch").addEventListener("click", this.output.switch_click.bind(this.output));
document.getElementById("undo-switch").addEventListener("click", this.output.undo_switch_click.bind(this.output));
document.getElementById("maximise-output").addEventListener("click", this.output.maximise_output_click.bind(this.output));
document.getElementById("output-text").addEventListener("scroll", this.highlighter.output_scroll.bind(this.highlighter));
document.getElementById("output-text").addEventListener("mouseup", this.highlighter.output_mouseup.bind(this.highlighter));
document.getElementById("output-text").addEventListener("mousemove", this.highlighter.output_mousemove.bind(this.highlighter));

View file

@ -95,6 +95,32 @@ OutputWaiter.prototype.set_output_info = function(length, lines, duration) {
};
/**
* Adjusts the display properties of the output buttons so that they fit within the current width
* without wrapping or overflowing.
*/
OutputWaiter.prototype.adjust_width = function() {
var output = document.getElementById("output"),
save_to_file = document.getElementById("save-to-file"),
switch_io = document.getElementById("switch"),
undo_switch = document.getElementById("undo-switch"),
maximise_output = document.getElementById("maximise-output");
if (output.clientWidth < 680) {
save_to_file.childNodes[1].nodeValue = "";
switch_io.childNodes[1].nodeValue = "";
undo_switch.childNodes[1].nodeValue = "";
maximise_output.childNodes[1].nodeValue = "";
} else {
save_to_file.childNodes[1].nodeValue = " Save to file";
switch_io.childNodes[1].nodeValue = " Move output to input";
undo_switch.childNodes[1].nodeValue = " Undo";
maximise_output.childNodes[1].nodeValue =
maximise_output.getAttribute("title") === "Maximise" ? " Max" : " Restore";
}
};
/**
* Handler for save click events.
* Saves the current output to a file, downloaded as a URL octet stream.
@ -137,3 +163,26 @@ OutputWaiter.prototype.undo_switch_click = function() {
this.app.set_input(this.switch_orig_data);
document.getElementById("undo-switch").disabled = true;
};
/**
* Handler for maximise output click events.
* Resizes the output frame to be as large as possible, or restores it to its original size.
*/
OutputWaiter.prototype.maximise_output_click = function(e) {
var el = e.target.id === "maximise-output" ? e.target : e.target.parentNode;
if (el.getAttribute("title") === "Maximise") {
this.app.column_splitter.collapse(0);
this.app.column_splitter.collapse(1);
this.app.io_splitter.collapse(0);
el.setAttribute("title", "Restore");
el.innerHTML = "<img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAlUlEQVQ4y93RwQpBQRQG4C9ba1fxBteGPIj38BTejFJKLFnwCJIiCsW1mcV0k9yx82/OzGK+OXMGOpiiLTFjFNiilQI0sQ7IJiAjLKsgGVYB2YdaVO0kwy46/BVQi9ZDNPyQWen2ub/KufS8y7shfkq9tF9U7SC+/YluKvAI9YZeFeCECXJcA3JHP2WgMXJM/ZUcBwxeM+YuSWTgMtUAAAAASUVORK5CYII='> Restore";
this.adjust_width();
} else {
el.setAttribute("title", "Maximise");
el.innerHTML = "<img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAi0lEQVQ4y83TMQrCQBCF4S+5g4rJEdJ7KE+RQ1lrIQQCllroEULuoM0Ww3a7aXwwLAzMPzDvLcz4hnooUItT1rsoVNy+4lgLWNL7RlcCmDBij2eCfNCrUITc0dRCrhj8m5otw0O6SV8LuAV3uhrAAa8sJ2Np7KPFawhgscVLjH9bCDhjt8WNKft88w/HjCvuVqu53QAAAABJRU5ErkJggg=='> Max";
this.app.reset_layout();
}
};