moodle_local_treestudyplan/amd/build/util/textfit.min.js.map

1 line
12 KiB
Plaintext
Raw Normal View History

2024-02-23 09:20:10 +01:00
{"version":3,"file":"textfit.min.js","sources":["../../src/util/textfit.js"],"sourcesContent":["/**\n * textFit v2.3.1\n * Previously known as jQuery.textFit\n * 11/2014 by STRML (strml.github.com)\n * MIT License\n *\n * To use: textFit(document.getElementById('target-div'), options);\n *\n * Will make the *text* content inside a container scale to fit the container\n * The container is required to have a set width and height\n * Uses binary search to fit text with minimal layout calls.\n * Version 2.0 does not use jQuery.\n */\nvar defaultSettings = {\n alignVert: false, // if true, textFit will align vertically using css tables\n alignHoriz: false, // if true, textFit will set text-align: center\n multiLine: false, // if true, textFit will not set white-space: no-wrap\n detectMultiLine: true, // disable to turn off automatic multi-line sensing\n minFontSize: 6,\n maxFontSize: 80,\n reProcess: true, // if true, textFit will re-process already-fit nodes. Set to 'false' for better performance\n widthOnly: false, // if true, textFit will fit text to element width, regardless of text height\n alignVertWithFlexbox: false, // if true, textFit will use flexbox for vertical alignment\n};\n\n/**\n * Create new textFit element(S)\n * @param {*} els element or element list\n * @param {*} options Options (See default settings in textfit.js)\n */\nexport function textFit(els, options) {\n\n if (!options) { options = {}; }\n\n // Extend options.\n var settings = {};\n for(var key in defaultSettings){\n if(options.hasOwnProperty(key)){\n settings[key] = options[key];\n } else {\n settings[key] = defaultSettings[key];\n }\n }\n\n // Convert jQuery objects into arrays\n if (typeof els.toArray === \"function\") {\n els = els.toArray();\n }\n\n // Support passing a single el\n var elType = Object.prototype.toString.call(els);\n if (elType !== '[object Array]' && elType !== '[object NodeList]' &&\n elType !== '[object HTMLCollection]'){\n els = [els];\n }\n\n // Process each el we've passed.\n for(var i = 0; i < els.length; i++){\n processItem(els[i], settings);\n }\n}\n\n/**\n * The meat. Given an el, make the text inside it fit its parent.\n * @param {DOMElement} el Child el.\n * @param {Object} settings Options for fit.\n */\nfunction processItem(el, settings){\n if (!isElement(el) || (!settings.reProcess && el.getAttribute('textFitted'))) {\n return false;\n }\n\n // Set textFitted attribute so we know this was processed.\n if(!settings.reProcess){\n el.setAttribute('textFitted', 1);\n }\n\n var innerSpan, originalHeight, originalHTML, originalWidth;\n var low, mid, high;\n\n // Get element data.\n originalHTML = el.innerHTML;\n originalWidth = innerWidth(el);\n originalHeight = innerHeight(el);\n\n // Don't process if we can't find box dimensions\n if (!originalWidth || (!settings.widthOnly && !originalHeight)) {\n if(!settings.widthOnly) {\n throw new Error('Set a static height and width on the target element ' + el.outerHTML +\n ' before using textFit!');\n } else {\n throw new Error('Set a static width on the target element ' + el.outerHTML +\n ' before using textFit!');\n }\n }\n\n // Add textFitted span inside this container.\n if (originalHTML.indexOf('textFitted') === -1) {\n innerSpan = document.createElement('span');\n innerSpan.className = 'textFitted';\n // Inline block ensure it takes on the size of its contents, even if they are enclosed\n // in other tags like <p>\n innerSpan.style['display'] = 'inline-block';\n innerSpan.innerHTML = originalHTML;\n el.innerHTML = '';\n el.appendChild(innerSpan);\n } else {\n // Reprocessing.\n innerSpan = el.querySelector('span.textFitted');\n // Remove vertical align if we're reprocessing.\n if (hasClass(innerSpan, 'textFitAl