Created
August 3, 2014 05:37
-
-
Save dmuneras/29d167c1846363b79a97 to your computer and use it in GitHub Desktop.
etherpad-moodle-mod
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jq162 = jQuery.noConflict(); | |
(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, | |
'hideQRCode' : 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 = '<iframe id="'+epframeId; | |
iFrameLink = iFrameLink +'" name="'+epframeId; | |
iFrameLink = iFrameLink +'" src="'+settings.host+settings.baseUrl+settings.padId; | |
iFrameLink = iFrameLink + '?showControls='+settings.showControls; | |
iFrameLink = iFrameLink + '&showChat='+settings.showChat; | |
iFrameLink = iFrameLink + '&showLineNumbers='+settings.showLineNumbers; | |
iFrameLink = iFrameLink + '&useMonospaceFont='+settings.useMonospaceFont; | |
iFrameLink = iFrameLink + '&userName=' + settings.userName; | |
iFrameLink = iFrameLink + '&noColors=' + settings.noColors; | |
iFrameLink = iFrameLink + '&hideQRCode=' + settings.hideQRCode; | |
iFrameLink = iFrameLink +'" style="border:'+settings.border; | |
iFrameLink = iFrameLink +'; border-style:'+settings.borderStyle; | |
// iFrameLink = iFrameLink +'; width:'+settings.width; | |
// iFrameLink = iFrameLink +'; height:'+settings.height; | |
iFrameLink = iFrameLink +';" width="'+ '100%';//settings.width; | |
iFrameLink = iFrameLink +'" height="'+ settings.height; | |
iFrameLink = iFrameLink +'"></iframe>'; | |
var $iFrameLink = $(iFrameLink); | |
if (useValue) { | |
var $toggleLink = $('<a href="#'+ selfId +'">'+ settings.toggleTextOn +'</a>').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"; | |
// 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); | |
} | |
$('#'+ epframeId).remove(); | |
}); | |
} | |
return $self; | |
}; | |
})( jq162 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?PHP // $Id: view.php,v 1.0 2012/03/28 18:30:00 Serafim Panov Exp $ | |
/// This page prints a particular instance of etherpad | |
/// (Replace etherpad with the name of your module) | |
require_once("../../config.php"); | |
require_once("lib.php"); | |
require_once("etherpad-lite-client.php"); | |
$id = optional_param('id', 0, PARAM_INT); // Course Module ID | |
$a = optional_param('a', NULL, PARAM_TEXT); // etherpad ID | |
if ($id) { | |
if (! $cm = $DB->get_record("course_modules", array("id" => $id))) { | |
error("Course Module ID was incorrect"); | |
} | |
if (! $course = $DB->get_record("course", array("id" => $cm->course))) { | |
error("Course is misconfigured"); | |
} | |
if (! $etherpad = $DB->get_record("etherpad", array("id" => $cm->instance))) { | |
error("Course module is incorrect"); | |
} | |
} else { | |
if (! $etherpad = $DB->get_record("etherpad", array("id" => $a))) { | |
error("Course module is incorrect"); | |
} | |
if (! $course = $DB->get_record("course", array("id" => $etherpad->course))) { | |
error("Course is misconfigured"); | |
} | |
if (! $cm = get_coursemodule_from_instance("etherpad", $etherpad->id, $course->id)) { | |
error("Course Module ID was incorrect"); | |
} | |
} | |
require_login($course->id); | |
$context = get_context_instance(CONTEXT_MODULE, $cm->id); | |
/// Print the page header | |
add_to_log($course->id, "etherpad", "view", "view.php?id=$id", "$cm->instance"); | |
// Activate epad user | |
//etherpad_activate_session(); | |
// Initialize $PAGE, compute blocks | |
$PAGE->set_url('/mod/etherpad/view.php', array('id' => $id)); | |
$PAGE->requires->js('/mod/etherpad/js/jquery.min.js', true); | |
$PAGE->requires->js('/mod/etherpad/js/etherpad.js', true); | |
$title = $course->shortname . ': ' . format_string($etherpad->name); | |
$PAGE->set_title($title); | |
$PAGE->set_heading($course->fullname); | |
echo $OUTPUT->header(); | |
/// Print the main part of the page | |
echo $OUTPUT->box_start('generalbox'); | |
echo "<div align=center>".$etherpad->intro."</div>"; | |
echo $OUTPUT->box_end(); | |
echo $OUTPUT->box_start('generalbox'); | |
echo "<div align=center>"; | |
echo '<div id="ePad"></div>'; | |
echo "</div>"; | |
echo "<script type='text/javascript'>"; | |
echo "jq162(document).ready(function() { | |
jq162('#ePad').pad({'host': | |
'{$etherpadcfg->etherpad_baseurl}', | |
'padId':'{$etherpad->padname}', | |
'baseUrl': '/p/', | |
'showChat': true, | |
'userName': '{$USER->firstname} {$USER->lastname}', | |
'showControls': true, | |
'showLineNumbers': true, | |
'height': 500} | |
); | |
});"; | |
echo "</script>"; | |
echo $OUTPUT->box_end(); | |
/// Finish the page | |
echo $OUTPUT->footer(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment