mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-29 05:28:44 +02:00
poc form SDK (extends to form)
This commit is contained in:
69
js/DI/toolkit.js
Normal file
69
js/DI/toolkit.js
Normal file
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* Toolkit.
|
||||
*
|
||||
* @returns {{init: init, parseTextToHtml: (function(*): Document), createElementFromHtml: (function(*): DocumentFragment)}}
|
||||
* @constructor
|
||||
*/
|
||||
const Toolkit = function(){
|
||||
|
||||
function init(){
|
||||
installStringFormatFunction();
|
||||
}
|
||||
|
||||
/**
|
||||
* installStringFormatFunction.
|
||||
*
|
||||
* String formatter utility.
|
||||
*/
|
||||
function installStringFormatFunction(){
|
||||
if (!String.format) {
|
||||
String.format = function(format) {
|
||||
const args = Array.prototype.slice.call(arguments, 1);
|
||||
return format.replace(/{(\d+)}/g, function(match, number) {
|
||||
return typeof args[number] != 'undefined' ? args[number] : match;
|
||||
});
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* parseTextToHtml.
|
||||
*
|
||||
* @param sText
|
||||
* @returns {Document}
|
||||
*/
|
||||
function parseTextToHtml(sText){
|
||||
const oParser = new DOMParser();
|
||||
return oParser.parseFromString(sText, 'text/html');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param html
|
||||
* @returns {DocumentFragment}
|
||||
*/
|
||||
function createElementFromHtml(html) {
|
||||
const t = document.createElement('template');
|
||||
t.innerHTML = html;
|
||||
return t.content;
|
||||
}
|
||||
|
||||
return {
|
||||
init,
|
||||
parseTextToHtml,
|
||||
createElementFromHtml
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user