From df8996930150bc9874458fb24d9636e51093251f Mon Sep 17 00:00:00 2001
From: Alejandro Gallardo Escobar
) and a new line followed by a blank line becomes a paragraph break (
Joel
is a
slug
+ */ + humanize.linebreaks = function(str) { + // remove beginning and ending newlines + str = str.replace(/^([\n|\r]*)/, ''); + str = str.replace(/([\n|\r]*)$/, ''); + + // normalize all to \n + str = str.replace(/(\r\n|\n|\r)/g, "\n"); + + // any consecutive new lines more than 2 gets turned into p tags + str = str.replace(/(\n{2,})/g, '');
+
+ // any that are singletons get turned into br
+ str = str.replace(/\n/g, '
');
+ return '
' + str + '
'; + }; + + /** + * Converts all newlines in a piece of plain text to HTML line breaks (+ * var md = new MobileDetect(window.navigator.userAgent); + * if (md.mobile()) { + * location.href = (md.mobileGrade() === 'A') ? '/mobile/' : '/lynx/'; + * } + *+ * + * @param {string} userAgent typically taken from window.navigator.userAgent or http_header['User-Agent'] + * @param {number} [maxPhoneWidth=600] only for browsers specify a value for the maximum + * width of smallest device side (in logical "CSS" pixels) until a device detected as mobile will be handled + * as phone. + * This is only used in cases where the device cannot be classified as phone or tablet.
UnknownPhone
, UnknownTablet
or
+ * UnknownMobile
is returned.screen.width/height
.UnknownTablet
+ * and UnknownMobile
, so you will get UnknownMobile
here.UnknownMobile
only for:
+ * {@link MobileDetect#mobile}, not for {@link MobileDetect#phone} and {@link MobileDetect#tablet}.
+ * In versions before v1.0.0 all 3 methods returned UnknownMobile
which was tedious to use.
+ * UnknownPhone
or UnknownMobile
is returned.screen.width/height
.UnknownTablet
+ * and UnknownMobile
, so you will get null
here, while {@link MobileDetect#mobile}
+ * will return UnknownMobile
.UnknownMobile
only for:
+ * {@link MobileDetect#mobile}, not for {@link MobileDetect#phone} and {@link MobileDetect#tablet}.
+ * In versions before v1.0.0 all 3 methods returned UnknownMobile
which was tedious to use.
+ * UnknownTablet
or UnknownMobile
is returned.screen.width/height
.UnknownTablet
+ * and UnknownMobile
, so you will get null
here, while {@link MobileDetect#mobile}
+ * will return UnknownMobile
.UnknownMobile
only for:
+ * {@link MobileDetect#mobile}, not for {@link MobileDetect#phone} and {@link MobileDetect#tablet}.
+ * In versions before v1.0.0 all 3 methods returned UnknownMobile
which was tedious to use.
+ * screen.width
.
+ * undefined
if screen size wasn't detectable, else true
+ * when screen.width is less or equal to maxPhoneWidth, otherwise false
.undefined
server-side.
+ */
+ isPhoneSized: function (maxPhoneWidth) {
+ return MobileDetect.isPhoneSized(maxPhoneWidth || this.maxPhoneWidth);
+ },
+
+ /**
+ * Returns the mobile grade ('A', 'B', 'C').
+ *
+ * @returns {String} one of the mobile grades ('A', 'B', 'C').
+ * @function MobileDetect#mobileGrade
+ */
+ mobileGrade: function () {
+ if (this._cache.grade === undefined) {
+ this._cache.grade = impl.mobileGrade(this);
+ }
+ return this._cache.grade;
+ }
+ };
+
+ // environment-dependent
+ if (typeof window !== 'undefined' && window.screen) {
+ MobileDetect.isPhoneSized = function (maxPhoneWidth) {
+ return maxPhoneWidth < 0 ? undefined : impl.getDeviceSmallerSide() <= maxPhoneWidth;
+ };
+ } else {
+ MobileDetect.isPhoneSized = function () {};
+ }
+
+ // should not be replaced by a completely new object - just overwrite existing methods
+ MobileDetect._impl = impl;
+
+ return MobileDetect;
+}); // end of call of define()
+})((function (undefined) {
+ if (typeof module !== 'undefined' && module.exports) {
+ return function (factory) { module.exports = factory(); };
+ } else if (typeof define === 'function' && define.amd) {
+ return define;
+ } else if (typeof window !== 'undefined') {
+ return function (factory) { window.MobileDetect = factory(); };
+ } else {
+ // please file a bug if you get this error!
+ throw new Error('unknown environment');
+ }
+})());
+},{}],255:[function(require,module,exports){
+/**
+ * Helpers.
+ */
+
+var s = 1000;
+var m = s * 60;
+var h = m * 60;
+var d = h * 24;
+var y = d * 365.25;
+
+/**
+ * Parse or format the given `val`.
+ *
+ * Options:
+ *
+ * - `long` verbose formatting [false]
+ *
+ * @param {String|Number} val
+ * @param {Object} options
+ * @return {String|Number}
+ * @api public
+ */
+
+module.exports = function(val, options){
+ options = options || {};
+ if ('string' == typeof val) return parse(val);
+ return options.long
+ ? long(val)
+ : short(val);
+};
+
+/**
+ * Parse the given `str` and return milliseconds.
+ *
+ * @param {String} str
+ * @return {Number}
+ * @api private
+ */
+
+function parse(str) {
+ str = '' + str;
+ if (str.length > 10000) return;
+ var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(str);
+ if (!match) return;
+ var n = parseFloat(match[1]);
+ var type = (match[2] || 'ms').toLowerCase();
+ switch (type) {
+ case 'years':
+ case 'year':
+ case 'yrs':
+ case 'yr':
+ case 'y':
+ return n * y;
+ case 'days':
+ case 'day':
+ case 'd':
+ return n * d;
+ case 'hours':
+ case 'hour':
+ case 'hrs':
+ case 'hr':
+ case 'h':
+ return n * h;
+ case 'minutes':
+ case 'minute':
+ case 'mins':
+ case 'min':
+ case 'm':
+ return n * m;
+ case 'seconds':
+ case 'second':
+ case 'secs':
+ case 'sec':
+ case 's':
+ return n * s;
+ case 'milliseconds':
+ case 'millisecond':
+ case 'msecs':
+ case 'msec':
+ case 'ms':
+ return n;
+ }
+}
+
+/**
+ * Short format for `ms`.
+ *
+ * @param {Number} ms
+ * @return {String}
+ * @api private
+ */
+
+function short(ms) {
+ if (ms >= d) return Math.round(ms / d) + 'd';
+ if (ms >= h) return Math.round(ms / h) + 'h';
+ if (ms >= m) return Math.round(ms / m) + 'm';
+ if (ms >= s) return Math.round(ms / s) + 's';
+ return ms + 'ms';
+}
+
+/**
+ * Long format for `ms`.
+ *
+ * @param {Number} ms
+ * @return {String}
+ * @api private
+ */
+
+function long(ms) {
+ return plural(ms, d, 'day')
+ || plural(ms, h, 'hour')
+ || plural(ms, m, 'minute')
+ || plural(ms, s, 'second')
+ || ms + ' ms';
+}
+
+/**
+ * Pluralization helper.
+ */
+
+function plural(ms, n, name) {
+ if (ms < n) return;
+ if (ms < n * 1.5) return Math.floor(ms / n) + ' ' + name;
+ return Math.ceil(ms / n) + ' ' + name + 's';
+}
+
+},{}],256:[function(require,module,exports){
+/**
+ * Dependencies.
+ */
+var Util = require('./lib/util');
+var Keys = require('./lib/keys');
+var KbdUtil = require('./lib/kbdutil');
+var Input = require('./lib/input');
+var Websock = require('./lib/websock');
+var Base64 = require('./lib/base64');
+var DES = require('./lib/des');
+var TINF = require('./lib/tinf');
+var Display = require('./lib/display');
+var RFB = require('./lib/rfb');
+
+
+
+var noVNC = {
+ Util: Util,
+ Keys: Keys,
+ KbdUtil: KbdUtil,
+ Input: Input,
+ Websock: Websock,
+ Base64: Base64,
+ DES: DES,
+ TINF: TINF,
+ Display: Display,
+ RFB: RFB
+};
+
+
+module.exports = noVNC;
+
+},{"./lib/base64":257,"./lib/des":258,"./lib/display":259,"./lib/input":260,"./lib/kbdutil":261,"./lib/keys":262,"./lib/rfb":263,"./lib/tinf":264,"./lib/util":265,"./lib/websock":266}],257:[function(require,module,exports){
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/**
+ * Dependencies.
+ */
+var debugerror = require('debug')('noVNC:ERROR:Base64');
+debugerror.log = console.warn.bind(console);
+
+
+/**
+ * Local variables.
+ */
+var toBase64Table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='.split('');
+var base64Pad = '=';
+var toBinaryTable = [
+ -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
+ -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
+ -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,62, -1,-1,-1,63,
+ 52,53,54,55, 56,57,58,59, 60,61,-1,-1, -1, 0,-1,-1,
+ -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11,12,13,14,
+ 15,16,17,18, 19,20,21,22, 23,24,25,-1, -1,-1,-1,-1,
+ -1,26,27,28, 29,30,31,32, 33,34,35,36, 37,38,39,40,
+ 41,42,43,44, 45,46,47,48, 49,50,51,-1, -1,-1,-1,-1
+];
+
+
+/**
+ * Expose the Base64 Object.
+ */
+module.exports = {
+ encode: function (data) {
+ var result = '';
+ var length = data.length;
+ var lengthpad = (length % 3);
+
+ // Convert every three bytes to 4 ascii characters.
+ for (var i = 0; i < (length - 2); i += 3) {
+ result += toBase64Table[data[i] >> 2];
+ result += toBase64Table[((data[i] & 0x03) << 4) + (data[i + 1] >> 4)];
+ result += toBase64Table[((data[i + 1] & 0x0f) << 2) + (data[i + 2] >> 6)];
+ result += toBase64Table[data[i + 2] & 0x3f];
+ }
+
+ // Convert the remaining 1 or 2 bytes, pad out to 4 characters.
+ var j = 0;
+ if (lengthpad === 2) {
+ j = length - lengthpad;
+ result += toBase64Table[data[j] >> 2];
+ result += toBase64Table[((data[j] & 0x03) << 4) + (data[j + 1] >> 4)];
+ result += toBase64Table[(data[j + 1] & 0x0f) << 2];
+ result += toBase64Table[64];
+ } else if (lengthpad === 1) {
+ j = length - lengthpad;
+ result += toBase64Table[data[j] >> 2];
+ result += toBase64Table[(data[j] & 0x03) << 4];
+ result += toBase64Table[64];
+ result += toBase64Table[64];
+ }
+
+ return result;
+ },
+
+ decode: function (data, offset) {
+ offset = typeof(offset) !== 'undefined' ? offset : 0;
+ var result, result_length;
+ var leftbits = 0; // number of bits decoded, but yet to be appended
+ var leftdata = 0; // bits decoded, but yet to be appended
+ var data_length = data.indexOf('=') - offset;
+
+ if (data_length < 0) { data_length = data.length - offset; }
+
+ /* Every four characters is 3 resulting numbers */
+ result_length = (data_length >> 2) * 3 + Math.floor((data_length % 4) / 1.5);
+ result = new Array(result_length);
+
+ // Convert one by one.
+ for (var idx = 0, i = offset; i < data.length; i++) {
+ var c = toBinaryTable[data.charCodeAt(i) & 0x7f];
+ var padding = (data.charAt(i) === base64Pad);
+ // Skip illegal characters and whitespace
+ if (c === -1) {
+ debugerror('decode() | illegal character code ' + data.charCodeAt(i) + ' at position ' + i);
+ continue;
+ }
+
+ // Collect data into leftdata, update bitcount
+ leftdata = (leftdata << 6) | c;
+ leftbits += 6;
+
+ // If we have 8 or more bits, append 8 bits to the result
+ if (leftbits >= 8) {
+ leftbits -= 8;
+ // Append if not padding.
+ if (!padding) {
+ result[idx++] = (leftdata >> leftbits) & 0xff;
+ }
+ leftdata &= (1 << leftbits) - 1;
+ }
+ }
+
+ // If there are any bits left, the base64 string was corrupted
+ if (leftbits) {
+ debugerror('decode() | corrupted Base64 string');
+ var err = new Error('Corrupted Base64 string');
+ err.name = 'Base64-Error';
+ throw err;
+ }
+
+ return result;
+ }
+};
+
+},{"debug":123}],258:[function(require,module,exports){
+/*
+ * Ported from Flashlight VNC ActionScript implementation:
+ * http://www.wizhelp.com/flashlight-vnc/
+ *
+ * Full attribution follows:
+ *
+ * -------------------------------------------------------------------------
+ *
+ * This DES class has been extracted from package Acme.Crypto for use in VNC.
+ * The unnecessary odd parity code has been removed.
+ *
+ * These changes are:
+ * Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+
+ * DesCipher - the DES encryption method
+ *
+ * The meat of this code is by Dave Zimmerman