Sha256: e7433942c6e3d9d0a045b818992411eba3ed5ce0dd91d264e8a243361a160696

Contents?: true

Size: 1.85 KB

Versions: 33

Compression:

Stored size: 1.85 KB

Contents

#= require jsuri
class window.Spree
  @ready: (callback) ->
    jQuery(document).ready(callback)

    # fire ready callbacks also on turbolinks page change event
    jQuery(document).on 'page:load', ->
      callback(jQuery)

  @mountedAt: ->
    window.SpreePaths.mounted_at

  @adminPath: ->
    window.SpreePaths.admin

  @pathFor: (path) ->
    locationOrigin = "#{window.location.protocol}//#{window.location.hostname}" + (if window.location.port then ":#{window.location.port}" else "")
    @url("#{locationOrigin}#{@mountedAt()}#{path}", @url_params).toString()

  @adminPathFor: (path) ->
    @pathFor("#{@adminPath()}#{path}")

  # Helper function to take a URL and add query parameters to it
  # Uses the JSUri library from here: https://github.com/derek-watson/jsUri
  # Thanks to Jake Moffat for the suggestion: https://twitter.com/jakeonrails/statuses/321776992221544449
  @url: (uri, query) ->
    if uri.path == undefined
      uri = new Uri(uri)
    if query
      $.each query, (key, value) ->
        uri.addQueryParam(key, value)
    return uri

  # This function automatically appends the API token
  # for the user to the end of any URL.
  # Immediately after, this string is then passed to jQuery.ajax.
  #
  # ajax works in two ways in jQuery:
  #
  # $.ajax("url", {settings: 'go here'})
  # or:
  # $.ajax({url: "url", settings: 'go here'})
  #
  # This function will support both of these calls.
  @ajax: (url_or_settings, settings) ->
    if (typeof(url_or_settings) == "string")
      $.ajax(Spree.url(url_or_settings).toString(), settings)
    else
      url = url_or_settings['url']
      delete url_or_settings['url']
      $.ajax(Spree.url(url).toString(), url_or_settings)

  @routes:
    states_search: @pathFor('api/v1/states')
    apply_coupon_code: (order_id) ->
      Spree.pathFor("api/v1/orders/#{order_id}/apply_coupon_code")

  @url_params:
    {}

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
spree_core-3.4.6 app/assets/javascripts/spree.js.coffee
spree_core-3.2.9 app/assets/javascripts/spree.js.coffee
spree_core-3.3.6 app/assets/javascripts/spree.js.coffee
spree_core-3.2.8 app/assets/javascripts/spree.js.coffee
spree_core-3.4.5 app/assets/javascripts/spree.js.coffee
spree_core-3.3.5 app/assets/javascripts/spree.js.coffee
spree_core-3.4.4 app/assets/javascripts/spree.js.coffee
spree_core-3.4.3 app/assets/javascripts/spree.js.coffee
spree_core-3.3.4 app/assets/javascripts/spree.js.coffee
spree_core-3.2.7 app/assets/javascripts/spree.js.coffee
spree_core-3.4.2 app/assets/javascripts/spree.js.coffee
spree_core-3.3.3 app/assets/javascripts/spree.js.coffee
spree_core-3.2.6 app/assets/javascripts/spree.js.coffee
spree_core-3.4.1 app/assets/javascripts/spree.js.coffee
spree_core-3.4.0 app/assets/javascripts/spree.js.coffee
spree_core-3.4.0.rc2 app/assets/javascripts/spree.js.coffee
spree_core-3.4.0.rc1 app/assets/javascripts/spree.js.coffee
spree_core-3.3.2 app/assets/javascripts/spree.js.coffee
spree_core-3.2.5 app/assets/javascripts/spree.js.coffee
spree_core-3.3.1 app/assets/javascripts/spree.js.coffee