kiwix-js-pwa/www/js/lib/uiUtil.js
Jaifroid 9b776fabb7 Improvements to stylesheet injection
Former-commit-id: 86f79bd93f6a2dd07a24f17409e3f57c1554689f [formerly f2b9d4d81ef1ca875595a651c74bb20d062bfe79]
Former-commit-id: 92e3b3e933fca77ba3985679dca3e3efbef40233
2017-07-13 13:41:51 +01:00

64 lines
2.0 KiB
JavaScript

/**
* uiUtil.js : Utility functions for the User Interface
*
* Copyright 2013-2014 Mossroy and contributors
* License GPL v3:
*
* This file is part of Kiwix.
*
* Kiwix is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Kiwix 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. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Kiwix (file LICENSE-GPLv3.txt). If not, see <http://www.gnu.org/licenses/>
*/
'use strict';
define([], function() {
/**
* Creates a Blob from the given content, then a URL from this Blob
* And put this URL in the attribute of the DOM node
*
* This is useful to inject images (and other dependencies) inside an article
*
* @param {Object} jQueryNode
* @param {String} nodeAttribute
* @param {Uint8Array} content
* @param {String} mimeType
*/
function feedNodeWithBlob(jQueryNode, nodeAttribute, content, mimeType) {
var blob = new Blob([content], { type: mimeType }, {oneTimeOnly: true});
var url = URL.createObjectURL(blob);
/*jQueryNode.on('load', function () {
URL.revokeObjectURL(url);
});*/
jQueryNode.attr(nodeAttribute, url);
}
var regexpRemoveUrlParameters = new RegExp(/([^\?]+)\?.*$/);
function removeUrlParameters(url) {
if (regexpRemoveUrlParameters.test(url)) {
return regexpRemoveUrlParameters.exec(url)[1];
} else {
return url;
}
}
/**
* Functions and classes exposed by this module
*/
return {
feedNodeWithBlob: feedNodeWithBlob,
removeUrlParameters: removeUrlParameters
};
});