Committer: dpetrov
LJSUP-10133: Save data with ajax request in s2 layers editorU trunk/cgi-bin/LJ/Widget/LayerEditor.pm U trunk/htdocs/js/s2edit/s2edit.js U trunk/htdocs/js/s2edit/s2gui.js U trunk/htdocs/stc/s2edit.css
Modified: trunk/cgi-bin/LJ/Widget/LayerEditor.pm =================================================================== --- trunk/cgi-bin/LJ/Widget/LayerEditor.pm 2011-10-14 08:12:08 UTC (rev 20317) +++ trunk/cgi-bin/LJ/Widget/LayerEditor.pm 2011-10-14 08:27:37 UTC (rev 20318) @@ -5,7 +5,7 @@ use Carp qw(croak); sub ajax { 1 } sub authas { 1 } -sub need_res { qw( stc/widgets/layereditor.css js/s2edit/xlib.js js/s2edit/s2edit.js js/s2edit/s2gui.js js/s2edit/s2parser.js js/s2edit/s2sense.js js/s2edit/s2library.js stc/s2edit.css) } +sub need_res { qw( stc/s2edit.css stc/widgets/layereditor.css js/s2edit/xlib.js js/s2edit/s2edit.js js/s2edit/s2gui.js js/s2edit/s2parser.js js/s2edit/s2sense.js js/s2edit/s2library.js) } =head2 template_filename # path to template file, @@ -203,25 +203,16 @@ sub js { q [ initWidget: function () { - var self = this; - - var form = DOM.getElement("s2"); - DOM.addEventListener(form, "submit", function (evt) { self.warnWord(evt, form) }); + s2edit.init(this); }, - warnWord: function (evt, form) { - var given_text = form["Widget[LayerEditor]_s2code"].value + ""; - - this.doPostAndUpdateContent({ - s2code: given_text, + saveContent: function(text) { + var form = jQuery('#s2').get(0); + this.doPost({ + s2code: text, action: 'compile', - id: form["Widget[LayerEditor]_id"].value, + id: form["Widget[LayerEditor]_id"].value }); - - Event.stop(evt); - }, - onRefresh: function (data) { - this.initWidget(); } ]; Modified: trunk/htdocs/js/s2edit/s2edit.js =================================================================== --- trunk/htdocs/js/s2edit/s2edit.js 2011-10-14 08:12:08 UTC (rev 20317) +++ trunk/htdocs/js/s2edit/s2edit.js 2011-10-14 08:27:37 UTC (rev 20318) @@ -9,26 +9,40 @@ var s2dirty; var s2lineCount; -function s2init() -{ - s2dirty = 1; - s2lineCount = 0; +var s2edit = function() { + return { + init: function(widget) { + this.widget = widget; + this.widget.onData = this.drawCompileResults.bind(this); - s2initIndex(); - s2initParser(); - s2initSense(); - s2buildReference(); - s2initDrag(); + s2dirty = 1; + s2lineCount = 0; - // Disable selection in the document (IE only - prevents wacky dragging bugs) - document.onselectstart = function () { return false; }; -} + s2initIndex(); + s2initParser(); + s2initSense(); + s2buildReference(); + s2initDrag(); + s2output.init(); + + // Disable selection in the document (IE only - prevents wacky dragging bugs) + document.onselectstart = function () { return false; }; + }, + + save: function(text) { + s2output.add('Compiling..', true); + this.widget.saveContent(text); + }, + + drawCompileResults: function(data) { + s2output.add(data.res.build, true); + } + } +}(); + + function s2initIndex() { s2index = new Object(); } - -LiveJournal.register_hook('page_load', function () { - s2init(); -}); Modified: trunk/htdocs/js/s2edit/s2gui.js =================================================================== --- trunk/htdocs/js/s2edit/s2gui.js 2011-10-14 08:12:08 UTC (rev 20317) +++ trunk/htdocs/js/s2edit/s2gui.js 2011-10-14 08:27:37 UTC (rev 20318) @@ -4,6 +4,48 @@ // s2gui.js - S2 GUI routines // --------------------------------------------------------------------------- +var s2output = function() { + var el; + + function parseLineNumbers(text) { + var match, + regex = /line\s+(\d+),\s+column\s+(\d+)/g, + subs = []; + while (match = regex.exec(text)) { + subs.push({ key: match[0], link: '<a href="javascript:s2jumpTo(' + + match[1] + ',' + match[2] + ')">' + match[0] + '</a>'}); + } + subs.forEach(function(el) { + text = text.replace(el.key, el.link); + }); + + return text; + } + + return { + init: function() { + el = jQuery('#out'); + + var text = el.html(); + if (text.length > 0) { + text = parseLineNumbers(text); + el.html(text); + } + }, + + add: function(text, overwrite) { + overwrite = overwrite || false; + text = parseLineNumbers(text); + + if (overwrite) { + el.html(text); + } else { + el.append(text); + } + } + } +}(); + var s2status; function s2printStatus(str) @@ -111,6 +153,18 @@ } } +function s2jumpTo(line, column) { + var main = s2getCodeArea(), + text = main.value, + pos = text.split('\n').slice(0, line - 1).join('\n').length + column; + + if (jQuery.browser.msie) { //ie doesn't count linebreaks when positioning cursor + pos -= line - 1; + } + + s2jumpToPos(pos, line); +} + function s2jumpToPos(pos, line) { var main = s2getCodeArea(); @@ -464,5 +518,6 @@ { // save position textarea, where reload page var textarea = s2getCodeArea(); - window.name = textarea.scrollTop + ':' + nxgetPositionCursor(textarea); + s2edit.save(textarea.value); + return false; } Modified: trunk/htdocs/stc/s2edit.css =================================================================== --- trunk/htdocs/stc/s2edit.css 2011-10-14 08:12:08 UTC (rev 20317) +++ trunk/htdocs/stc/s2edit.css 2011-10-14 08:27:37 UTC (rev 20318) @@ -8,7 +8,6 @@ } div.header { - position: absolute; top: 0px; height: 19px; width: 100%; @@ -121,7 +120,7 @@ height: auto; } -textarea.maintext { +.maintext { position: absolute; border: solid #808080 1px; font-family: monospace; @@ -146,7 +145,7 @@ height: 90px; padding: 3px; width: auto; - overflow: scroll; + overflow: auto; } div.divider { @@ -199,6 +198,10 @@ color: #000000; } +.output a { + text-decoration: underline; +} + a:hover { text-decoration: underline; color: #000000;