From 1bf4330ec9d21f600ce0cfb07b24bb07b8d13d77 Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Fri, 13 Jun 2014 11:30:24 +0200 Subject: [PATCH] Add jquery etherpad-lite plugin --- public/js/etherpad.js | 100 ++++++++++++++++++++++++++++++++++++++ public/vroom.pl | 3 ++ templates/default/js_room.html.ep | 2 +- 3 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 public/js/etherpad.js diff --git a/public/js/etherpad.js b/public/js/etherpad.js new file mode 100644 index 0000000..d445e1f --- /dev/null +++ b/public/js/etherpad.js @@ -0,0 +1,100 @@ +(function( $ ){ + + $.fn.pad = function( options ) { + var settings = { + 'host' : 'http://beta.etherpad.org', + 'baseUrl' : '/p/', + 'showControls' : false, + 'showChat' : false, + 'showLineNumbers' : false, + 'userName' : 'unnamed', + 'useMonospaceFont' : false, + 'noColors' : false, + 'userColor' : false, + 'hideQRCode' : false, + 'alwaysShowChat' : false, + 'width' : 100, + 'height' : 100, + 'border' : 0, + 'borderStyle' : 'solid', + 'toggleTextOn' : 'Disable Rich-text', + 'toggleTextOff' : 'Enable Rich-text' + }; + + var $self = this; + if (!$self.length) return; + if (!$self.attr('id')) throw new Error('No "id" attribute'); + + 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.getContents ) { + if ( options ) { + $.extend( settings, options ); + } + + var iFrameLink = ''; + + + var $iFrameLink = $(iFrameLink); + + if (useValue) { + var $toggleLink = $(''+ settings.toggleTextOn +'').click(function(){ + var $this = $(this); + $this.toggleClass('active'); + if ($this.hasClass('active')) $this.text(settings.toggleTextOff); + $self.pad({getContents: true}); + return false; + }); + $self + .hide() + .after($toggleLink) + .after($iFrameLink) + ; + } + else { + $self.html(iFrameLink); + } + } + + // This reads the etherpad contents if required + else { + var frameUrl = $('#'+ epframeId).attr('src').split('?')[0]; + var contentsUrl = frameUrl + "/export/html"; + var target = $('#'+ options.getContents); + + // perform an ajax call on contentsUrl and write it to the parent + $.get(contentsUrl, function(data) { + + if (target.is(':input')) { + target.val(data).show(); + } + else { + target.html(data); + } + + $('#'+ epframeId).remove(); + }); + } + + + return $self; + }; +})( jQuery ); diff --git a/public/vroom.pl b/public/vroom.pl index 9b2bf58..3b5f210 100755 --- a/public/vroom.pl +++ b/public/vroom.pl @@ -41,6 +41,9 @@ our $components = { "jquery-tinytimer" => { url => 'https://github.com/odyniec/jQuery-tinyTimer' }, + "jquery-etherpad-lite" => { + url => 'https://github.com/ether/etherpad-lite-jquery-plugin' + }, "sprintf.js" => { url => 'http://hexmen.com/blog/2007/03/printf-sprintf/' }, diff --git a/templates/default/js_room.html.ep b/templates/default/js_room.html.ep index 8df74ab..7b1c9a5 100644 --- a/templates/default/js_room.html.ep +++ b/templates/default/js_room.html.ep @@ -1,5 +1,5 @@ <% - foreach my $js (qw(simplewebrtc.bundle.js jquery.browser.min.js sprintf.js FileSaver.js jquery.tinytimer.min.js)){ + foreach my $js (qw(simplewebrtc.bundle.js jquery.browser.min.js sprintf.js FileSaver.js jquery.tinytimer.min.js etherpad.js)){ %> <% } %>