From 84b60810dad1552a7fb25df0c64733f29123620e Mon Sep 17 00:00:00 2001 From: Jakub Jankiewicz Date: Thu, 16 Aug 2018 18:02:07 +0200 Subject: [PATCH] UMD for unix_formatting #418 --- CHANGELOG.md | 1 + js/jquery.terminal.d.ts | 1 + js/unix_formatting.js | 43 +++++++++++++++++++++++++++++++++++------ 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae11bb158..b03741703 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Features * linksNoFollow option (default false) +* add UMD for utility files [#418](https://github.com/jcubic/jquery.terminal/issues/418) ### Bug Fixes * handling backspaces in unix formatting [#409](https://github.com/jcubic/jquery.terminal/issues/409) diff --git a/js/jquery.terminal.d.ts b/js/jquery.terminal.d.ts index 71a220919..3f62642fe 100644 --- a/js/jquery.terminal.d.ts +++ b/js/jquery.terminal.d.ts @@ -392,6 +392,7 @@ type TerminalOptions = { processRPCResponse?: null | JQueryTerminal.processRPCResponseFunction; completionEscape?: boolean; convertLinks?: boolean; + unixFormattingEscapeBrackets?: boolean; // provided by unix_formatting extra?: any; tabs?: number; historySize?: number; diff --git a/js/unix_formatting.js b/js/unix_formatting.js index cd8431c82..000df9105 100644 --- a/js/unix_formatting.js +++ b/js/unix_formatting.js @@ -13,12 +13,43 @@ * Released under the MIT license * */ -/* global jQuery */ -(function($) { - if (!$.terminal) { - throw new Error('$.terminal is not defined'); +/* global jQuery, define, global, require, module */ +(function(factory) { + var root = typeof window !== 'undefined' ? window : global; + if (typeof define === 'function' && define.amd) { + // AMD. Register as an anonymous module. + // istanbul ignore next + define(['jquery', 'jquery.terminal'], factory); + } else if (typeof module === 'object' && module.exports) { + // Node/CommonJS + module.exports = function(root, jQuery) { + if (jQuery === undefined) { + // require('jQuery') returns a factory that requires window to + // build a jQuery instance, we normalize how we use modules + // that require this pattern but the window provided is a noop + // if it's defined (how jquery works) + if (typeof window !== 'undefined') { + jQuery = require('jquery'); + } else { + jQuery = require('jquery')(root); + } + } + if (!jQuery.fn.terminal) { + if (typeof window !== 'undefined') { + require('jquery.terminal'); + } else { + require('jquery.terminal')(jQuery); + } + } + factory(jQuery); + return jQuery; + }; + } else { + // Browser + // istanbul ignore next + factory(root.jQuery); } - +})(function($) { $.terminal.defaults.unixFormattingEscapeBrackets = false; // we match characters and html entities because command line escape brackets // echo don't, when writing formatter always process html entitites so it work @@ -515,4 +546,4 @@ $.terminal.defaults.formatters.unshift($.terminal.overtyping); $.terminal.defaults.formatters.unshift($.terminal.from_ansi); -})(jQuery); +});