awe-rails 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +109 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +28 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/awe-rails-1.0.17.gem +0 -0
- data/awe-rails.gemspec +74 -0
- data/lib/awe/rails/engine.rb +12 -0
- data/lib/awe/rails.rb +5 -0
- data/lib/awe-rails.rb +1 -0
- data/lib/generators/awe/install/install_generator.rb +20 -0
- data/spec/awe-rails_spec.rb +5 -0
- data/spec/lib/awe-rails_spec.rb +3 -0
- data/spec/spec_helper.rb +50 -0
- data/vendor/assets/javascripts/awe-core.js +537 -0
- data/vendor/assets/javascripts/awe-state-machine.js +128 -0
- metadata +137 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
gem "rails", ">= 3.1"
|
7
|
+
|
8
|
+
# Add dependencies to develop your gem here.
|
9
|
+
# Include everything needed to run rake, tests, features, etc.
|
10
|
+
group :development do
|
11
|
+
gem "rspec", "~> 2.8.0"
|
12
|
+
gem "rdoc", "~> 3.12"
|
13
|
+
gem "bundler", "~> 1.0.0"
|
14
|
+
gem "jeweler", "~> 1.8.3"
|
15
|
+
gem "simplecov", ">= 0"
|
16
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
actionmailer (3.2.0)
|
5
|
+
actionpack (= 3.2.0)
|
6
|
+
mail (~> 2.4.0)
|
7
|
+
actionpack (3.2.0)
|
8
|
+
activemodel (= 3.2.0)
|
9
|
+
activesupport (= 3.2.0)
|
10
|
+
builder (~> 3.0.0)
|
11
|
+
erubis (~> 2.7.0)
|
12
|
+
journey (~> 1.0.0)
|
13
|
+
rack (~> 1.4.0)
|
14
|
+
rack-cache (~> 1.1)
|
15
|
+
rack-test (~> 0.6.1)
|
16
|
+
sprockets (~> 2.1.2)
|
17
|
+
activemodel (3.2.0)
|
18
|
+
activesupport (= 3.2.0)
|
19
|
+
builder (~> 3.0.0)
|
20
|
+
activerecord (3.2.0)
|
21
|
+
activemodel (= 3.2.0)
|
22
|
+
activesupport (= 3.2.0)
|
23
|
+
arel (~> 3.0.0)
|
24
|
+
tzinfo (~> 0.3.29)
|
25
|
+
activeresource (3.2.0)
|
26
|
+
activemodel (= 3.2.0)
|
27
|
+
activesupport (= 3.2.0)
|
28
|
+
activesupport (3.2.0)
|
29
|
+
i18n (~> 0.6)
|
30
|
+
multi_json (~> 1.0)
|
31
|
+
arel (3.0.0)
|
32
|
+
builder (3.0.0)
|
33
|
+
diff-lcs (1.1.3)
|
34
|
+
erubis (2.7.0)
|
35
|
+
git (1.2.5)
|
36
|
+
hike (1.2.1)
|
37
|
+
i18n (0.6.0)
|
38
|
+
jeweler (1.8.3)
|
39
|
+
bundler (~> 1.0)
|
40
|
+
git (>= 1.2.5)
|
41
|
+
rake
|
42
|
+
rdoc
|
43
|
+
journey (1.0.0)
|
44
|
+
json (1.6.5)
|
45
|
+
mail (2.4.1)
|
46
|
+
i18n (>= 0.4.0)
|
47
|
+
mime-types (~> 1.16)
|
48
|
+
treetop (~> 1.4.8)
|
49
|
+
mime-types (1.17.2)
|
50
|
+
multi_json (1.0.4)
|
51
|
+
polyglot (0.3.3)
|
52
|
+
rack (1.4.1)
|
53
|
+
rack-cache (1.1)
|
54
|
+
rack (>= 0.4)
|
55
|
+
rack-ssl (1.3.2)
|
56
|
+
rack
|
57
|
+
rack-test (0.6.1)
|
58
|
+
rack (>= 1.0)
|
59
|
+
rails (3.2.0)
|
60
|
+
actionmailer (= 3.2.0)
|
61
|
+
actionpack (= 3.2.0)
|
62
|
+
activerecord (= 3.2.0)
|
63
|
+
activeresource (= 3.2.0)
|
64
|
+
activesupport (= 3.2.0)
|
65
|
+
bundler (~> 1.0)
|
66
|
+
railties (= 3.2.0)
|
67
|
+
railties (3.2.0)
|
68
|
+
actionpack (= 3.2.0)
|
69
|
+
activesupport (= 3.2.0)
|
70
|
+
rack-ssl (~> 1.3.2)
|
71
|
+
rake (>= 0.8.7)
|
72
|
+
rdoc (~> 3.4)
|
73
|
+
thor (~> 0.14.6)
|
74
|
+
rake (0.9.2.2)
|
75
|
+
rdoc (3.12)
|
76
|
+
json (~> 1.4)
|
77
|
+
rspec (2.8.0)
|
78
|
+
rspec-core (~> 2.8.0)
|
79
|
+
rspec-expectations (~> 2.8.0)
|
80
|
+
rspec-mocks (~> 2.8.0)
|
81
|
+
rspec-core (2.8.0)
|
82
|
+
rspec-expectations (2.8.0)
|
83
|
+
diff-lcs (~> 1.1.2)
|
84
|
+
rspec-mocks (2.8.0)
|
85
|
+
simplecov (0.5.4)
|
86
|
+
multi_json (~> 1.0.3)
|
87
|
+
simplecov-html (~> 0.5.3)
|
88
|
+
simplecov-html (0.5.3)
|
89
|
+
sprockets (2.1.2)
|
90
|
+
hike (~> 1.2)
|
91
|
+
rack (~> 1.0)
|
92
|
+
tilt (~> 1.1, != 1.3.0)
|
93
|
+
thor (0.14.6)
|
94
|
+
tilt (1.3.3)
|
95
|
+
treetop (1.4.10)
|
96
|
+
polyglot
|
97
|
+
polyglot (>= 0.3.1)
|
98
|
+
tzinfo (0.3.31)
|
99
|
+
|
100
|
+
PLATFORMS
|
101
|
+
ruby
|
102
|
+
|
103
|
+
DEPENDENCIES
|
104
|
+
bundler (~> 1.0.0)
|
105
|
+
jeweler (~> 1.8.3)
|
106
|
+
rails (>= 3.1)
|
107
|
+
rdoc (~> 3.12)
|
108
|
+
rspec (~> 2.8.0)
|
109
|
+
simplecov
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Artefact Group LLC
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
= awe-rails
|
2
|
+
|
3
|
+
* This gem adds a single generator to Rails 3.1, awe:install.
|
4
|
+
* Running the generator will install AWE for Rails.
|
5
|
+
* See https://github.com/sambaker/awe-core
|
6
|
+
* AWE is installed into the rails asset pipeline.
|
7
|
+
* These lines will be added to the file `app/assets/javascripts/application.js` by default:
|
8
|
+
|
9
|
+
//= require awe
|
10
|
+
|
11
|
+
== Installation
|
12
|
+
|
13
|
+
In your Gemfile, add this line:
|
14
|
+
|
15
|
+
gem "awe-rails"
|
16
|
+
|
17
|
+
Then, run bundle install. To invoke the generator, run:
|
18
|
+
|
19
|
+
rails generate awe:install
|
20
|
+
|
21
|
+
You're done!
|
22
|
+
|
23
|
+
== Copyright
|
24
|
+
|
25
|
+
Copyright (c) 2012 Artefact Group LLC.
|
26
|
+
|
27
|
+
See LICENSE.txt for further details.
|
28
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "awe-rails"
|
18
|
+
gem.homepage = "http://www.artefactgroup.com"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Gem for integrating AWE into the rails asset pipeline}
|
21
|
+
gem.description = %Q{Modeled after the jquery-rails gem. Installs the AWE files into the rails 3.1 asset pipeline}
|
22
|
+
gem.email = "shyam.habarakada@gmail.com"
|
23
|
+
gem.authors = ["Shyam Habarakada"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rdoc/task'
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "awe-rails #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
Binary file
|
data/awe-rails.gemspec
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "awe-rails"
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Shyam Habarakada"]
|
12
|
+
s.date = "2012-02-04"
|
13
|
+
s.description = "Modeled after the jquery-rails gem. Installs the AWE files into the rails 3.1 asset pipeline"
|
14
|
+
s.email = "shyam.habarakada@gmail.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
"CHANGELOG.md",
|
23
|
+
"Gemfile",
|
24
|
+
"Gemfile.lock",
|
25
|
+
"LICENSE.txt",
|
26
|
+
"README.rdoc",
|
27
|
+
"Rakefile",
|
28
|
+
"VERSION",
|
29
|
+
"awe-rails-1.0.17.gem",
|
30
|
+
"awe-rails.gemspec",
|
31
|
+
"lib/awe-rails.rb",
|
32
|
+
"lib/awe/rails.rb",
|
33
|
+
"lib/awe/rails/engine.rb",
|
34
|
+
"lib/generators/awe/install/install_generator.rb",
|
35
|
+
"spec/awe-rails_spec.rb",
|
36
|
+
"spec/lib/awe-rails_spec.rb",
|
37
|
+
"spec/spec_helper.rb",
|
38
|
+
"vendor/assets/javascripts/awe-core.js",
|
39
|
+
"vendor/assets/javascripts/awe-state-machine.js"
|
40
|
+
]
|
41
|
+
s.homepage = "http://www.artefactgroup.com"
|
42
|
+
s.licenses = ["MIT"]
|
43
|
+
s.require_paths = ["lib"]
|
44
|
+
s.rubygems_version = "1.8.10"
|
45
|
+
s.summary = "Gem for integrating AWE into the rails asset pipeline"
|
46
|
+
|
47
|
+
if s.respond_to? :specification_version then
|
48
|
+
s.specification_version = 3
|
49
|
+
|
50
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
51
|
+
s.add_runtime_dependency(%q<rails>, [">= 3.1"])
|
52
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
|
53
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
54
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
55
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
|
56
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
57
|
+
else
|
58
|
+
s.add_dependency(%q<rails>, [">= 3.1"])
|
59
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
60
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
61
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
62
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
63
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
64
|
+
end
|
65
|
+
else
|
66
|
+
s.add_dependency(%q<rails>, [">= 3.1"])
|
67
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
68
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
69
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
70
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
71
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
data/lib/awe/rails.rb
ADDED
data/lib/awe-rails.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'awe/rails'
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rails'
|
2
|
+
|
3
|
+
module Awe
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < ::Rails::Generators::Base
|
6
|
+
|
7
|
+
desc "This generator installs AWE (Artefact Web Extensions) into the rails asset pipeline"
|
8
|
+
source_root File.expand_path('../../../../../vendor/assets/javascripts', __FILE__)
|
9
|
+
|
10
|
+
def copy_awe
|
11
|
+
say_status("copying", "awe-core", :green)
|
12
|
+
copy_file "awe-core.js", "public/javascripts/awe-core.js"
|
13
|
+
say_status("copying", "awe-state-machine", :green)
|
14
|
+
copy_file "awe-state-machine.js", "public/javascripts/awe-state-machine.js"
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
<<<<<<< HEAD
|
2
|
+
<<<<<<< HEAD
|
3
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
5
|
+
require 'rspec'
|
6
|
+
require 'awe-rails'
|
7
|
+
|
8
|
+
# Requires supporting files with custom matchers and macros, etc,
|
9
|
+
# in ./support/ and its subdirectories.
|
10
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
|
14
|
+
end
|
15
|
+
=======
|
16
|
+
=======
|
17
|
+
>>>>>>> ccf863516cd6c75a59a22dde092099839482274b
|
18
|
+
# Set up RSpec
|
19
|
+
require 'webmock/rspec'
|
20
|
+
|
21
|
+
Spec::Runner.configure do |config|
|
22
|
+
config.include WebMock::API
|
23
|
+
end
|
24
|
+
|
25
|
+
# Set up generator tests
|
26
|
+
require 'rails/all'
|
27
|
+
require 'rails/generators'
|
28
|
+
require 'rails/generators/test_case'
|
29
|
+
|
30
|
+
class TestApp < Rails::Application
|
31
|
+
config.root = File.dirname(__FILE__)
|
32
|
+
end
|
33
|
+
Rails.application = TestApp
|
34
|
+
|
35
|
+
module Rails
|
36
|
+
def self.root
|
37
|
+
@root ||= File.expand_path("../../tmp/rails", __FILE__)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
Rails.application.config.root = Rails.root
|
41
|
+
|
42
|
+
# Call configure to load the settings from
|
43
|
+
# Rails.application.config.generators to Rails::Generators
|
44
|
+
Rails::Generators.configure!
|
45
|
+
|
46
|
+
|
47
|
+
<<<<<<< HEAD
|
48
|
+
>>>>>>> ccf863516cd6c75a59a22dde092099839482274b
|
49
|
+
=======
|
50
|
+
>>>>>>> ccf863516cd6c75a59a22dde092099839482274b
|
@@ -0,0 +1,537 @@
|
|
1
|
+
/*
|
2
|
+
* Artefact Web Extensions
|
3
|
+
*
|
4
|
+
* Copyright 2012, Artefact Group LLC
|
5
|
+
* Licensed under MIT.
|
6
|
+
*/
|
7
|
+
(function(global, document, namespace, undefined) {
|
8
|
+
namespace = namespace || "Awe";
|
9
|
+
|
10
|
+
// Create and export Awe
|
11
|
+
var Awe = {}
|
12
|
+
|
13
|
+
// Helpers
|
14
|
+
Awe.isArray = function(o) {
|
15
|
+
return o && o.constructor == Array.prototype.constructor;
|
16
|
+
}
|
17
|
+
|
18
|
+
Awe.isArrayOrString = function(o) {
|
19
|
+
return o && o.constructor == Array.prototype.constructor || o.constructor == String.prototype.constructor;
|
20
|
+
}
|
21
|
+
|
22
|
+
Awe.isType = function(o, type) {
|
23
|
+
return o && o.constructor == type.prototype.constructor;
|
24
|
+
}
|
25
|
+
|
26
|
+
Awe.isFunction = function(o) {
|
27
|
+
return o && o.constructor == Function.prototype.constructor;
|
28
|
+
}
|
29
|
+
|
30
|
+
// Environment-specific vars
|
31
|
+
Awe.env = {};
|
32
|
+
Awe.env.inputTouch = "ontouchstart" in global;
|
33
|
+
Awe.env.inputMouse = !Awe.env.inputTouch;
|
34
|
+
|
35
|
+
Awe.env.eventDragStart = Awe.env.inputTouch ? "touchstart" : "mousedown";
|
36
|
+
Awe.env.eventDragMove = Awe.env.inputTouch ? "touchmove" : "mousemove";
|
37
|
+
Awe.env.eventDragEnd = Awe.env.inputTouch ? "touchend" : "mouseup";
|
38
|
+
Awe.env.eventClick = Awe.env.inputTouch ? "touchend" : "click";
|
39
|
+
|
40
|
+
// Clamp a number between min/max
|
41
|
+
Awe.clamp = function(n, min, max) {
|
42
|
+
return Math.min(Math.max(n, min), max);
|
43
|
+
}
|
44
|
+
|
45
|
+
// Clamp a number between -1 and 1 before passing to Math.acos to prevent an exception.
|
46
|
+
// Ensure that this makes sense for your parameters - it is assumed they will be close to
|
47
|
+
// the clamped range but allows computational errors to be safely ignored.
|
48
|
+
Awe.acosSafe = function(rad) {
|
49
|
+
return Math.acos(Awe.clamp(rad, -1, 1));
|
50
|
+
}
|
51
|
+
|
52
|
+
// Get a query string parameter value by name
|
53
|
+
Awe.getQueryParam = function(name, url) {
|
54
|
+
url = url || global.location.href;
|
55
|
+
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
|
56
|
+
var regexS = "[\\?&]"+name+"=([^&#]*)";
|
57
|
+
var regex = new RegExp( regexS );
|
58
|
+
var results = regex.exec( url );
|
59
|
+
if (!results)
|
60
|
+
return "";
|
61
|
+
return results[1];
|
62
|
+
}
|
63
|
+
|
64
|
+
if (Array.prototype.forEach) {
|
65
|
+
Awe.forEach = function(array, callback, thisArg) {
|
66
|
+
array.forEach(callback, thisArg);
|
67
|
+
}
|
68
|
+
} else {
|
69
|
+
Awe.forEach = function(array, callback, thisArg) {
|
70
|
+
var length = array.length;
|
71
|
+
var i = 0;
|
72
|
+
while (i < length) {
|
73
|
+
callback.call(thisArg, array[i], i);
|
74
|
+
++i;
|
75
|
+
}
|
76
|
+
}
|
77
|
+
}
|
78
|
+
|
79
|
+
// Create an HTML element of the given type and attach to the given parent if not null.
|
80
|
+
// The config object can contain styles, attrs, a class and a background sprite to apply
|
81
|
+
// to the element
|
82
|
+
Awe.createElement = function(type, parent, config) {
|
83
|
+
var k;
|
84
|
+
var el = document.createElement(type);
|
85
|
+
config = config || {};
|
86
|
+
if (config.backgroundSprite) {
|
87
|
+
// TODO:
|
88
|
+
throw("TODO:");
|
89
|
+
//setBackgroundSprite(el, config.backgroundSprite);
|
90
|
+
}
|
91
|
+
for (k in (config.styles || {})) {
|
92
|
+
el.style[k] = config.styles[k];
|
93
|
+
}
|
94
|
+
for (k in (config.attrs || {})) {
|
95
|
+
el[k] = config.attrs[k];
|
96
|
+
}
|
97
|
+
for (k in (config.setAttrs || {})) {
|
98
|
+
el.setAttribute(k, config.setAttrs[k]);
|
99
|
+
}
|
100
|
+
|
101
|
+
if (parent)
|
102
|
+
parent.appendChild(el);
|
103
|
+
|
104
|
+
if (config.className)
|
105
|
+
el.className = config.className;
|
106
|
+
|
107
|
+
return el;
|
108
|
+
}
|
109
|
+
|
110
|
+
/*
|
111
|
+
* method: Awe.enableDrag
|
112
|
+
*
|
113
|
+
* purpose: enable drag on a DOM element
|
114
|
+
*
|
115
|
+
*/
|
116
|
+
|
117
|
+
Awe.enableDrag = function(el, config) {
|
118
|
+
|
119
|
+
config = config || {};
|
120
|
+
var filters = config.filters;
|
121
|
+
var updater = config.updater || new Awe.DragUpdaterTopLeft();
|
122
|
+
|
123
|
+
// Convert a single drag filter
|
124
|
+
if (filters) {
|
125
|
+
if (!Awe.isArray(filters)) {
|
126
|
+
filters = [filters];
|
127
|
+
}
|
128
|
+
} else {
|
129
|
+
filters = [];
|
130
|
+
}
|
131
|
+
|
132
|
+
// Drag state
|
133
|
+
var touch = {};
|
134
|
+
|
135
|
+
function getClientPos(evt)
|
136
|
+
{
|
137
|
+
var p;
|
138
|
+
if (Awe.env.inputTouch)
|
139
|
+
{
|
140
|
+
// TODO: Use correct touch (lookup by touch start ID instead of always using index 0)
|
141
|
+
p = { x: evt.changedTouches[0].clientX, y: evt.changedTouches[0].clientY };
|
142
|
+
} else {
|
143
|
+
p = { x: evt.clientX, y: evt.clientY };
|
144
|
+
}
|
145
|
+
p.x += touch.anchor.x;
|
146
|
+
p.y += touch.anchor.y;
|
147
|
+
return p
|
148
|
+
}
|
149
|
+
|
150
|
+
function processDrag(clientPos, pos, start) {
|
151
|
+
if (touch.now) {
|
152
|
+
touch.maxDistanceSquared = Math.max(touch.maxDistanceSquared, (touch.now.x - touch.start.x) * (touch.now.x - touch.start.x) + (touch.now.y - touch.start.y) * (touch.now.y - touch.start.y));
|
153
|
+
} else {
|
154
|
+
touch.maxDistanceSquared = 0;
|
155
|
+
}
|
156
|
+
|
157
|
+
// Create the new drag state
|
158
|
+
var newDrag = {
|
159
|
+
clientPos: { x: clientPos.x, y: clientPos.y },
|
160
|
+
pos: { x: pos.x, y: pos.y },
|
161
|
+
dragTime: (Date.now() - touch.startTime) * 0.001,
|
162
|
+
maxDistanceSquared: touch.maxDistanceSquared
|
163
|
+
}
|
164
|
+
if (touch.lastDrag) {
|
165
|
+
newDrag.clientDelta = {
|
166
|
+
x: newDrag.clientPos.x - touch.lastDrag.clientPos.x,
|
167
|
+
y: newDrag.clientPos.y - touch.lastDrag.clientPos.y
|
168
|
+
}
|
169
|
+
newDrag.delta = {
|
170
|
+
x: newDrag.pos.x - touch.lastDrag.pos.x,
|
171
|
+
y: newDrag.pos.y - touch.lastDrag.pos.y
|
172
|
+
}
|
173
|
+
} else {
|
174
|
+
newDrag.clientDelta = { x: 0, y: 0 };
|
175
|
+
newDrag.delta = { x: 0, y: 0 };
|
176
|
+
}
|
177
|
+
|
178
|
+
// Copy current drag state to last
|
179
|
+
touch.lastDrag = {
|
180
|
+
clientPos: { x: newDrag.clientPos.x, y: newDrag.clientPos.y },
|
181
|
+
pos: { x: newDrag.pos.x, y: newDrag.pos.y },
|
182
|
+
delta: { x: newDrag.delta.x, y: newDrag.delta.y },
|
183
|
+
clientDelta: { x: newDrag.clientDelta.x, y: newDrag.clientDelta.y },
|
184
|
+
dragTime: newDrag.dragTime,
|
185
|
+
maxDistanceSquared: newDrag.maxDistanceSquared
|
186
|
+
}
|
187
|
+
|
188
|
+
return newDrag;
|
189
|
+
}
|
190
|
+
|
191
|
+
function updateDrag() {
|
192
|
+
return touch.lastDrag && {
|
193
|
+
clientPos: touch.lastDrag.clientPos,
|
194
|
+
pos: touch.lastDrag.pos,
|
195
|
+
clientDelta: { x: 0, y: 0 },
|
196
|
+
delta: { x: 0, y: 0 },
|
197
|
+
dragTime: (Date.now() - touch.startTime) * 0.001,
|
198
|
+
maxDistanceSquared: touch.lastDrag.maxDistanceSquared
|
199
|
+
}
|
200
|
+
}
|
201
|
+
|
202
|
+
// Per-frame updates
|
203
|
+
function dragUpdate(evt) {
|
204
|
+
var clientPos = touch.now || touch.start;
|
205
|
+
clientPos = { x: clientPos.x, y: clientPos.y };
|
206
|
+
var pos;
|
207
|
+
Awe.forEach(filters, function(filter) {
|
208
|
+
if (!pos && filter.animating) {
|
209
|
+
pos = filter.animate();
|
210
|
+
}
|
211
|
+
});
|
212
|
+
if (pos) {
|
213
|
+
updater.move(el, pos);
|
214
|
+
config.onChange(processDrag(clientPos, pos));
|
215
|
+
}
|
216
|
+
if (config.onUpdate) {
|
217
|
+
var drag = updateDrag();
|
218
|
+
drag && config.onUpdate(drag);
|
219
|
+
}
|
220
|
+
}
|
221
|
+
|
222
|
+
function dragMove(evt) {
|
223
|
+
Awe.cancelEvent(evt);
|
224
|
+
touch.now = getClientPos(evt);
|
225
|
+
var pos = applyFilters(touch.now);
|
226
|
+
var drag = processDrag(touch.now, pos);
|
227
|
+
if (config.onChange) {
|
228
|
+
config.onChange(drag);
|
229
|
+
}
|
230
|
+
}
|
231
|
+
|
232
|
+
function dragEnd(evt) {
|
233
|
+
if (!touch.dragging) {
|
234
|
+
return;
|
235
|
+
}
|
236
|
+
evt && Awe.cancelEvent(evt);
|
237
|
+
xRemoveEventListener(Awe.env.inputTouch ? el : document, Awe.env.eventDragMove, dragMove);
|
238
|
+
xRemoveEventListener(Awe.env.inputTouch ? el : document, Awe.env.eventDragEnd, dragEnd);
|
239
|
+
// TODO Check for animating filters before cancelling event bits
|
240
|
+
Awe.forEach(filters, function(filter) {
|
241
|
+
if (filter.end) {
|
242
|
+
filter.end();
|
243
|
+
}
|
244
|
+
});
|
245
|
+
if (updater.end) {
|
246
|
+
updater.end();
|
247
|
+
}
|
248
|
+
if (config.onRelease && evt) {
|
249
|
+
var pos = getClientPos(evt);
|
250
|
+
config.onRelease(processDrag(pos, pos));
|
251
|
+
}
|
252
|
+
if (touch.updateIntervalId) {
|
253
|
+
clearInterval(touch.updateIntervalId);
|
254
|
+
touch.updateIntervalId = null;
|
255
|
+
}
|
256
|
+
}
|
257
|
+
|
258
|
+
function applyFilters(pos) {
|
259
|
+
Awe.forEach(filters, function(filter) {
|
260
|
+
pos = filter.move(el, pos) || pos;
|
261
|
+
});
|
262
|
+
return pos;
|
263
|
+
}
|
264
|
+
|
265
|
+
function dragStart(evt) {
|
266
|
+
Awe.cancelEvent(evt);
|
267
|
+
touch.dragging = true;
|
268
|
+
touch.anchor = { x: 0, y: 0 }
|
269
|
+
// Calculate the position without the anchor
|
270
|
+
touch.now = getClientPos(evt);
|
271
|
+
// Calculate the anchor position
|
272
|
+
if (config.anchor) {
|
273
|
+
touch.anchor = config.anchor.getAnchor(el, touch.now);
|
274
|
+
// Get the client position again, taking the anchor into account
|
275
|
+
touch.now = getClientPos(evt);
|
276
|
+
}
|
277
|
+
touch.lastDrag = null;
|
278
|
+
touch.start = getClientPos(evt);
|
279
|
+
touch.startTime = Date.now();
|
280
|
+
touch.maxDistanceSquared = 0;
|
281
|
+
|
282
|
+
var pos = touch.start;
|
283
|
+
Awe.forEach(filters, function(filter) {
|
284
|
+
pos = filter.start(el, pos) || pos;
|
285
|
+
});
|
286
|
+
if (updater.start) {
|
287
|
+
updater.start(el, pos);
|
288
|
+
}
|
289
|
+
|
290
|
+
var pos = applyFilters(touch.now);
|
291
|
+
|
292
|
+
var drag = processDrag(touch.now, pos);
|
293
|
+
xAddEventListener(Awe.env.inputTouch ? el : document, Awe.env.eventDragMove, dragMove);
|
294
|
+
xAddEventListener(Awe.env.inputTouch ? el : document, Awe.env.eventDragEnd, dragEnd);
|
295
|
+
if (config.onUpdate) {
|
296
|
+
touch.updateIntervalId = setInterval(dragUpdate, config.dragUpdateInterval || 33);
|
297
|
+
}
|
298
|
+
}
|
299
|
+
|
300
|
+
xAddEventListener(el, Awe.env.eventDragStart, dragStart);
|
301
|
+
|
302
|
+
el._disableDrag = function() {
|
303
|
+
xRemoveEventListener(el, Awe.env.eventDragStart, dragStart);
|
304
|
+
// Make sure any in-progress drags have their listeners removed
|
305
|
+
dragEnd();
|
306
|
+
}
|
307
|
+
}
|
308
|
+
|
309
|
+
/*
|
310
|
+
* method: Awe.disableDrag
|
311
|
+
*
|
312
|
+
* purpose: disable drag on a DOM element
|
313
|
+
*
|
314
|
+
*/
|
315
|
+
Awe.disableDrag = function(el) {
|
316
|
+
if (el._disableDrag) {
|
317
|
+
el._disableDrag();
|
318
|
+
el._disableDrag = null;
|
319
|
+
}
|
320
|
+
}
|
321
|
+
|
322
|
+
Awe.DragAnchorTopLeft = function() {
|
323
|
+
var _i = this;
|
324
|
+
|
325
|
+
_i.getAnchor = function(el, pos) {
|
326
|
+
return { x: xLeft(el) - pos.x, y: xTop(el) - pos.y }
|
327
|
+
}
|
328
|
+
}
|
329
|
+
|
330
|
+
Awe.DragFilterLimitAxes = function(minX, maxX, minY, maxY) {
|
331
|
+
var _i = this;
|
332
|
+
|
333
|
+
_i.start = function(el, pos) {
|
334
|
+
}
|
335
|
+
|
336
|
+
_i.move = function(el, pos) {
|
337
|
+
var x = Awe.clamp(pos.x, minX, maxX);
|
338
|
+
var y = Awe.clamp(pos.y, minY, maxY);
|
339
|
+
return { x: x, y: y };
|
340
|
+
}
|
341
|
+
}
|
342
|
+
|
343
|
+
// To be continued...
|
344
|
+
/*
|
345
|
+
Awe.DragFilterMomentum = function() {
|
346
|
+
var _i = this;
|
347
|
+
|
348
|
+
_i.start = function(el, pos) {
|
349
|
+
}
|
350
|
+
|
351
|
+
_i.move = function(el, pos) {
|
352
|
+
_i.animating = true;
|
353
|
+
return { x: x, y: y };
|
354
|
+
}
|
355
|
+
|
356
|
+
_i.animate = function() {
|
357
|
+
// Apply velocity and acceleration
|
358
|
+
if (vel == 0) {
|
359
|
+
_i.animating = false;
|
360
|
+
}
|
361
|
+
}
|
362
|
+
*/
|
363
|
+
|
364
|
+
Awe.DragUpdaterTopLeft = function() {
|
365
|
+
var _i = this;
|
366
|
+
|
367
|
+
_i.start = function(el, pos) {
|
368
|
+
}
|
369
|
+
|
370
|
+
_i.move = function(el, pos) {
|
371
|
+
var left = pos.x;
|
372
|
+
var top = pos.y;
|
373
|
+
el.style.left = left + "px";
|
374
|
+
el.style.top = top + "px";
|
375
|
+
|
376
|
+
return pos;
|
377
|
+
}
|
378
|
+
}
|
379
|
+
|
380
|
+
/*
|
381
|
+
* method: Awe.objectToString
|
382
|
+
*
|
383
|
+
* purpose: convert an arbitrary object to string representation for logging
|
384
|
+
*
|
385
|
+
*/
|
386
|
+
Awe.objectToString = function(o) {
|
387
|
+
// Do something more interesting in the future?
|
388
|
+
return JSON.stringify(o);
|
389
|
+
}
|
390
|
+
|
391
|
+
var requestAnimationFrameShim = (function() {
|
392
|
+
return global.requestAnimationFrame ||
|
393
|
+
global.webkitRequestAnimationFrame ||
|
394
|
+
global.mozRequestAnimationFrame ||
|
395
|
+
global.oRequestAnimationFrame ||
|
396
|
+
global.msRequestAnimationFrame ||
|
397
|
+
function( callback ){
|
398
|
+
global.setTimeout(callback, 1000 / 60);
|
399
|
+
};
|
400
|
+
})();
|
401
|
+
|
402
|
+
// Specify a callback
|
403
|
+
Awe.addAnimationCallback = function(callback, interval) {
|
404
|
+
var startTime = Date.now();
|
405
|
+
var lastTime = startTime;
|
406
|
+
if (interval === undefined) {
|
407
|
+
requestAnimationFrameShim(function wrapper() {
|
408
|
+
time = Date.now();
|
409
|
+
if (!callback(time - lastTime, time - startTime)) {
|
410
|
+
requestAnimationFrameShim(wrapper);
|
411
|
+
}
|
412
|
+
lastTime = time;
|
413
|
+
})
|
414
|
+
} else {
|
415
|
+
var intervalId = setInterval(function () {
|
416
|
+
time = Date.now();
|
417
|
+
if (callback(time - lastTime, time - startTime)) {
|
418
|
+
clearInterval(intervalId);
|
419
|
+
}
|
420
|
+
lastTime = time;
|
421
|
+
}, interval);
|
422
|
+
}
|
423
|
+
}
|
424
|
+
|
425
|
+
// Cancels an event to stop propogation. Use this to swallow events in listeners.
|
426
|
+
Awe.cancelEvent = function(e) {
|
427
|
+
if (e == null) {
|
428
|
+
e = global.event;
|
429
|
+
}
|
430
|
+
|
431
|
+
if (!e) {
|
432
|
+
return;
|
433
|
+
}
|
434
|
+
|
435
|
+
if (!global.attachEvent) {
|
436
|
+
|
437
|
+
if (e.stopPropagation) {
|
438
|
+
e.stopPropagation();
|
439
|
+
}
|
440
|
+
e.preventDefault();
|
441
|
+
return false
|
442
|
+
}
|
443
|
+
|
444
|
+
e.cancelBubble = true;
|
445
|
+
e.returnValue = false;
|
446
|
+
|
447
|
+
return false;
|
448
|
+
}
|
449
|
+
|
450
|
+
var _nextGuid = 0;
|
451
|
+
|
452
|
+
// Returns a string unique to this session
|
453
|
+
Awe.getGuid = function() {
|
454
|
+
return "_guid_" + ++_nextGuid;
|
455
|
+
}
|
456
|
+
|
457
|
+
// Returns a unique positive integral number > 0
|
458
|
+
Awe.getGuidNumeric = function() {
|
459
|
+
return ++_nextGuid;
|
460
|
+
}
|
461
|
+
|
462
|
+
// Classes
|
463
|
+
var hexToInt = {
|
464
|
+
"0":0,
|
465
|
+
"1":1,
|
466
|
+
"2":2,
|
467
|
+
"3":3,
|
468
|
+
"4":4,
|
469
|
+
"5":5,
|
470
|
+
"6":6,
|
471
|
+
"7":7,
|
472
|
+
"8":8,
|
473
|
+
"9":9,
|
474
|
+
"a":10,"A":10,
|
475
|
+
"b":11,"B":11,
|
476
|
+
"c":12,"C":12,
|
477
|
+
"d":13,"D":13,
|
478
|
+
"e":14,"E":14,
|
479
|
+
"f":15,"F":15,
|
480
|
+
}
|
481
|
+
|
482
|
+
// Color class parses CSS color specs in different formats ("#rrggbb", "rgb(r, g, b)" or "rgba(r, g, b, a)") and provides
|
483
|
+
// accessors to r/g/b/a components and CSS color strings.
|
484
|
+
Awe.Color = function(color) {
|
485
|
+
var _i = this;
|
486
|
+
|
487
|
+
_i.toHex = function() {
|
488
|
+
return _i.hex;
|
489
|
+
}
|
490
|
+
|
491
|
+
_i.toRGBA = function(alpha) {
|
492
|
+
if (alpha == undefined) {
|
493
|
+
alpha = _i.a;
|
494
|
+
}
|
495
|
+
return "rgba("+_i.r+","+_i.g+","+_i.b+","+alpha+")";
|
496
|
+
}
|
497
|
+
|
498
|
+
_i.toRGB = function() {
|
499
|
+
return "rgba("+_i.r+","+_i.g+","+_i.b+")";
|
500
|
+
}
|
501
|
+
|
502
|
+
if (color[0] == "#") {
|
503
|
+
_i.hex = color;
|
504
|
+
_i.r = (hexToInt[color[1]] << 4) + hexToInt[color[2]];
|
505
|
+
_i.g = (hexToInt[color[3]] << 4) + hexToInt[color[4]];
|
506
|
+
_i.b = (hexToInt[color[5]] << 4) + hexToInt[color[6]];
|
507
|
+
_i.a = 1;
|
508
|
+
} else {
|
509
|
+
if (color.indexOf('rgb(') == 0) {
|
510
|
+
color = color.substring(4,color.length-1);
|
511
|
+
} else if (color.indexOf('rgba(') == 0) {
|
512
|
+
color = color.substring(5,color.length-1);
|
513
|
+
}
|
514
|
+
var i;
|
515
|
+
_i.r = parseInt(color);
|
516
|
+
color = color.substring(color.indexOf(',')+1);
|
517
|
+
_i.g = parseInt(color);
|
518
|
+
color = color.substring(color.indexOf(',')+1);
|
519
|
+
_i.b = parseInt(color);
|
520
|
+
color = color.substring(color.indexOf(',')+1);
|
521
|
+
if (color) {
|
522
|
+
_i.a = parseFloat(color);
|
523
|
+
} else {
|
524
|
+
_i.a = 1;
|
525
|
+
}
|
526
|
+
}
|
527
|
+
}
|
528
|
+
|
529
|
+
// Allow the script URL to override the namespace, naming the library Monkey instead of Awe etc
|
530
|
+
// NOTE: This is not likely to ever be necessary, but it's an interesting theoretical exercise
|
531
|
+
var scripts = document.getElementsByTagName('script');
|
532
|
+
var scriptUrl = scripts && scripts.length && scripts[scripts.length - 1].src;
|
533
|
+
var overrideNamespace = scriptUrl && Awe.getQueryParam("namespace", scriptUrl);
|
534
|
+
|
535
|
+
global[overrideNamespace || namespace] = Awe;
|
536
|
+
|
537
|
+
})(this, document)
|
@@ -0,0 +1,128 @@
|
|
1
|
+
/*
|
2
|
+
* Artefact Web Extensions
|
3
|
+
*
|
4
|
+
* Copyright 2012, Artefact Group LLC
|
5
|
+
* Licensed under MIT.
|
6
|
+
*/
|
7
|
+
(function(Awe, global, document, undefined) {
|
8
|
+
|
9
|
+
// State contains any of:
|
10
|
+
// allowOnly - array with 0 or more states (or null)
|
11
|
+
// doNotAllow - array with 1 or more states (or null)
|
12
|
+
// start function (or null)
|
13
|
+
// update function (or null)
|
14
|
+
// end function (or null)
|
15
|
+
|
16
|
+
var StateMachine = Awe.StateMachine = function(name, stateMap, initialStateId) {
|
17
|
+
var _i = this;
|
18
|
+
|
19
|
+
StateMachine.stateMachines.push(_i);
|
20
|
+
|
21
|
+
_i.name = name;
|
22
|
+
_i.states = stateMap || [];
|
23
|
+
_i.currentStateId = null;
|
24
|
+
|
25
|
+
_i.addState = function(id, state) {
|
26
|
+
if (_i.states[id]) {
|
27
|
+
throw "Duplicate state added!";
|
28
|
+
}
|
29
|
+
_i.states[id] = state;
|
30
|
+
}
|
31
|
+
|
32
|
+
_i.getCurrentStateId = function() {
|
33
|
+
return _i.currentStateId;
|
34
|
+
}
|
35
|
+
|
36
|
+
// Request a state that is assumed to be a transitional state and call the supplied callback on completion.
|
37
|
+
// The callback will not be called if the transition state is interrupted, but you can prevent this by making
|
38
|
+
// the transition state uninterruptable: pass an empty array in the transition states allowOnly field, which will
|
39
|
+
// disallow any transitions while the state is active. The transitionCompleteCallback should then change state
|
40
|
+
// once the transition is complete.
|
41
|
+
_i.requestTransitionState = function(id) {
|
42
|
+
|
43
|
+
if (typeof(arguments[arguments.length - 1]) != "function") {
|
44
|
+
throw "Last argument of StateMachine.requestTransitionState must be an on-complete callback"
|
45
|
+
}
|
46
|
+
|
47
|
+
if (_i.requestState.apply(_i, arguments)) {
|
48
|
+
_i.transitionCompleteCallback = arguments[arguments.length - 1];
|
49
|
+
|
50
|
+
if (!_i.states[_i.currentStateId].update) {
|
51
|
+
throw "ERROR: Transition states must have an update method, otherwise they will never be able to complete.";
|
52
|
+
}
|
53
|
+
return true;
|
54
|
+
}
|
55
|
+
|
56
|
+
// Remove the transition complete callback if the switch to the transition state was refused.
|
57
|
+
_i.transitionCompleteCallback = null;
|
58
|
+
return false;
|
59
|
+
}
|
60
|
+
|
61
|
+
// Request a change to the supplied state. If a current state exists that will be checked for any conditions that
|
62
|
+
// disallow transition to the new state.
|
63
|
+
_i.requestState = function(id) {
|
64
|
+
|
65
|
+
var nextState = id && _i.states[id];
|
66
|
+
|
67
|
+
if (id && !nextState) {
|
68
|
+
return false;
|
69
|
+
}
|
70
|
+
|
71
|
+
if (_i.currentStateId) {
|
72
|
+
var currentState = _i.states[_i.currentStateId];
|
73
|
+
|
74
|
+
if (!_i.currentStateDone && currentState.allowOnly && !currentState.allowOnly.indexOf(id)) {
|
75
|
+
return false;
|
76
|
+
}
|
77
|
+
if (!_i.currentStateDone && currentState.doNotAllow && currentState.doNotAllow.indexOf(id)) {
|
78
|
+
return false;
|
79
|
+
}
|
80
|
+
|
81
|
+
if (currentState.end) {
|
82
|
+
currentState.end.call(currentState, id);
|
83
|
+
}
|
84
|
+
}
|
85
|
+
|
86
|
+
if (nextState) {
|
87
|
+
nextState._startTime = Date.now();
|
88
|
+
nextState.runTime = 0;
|
89
|
+
if (nextState.start) {
|
90
|
+
nextState.start.apply(nextState, [_i.currentState && _i.currentState.id].concat(Array.prototype.slice.call(arguments,1)));
|
91
|
+
}
|
92
|
+
}
|
93
|
+
|
94
|
+
_i.currentStateId = id;
|
95
|
+
|
96
|
+
return true;
|
97
|
+
}
|
98
|
+
|
99
|
+
_i.update = function() {
|
100
|
+
var currentState = _i.states[_i.currentStateId];
|
101
|
+
currentState.runTime = (Date.now() - currentState._startTime) * 0.001;
|
102
|
+
if (currentState && currentState.update) {
|
103
|
+
// Update the current state and if it's a transition state, call the transition state callback once the
|
104
|
+
// transition state's update returns true to signify completion
|
105
|
+
if (currentState.update.call(currentState) && _i.transitionCompleteCallback) {
|
106
|
+
var callback = _i.transitionCompleteCallback;
|
107
|
+
_i.transitionCompleteCallback = null;
|
108
|
+
_i.currentStateDone = true;
|
109
|
+
callback();
|
110
|
+
_i.currentStateDone = false;
|
111
|
+
}
|
112
|
+
}
|
113
|
+
}
|
114
|
+
|
115
|
+
if (initialStateId) {
|
116
|
+
_i.requestState(initialStateId);
|
117
|
+
}
|
118
|
+
|
119
|
+
return _i;
|
120
|
+
}
|
121
|
+
|
122
|
+
StateMachine.stateMachines = []
|
123
|
+
StateMachine.update = function() {
|
124
|
+
for (var i = 0; i < StateMachine.stateMachines.length; ++i) {
|
125
|
+
StateMachine.stateMachines[i].update();
|
126
|
+
}
|
127
|
+
}
|
128
|
+
})(Awe, this, document)
|
metadata
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: awe-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Shyam Habarakada
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-02-04 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: &70279789265900 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.1'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70279789265900
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &70279789265020 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.8.0
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70279789265020
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rdoc
|
38
|
+
requirement: &70279789264460 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '3.12'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70279789264460
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: bundler
|
49
|
+
requirement: &70279789263860 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.0.0
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70279789263860
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: jeweler
|
60
|
+
requirement: &70279789263300 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ~>
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 1.8.3
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70279789263300
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: &70279789262680 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70279789262680
|
80
|
+
description: Modeled after the jquery-rails gem. Installs the AWE files into the rails
|
81
|
+
3.1 asset pipeline
|
82
|
+
email: shyam.habarakada@gmail.com
|
83
|
+
executables: []
|
84
|
+
extensions: []
|
85
|
+
extra_rdoc_files:
|
86
|
+
- LICENSE.txt
|
87
|
+
- README.rdoc
|
88
|
+
files:
|
89
|
+
- .document
|
90
|
+
- .rspec
|
91
|
+
- CHANGELOG.md
|
92
|
+
- Gemfile
|
93
|
+
- Gemfile.lock
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.rdoc
|
96
|
+
- Rakefile
|
97
|
+
- VERSION
|
98
|
+
- awe-rails-1.0.17.gem
|
99
|
+
- awe-rails.gemspec
|
100
|
+
- lib/awe-rails.rb
|
101
|
+
- lib/awe/rails.rb
|
102
|
+
- lib/awe/rails/engine.rb
|
103
|
+
- lib/generators/awe/install/install_generator.rb
|
104
|
+
- spec/awe-rails_spec.rb
|
105
|
+
- spec/lib/awe-rails_spec.rb
|
106
|
+
- spec/spec_helper.rb
|
107
|
+
- vendor/assets/javascripts/awe-core.js
|
108
|
+
- vendor/assets/javascripts/awe-state-machine.js
|
109
|
+
homepage: http://www.artefactgroup.com
|
110
|
+
licenses:
|
111
|
+
- MIT
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
none: false
|
118
|
+
requirements:
|
119
|
+
- - ! '>='
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
segments:
|
123
|
+
- 0
|
124
|
+
hash: -4385544839732221746
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
none: false
|
127
|
+
requirements:
|
128
|
+
- - ! '>='
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
requirements: []
|
132
|
+
rubyforge_project:
|
133
|
+
rubygems_version: 1.8.10
|
134
|
+
signing_key:
|
135
|
+
specification_version: 3
|
136
|
+
summary: Gem for integrating AWE into the rails asset pipeline
|
137
|
+
test_files: []
|