diff --git a/src/etherpad-editor.js b/src/etherpad-editor.js index c0ba3fb..88acfef 100644 --- a/src/etherpad-editor.js +++ b/src/etherpad-editor.js @@ -1,21 +1,15 @@ import jQuery from 'jquery'; import { collabuml } from './config'; - -export const getText = (callback) => { - jQuery.ajax({ - 'url': collabuml.host + '/api/1/getText?apikey=' + collabuml.apikey + '&padID=' + collabuml.padId + '&jsonp=?', - 'type': 'GET', - 'dataType': "jsonp", - 'success': function (response) { - callback(response.data.text); - } - }); -}; +const plantumlEncoder = require('plantuml-encoder') export const renderPad = (selector, padId) => { jQuery(selector).pad({ 'padId': padId, 'showChat': 'false' }); }; +export const getText = (selector, padId, getContents, callback) => { + jQuery(selector).pad({ 'padId': padId, 'getContents': getContents, 'callback': callback}); +}; + (function (jQuery) { jQuery.fn.pad = function (options) { var settings = { @@ -47,60 +41,88 @@ export const renderPad = (selector, padId) => { var useValue = $self[0].tagName.toLowerCase() == 'textarea'; var selfId = $self.attr('id'); var epframeId = 'epframe' + selfId; - // This writes a new frame if required - if (options) { - jQuery.extend(settings, options); - } - var pluginParams = ''; - for (var option in settings.plugins) { - pluginParams += '&' + option + '=' + settings.plugins[option] - } + if (!options.getContents){ + if (options) { + jQuery.extend(settings, options); + } - var iFrameLink = ''; + var pluginParams = ''; + for (var option in settings.plugins) { + pluginParams += '&' + option + '=' + settings.plugins[option] + } + var iFrameLink = ''; - var $iFrameLink = jQuery(iFrameLink); + var $iFrameLink = jQuery(iFrameLink); - if (useValue) { - var $toggleLink = jQuery('' + settings.toggleTextOn + '').click(function () { + if (useValue) { + var $toggleLink = jQuery('' + settings.toggleTextOn + '').click(function () { var $this = jQuery(this); $this.toggleClass('active'); if ($this.hasClass('active')) $this.text(settings.toggleTextOff); - $self.pad({ getContents: true }); - return false; - }); - $self - .hide() - .after($toggleLink) - .after($iFrameLink) - ; + $self.pad({ getContents: true }); + return false; + }); + $self + .hide() + .after($toggleLink) + .after($iFrameLink); + } + else { + $self.html(iFrameLink); + } } else { - $self.html(iFrameLink); - } + var frameUrl = jQuery('#'+ epframeId).attr('src').split('?')[0]; + var contentsUrl = frameUrl + "/export/html"; + var target = jQuery(options.getContents); + jQuery.get(contentsUrl, function(data) { + var bodyContentRegex = /
]*>([\s\S]+)<\/body>/i; + var bodyContentMatch = data.match(bodyContentRegex); + var bodyContent = bodyContentMatch ? bodyContentMatch[1] : ''; + + const toText = function (text) { + var br = /