diff -r 02c04d2c8fd8 -r ac1eacb3aa33 src/js/utils.js --- a/src/js/utils.js Sun Nov 12 22:07:33 2017 +0100 +++ b/src/js/utils.js Wed Sep 04 17:32:50 2024 +0200 @@ -1,35 +1,12 @@ /* utils.js - various utils that don't belong anywhere else */ - -IriSP.jqEscape = function(_text) { - return _text.replace(/(:|\.)/g,'\\$1'); -}; +import _ from "lodash"; -IriSP.getLib = function(lib) { - if (IriSP.libFiles.useCdn && typeof IriSP.libFiles.cdn[lib] == "string") { - return IriSP.libFiles.cdn[lib]; - } - if (typeof IriSP.libFiles.locations[lib] == "string") { - return IriSP.libFiles.locations[lib]; - } - if (typeof IriSP.libFiles.inDefaultDir[lib] == "string") { - return IriSP.libFiles.defaultDir + '/' + IriSP.libFiles.inDefaultDir[lib]; - } -}; +export default function(IriSP) { return { + jqEscape: function(_text) { + return _text.replace(/(:|\.)/g,'\\$1'); + }, -IriSP._cssCache = []; - -IriSP.loadCss = function(_cssFile) { - if (IriSP._(IriSP._cssCache).indexOf(_cssFile) === -1) { - IriSP.jQuery("", { - rel : "stylesheet", - type : "text/css", - href : _cssFile - }).appendTo('head'); - IriSP._cssCache.push(_cssFile); - } -}; - -IriSP.textFieldHtml = function(_text, _regexp, _extend) { + textFieldHtml: function(_text, _regexp, _extend) { var list = [], positions = [], text = _text.replace(/(^\s+|\s+$)/g,''); @@ -66,11 +43,11 @@ addToList(/\*[^*]+\*/gm, '', ''); addToList(/[\n\r]+/gm, '', '
'); - IriSP._(_extend).each(function(x) { + _(_extend).each(function(x) { addToList.apply(null, x); }); - positions = IriSP._(positions) + positions = _(positions) .chain() .uniq() .sortBy(function(p) { return parseInt(p); }) @@ -100,22 +77,22 @@ return res; -}; + }, -IriSP.log = function() { + log: function() { if (typeof console !== "undefined" && typeof IriSP.logging !== "undefined" && IriSP.logging) { console.log.apply(console, arguments); } -}; + }, -IriSP.attachDndData = function(jqSel, data) { + attachDndData: function(jqSel, data) { jqSel.attr("draggable", "true").on("dragstart", function(_event) { var d = (typeof data === "function" ? data.call(this) : data); try { if (d.html === undefined && d.uri && d.text) { d.html = '' + d.text + ''; } - IriSP._(d).each(function(v, k) { + _(d).each(function(v, k) { if (v && k != 'text' && k != 'html') { _event.originalEvent.dataTransfer.setData("text/x-iri-" + k, v); } @@ -137,17 +114,17 @@ _event.originalEvent.dataTransfer.setData("Text", JSON.stringify(d)); } }); -}; + }, -IriSP.FakeClass = function(properties) { + FakeClass: function(properties) { var _this = this, noop = (function() {}); - IriSP._(properties).each(function(p) { + _(properties).each(function(p) { _this[p] = noop; }); -}; + }, -IriSP.timestamp2ms = function(t) { + timestamp2ms: function(t) { // Convert timestamp to numeric value // It accepts the following forms: // [h:mm:ss] [mm:ss] [ss] @@ -156,9 +133,9 @@ s.push("0"); } return 1000 * (3600 * parseInt(s[2], 10) + 60 * parseInt(s[1], 10) + parseInt(s[0], 10)); -}; + }, -IriSP.setFullScreen= function(elem, value) { + setFullScreen: function(elem, value) { // Set fullscreen on or off if (value) { if (elem.requestFullscreen) { @@ -181,24 +158,25 @@ document.webkitExitFullscreen(); } } -}; + }, -IriSP.isFullscreen = function() { + isFullscreen: function() { return (document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement); -}; + }, -IriSP.getFullscreenElement = function () { + getFullscreenElement: function () { return (document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement || undefined); -}; + }, -IriSP.getFullscreenEventname = function () { + getFullscreenEventname: function () { return ((document.exitFullscreen && "fullscreenchange") || (document.webkitExitFullscreen && "webkitfullscreenchange") || (document.mozExitFullScreen && "mozfullscreenchange") || (document.msExitFullscreen && "msfullscreenchange") || ""); -}; + }, +}}; \ No newline at end of file