diff --git a/src/js/rbuttonJS.js b/src/js/rbuttonJS.js index 06ff286cd4942cb79649c975b599252f20a91c30..8c37e7336e3da3cdf4b56975ae41eb9b304c04ba 100644 --- a/src/js/rbuttonJS.js +++ b/src/js/rbuttonJS.js @@ -12,22 +12,22 @@ Group of radiobutton will be created based on variable name. Checked state will Macro.add('rbutton', { handler() { if (this.args.length < 2) { - const errors = []; - if (this.args.length < 1) { errors.push('variable name'); } - if (this.args.length < 2) { errors.push('checked value'); } - return this.error(`no ${errors.join(' or ')} specified`); + const errors = []; + if (this.args.length < 1) { errors.push('variable name'); } + if (this.args.length < 2) { errors.push('checked value'); } + return this.error(`no ${errors.join(' or ')} specified`); } // Ensure that the variable name argument is a string. if (typeof this.args[0] !== 'string') { - return this.error('variable name argument is not a string'); + return this.error('variable name argument is not a string'); } const varName = this.args[0].trim(); // Try to ensure that we receive the variable's name (incl. sigil), not its value. if (varName[0] !== '$' && varName[0] !== '_') { - return this.error(`variable name "${this.args[0]}" is missing its sigil ($ or _)`); + return this.error(`variable name "${this.args[0]}" is missing its sigil ($ or _)`); } const initValue = Wikifier.getValue(this.args[0]); @@ -48,59 +48,59 @@ Macro.add('rbutton', { Setup and initialize the group counter. */ if (!TempState.hasOwnProperty(this.name)) { - TempState[this.name] = {}; + TempState[this.name] = {}; } if (!TempState[this.name].hasOwnProperty(varId)) { - TempState[this.name][varId] = 0; + TempState[this.name][varId] = 0; } /* Setup and append the input element to the output buffer. */ jQuery(el) - .attr({ - id : `${this.name}-${varId}-${TempState[this.name][varId]++}`, - name : `${this.name}-${varId}`, - type : 'radio', - tabindex : 0 // for accessibility - }) - .addClass(`macro-${this.name}`) - .on('change', function () { - if (this.checked) { - Wikifier.setValue(varName, checkValue); - - if (replaceID.length > 0 && replaceText.length > 0){ + .attr({ + id : `${this.name}-${varId}-${TempState[this.name][varId]++}`, + name : `${this.name}-${varId}`, + type : 'radio', + tabindex : 0 // for accessibility + }) + .addClass(`macro-${this.name}`) + .on('change', function () { + if (this.checked) { + Wikifier.setValue(varName, checkValue); + + if (replaceID.length > 0 && replaceText.length > 0){ + + var replaceEl = document.getElementById(replaceID); + //alert (replaceEl); + if (replaceEl !== null) { + replaceEl.innerHTML = replaceText; + } - var replaceEl = document.getElementById(replaceID); - //alert (replaceEl); - if (replaceEl !== null) { - replaceEl.innerHTML = replaceText; } - } - } - }) - .ready (function () { + }) + .ready (function () { //alert ("DOM finished"); - if (el.checked && replaceID.length > 0 && replaceText.length > 0){ + if (el.checked && replaceID.length > 0 && replaceText.length > 0){ - var replaceEl = document.getElementById(replaceID); - //alert (replaceEl); - if (replaceEl !== null) { - replaceEl.innerHTML = replaceText; - } + var replaceEl = document.getElementById(replaceID); + //alert (replaceEl); + if (replaceEl !== null) { + replaceEl.innerHTML = replaceText; + } - } - }) - .appendTo(this.output); + } + }) + .appendTo(this.output); /* Set the story variable to the checked value and the input element to checked, if requested. */ if (initValue === checkValue) { - el.checked = true; - Wikifier.setValue(varName, checkValue); + el.checked = true; + Wikifier.setValue(varName, checkValue); } } });