Commit 6212507b by Calen Pennington

Merge pull request #1008 from MITx/ie8patch

merge to master
parents f6a56a19 7f4bb63d
...@@ -3,8 +3,7 @@ from staticfiles.storage import staticfiles_storage ...@@ -3,8 +3,7 @@ from staticfiles.storage import staticfiles_storage
from pipeline_mako import compressed_css, compressed_js from pipeline_mako import compressed_css, compressed_js
%> %>
<%def name='url(file)'> <%def name='url(file)'><%
<%
try: try:
url = staticfiles_storage.url(file) url = staticfiles_storage.url(file)
except: except:
......
...@@ -1995,7 +1995,7 @@ cktsim = (function() { ...@@ -1995,7 +1995,7 @@ cktsim = (function() {
// set up each schematic entry widget // set up each schematic entry widget
function update_schematics() { function update_schematics() {
// set up each schematic on the page // set up each schematic on the page
var schematics = document.getElementsByClassName('schematic'); var schematics = $('.schematic');
for (var i = 0; i < schematics.length; ++i) for (var i = 0; i < schematics.length; ++i)
if (schematics[i].getAttribute("loaded") != "true") { if (schematics[i].getAttribute("loaded") != "true") {
try { try {
...@@ -2036,7 +2036,7 @@ function add_schematic_handler(other_onload) { ...@@ -2036,7 +2036,7 @@ function add_schematic_handler(other_onload) {
// ask each schematic input widget to update its value field for submission // ask each schematic input widget to update its value field for submission
function prepare_schematics() { function prepare_schematics() {
var schematics = document.getElementsByClassName('schematic'); var schematics = $('.schematic');
for (var i = schematics.length - 1; i >= 0; i--) for (var i = schematics.length - 1; i >= 0; i--)
schematics[i].schematic.update_value(); schematics[i].schematic.update_value();
} }
...@@ -3339,23 +3339,28 @@ schematic = (function() { ...@@ -3339,23 +3339,28 @@ schematic = (function() {
} }
// add method to canvas to compute relative coords for event // add method to canvas to compute relative coords for event
HTMLCanvasElement.prototype.relMouseCoords = function(event){ try {
// run up the DOM tree to figure out coords for top,left of canvas if (HTMLCanvasElement)
var totalOffsetX = 0; HTMLCanvasElement.prototype.relMouseCoords = function(event){
var totalOffsetY = 0; // run up the DOM tree to figure out coords for top,left of canvas
var currentElement = this; var totalOffsetX = 0;
do { var totalOffsetY = 0;
totalOffsetX += currentElement.offsetLeft; var currentElement = this;
totalOffsetY += currentElement.offsetTop; do {
} totalOffsetX += currentElement.offsetLeft;
while (currentElement = currentElement.offsetParent); totalOffsetY += currentElement.offsetTop;
}
// now compute relative position of click within the canvas while (currentElement = currentElement.offsetParent);
this.mouse_x = event.pageX - totalOffsetX;
this.mouse_y = event.pageY - totalOffsetY; // now compute relative position of click within the canvas
this.mouse_x = event.pageX - totalOffsetX;
this.page_x = event.pageX; this.mouse_y = event.pageY - totalOffsetY;
this.page_y = event.pageY;
this.page_x = event.pageX;
this.page_y = event.pageY;
}
}
catch (err) { // ignore
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
...@@ -3718,7 +3723,7 @@ schematic = (function() { ...@@ -3718,7 +3723,7 @@ schematic = (function() {
// look for property input fields in the content and give // look for property input fields in the content and give
// them a keypress listener that interprets ENTER as // them a keypress listener that interprets ENTER as
// clicking OK. // clicking OK.
var plist = content.getElementsByClassName('property'); var plist = content.$('.property');
for (var i = plist.length - 1; i >= 0; --i) { for (var i = plist.length - 1; i >= 0; --i) {
var field = plist[i]; var field = plist[i];
field.dialog = dialog; // help event handler find us... field.dialog = dialog; // help event handler find us...
...@@ -4091,48 +4096,52 @@ schematic = (function() { ...@@ -4091,48 +4096,52 @@ schematic = (function() {
// add dashed lines! // add dashed lines!
// from http://davidowens.wordpress.com/2010/09/07/html-5-canvas-and-dashed-lines/ // from http://davidowens.wordpress.com/2010/09/07/html-5-canvas-and-dashed-lines/
CanvasRenderingContext2D.prototype.dashedLineTo = function(fromX, fromY, toX, toY, pattern) { try {
// Our growth rate for our line can be one of the following: if (CanvasRenderingContext2D)
// (+,+), (+,-), (-,+), (-,-) CanvasRenderingContext2D.prototype.dashedLineTo = function(fromX, fromY, toX, toY, pattern) {
// Because of this, our algorithm needs to understand if the x-coord and // Our growth rate for our line can be one of the following:
// y-coord should be getting smaller or larger and properly cap the values // (+,+), (+,-), (-,+), (-,-)
// based on (x,y). // Because of this, our algorithm needs to understand if the x-coord and
var lt = function (a, b) { return a <= b; }; // y-coord should be getting smaller or larger and properly cap the values
var gt = function (a, b) { return a >= b; }; // based on (x,y).
var capmin = function (a, b) { return Math.min(a, b); }; var lt = function (a, b) { return a <= b; };
var capmax = function (a, b) { return Math.max(a, b); }; var gt = function (a, b) { return a >= b; };
var capmin = function (a, b) { return Math.min(a, b); };
var checkX = { thereYet: gt, cap: capmin }; var capmax = function (a, b) { return Math.max(a, b); };
var checkY = { thereYet: gt, cap: capmin };
var checkX = { thereYet: gt, cap: capmin };
if (fromY - toY > 0) { var checkY = { thereYet: gt, cap: capmin };
checkY.thereYet = lt;
checkY.cap = capmax; if (fromY - toY > 0) {
} checkY.thereYet = lt;
if (fromX - toX > 0) { checkY.cap = capmax;
checkX.thereYet = lt; }
checkX.cap = capmax; if (fromX - toX > 0) {
} checkX.thereYet = lt;
checkX.cap = capmax;
this.moveTo(fromX, fromY); }
var offsetX = fromX;
var offsetY = fromY; this.moveTo(fromX, fromY);
var idx = 0, dash = true; var offsetX = fromX;
while (!(checkX.thereYet(offsetX, toX) && checkY.thereYet(offsetY, toY))) { var offsetY = fromY;
var ang = Math.atan2(toY - fromY, toX - fromX); var idx = 0, dash = true;
var len = pattern[idx]; while (!(checkX.thereYet(offsetX, toX) && checkY.thereYet(offsetY, toY))) {
var ang = Math.atan2(toY - fromY, toX - fromX);
offsetX = checkX.cap(toX, offsetX + (Math.cos(ang) * len)); var len = pattern[idx];
offsetY = checkY.cap(toY, offsetY + (Math.sin(ang) * len));
offsetX = checkX.cap(toX, offsetX + (Math.cos(ang) * len));
if (dash) this.lineTo(offsetX, offsetY); offsetY = checkY.cap(toY, offsetY + (Math.sin(ang) * len));
else this.moveTo(offsetX, offsetY);
if (dash) this.lineTo(offsetX, offsetY);
idx = (idx + 1) % pattern.length; else this.moveTo(offsetX, offsetY);
dash = !dash;
} idx = (idx + 1) % pattern.length;
}; dash = !dash;
}
};
}
catch (err) { //noop
}
// given a range of values, return a new range [vmin',vmax'] where the limits // given a range of values, return a new range [vmin',vmax'] where the limits
// have been chosen "nicely". Taken from matplotlib.ticker.LinearLocator // have been chosen "nicely". Taken from matplotlib.ticker.LinearLocator
function view_limits(vmin,vmax) { function view_limits(vmin,vmax) {
......
...@@ -217,6 +217,7 @@ def index(request, course_id, chapter=None, section=None, ...@@ -217,6 +217,7 @@ def index(request, course_id, chapter=None, section=None,
'init': '', 'init': '',
'content': '', 'content': '',
'staff_access': staff_access, 'staff_access': staff_access,
'xqa_server': settings.MITX_FEATURES.get('USE_XQA_SERVER','http://xqa:server@content-qa.mitx.mit.edu/xqa')
} }
chapter_descriptor = course.get_child_by_url_name(chapter) chapter_descriptor = course.get_child_by_url_name(chapter)
......
...@@ -25,7 +25,9 @@ ...@@ -25,7 +25,9 @@
<%static:js group='discussion'/> <%static:js group='discussion'/>
<%include file="../discussion/_js_body_dependencies.html" /> <%include file="../discussion/_js_body_dependencies.html" />
% if staff_access:
<%include file="xqa_interface.html"/>
% endif
<!-- TODO: http://docs.jquery.com/Plugins/Validation --> <!-- TODO: http://docs.jquery.com/Plugins/Validation -->
<script type="text/javascript"> <script type="text/javascript">
......
<script type="text/javascript" src="/static/js/vendor/jquery.leanModal.min.js"></script>
<script type="text/javascript">
function setup_debug(element_id, edit_link, staff_context){
$('#' + element_id + '_trig').leanModal();
$('#' + element_id + '_xqa_log').leanModal();
$('#' + element_id + '_xqa_form').submit(function () {sendlog(element_id, edit_link, staff_context);});
}
function sendlog(element_id, edit_link, staff_context){
var xqaLog = {
authkey: staff_context.xqa_key,
location: staff_context.location,
category : staff_context.category,
'username' : staff_context.user.username,
return : 'query',
format : 'html',
email : staff_context.user.email,
tag:$('#' + element_id + '_xqa_tag').val(),
entry: $('#' + element_id + '_xqa_entry').val()
};
if (edit_link) xqaLog["giturl"] = edit_link;
$.ajax({
url: '${xqa_server}/log',
type: 'GET',
contentType: 'application/json',
data: JSON.stringify(xqaLog),
crossDomain: true,
dataType: 'jsonp',
beforeSend: function (xhr) {
xhr.setRequestHeader ("Authorization", "Basic eHFhOmFnYXJ3YWw="); },
timeout : 1000,
success: function(result) {
$('#' + element_id + '_xqa_log_data').html(result);
},
error: function() {
alert('Error: cannot connect to XQA server');
console.log('error!');
}
});
return false;
};
function getlog(element_id, staff_context){
var xqaQuery = {
authkey: staff_context.xqa_key,
location: staff_context.location,
format: 'html'
};
$.ajax({
url: '${xqa_server}/query',
type: 'GET',
contentType: 'application/json',
data: JSON.stringify(xqaQuery),
crossDomain: true,
dataType: 'jsonp',
timeout : 1000,
success: function(result) {
$('#' + element_id + '_xqa_log_data').html(result);
},
error: function() {
alert('Error: cannot connect to XQA server');
}
});
};
</script>
\ No newline at end of file
${module_content} ${module_content}
%if edit_link: %if edit_link:
<div><a href="${edit_link}">Edit</a> / <a href="#${element_id}_xqa-modal" onclick="getlog_${element_id}()" id="${element_id}_xqa_log">QA</a></div> <div>
<a href="${edit_link}">Edit</a> /
<a href="#${element_id}_xqa-modal" onclick="javascript:getlog('${element_id}', {
'location': '${location}',
'xqa_key': '${xqa_key}',
'category': '${category}',
'user': '${user}'
})" id="${element_id}_xqa_log">QA</a>
</div>
% endif % endif
<div><a href="#${element_id}_debug" id="${element_id}_trig">Staff Debug Info</a></div> <div><a href="#${element_id}_debug" id="${element_id}_trig">Staff Debug Info</a></div>
...@@ -50,77 +58,19 @@ category = ${category | h} ...@@ -50,77 +58,19 @@ category = ${category | h}
<div id="${element_id}_setup"></div> <div id="${element_id}_setup"></div>
## leanModal needs to be included here otherwise this breaks when in a <vertical>
<script type="text/javascript" src="/static/js/vendor/jquery.leanModal.min.js"></script>
<script type="text/javascript"> <script type="text/javascript">
// assumes courseware.html's loaded this method.
function setup_debug_${element_id}(){ setup_debug('${element_id}',
$('#${element_id}_trig').leanModal(); %if edit_link:
$('#${element_id}_xqa_log').leanModal(); '${edit_link}',
$('#${element_id}_xqa_form').submit(sendlog_${element_id}); %else:
} null,
%endif
setup_debug_${element_id}(); {
'location': '${location}',
function sendlog_${element_id}(){ 'xqa_key': '${xqa_key}',
'category': '${category}',
var xqaLog = {authkey: '${xqa_key}', 'user': '${user}'
location: '${location}', });
%if edit_link:
giturl: '${edit_link}',
%endif
category : '${category}',
username : '${user.username}',
return : 'query',
format : 'html',
email : '${user.email}',
tag:$('#${element_id}_xqa_tag').val(),
entry: $('#${element_id}_xqa_entry').val()};
$.ajax({
url: '${xqa_server}/log',
type: 'GET',
contentType: 'application/json',
data: JSON.stringify(xqaLog),
crossDomain: true,
dataType: 'jsonp',
beforeSend: function (xhr) { xhr.setRequestHeader ("Authorization", "Basic eHFhOmFnYXJ3YWw="); },
timeout : 1000,
success: function(result) {
$('#${element_id}_xqa_log_data').html(result);
},
error: function() {
alert('Error: cannot connect to XQA server');
console.log('error!');
}
});
return false;
};
function getlog_${element_id}(){
var xqaQuery = {authkey: '${xqa_key}',
location: '${location}',
format: 'html'};
$.ajax({
url: '${xqa_server}/query',
type: 'GET',
contentType: 'application/json',
data: JSON.stringify(xqaQuery),
crossDomain: true,
dataType: 'jsonp',
timeout : 1000,
success: function(result) {
$('#${element_id}_xqa_log_data').html(result);
},
error: function() {
alert('Error: cannot connect to XQA server');
}
});
};
</script> </script>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment