stay 0.1.3.4.4 → 0.1.3.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -83,10 +83,10 @@ Example
83
83
 
84
84
  Remember to put width and height respectively
85
85
 
86
- When called, by default **Stay** triggered by clicking the displayed text on HTML page.
87
- **Stay** accept external trigger and submit button:
86
+ When called, by default **Stay** triggered by clicking the displayed text on HTML page, submitted by blur, and cancelled by pressing ESC key on your keyboard.
87
+ **Stay** accept external trigger, submit, and cancel button:
88
88
 
89
- To use, just passed **activator:** followed by id of HTML element id
89
+ To use external activator, just passed **activator:** followed by id of HTML element id
90
90
 
91
91
  Example:
92
92
 
@@ -94,20 +94,29 @@ Example:
94
94
  stay [@user, @article], :body, type: [:tiny_mce, "advanced"], activator: "#id_of_activator"
95
95
  ```
96
96
 
97
- To use external submit button, just passed **submitter:** followed by id of HTML element id
97
+ To use external submit button, just passed **submitter:** followed by id of HTML element id.
98
+ Note that this external submit button will be hidden by **Stay** and will be visible once **Stay** editor is visible (stay triggered).
98
99
 
99
100
  ```ruby
100
101
  stay [@user, @article], :body, type: [:tiny_mce, "advanced"], activator: "#id_of_activator", submitter: "#id_of_submit_button"
101
102
  ```
103
+
104
+ To use external cancel button, just passed **canceller:** followed by id of HTML element id
105
+ Note that this external cancel button will be hidden by **Stay** and will be visible once **Stay** editor is visible (stay triggered).
106
+ Due to **Stay** default submit event is triggered by blur **Stay** will raise ArgumentError if you specified external canceller without external submitter.
107
+
108
+ ```ruby
109
+ stay [@user, @article], :body, type: [:tiny_mce, "advanced"], activator: "#id_of_activator", submitter: "#id_of_submit_button", canceller: "#id_of_cancel_button"
110
+ ```
102
111
 
103
112
  Example of complete use:
104
113
 
105
114
  ```ruby
106
115
  <%= link_to "Click me to activate", "#", id: "activate_here" %>
107
116
  <%= stay [@user, @article], :body, type: :tiny_mce, activator: "#activate_here", submitter: "#submit_here" %>
108
- <%= link_to "Click me to submit", "#", id: "submit_here" %>
117
+ <%= link_to "Click me to submit", "#", id: "submit_here" #this will be hide by Stay %>
109
118
  ```
110
-
119
+
111
120
  ### call this in your controller
112
121
 
113
122
  stay_response object
@@ -127,3 +136,11 @@ Example of complete use:
127
136
  end
128
137
  end
129
138
  ```
139
+
140
+ ### JSON callback
141
+ When Rails Model refuse to save object due to validation errors, **Stay** will carry this errors in its response text, you can evaluate the error by passing this response text as JSON and call the errors properties. You can do whatever you wish with the errors messages.
142
+
143
+ ```javascript
144
+ cb_data = jQuery.parseJSON(data.responseText);
145
+ errs = cb_data.errors; //this contains array of errors
146
+ ```
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('stay', '0.1.3.4.4') do |p|
5
+ Echoe.new('stay', '0.1.3.5') do |p|
6
6
  p.description = "Form ajax helper with tinymce support"
7
7
  p.summary = "Helper for building ajax form, inspired by best_in_place, with some modifications, support tinymce as editor"
8
8
  p.url = "http://github.com/tejanium/stay"
@@ -36,6 +36,11 @@ Stay.prototype = {
36
36
  self.submitter_id = this.stayWrapper.data("submitter")
37
37
  self.submitter = (typeof self.submitter_id === "undefined") ? self.stayFormInput : jQuery(self.submitter_id)
38
38
 
39
+ self.canceller_id = this.stayWrapper.data("canceller")
40
+
41
+ if(typeof self.submitter_id !== "undefined"){jQuery(self.submitter_id).hide()}
42
+ if(typeof self.canceller_id !== "undefined"){jQuery(self.canceller_id).hide()}
43
+
39
44
  if(self.tinyMCEUsed){
40
45
  this.stayTinyMCE.tinymce({
41
46
  theme: self.tinyMCETheme,
@@ -52,6 +57,17 @@ Stay.prototype = {
52
57
  self.stayFormForm.submit();
53
58
  });
54
59
  }
60
+ if(typeof self.canceller_id === "undefined"){
61
+ tinymce.dom.Event.add(doc, 'keydown', function(e) {
62
+ if (e.keyCode == 27) {
63
+ self.reShowObject();
64
+ }
65
+ });
66
+ }else{
67
+ jQuery(self.canceller_id).click(function(){
68
+ self.reShowObject();
69
+ });
70
+ }
55
71
  });
56
72
  }
57
73
  });
@@ -63,10 +79,12 @@ Stay.prototype = {
63
79
 
64
80
  bindTrigger: function(){
65
81
  var self = this;
66
-
82
+
67
83
  self.activator.click(function(){
68
84
  self.stayObject.hide();
69
85
  self.stayForm.show();
86
+ if(typeof self.submitter_id !== "undefined"){jQuery(self.submitter_id).show()}
87
+ if(typeof self.canceller_id !== "undefined"){jQuery(self.canceller_id).show()}
70
88
  if(self.tinyMCEUsed){
71
89
  self.stayTinyMCE.tinymce().focus();
72
90
  }else{
@@ -80,6 +98,18 @@ Stay.prototype = {
80
98
  self.stayFormForm.submit();
81
99
  self.stayFormInput.disable();
82
100
  });
101
+
102
+ if(typeof self.canceller_id === "undefined"){
103
+ self.stayFormInput.keydown(function(e) {
104
+ if (e.keyCode == 27) {
105
+ self.reShowObject();
106
+ }
107
+ });
108
+ }else{
109
+ jQuery(self.canceller_id).click(function(){
110
+ self.reShowObject();
111
+ });
112
+ }
83
113
  }
84
114
  },
85
115
 
@@ -102,6 +132,8 @@ Stay.prototype = {
102
132
 
103
133
  reShowObject: function(){
104
134
  this.stayForm.hide();
135
+ if(typeof this.submitter_id !== "undefined"){jQuery(this.submitter_id).hide()}
136
+ if(typeof this.canceller_id !== "undefined"){jQuery(this.canceller_id).hide()}
105
137
  this.stayObject.show();
106
138
  this.stayFormInput.enable();
107
139
  }
@@ -14,7 +14,7 @@ module Stay
14
14
  def response_error(obj)
15
15
  field = params[obj.class.to_s.underscore].keys.first
16
16
  value = obj.send("#{field}_was".to_sym)
17
- render json: { :display => (value.nil? ? "-" : value.to_html), :input => value, :error => obj.errors }, status: :unprocessable_entity
17
+ render json: { :display => (value.nil? ? "-" : value.to_html), :input => value, :errors => obj.errors }, status: :unprocessable_entity
18
18
  end
19
19
  end
20
20
  end
data/lib/stay/helper.rb CHANGED
@@ -22,10 +22,13 @@ module Stay
22
22
  ActionView::Helpers::FormHelper.send(:include, FormHelper)
23
23
 
24
24
  module StayHelpers
25
- def stay(record, field, opts = {})
25
+ def stay(record, field, opts = {})
26
+ raise ArgumentError, "Can't have Canceller without Submitter" if opts[:canceller] && opts[:submitter].nil?
27
+ opts[:type] ||= :text_field
26
28
  html = "<span class='stay' "
27
29
  html << "data-activator='#{ opts[:activator] }' " if opts[:activator]
28
30
  html << "data-submitter='#{ opts[:submitter] }' " if opts[:submitter]
31
+ html << "data-canceller='#{ opts[:canceller] }' " if opts[:canceller]
29
32
  html << "data-tinymce-theme='simple' " if opts[:type] == :tiny_mce
30
33
  html << "data-tinymce-theme='#{ opts[:type][1] }' " if opts[:type].is_a?(Array)
31
34
  html << ">"
data/stay.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "stay"
5
- s.version = "0.1.3.4.4"
5
+ s.version = "0.1.3.5"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Teja Sophista"]
9
- s.date = "2012-02-28"
9
+ s.date = "2012-03-09"
10
10
  s.description = "Form ajax helper with tinymce support"
11
11
  s.email = "tejanium@yahoo.com"
12
12
  s.extra_rdoc_files = ["README.md", "README.rdoc", "lib/assets/javascripts/stay.js", "lib/stay.rb", "lib/stay/controller_extensions.rb", "lib/stay/engine.rb", "lib/stay/helper.rb", "lib/stay/string_extensions.rb"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3.4.4
4
+ version: 0.1.3.5
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-28 00:00:00.000000000Z
12
+ date: 2012-03-09 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jquery-rails
16
- requirement: &22993880 !ruby/object:Gem::Requirement
16
+ requirement: &28148600 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *22993880
24
+ version_requirements: *28148600
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: tinymce-rails
27
- requirement: &22993420 !ruby/object:Gem::Requirement
27
+ requirement: &28148140 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *22993420
35
+ version_requirements: *28148140
36
36
  description: Form ajax helper with tinymce support
37
37
  email: tejanium@yahoo.com
38
38
  executables: []