awe-rails 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile CHANGED
@@ -1,7 +1,5 @@
1
1
  source "http://rubygems.org"
2
2
  # Add dependencies required to use your gem here.
3
- # Example:
4
- # gem "activesupport", ">= 2.3.5"
5
3
 
6
4
  gem "rails", ">= 3.1"
7
5
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.5.0
data/awe-rails.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "awe-rails"
8
- s.version = "0.4.0"
8
+ s.version = "0.5.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Shyam Habarakada"]
12
- s.date = "2012-02-06"
12
+ s.date = "2012-02-12"
13
13
  s.description = "Modeled after the jquery-rails gem. Installs the AWE files into the rails 3.1 asset pipeline"
14
14
  s.email = "shyam.habarakada@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -35,7 +35,8 @@ Gem::Specification.new do |s|
35
35
  "spec/lib/awe-rails_spec.rb",
36
36
  "spec/spec_helper.rb",
37
37
  "vendor/assets/javascripts/awe-core.js",
38
- "vendor/assets/javascripts/awe-state-machine.js"
38
+ "vendor/assets/javascripts/awe-state-machine.js",
39
+ "vendor/assets/javascripts/awe-ui.js"
39
40
  ]
40
41
  s.homepage = "http://www.artefactgroup.com"
41
42
  s.licenses = ["MIT"]
@@ -6,16 +6,13 @@ module Awe
6
6
 
7
7
  desc "This generator installs AWE (Artefact Web Extensions) into rails"
8
8
  source_root File.expand_path('../../../../../vendor/assets/javascripts', __FILE__)
9
+ javascripts_path = ::Rails.application.config.assets.enabled ? "vendor/assets/javascripts" : "public/javascripts"
9
10
 
10
11
  def copy_awe
11
- say_status("copying", "awe files", :green)
12
- if ::Rails.application.config.assets.enabled
13
- copy_file "awe-core.js", "vendor/assets/javascripts/awe-core.js"
14
- copy_file "awe-state-machine.js", "vendor/assets/javascripts/awe-state-machine.js"
15
- else
16
- copy_file "awe-core.js", "public/javascripts/awe-core.js"
17
- copy_file "awe-state-machine.js", "public/javascripts/awe-state-machine.js"
18
- end
12
+ say_status("copying", "The AWE files", :green)
13
+ copy_file "awe-core.js", "#{javascripts_path}/awe-core.js"
14
+ copy_file "awe-state-machine.js", "#{javascripts_path}/awe-state-machine.js"
15
+ copy_file "awe-ui.js", "#{javascripts_path}/awe-ui.js"
19
16
  end
20
17
 
21
18
  end
@@ -1,4 +1,5 @@
1
1
  require 'rails'
2
+ require 'open-uri'
2
3
 
3
4
  module Awe
4
5
  module Generators
@@ -6,26 +7,27 @@ module Awe
6
7
 
7
8
  desc "This generator updates AWE (Artefact Web Extensions) to the latest"
8
9
 
9
- @@tmp_path = "tmp/vendor/assets/javascripts"
10
10
  @@github = "https://raw.github.com/sambaker/awe-core/master"
11
11
 
12
12
  source_root Rails.root
13
13
 
14
14
  def download_and_copy_awe
15
- say_status("fetching", "awe files from #{@@github}/ ...", :green)
16
- get "#{@@github}/awe-core.js", "#{@@tmp_path}/awe-core.js"
17
- get "#{@@github}/awe-state-machine.js", "#{@@tmp_path}/awe-state-machine.js"
15
+ files = []
16
+ javascripts_path = ::Rails.application.config.assets.enabled ? "vendor/assets/javascripts" : "public/javascripts"
17
+
18
+ say_status("getting", "The AWE file list from #{@@github}/ ...", :green)
19
+ open("#{@@github}/files") { |f|
20
+ f.each_line { |line| files.push(line.strip) unless line.starts_with?("#") }
21
+ }
22
+
23
+ # fetch files
24
+ files.each { |file|
25
+ say_status("fetching", "#{@@github}/#{file} into #{javascripts_path} ...", :green)
26
+ get "#{@@github}/#{file}", "#{javascripts_path}/#{file}"
27
+ }
18
28
 
19
- say_status("copying", "awe files", :green)
20
- if ::Rails.application.config.assets.enabled
21
- copy_file "#{@@tmp_path}/awe-core.js", "vendor/assets/javascripts/awe-core.js"
22
- copy_file "#{@@tmp_path}/awe-state-machine.js", "vendor/assets/javascripts/awe-state-machine.js"
23
- else
24
- copy_file "#{@@tmp_path}/awe-core.js", "public/javascripts/awe-core.js"
25
- copy_file "#{@@tmp_path}/awe-state-machine.js", "public/javascripts/awe-state-machine.js"
26
- end
27
29
  rescue OpenURI::HTTPError
28
- say_status("error", "could not fetch awe files", :red)
30
+ say_status("error", "error fetching files", :red)
29
31
  end
30
32
 
31
33
  end
@@ -42,6 +42,11 @@
42
42
  return Math.min(Math.max(n, min), max);
43
43
  }
44
44
 
45
+ // Return -1 if n < 0 or 1 otherwise
46
+ Awe.sign = function(n) {
47
+ return (n < 0) ? -1 : 1;
48
+ }
49
+
45
50
  // Clamp a number between -1 and 1 before passing to Math.acos to prevent an exception.
46
51
  // Ensure that this makes sense for your parameters - it is assumed they will be close to
47
52
  // the clamped range but allows computational errors to be safely ignored.
@@ -76,9 +81,10 @@
76
81
  }
77
82
  }
78
83
 
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
84
+ /* Create an HTML element of the given type and attach to the given parent if not null.
85
+ * The config object can contain styles, attrs, a class and a background sprite to apply
86
+ * to the element
87
+ */
82
88
  Awe.createElement = function(type, parent, config) {
83
89
  var k;
84
90
  var el = document.createElement(type);
@@ -107,13 +113,13 @@
107
113
  return el;
108
114
  }
109
115
 
116
+
110
117
  /*
111
118
  * method: Awe.enableDrag
112
119
  *
113
120
  * purpose: enable drag on a DOM element
114
121
  *
115
- */
116
-
122
+ */
117
123
  Awe.enableDrag = function(el, config) {
118
124
 
119
125
  config = config || {};
@@ -403,23 +409,44 @@
403
409
  Awe.addAnimationCallback = function(callback, interval) {
404
410
  var startTime = Date.now();
405
411
  var lastTime = startTime;
412
+ var handle = {};
413
+ var cancelled = false;
414
+
406
415
  if (interval === undefined) {
407
416
  requestAnimationFrameShim(function wrapper() {
408
417
  time = Date.now();
409
- if (!callback(time - lastTime, time - startTime)) {
418
+ if (!cancelled && !callback(time - lastTime, time - startTime)) {
410
419
  requestAnimationFrameShim(wrapper);
411
420
  }
412
421
  lastTime = time;
413
422
  })
423
+ handle.cancel = function() {
424
+ cancelled = true;
425
+ }
414
426
  } else {
415
427
  var intervalId = setInterval(function () {
416
428
  time = Date.now();
417
429
  if (callback(time - lastTime, time - startTime)) {
418
- clearInterval(intervalId);
430
+ if (intervalId) {
431
+ clearInterval(intervalId);
432
+ intervalId = null;
433
+ }
419
434
  }
420
435
  lastTime = time;
421
436
  }, interval);
437
+ handle.cancel = function() {
438
+ if (intervalId) {
439
+ clearInterval(intervalId);
440
+ intervalId = null;
441
+ }
442
+ }
422
443
  }
444
+
445
+ return handle;
446
+ }
447
+
448
+ Awe.cancelAnimationCallback = function(handle) {
449
+ handle.cancel();
423
450
  }
424
451
 
425
452
  // Cancels an event to stop propogation. Use this to swallow events in listeners.
@@ -0,0 +1,68 @@
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
+ // Stack of saved document.onclick handlers
10
+ var _savedDocumentOnClickCallbacks = [];
11
+
12
+ /*
13
+ * purpose: Helper function to ensure that we have an element. Allows called
14
+ * of ui* functions to pass in either an HTML element object or an id string,
15
+ * in which case we will look it up by id.
16
+ */
17
+ var ensureElement = function(element) {
18
+ if(typeof(element) == "string") {
19
+ return document.getElementById(element);
20
+ } else {
21
+ return element;
22
+ }
23
+ }
24
+
25
+ /*
26
+ * method: Awe.uiPopup
27
+ *
28
+ * purpose: Attach show/hide popup behavior to an element.
29
+ *
30
+ */
31
+ Awe.uiPopup = function(element) {
32
+
33
+ if ( !(this instanceof Awe.uiPopup) ) return new Awe.uiPopup(element);
34
+
35
+ var _i = this;
36
+
37
+ element = ensureElement(element);
38
+
39
+ if(!element) throw "cannot find element with given id";
40
+
41
+ _i.show = function(dismissedCallback) {
42
+ if(element.style.visibility != "visible") {
43
+ element.style.visibility = "visible";
44
+ _savedDocumentOnClickCallbacks.push(document.onclick);
45
+ document.onclick = (function(e) {
46
+ e = e || window.event;
47
+ if (!xHasPoint(element, e.x, e.y)) { // TODO Handle x dependency
48
+ _i.hide(true);
49
+ if(dismissedCallback) dismissedCallback();
50
+ }
51
+ return;
52
+ });
53
+ // if call context is a click handler
54
+ if(window.event && window.event.type == "click") Awe.cancelEvent(window.event);
55
+ }
56
+ }
57
+
58
+ _i.hide = function(bubbleCurrentEvent) {
59
+ if(element.style.visibility != "hidden") {
60
+ element.style.visibility = "hidden";
61
+ document.onclick = _savedDocumentOnClickCallbacks.pop();
62
+ }
63
+ if(!bubbleCurrentEvent && window.event && window.event.type == "click") Awe.cancelEvent(window.event);
64
+ return;
65
+ }
66
+ }
67
+
68
+ })(Awe, this, document)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awe-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-06 00:00:00.000000000Z
12
+ date: 2012-02-12 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70345636688900 !ruby/object:Gem::Requirement
16
+ requirement: &70293535279340 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3.1'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70345636688900
24
+ version_requirements: *70293535279340
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70345636688080 !ruby/object:Gem::Requirement
27
+ requirement: &70293535278400 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 2.8.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70345636688080
35
+ version_requirements: *70293535278400
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rdoc
38
- requirement: &70345636687160 !ruby/object:Gem::Requirement
38
+ requirement: &70293535277380 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '3.12'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70345636687160
46
+ version_requirements: *70293535277380
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: bundler
49
- requirement: &70345636686340 !ruby/object:Gem::Requirement
49
+ requirement: &70293535266040 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.0.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70345636686340
57
+ version_requirements: *70293535266040
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: jeweler
60
- requirement: &70345636685360 !ruby/object:Gem::Requirement
60
+ requirement: &70293535264900 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 1.8.3
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70345636685360
68
+ version_requirements: *70293535264900
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: simplecov
71
- requirement: &70345636684240 !ruby/object:Gem::Requirement
71
+ requirement: &70293535263660 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70345636684240
79
+ version_requirements: *70293535263660
80
80
  description: Modeled after the jquery-rails gem. Installs the AWE files into the rails
81
81
  3.1 asset pipeline
82
82
  email: shyam.habarakada@gmail.com
@@ -105,6 +105,7 @@ files:
105
105
  - spec/spec_helper.rb
106
106
  - vendor/assets/javascripts/awe-core.js
107
107
  - vendor/assets/javascripts/awe-state-machine.js
108
+ - vendor/assets/javascripts/awe-ui.js
108
109
  homepage: http://www.artefactgroup.com
109
110
  licenses:
110
111
  - MIT
@@ -120,7 +121,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
120
121
  version: '0'
121
122
  segments:
122
123
  - 0
123
- hash: 1471001142678456215
124
+ hash: -1924670085795893892
124
125
  required_rubygems_version: !ruby/object:Gem::Requirement
125
126
  none: false
126
127
  requirements: