2007-01-16 12:52:13 -05:00
|
|
|
/**
|
2010-10-02 01:14:12 -04:00
|
|
|
* form_utils.js
|
2007-01-16 12:52:13 -05:00
|
|
|
*
|
2010-10-02 01:14:12 -04:00
|
|
|
* Released under LGPL License.
|
2017-05-08 01:32:46 -04:00
|
|
|
* Copyright (c) 1999-2017 Ephox Corp. All rights reserved
|
2007-01-16 12:52:13 -05:00
|
|
|
*
|
TinyMCE 4.0.12, first run.
- Removes wp-tinymce-schema.js and mark-loaded.js, no longer needed.
- Removes the inlinepopups and most of the wpdialogs plugins; wpdialog.js is moved to wp-includes/js.
- Adds charmap, compat3x, image, link and textcolor plugins, previously contained in /themes/advanced.
- Updates the wordpress, wpeditimage, wpfullscreen, wpgallery and wplink plugins.
- Updates DFW, wp-admin/js/wp-fullscreen.js.
See #24067.
Built from https://develop.svn.wordpress.org/trunk@26876
git-svn-id: http://core.svn.wordpress.org/trunk@26759 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-12-28 18:53:15 -05:00
|
|
|
* License: http://www.tinymce.com/license
|
|
|
|
* Contributing: http://www.tinymce.com/contributing
|
2007-01-16 12:52:13 -05:00
|
|
|
*/
|
|
|
|
|
2008-01-17 10:44:05 -05:00
|
|
|
var themeBaseURL = tinyMCEPopup.editor.baseURI.toAbsolute('themes/' + tinyMCEPopup.getParam("theme"));
|
2007-01-16 12:52:13 -05:00
|
|
|
|
|
|
|
function getColorPickerHTML(id, target_form_element) {
|
2017-05-08 01:32:46 -04:00
|
|
|
var h = "", dom = tinyMCEPopup.dom;
|
2007-01-16 12:52:13 -05:00
|
|
|
|
2017-05-08 01:32:46 -04:00
|
|
|
if (label = dom.select('label[for=' + target_form_element + ']')[0]) {
|
|
|
|
label.id = label.id || dom.uniqueId();
|
|
|
|
}
|
2011-04-10 14:36:05 -04:00
|
|
|
|
2017-05-08 01:32:46 -04:00
|
|
|
h += '<a role="button" aria-labelledby="' + id + '_label" id="' + id + '_link" href="javascript:;" onclick="tinyMCEPopup.pickColor(event,\'' + target_form_element + '\');" onmousedown="return false;" class="pickcolor">';
|
|
|
|
h += '<span id="' + id + '" title="' + tinyMCEPopup.getLang('browse') + '"> <span id="' + id + '_label" class="mceVoiceLabel mceIconOnly" style="display:none;">' + tinyMCEPopup.getLang('browse') + '</span></span></a>';
|
2007-01-16 12:52:13 -05:00
|
|
|
|
2017-05-08 01:32:46 -04:00
|
|
|
return h;
|
2007-01-16 12:52:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function updateColor(img_id, form_element_id) {
|
2017-05-08 01:32:46 -04:00
|
|
|
document.getElementById(img_id).style.backgroundColor = document.forms[0].elements[form_element_id].value;
|
2007-01-16 12:52:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function setBrowserDisabled(id, state) {
|
2017-05-08 01:32:46 -04:00
|
|
|
var img = document.getElementById(id);
|
|
|
|
var lnk = document.getElementById(id + "_link");
|
|
|
|
|
|
|
|
if (lnk) {
|
|
|
|
if (state) {
|
|
|
|
lnk.setAttribute("realhref", lnk.getAttribute("href"));
|
|
|
|
lnk.removeAttribute("href");
|
|
|
|
tinyMCEPopup.dom.addClass(img, 'disabled');
|
|
|
|
} else {
|
|
|
|
if (lnk.getAttribute("realhref")) {
|
|
|
|
lnk.setAttribute("href", lnk.getAttribute("realhref"));
|
|
|
|
}
|
|
|
|
|
|
|
|
tinyMCEPopup.dom.removeClass(img, 'disabled');
|
|
|
|
}
|
|
|
|
}
|
2007-01-16 12:52:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function getBrowserHTML(id, target_form_element, type, prefix) {
|
2017-05-08 01:32:46 -04:00
|
|
|
var option = prefix + "_" + type + "_browser_callback", cb, html;
|
2007-01-16 12:52:13 -05:00
|
|
|
|
2017-05-08 01:32:46 -04:00
|
|
|
cb = tinyMCEPopup.getParam(option, tinyMCEPopup.getParam("file_browser_callback"));
|
2007-01-16 12:52:13 -05:00
|
|
|
|
2017-05-08 01:32:46 -04:00
|
|
|
if (!cb) {
|
|
|
|
return "";
|
|
|
|
}
|
2008-01-17 10:44:05 -05:00
|
|
|
|
2017-05-08 01:32:46 -04:00
|
|
|
html = "";
|
|
|
|
html += '<a id="' + id + '_link" href="javascript:openBrowser(\'' + id + '\',\'' + target_form_element + '\', \'' + type + '\',\'' + option + '\');" onmousedown="return false;" class="browse">';
|
|
|
|
html += '<span id="' + id + '" title="' + tinyMCEPopup.getLang('browse') + '"> </span></a>';
|
2007-01-16 12:52:13 -05:00
|
|
|
|
2017-05-08 01:32:46 -04:00
|
|
|
return html;
|
2007-01-16 12:52:13 -05:00
|
|
|
}
|
|
|
|
|
2008-01-17 10:44:05 -05:00
|
|
|
function openBrowser(img_id, target_form_element, type, option) {
|
2017-05-08 01:32:46 -04:00
|
|
|
var img = document.getElementById(img_id);
|
2007-01-16 12:52:13 -05:00
|
|
|
|
2017-05-08 01:32:46 -04:00
|
|
|
if (img.className != "mceButtonDisabled") {
|
|
|
|
tinyMCEPopup.openBrowser(target_form_element, type, option);
|
|
|
|
}
|
2007-01-16 12:52:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function selectByValue(form_obj, field_name, value, add_custom, ignore_case) {
|
2017-05-08 01:32:46 -04:00
|
|
|
if (!form_obj || !form_obj.elements[field_name]) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!value) {
|
|
|
|
value = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
var sel = form_obj.elements[field_name];
|
|
|
|
|
|
|
|
var found = false;
|
|
|
|
for (var i = 0; i < sel.options.length; i++) {
|
|
|
|
var option = sel.options[i];
|
|
|
|
|
|
|
|
if (option.value == value || (ignore_case && option.value.toLowerCase() == value.toLowerCase())) {
|
|
|
|
option.selected = true;
|
|
|
|
found = true;
|
|
|
|
} else {
|
|
|
|
option.selected = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found && add_custom && value != '') {
|
|
|
|
var option = new Option(value, value);
|
|
|
|
option.selected = true;
|
|
|
|
sel.options[sel.options.length] = option;
|
|
|
|
sel.selectedIndex = sel.options.length - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return found;
|
2007-01-16 12:52:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function getSelectValue(form_obj, field_name) {
|
2017-05-08 01:32:46 -04:00
|
|
|
var elm = form_obj.elements[field_name];
|
2007-01-16 12:52:13 -05:00
|
|
|
|
2017-05-08 01:32:46 -04:00
|
|
|
if (elm == null || elm.options == null || elm.selectedIndex === -1) {
|
|
|
|
return "";
|
|
|
|
}
|
2007-01-16 12:52:13 -05:00
|
|
|
|
2017-05-08 01:32:46 -04:00
|
|
|
return elm.options[elm.selectedIndex].value;
|
2007-01-16 12:52:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function addSelectValue(form_obj, field_name, name, value) {
|
2017-05-08 01:32:46 -04:00
|
|
|
var s = form_obj.elements[field_name];
|
|
|
|
var o = new Option(name, value);
|
|
|
|
s.options[s.options.length] = o;
|
2007-01-16 12:52:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function addClassesToList(list_id, specific_option) {
|
2017-05-08 01:32:46 -04:00
|
|
|
// Setup class droplist
|
|
|
|
var styleSelectElm = document.getElementById(list_id);
|
|
|
|
var styles = tinyMCEPopup.getParam('theme_advanced_styles', false);
|
|
|
|
styles = tinyMCEPopup.getParam(specific_option, styles);
|
|
|
|
|
|
|
|
if (styles) {
|
|
|
|
var stylesAr = styles.split(';');
|
|
|
|
|
|
|
|
for (var i = 0; i < stylesAr.length; i++) {
|
|
|
|
if (stylesAr != "") {
|
|
|
|
var key, value;
|
|
|
|
|
|
|
|
key = stylesAr[i].split('=')[0];
|
|
|
|
value = stylesAr[i].split('=')[1];
|
|
|
|
|
|
|
|
styleSelectElm.options[styleSelectElm.length] = new Option(key, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*tinymce.each(tinyMCEPopup.editor.dom.getClasses(), function(o) {
|
|
|
|
styleSelectElm.options[styleSelectElm.length] = new Option(o.title || o['class'], o['class']);
|
|
|
|
});*/
|
|
|
|
}
|
2007-01-16 12:52:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function isVisible(element_id) {
|
2017-05-08 01:32:46 -04:00
|
|
|
var elm = document.getElementById(element_id);
|
2007-01-16 12:52:13 -05:00
|
|
|
|
2017-05-08 01:32:46 -04:00
|
|
|
return elm && elm.style.display != "none";
|
2007-01-16 12:52:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function convertRGBToHex(col) {
|
2017-05-08 01:32:46 -04:00
|
|
|
var re = new RegExp("rgb\\s*\\(\\s*([0-9]+).*,\\s*([0-9]+).*,\\s*([0-9]+).*\\)", "gi");
|
2007-01-16 12:52:13 -05:00
|
|
|
|
2017-05-08 01:32:46 -04:00
|
|
|
var rgb = col.replace(re, "$1,$2,$3").split(',');
|
|
|
|
if (rgb.length == 3) {
|
|
|
|
r = parseInt(rgb[0]).toString(16);
|
|
|
|
g = parseInt(rgb[1]).toString(16);
|
|
|
|
b = parseInt(rgb[2]).toString(16);
|
2007-01-16 12:52:13 -05:00
|
|
|
|
2017-05-08 01:32:46 -04:00
|
|
|
r = r.length == 1 ? '0' + r : r;
|
|
|
|
g = g.length == 1 ? '0' + g : g;
|
|
|
|
b = b.length == 1 ? '0' + b : b;
|
2007-01-16 12:52:13 -05:00
|
|
|
|
2017-05-08 01:32:46 -04:00
|
|
|
return "#" + r + g + b;
|
|
|
|
}
|
2007-01-16 12:52:13 -05:00
|
|
|
|
2017-05-08 01:32:46 -04:00
|
|
|
return col;
|
2007-01-16 12:52:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function convertHexToRGB(col) {
|
2017-05-08 01:32:46 -04:00
|
|
|
if (col.indexOf('#') != -1) {
|
|
|
|
col = col.replace(new RegExp('[^0-9A-F]', 'gi'), '');
|
2007-01-16 12:52:13 -05:00
|
|
|
|
2017-05-08 01:32:46 -04:00
|
|
|
r = parseInt(col.substring(0, 2), 16);
|
|
|
|
g = parseInt(col.substring(2, 4), 16);
|
|
|
|
b = parseInt(col.substring(4, 6), 16);
|
2007-01-16 12:52:13 -05:00
|
|
|
|
2017-05-08 01:32:46 -04:00
|
|
|
return "rgb(" + r + "," + g + "," + b + ")";
|
|
|
|
}
|
2007-01-16 12:52:13 -05:00
|
|
|
|
2017-05-08 01:32:46 -04:00
|
|
|
return col;
|
2007-01-16 12:52:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function trimSize(size) {
|
2017-05-08 01:32:46 -04:00
|
|
|
return size.replace(/([0-9\.]+)(px|%|in|cm|mm|em|ex|pt|pc)/i, '$1$2');
|
2007-01-16 12:52:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function getCSSSize(size) {
|
2017-05-08 01:32:46 -04:00
|
|
|
size = trimSize(size);
|
|
|
|
|
|
|
|
if (size == "") {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add px
|
|
|
|
if (/^[0-9]+$/.test(size)) {
|
|
|
|
size += 'px';
|
|
|
|
}
|
Docs: Replace "sanity" with "confidence" for inclusive language.
The phrase "sanity check" unnecessarily references mental health. It's an old phrase used to denote an extra step in verifying code works as expected.
“The WordPress open source community cares about diversity. We strive to maintain a welcoming environment where everyone can feel included.”
While "sanity check" is a well-known phrase with a specific meaning, "confidence check" is a direct replacement that is more clear of its intent while being more inclusive.
Words matter.
Follow-up to [49216], [46271], [40583], [38832], [38637], [37409], [33359], [32162], [30346], [30345], [30238], [30055], [29902], [28763], [26141], [25002], [22227], [13428], [12148], [11025], [8927].
Props dartiss, hellofromTonya.
Fixes #60187.
Built from https://develop.svn.wordpress.org/trunk@57239
git-svn-id: http://core.svn.wordpress.org/trunk@56745 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-03 16:59:19 -05:00
|
|
|
// Confidence check, IE doesn't like broken values
|
2017-05-08 01:32:46 -04:00
|
|
|
else if (!(/^[0-9\.]+(px|%|in|cm|mm|em|ex|pt|pc)$/i.test(size))) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
return size;
|
2007-01-16 12:52:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function getStyle(elm, attrib, style) {
|
2017-05-08 01:32:46 -04:00
|
|
|
var val = tinyMCEPopup.dom.getAttrib(elm, attrib);
|
2007-01-16 12:52:13 -05:00
|
|
|
|
2017-05-08 01:32:46 -04:00
|
|
|
if (val != '') {
|
|
|
|
return '' + val;
|
|
|
|
}
|
2007-01-16 12:52:13 -05:00
|
|
|
|
2017-05-08 01:32:46 -04:00
|
|
|
if (typeof (style) == 'undefined') {
|
|
|
|
style = attrib;
|
|
|
|
}
|
2007-01-16 12:52:13 -05:00
|
|
|
|
2017-05-08 01:32:46 -04:00
|
|
|
return tinyMCEPopup.dom.getStyle(elm, style);
|
2007-01-16 12:52:13 -05:00
|
|
|
}
|