diff --git a/static/coffee/spec/calculator_spec.coffee b/static/coffee/spec/calculator_spec.coffee index 5c3fde5e2d..a9ef69ed26 100644 --- a/static/coffee/spec/calculator_spec.coffee +++ b/static/coffee/spec/calculator_spec.coffee @@ -60,7 +60,7 @@ describe 'Calculator', -> @calculator.calculate() it 'send data to /calculate', -> - expect($.getJSON).toHaveBeenCalledWith '/calculate', + expect($.getWithPrefix).toHaveBeenCalledWith '/calculate', equation: '1+2' , jasmine.any(Function) diff --git a/static/coffee/spec/feedback_form_spec.coffee b/static/coffee/spec/feedback_form_spec.coffee index 41ba2ec04d..64fa5cba24 100644 --- a/static/coffee/spec/feedback_form_spec.coffee +++ b/static/coffee/spec/feedback_form_spec.coffee @@ -16,7 +16,7 @@ describe 'FeedbackForm', -> $('#feedback_message').val 'This site is really good.' $('#feedback_button').click() - expect($.post).toHaveBeenCalledWith '/send_feedback', { + expect($.postWithPrefix).toHaveBeenCalledWith '/send_feedback', { subject: 'Awesome!' message: 'This site is really good.' url: window.location.href diff --git a/static/coffee/src/calculator.coffee b/static/coffee/src/calculator.coffee index bca88503fd..2f9b8a1aa8 100644 --- a/static/coffee/src/calculator.coffee +++ b/static/coffee/src/calculator.coffee @@ -20,5 +20,5 @@ class @Calculator $('.help').toggleClass 'shown' calculate: -> - $.getJSON '/calculate', { equation: $('#calculator_input').val() }, (data) -> + $.getWithPrefix '/calculate', { equation: $('#calculator_input').val() }, (data) -> $('#calculator_output').val(data.result) diff --git a/static/coffee/src/courseware.coffee b/static/coffee/src/courseware.coffee index e2f015baef..b495e14bc2 100644 --- a/static/coffee/src/courseware.coffee +++ b/static/coffee/src/courseware.coffee @@ -1,5 +1,6 @@ class @Courseware constructor: -> + Courseware.prefix = $("meta[name='path_prefix']").attr('content') new Navigation new Calculator new FeedbackForm diff --git a/static/coffee/src/feedback_form.coffee b/static/coffee/src/feedback_form.coffee index ffb8b37521..3394db448f 100644 --- a/static/coffee/src/feedback_form.coffee +++ b/static/coffee/src/feedback_form.coffee @@ -5,6 +5,6 @@ class @FeedbackForm subject: $('#feedback_subject').val() message: $('#feedback_message').val() url: window.location.href - $.post '/send_feedback', data, -> + $.postWithPrefix '/send_feedback', data, -> $('#feedback_div').html 'Feedback submitted. Thank you' ,'json' diff --git a/static/coffee/src/main.coffee b/static/coffee/src/main.coffee index 85c98ff929..733322b9bb 100644 --- a/static/coffee/src/main.coffee +++ b/static/coffee/src/main.coffee @@ -1,3 +1,9 @@ +jQuery.postWithPrefix = (url, data, callback, type) -> + $.post("#{Courseware.prefix}#{url}", data, callback, type) + +jQuery.getWithPrefix = (url, data, callback, type) -> + $.get("#{Courseware.prefix}#{url}", data, callback, type) + $ -> $.ajaxSetup headers : { 'X-CSRFToken': $.cookie 'csrftoken' } @@ -18,8 +24,8 @@ $ -> element.schematic.update_value() schematic_value $("#schematic_#{circuit_id}").attr("value") - $.post "/save_circuit/#{circuit_id}", schematic: schematic_value, (data) -> + $.postWithPrefix "/save_circuit/#{circuit_id}", schematic: schematic_value, (data) -> alert('Saved') if data.results == 'success' window.postJSON = (url, data, callback) -> - $.post url, data, callback + $.postWithPrefix url, data, callback diff --git a/templates/coffee/src/logger.coffee b/templates/coffee/src/logger.coffee index 729cb54982..97d6deaacc 100644 --- a/templates/coffee/src/logger.coffee +++ b/templates/coffee/src/logger.coffee @@ -1,6 +1,6 @@ class @Logger @log: (event_type, data) -> - $.getJSON '/event', + $.getWithPrefix '/event', event_type: event_type event: JSON.stringify(data) page: window.location.href @@ -8,7 +8,7 @@ class @Logger @bind: -> window.onunload = -> $.ajax - url: '/event' + url: "#{Courseware.prefix}/event" data: event_type: 'page_close' event: '' diff --git a/templates/coffee/src/modules/problem.coffee b/templates/coffee/src/modules/problem.coffee index add045266c..b2d4d0f5ed 100644 --- a/templates/coffee/src/modules/problem.coffee +++ b/templates/coffee/src/modules/problem.coffee @@ -25,7 +25,7 @@ class @Problem check: => Logger.log 'problem_check', @answers - $.post "/modx/problem/#{@id}/problem_check", @answers, (response) => + $.postWithPrefix "/modx/problem/#{@id}/problem_check", @answers, (response) => switch response.success when 'incorrect', 'correct' @render(response.contents) @@ -34,18 +34,18 @@ class @Problem reset: => Logger.log 'problem_reset', @answers - $.post "/modx/problem/#{@id}/problem_reset", id: @id, (content) => + $.postWithPrefix "/modx/problem/#{@id}/problem_reset", id: @id, (content) => @render(content) show: => Logger.log 'problem_show', problem: @id - $.post "/modx/problem/#{@id}/problem_show", (response) => + $.postWithPrefix "/modx/problem/#{@id}/problem_show", (response) => $.each response, (key, value) => @$("#answer_#{key}").text(value) save: => Logger.log 'problem_save', @answers - $.post "/modx/problem/#{@id}/problem_save", @answers, (response) => + $.postWithPrefix "/modx/problem/#{@id}/problem_save", @answers, (response) => if response.success alert 'Saved' diff --git a/templates/coffee/src/modules/sequence.coffee b/templates/coffee/src/modules/sequence.coffee index 9c1549ff78..4fb6225bbc 100644 --- a/templates/coffee/src/modules/sequence.coffee +++ b/templates/coffee/src/modules/sequence.coffee @@ -36,7 +36,7 @@ class @Sequence render: (new_position) -> if @position != undefined @mark_visited @position - $.post "/modx/#{@tag}/#{@id}/goto_position", position: new_position + $.postWithPrefix "/modx/#{@tag}/#{@id}/goto_position", position: new_position if @position != new_position @mark_active new_position diff --git a/templates/coffee/src/modules/video/video_caption.coffee b/templates/coffee/src/modules/video/video_caption.coffee index 9115274222..97122e1704 100644 --- a/templates/coffee/src/modules/video/video_caption.coffee +++ b/templates/coffee/src/modules/video/video_caption.coffee @@ -45,7 +45,7 @@ class VideoCaption .append($('
  • ').height(@bottomSpacingHeight())) fetchCaption: -> - $.getJSON @captionURL(), (captions) => + $.getWithPrefix @captionURL(), (captions) => @captions = captions.text @start = captions.start for index in [0...captions.start.length] diff --git a/templates/main.html b/templates/main.html index 00abe2902d..33ca0b85eb 100644 --- a/templates/main.html +++ b/templates/main.html @@ -28,6 +28,7 @@ It can't be run through static.url because MathJax uses crazy url introspection to do lazy loading of MathJax extension libraries --> + diff --git a/templates/profile.html b/templates/profile.html index 98d5b38c7b..e732616d5a 100644 --- a/templates/profile.html +++ b/templates/profile.html @@ -75,7 +75,7 @@ $(function() { }); $('#pwd_reset_button').click(function() { - $.post('/password_reset/',{ "csrfmiddlewaretoken" : "${ csrf }", + $.postWithPrefix('/password_reset/',{ "csrfmiddlewaretoken" : "${ csrf }", "email" : $('#id_email').val()}, function(data){ $("#password_reset_complete_link").click(); log_event("profile", {"type":"password_send"});