Skip to content

Commit

Permalink
Merge pull request #1754 from jhawthorn/cleanup_spree_js
Browse files Browse the repository at this point in the history
Cleanup spree.js (and rewrite as plain JS)
  • Loading branch information
jhawthorn authored Mar 7, 2017
2 parents 15928c6 + 6803a3e commit 80d63c2
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 64 deletions.
64 changes: 0 additions & 64 deletions core/app/assets/javascripts/spree.js.coffee.erb

This file was deleted.

72 changes: 72 additions & 0 deletions core/app/assets/javascripts/spree.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//= require jsuri

window.Spree = {};

Spree.ready = function(callback) {
if (typeof Turbolinks !== 'undefined' && Turbolinks.supported) {
jQuery(document).on('turbolinks:load', function() {
callback(jQuery);
});
} else {
jQuery(document).ready(callback);
}
};

Spree.mountedAt = function() {
return "<%= Rails.application.routes.url_helpers.spree_path(trailing_slash: true) %>";
};

Spree.pathFor = function(path) {
var locationOrigin;
locationOrigin = (window.location.protocol + "//" + window.location.hostname) + (window.location.port ? ":" + window.location.port : "");
return locationOrigin + Spree.mountedAt() + path;
};

Spree.url = function(uri, query) {
if (Spree.env === 'development' || Spree.env === 'test') {
console.warn('Spree.url is deprecated, please use Spree.ajax for your request instead.');
}
if (uri.path === undefined) {
uri = new Uri(uri);
}
if (query) {
$.each(query, function(key, value) {
return uri.addQueryParam(key, value);
});
}
return uri;
};

Spree.ajax = function(url, options) {
if (typeof url === "object") {
options = url;
url = undefined;
}
options = options || {};
options = $.extend(options, {
headers: {
"X-Spree-Token": Spree.api_key
}
});
return $.ajax(url, options);
};

Spree.routes = {
states_search: Spree.pathFor('api/states'),
apply_coupon_code: function(order_id) {
return Spree.pathFor("api/orders/" + order_id + "/apply_coupon_code");
}
};

Spree.getJSON = function(url, data, success) {
if (typeof data === 'function') {
success = data;
data = undefined;
}
return Spree.ajax({
dataType: "json",
url: url,
data: data,
success: success
});
};

0 comments on commit 80d63c2

Please sign in to comment.