From 8814b2d9e84e3cd6e8a427bcce8c7bc665208a4f Mon Sep 17 00:00:00 2001
From: zeropaper
Date: Fri, 23 Mar 2012 11:05:30 +0100
Subject: [PATCH 1/3] Some misc improvements
---
js/etherpad.js | 124 +++++++++++++++++++++++++++++++------------------
1 file changed, 78 insertions(+), 46 deletions(-)
diff --git a/js/etherpad.js b/js/etherpad.js
index 5c9b1d2..ffba2be 100644
--- a/js/etherpad.js
+++ b/js/etherpad.js
@@ -1,5 +1,8 @@
(function( $ ){
-
+
+ // used to generate unique IDs
+ var padCount = window.__padCount = 0;
+
$.fn.pad = function( options ) {
var settings = {
'host' : 'http://beta.etherpad.org',
@@ -21,76 +24,105 @@
var $self = this;
if (!$self.length) return;
- if (!$self.attr('id')) throw new Error('No "id" attribute');
+ if (!$self.attr('id')) {
+ $self.attr('id', 'pad-'+ padCount);
+ padCount++;
+ }
var useValue = $self[0].tagName.toLowerCase() == 'textarea';
var selfId = $self.attr('id');
var epframeId = 'epframe'+ selfId;
- // This writes a new frame if required
+ var frameExists = $('#'+ epframeId).length;
+
if ( !options.getContents ) {
if ( options ) {
$.extend( settings, options );
- }
+ }
- var iFrameLink = '';
-
-
- var $iFrameLink = $(iFrameLink);
+ // This writes a new frame if required
+ if (!frameExists) {
+ var iFrame = '';
+
+ if (useValue) {
+ $self.after(iFrame);
+ }
+ else {
+ $self.html(iFrame);
+ }
+ }
+ var $iFrame = $('#'+ epframeId);
+
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)
- ;
+
+ if (!$('#'+ selfId +'-toggle').length) {
+ var $toggleLink = $(''+ settings.toggleTextOn +'').click(function(){
+ var $this = $(this);
+ $this.toggleClass('active');
+ if ($this.hasClass('active')) $this.text(settings.toggleTextOff);
+ $self.pad({
+ getContents: true,
+ returnValue: true
+ });
+ return false;
+ });
+
+ $self.after($toggleLink);
+ }
+
+ $self.hide();
+
}
else {
- $self.html(iFrameLink);
+ $self.html(iFrame);
}
}
// This reads the etherpad contents if required
else {
- var frameUrl = $('#'+ epframeId).attr('src').split('?')[0];
+ var $frame = $('#'+ epframeId).attr('src');
+ if (!$frame) return;
+
+ var frameUrl = $frame.split('?')[0];
var contentsUrl = frameUrl + "/export/html";
+ var rawContentsUrl = frameUrl + "/export/html?raw";
// perform an ajax call on contentsUrl and write it to the parent
$.get(contentsUrl, function(data) {
-
- if (useValue) {
- $self.val(data).show();
- }
- else {
- $self.html(data);
+ var $data = $(data);
+ var html = data;
+ if (!settings.returnValue) {
+ if (useValue) {
+ $self.val(html);
+ }
+ else {
+ $self.html(html);
+ }
}
-
- $('#'+ epframeId).remove();
});
}
+ if (settings.destroy) {
+ $self.show();
+ $('#'+ epframeId).remove();
+ $('#'+ selfId +'-toggle').remove();
+ }
return $self;
};
From 93fb4821cfdc7e609d9abf636a7c683ecf85e903 Mon Sep 17 00:00:00 2001
From: zeropaper
Date: Fri, 30 Mar 2012 11:03:55 +0200
Subject: [PATCH 2/3] Added a 'parse' method, allows some new tricky things.
---
js/etherpad.js | 83 +++++++++++++++++++++++++++++++++++++-------------
1 file changed, 61 insertions(+), 22 deletions(-)
diff --git a/js/etherpad.js b/js/etherpad.js
index ffba2be..96cfe5f 100644
--- a/js/etherpad.js
+++ b/js/etherpad.js
@@ -2,6 +2,25 @@
// used to generate unique IDs
var padCount = window.__padCount = 0;
+
+ /**
+ * Performs AJAX calls to retreive the HTML content of a pad
+ * and puts it into a target
+ */
+ function fetchHTML(frameUrl, $target, cb) {
+ var contentsUrl = frameUrl + "/export/html";
+// var rawContentsUrl = frameUrl + "/export/html?raw";
+
+ $.get(contentsUrl, function(data) {
+ var html = data;
+ if ($target[0].nodeName.toLowerCase() == 'textarea') {
+ $target.val(html);
+ }
+ else {
+ $target.html(html);
+ }
+ });
+ }
$.fn.pad = function( options ) {
var settings = {
@@ -19,11 +38,50 @@
'border' : 0,
'borderStyle' : 'solid',
'toggleTextOn' : 'Disable Rich-text',
- 'toggleTextOff' : 'Enable Rich-text'
+ 'toggleTextOff' : 'Enable Rich-text',
+
+ 'poll' : 3000
};
var $self = this;
if (!$self.length) return;
+
+ options = options || (options = {});
+ $.extend( settings, options );
+ if (console) console.info('Settings', settings);
+
+ if (options.parse) {
+ var context = (typeof options.parse != 'object' ? $('body')[0] : options.parse);
+
+ $('[data-pad-id]:not(.etherpad-lite-processed)')
+ .addClass('etherpad-lite-processed')
+ .each(function(){
+ var $display = $(this);
+ fetchHTML($display.attr('rel'), $display);
+ if (settings.poll > 500) {
+ $display
+ .data('pad-polling', setInterval(function(){
+ fetchHTML($display.attr('rel'), $display);
+ }, settings.poll))
+ .hover(function(){
+ $display.css('background-color', '#eee');
+ clearInterval($display.data('pad-polling'));
+ }, function(){
+ $display
+ .css('background-color', 'transparent')
+ .data('pad-polling', setInterval(function(){
+ fetchHTML($display.attr('rel'), $display);
+ }, settings.poll))
+ ;
+ })
+ ;
+ }
+ })
+ ;
+ return;
+ }
+
+
if (!$self.attr('id')) {
$self.attr('id', 'pad-'+ padCount);
padCount++;
@@ -35,9 +93,7 @@
var frameExists = $('#'+ epframeId).length;
if ( !options.getContents ) {
- if ( options ) {
- $.extend( settings, options );
- }
+// $.extend( settings, options );
// This writes a new frame if required
if (!frameExists) {
@@ -98,24 +154,7 @@
else {
var $frame = $('#'+ epframeId).attr('src');
if (!$frame) return;
-
- var frameUrl = $frame.split('?')[0];
- var contentsUrl = frameUrl + "/export/html";
- var rawContentsUrl = frameUrl + "/export/html?raw";
-
- // perform an ajax call on contentsUrl and write it to the parent
- $.get(contentsUrl, function(data) {
- var $data = $(data);
- var html = data;
- if (!settings.returnValue) {
- if (useValue) {
- $self.val(html);
- }
- else {
- $self.html(html);
- }
- }
- });
+ fetchHTML($frame.split('?')[0], $self);
}
if (settings.destroy) {
From 12e48f3b4a339b9926f38f8482ee74abe5592ddc Mon Sep 17 00:00:00 2001
From: Valentin Vago
Date: Fri, 30 Mar 2012 12:16:18 +0300
Subject: [PATCH 3/3] Update README.md
---
README.md | 34 +++++++++++++++++++++++-----------
1 file changed, 23 insertions(+), 11 deletions(-)
diff --git a/README.md b/README.md
index 7d36ebc..4eab179 100644
--- a/README.md
+++ b/README.md
@@ -20,20 +20,32 @@ The Etherpad jQuery Plugin Example plugin easily allows you to add and access a
# Available options and parameters
'host' : 'http://beta.etherpad.org', // the host and port of the Etherpad instance, by default the foundation will host your pads for you
-'baseUrl' : '/p/', // The base URL of the pads
-'showControls' : false, // If you want to show controls IE bold, italic, etc.
-'showChat' : false, // If you want to show the chat button or not
-'showLineNumbers' : false, // If you want to show the line numbers or not
+'baseUrl' : '/p/', // The base URL of the pads
+'showControls' : false, // If you want to show controls IE bold, italic, etc.
+'showChat' : false, // If you want to show the chat button or not
+'showLineNumbers' : false, // If you want to show the line numbers or not
'userName' : 'unnamed', // The username you want to pass to the pad
-'useMonospaceFont' : false, // Use monospaced fonts
-'noColors' : false, // Disable background colors on author text
-'hideQRCode' : false, // Hide QR code
-'width' : 100, // The width of the embedded IFrame
-'height' : 100, // The height of the embedded IFrame
-'border' : 0, // The width of the border (make sure to append px to a numerical value)
-'borderStyle' : 'solid' // The CSS style of the border [none, dotted, dashed, solid, double, groove, ridge, inset, outset]
+'useMonospaceFont' : false, // Use monospaced fonts
+'noColors' : false, // Disable background colors on author text
+'hideQRCode' : false, // Hide QR code
+'width' : 100, // The width of the embedded IFrame
+'height' : 100, // The height of the embedded IFrame
+'border' : 0, // The width of the border (make sure to append px to a numerical value)
+'borderStyle' : 'solid', // The CSS style of the border [none, dotted, dashed, solid, double, groove, ridge, inset, outset]
+
+'parse' : false, //
+'poll' : 1000 // Require 'parse' != false, time in milliseconds, if > 300 will refresh the pads found with 'parse'
+
+# Use of the 'parse' option
+You can pass either
+
+- **a boolean true**
+ Will scan within the body
+- **a DOM element object**
+ Will scan within the DOM element
+
# Copyright
jQuery Etherpad plugin written by John McLear (c) Primary Technology 2011
Feel free to re-use, distribute, butcher, edit and whatever else you want.