Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add some endpoint helpers

  • Loading branch information...
commit 59b8140678949adaca9fa1e0b7884cd48e443b22 1 parent b48e32c
@SlexAxton SlexAxton authored
View
2  .gitignore
@@ -0,0 +1,2 @@
+.DS_Store
+public/v1
View
6 README.md
@@ -0,0 +1,6 @@
+## Heroku 10 seconds setup
+
+ heroku create myapp
+ heroku addons:add mongohq:sandbox
+ git push heroku master
+ heroku open
View
11 Rakefile
@@ -0,0 +1,11 @@
+namespace :assets do
+ task :precompile do
+ require 'fileutils'
+ require './app'
+
+ FileUtils.mkdir_p(settings.root + '/public/v1')
+ File.open(settings.root + '/public/v1/abba.js', 'w+') do |file|
+ file.write settings.sprockets['client/index'].to_s
+ end
+ end
+end
View
2  app.rb
@@ -17,7 +17,7 @@
}, settings.environment.to_s)
set :sprockets, Sprockets::Environment.new
- settings.sprockets.append_path 'app/assets/javascripts'
+ settings.sprockets.append_path(settings.root + '/app/assets/javascripts')
end
helpers do
View
17 app/assets/javascripts/client/index.coffee
@@ -1,5 +1,5 @@
class @Abba
- @endpoint: 'http://localhost:4050'
+ @endpoint: 'http://localhost:4567'
constructor: (name, options = {}) ->
unless name
@@ -111,4 +111,17 @@ class @Abba
key = decodeURIComponent(cookie.substr(0, index))
value = decodeURIComponent(cookie.substr(index + 1))
return value if key is name
- null
+ null
+
+do ->
+ host = (url) ->
+ # IE6 only resolves resolves hrefs using innerHTML
+ parent = document.createElement('div')
+ parent.innerHTML = "<a href=\"#{url}\">x</a>"
+ parser = parent.firstChild
+ "#{parser.host}"
+
+ # Find Abba's endpoint from the script tag
+ scripts = document.getElementsByTagName('script')
+ scripts = (script.src for script in scripts when /abba\.js$/.test(script.src))
+ Abba.endpoint = "//#{host(scripts[0])}" if scripts[0]
View
6 public/test/complete.html
@@ -1,5 +1,7 @@
<script src="/v1/abba.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
- Abba('alert test').complete();
-</script>
+ Abba('My Checkout').complete();
+</script>
+
+<h1>Test complete!</h1>
View
27 public/test/start.html
@@ -1,15 +1,28 @@
<script src="/v1/abba.js" type="text/javascript" charset="utf-8"></script>
+<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
+
+<div id="tests">
+ <div id="control"><h1>The control was chosen!</h1></div>
+ <div id="variant1"><h1>&#x27;Variant 1&#x27; was chosen!</h1></div>
+ <div id="variant2"><h1>&#x27;Variant 2&#x27; was chosen!</h1></div>
+</div>
<script type="text/javascript" charset="utf-8">
- Abba('alert test')
+ $('#tests').children().hide()
+
+ Abba('My Checkout')
.control(function(){
- alert('control');
+ $('#control').show();
})
- .a(function(){
- alert('a');
+ .variant('Variant 1', function(){
+ $('#variant1').show();
})
- .b(function(){
- alert('b');
+ .variant('Variant 2', function(){
+ $('#variant2').show();
})
.start();
-</script>
+</script>
+
+<p>
+ <a href="complete.html">Now complete the test.</a>
+</p>
Please sign in to comment.
Something went wrong with that request. Please try again.