From 44f5a4ea4de7be723f69431eef31c18abe970bfa Mon Sep 17 00:00:00 2001 From: John Smith Date: Mon, 3 Aug 2015 15:59:03 +0100 Subject: [PATCH] Update to fix all text input and texture fields between v2.1 and v3 --- editor/js/application.js | 1 + editor/js/toolbox.js | 129 +++++++++++++++++++++++---------------- 2 files changed, 76 insertions(+), 54 deletions(-) diff --git a/editor/js/application.js b/editor/js/application.js index dca01963bb..9ccc798515 100755 --- a/editor/js/application.js +++ b/editor/js/application.js @@ -21,6 +21,7 @@ var wizard_data = {}; var lo_data = {}; var menu_data = []; var topLevelObject="learningObject"; +var alreadyUpgraded = false; // I would like to add some code here which includes data/layout/language etc rather than use a script tag in the edithtml file diff --git a/editor/js/toolbox.js b/editor/js/toolbox.js index cb8d657742..6d179d6599 100644 --- a/editor/js/toolbox.js +++ b/editor/js/toolbox.js @@ -157,7 +157,16 @@ var EDITOR = (function ($, parent) { $(xmlData[0].attributes).each(function() { attributes[this.name] = this.value; }); + + if (parent_id == null) + { + // Look for the editor version attribute and then add xml flag to show we've checked + if (attributes.editorVersion && parseInt("0" + attributes.editorVersion, 10) >= 3) alreadyUpgraded = true; + attributes["editorVersion"] = "3"; + } + // Expand FileLocation + to full path, except for attributes of type media + // also take care here of converting CRs to
where appropriate var options = wizard_data[xmlData[0].nodeName].node_options; $.each(attributes, function(key, attribute){ var attroptions = {}; @@ -169,6 +178,14 @@ var EDITOR = (function ($, parent) { break; } } + + // Deal with line breaks in TextInput and TextArea fields + if (!alreadyUpgraded && attroptions.type && (attroptions.type.toLowerCase() == 'textinput' || attroptions.type.toLowerCase() == 'textarea')) + { + attributes[key] = addLineBreaks(attributes[key]); + } + + // Deal with media if (attroptions.type != 'media') { attributes[key] = makeAbsolute(attributes[key]); @@ -1519,58 +1536,66 @@ var EDITOR = (function ($, parent) { * This is replica of the function used in Xenith.js (ref. x_addLineBreaks). */ addLineBreaks = function(text) { - if (text.indexOf("<") == 0) - { - // Seems to start with a tag - // probably with new editor, don't replace newlines! - return text; - } - if (text.indexOf(""); - - } else { // ignore any line breaks inside these tags as they don't work correctly with
- var newText = text; - if (newText.indexOf(""); - tempText += text1.substring(text1.indexOf("", tableNum) + 8); - tableNum = text1.indexOf("", tableNum) + 8; - } - tempText += text1.substring(tableNum).replace(/(\n|\r|\r\n)/g, "
"); - tempText += newText.substring(newText.indexOf("", mathNum) + 7); - mathNum = newText.indexOf("", mathNum) + 7; - } + // First test for new editor - Only applicable for Xenith.js + //if (x_params && x_params.editorVersion && parseInt("0" + x_params.editorVersion, 10) >= 3) + //{ + // return text; // Return text unchanged + //} + + // Now try to identify v3beta created LOs + if ((text.trim().indexOf(""); + } + else { // ignore any line breaks inside these tags as they don't work correctly with
+ var newText = text; + if (newText.indexOf(""); + tempText += text1.substring(text1.indexOf("", tableNum) + 8); + tableNum = text1.indexOf("", tableNum) + 8; + } + tempText += text1.substring(tableNum).replace(/(\n|\r|\r\n)/g, "
"); + tempText += newText.substring(newText.indexOf("", mathNum) + 7); + mathNum = newText.indexOf("", mathNum) + 7; + } - var text2 = newText.substring(mathNum), - tableNum = 0; - while (text2.indexOf(""); - tempText += text2.substring(text2.indexOf("", tableNum) + 8); - tableNum = text2.indexOf("", tableNum) + 8; - } - tempText += text2.substring(tableNum).replace(/(\n|\r|\r\n)/g, "
"); - newText = tempText; - - } else if (newText.indexOf(""); - tempText += newText.substring(newText.indexOf("", tableNum) + 8); - tableNum = newText.indexOf("", tableNum) + 8; - } - tempText += newText.substring(tableNum).replace(/(\n|\r|\r\n)/g, "
"); - newText = tempText; - } + var text2 = newText.substring(mathNum), + tableNum = 0; + while (text2.indexOf(""); + tempText += text2.substring(text2.indexOf("", tableNum) + 8); + tableNum = text2.indexOf("", tableNum) + 8; + } + tempText += text2.substring(tableNum).replace(/(\n|\r|\r\n)/g, "
"); + newText = tempText; + + } else if (newText.indexOf(""); + tempText += newText.substring(newText.indexOf("", tableNum) + 8); + tableNum = newText.indexOf("", tableNum) + 8; + } + tempText += newText.substring(tableNum).replace(/(\n|\r|\r\n)/g, "
"); + newText = tempText; + } - return newText; - } + return newText; + } }, displayDataType = function (value, options, name, key) { @@ -1625,10 +1650,6 @@ var EDITOR = (function ($, parent) { var id = "textarea_" + form_id_offset; var textvalue = value; - if (options.type.toLowerCase() == 'text' || options.type.toLowerCase() == 'textarea') - { - textvalue = addLineBreaks(value); - } form_id_offset++; var textarea = "