jquery_client 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile ADDED
@@ -0,0 +1,66 @@
1
+ require 'rake'
2
+ require 'fileutils'
3
+ current_dir = File.expand_path(File.dirname(__FILE__))
4
+ Dir.chdir current_dir
5
+
6
+
7
+ #
8
+ # Specs
9
+ #
10
+ require 'spec/rake/spectask'
11
+
12
+ task :default => :spec
13
+
14
+ Spec::Rake::SpecTask.new('spec') do |t|
15
+ t.spec_files = FileList["spec/**/*_spec.rb"].select{|f| f !~ /\/_/}
16
+ t.libs = ["#{current_dir}/lib"]
17
+ end
18
+
19
+
20
+ #
21
+ # Gem
22
+ #
23
+ require 'rake/clean'
24
+ require 'rake/gempackagetask'
25
+
26
+ gem_options = {
27
+ :name => "jquery_client",
28
+ :version => "0.1.0",
29
+ :summary => "jQuery client for Crystal Framework",
30
+ :dependencies => %w(crystal)
31
+ }
32
+
33
+ gem_name = gem_options[:name]
34
+ spec = Gem::Specification.new do |s|
35
+ gem_options.delete(:dependencies).each{|d| s.add_dependency d}
36
+ gem_options.each{|k, v| s.send "#{k}=", v}
37
+
38
+ s.name = gem_name
39
+ s.author = "Alexey Petrushin"
40
+ s.homepage = "http://github.com/alexeypetrushin/#{gem_options[:name]}"
41
+ s.require_path = "lib"
42
+ s.files = (%w{Rakefile readme.md} + Dir.glob("{lib,spec}/**/*"))
43
+
44
+ s.platform = Gem::Platform::RUBY
45
+ s.has_rdoc = true
46
+ end
47
+
48
+ package_dir = "#{current_dir}/build"
49
+ Rake::GemPackageTask.new(spec) do |p|
50
+ p.need_tar = true if RUBY_PLATFORM !~ /mswin/
51
+ p.need_zip = true
52
+ p.package_dir = package_dir
53
+ end
54
+
55
+ task :push do
56
+ # dir = Dir.chdir package_dir do
57
+ gem_file = Dir.glob("#{package_dir}/#{gem_name}*.gem").first
58
+ system "gem push #{gem_file}"
59
+ # end
60
+ end
61
+
62
+ task :clean do
63
+ system "rm -r #{package_dir}"
64
+ end
65
+
66
+ task :release => [:gem, :push, :clean]
@@ -0,0 +1,8 @@
1
+ module Crystal
2
+ module JQueryHelper
3
+ def initialize_js_commons
4
+ javascript_tag %{\
5
+ $.authenticity_token = "#{workspace.session_authenticity_token}";}
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,2 @@
1
+ .hidden{display: none;}
2
+ .todo{background: #ffa;}
@@ -0,0 +1,283 @@
1
+ //
2
+ // Requirements
3
+ //
4
+ $;
5
+ $.template;
6
+ $.toJSON;
7
+
8
+ railsExt = 'defined';
9
+
10
+ //
11
+ // JavaScript Extension
12
+ //
13
+ String.prototype.blank = function() {
14
+ return this.replace(/[\s\n\r]+/, '').length == 0;
15
+ };
16
+
17
+ String.prototype.size = function() {
18
+ return this.length;
19
+ };
20
+
21
+ Array.prototype.size = function() {
22
+ return this.length;
23
+ };
24
+
25
+ function Hash(hash) {
26
+ hash = hash || {};
27
+ var _this = this;
28
+ $.each(hash, function(key){_this[key] = this});
29
+ };
30
+
31
+ Hash.prototype.size = function () {
32
+ var l = -1;
33
+ for (var k in this) {
34
+ l++;
35
+ }
36
+ return l;
37
+ };
38
+
39
+ inspect = function(data){
40
+ console.dir(data);
41
+ };
42
+
43
+ log = function(data){
44
+ console.log(data);
45
+ };
46
+
47
+ warn = function(data){
48
+ console.warn(data);
49
+ }
50
+
51
+ decode_uri = function(uri){
52
+ return uri.replace(/\&/g,'&');
53
+ };
54
+
55
+ //
56
+ // jQuery Extension
57
+ //
58
+ $.extend({
59
+ infoMessage: function(message){
60
+ log(message);
61
+ },
62
+
63
+ message: function(msg){
64
+ $.infoMessage(msg)
65
+ },
66
+
67
+ errorMessage: function(message){
68
+ log(message);
69
+ },
70
+
71
+ checkForMessages: function(json){
72
+ if(json['info']) $.infoMessage(json['info']);
73
+ if(json['error']) $.errorMessage(json['error']);
74
+ }
75
+ });
76
+
77
+ $.fn.extend({
78
+ serializeObject: function(){
79
+ var o = {};
80
+ var a = this.serializeArray();
81
+ $.each(a, function() {
82
+ if (o[this.name]) {
83
+ if (!o[this.name].push) {
84
+ o[this.name] = [o[this.name]];
85
+ }
86
+ o[this.name].push(this.value || '');
87
+ } else {
88
+ o[this.name] = this.value || '';
89
+ }
90
+ });
91
+ return o;
92
+ },
93
+
94
+ identify: function() {
95
+ var id = $(this).attr('id');
96
+ if(!id){
97
+ var i = 0;
98
+ do {
99
+ i++;
100
+ id = 'auto_id_' + i;
101
+ } while($('#' + id).length > 0);
102
+ $(this).attr('id', id);
103
+ }
104
+ return id;
105
+ },
106
+
107
+ first: function(){
108
+ return $((this.size() > 0) ? this[0] : this)
109
+ },
110
+
111
+ last: function(){
112
+ return $((this.size() > 0) ? this[this.size() - 1] : this)
113
+ },
114
+
115
+ blank: function(){
116
+ return this.size() < 1
117
+ }
118
+ });
119
+
120
+ //
121
+ // jQuery Template
122
+ //
123
+ // try{
124
+ // $.template.regx.standard = /\#\{([\w-]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g;
125
+ // }catch(error){
126
+ // console.info('jquery.template not installed!');
127
+ // }
128
+
129
+ //
130
+ // Initializers
131
+ //
132
+ $.extend({
133
+ callOnceForEvery: function(name, query, initializer, dependencyLevel){
134
+ if(!(name && query && initializer)) throw "Invalid arguments!";
135
+ this._addInitializer({name: name, query: query, initializer: initializer}, this._processOnceForEveryInitializer, false, dependencyLevel)
136
+ },
137
+
138
+ callOnceAfterUpdate: function(name, initializer, dependencyLevel){
139
+ this._addInitializer({name: name, initializer: initializer}, this._processOnceAfterUpdateInitializer, true, dependencyLevel)
140
+ },
141
+
142
+ callAfterUpdate: function(name, initializer, dependencyLevel){
143
+ this._addInitializer({name: name, initializer: initializer}, this._processAfterUpdateInitializer, false, dependencyLevel)
144
+ },
145
+
146
+ _orderedInitializers: [[], [], [], [], [], []],
147
+ _addInitializer: function(definition, processor, callOnce, dependencyLevel){
148
+ definition.name = '_' + definition.name + '_initialized';
149
+ dependencyLevel = dependencyLevel || 0;
150
+ if(!(dependencyLevel >= 0 && dependencyLevel <= 5)) throw "Not supported Dependency Level Value: '" + dependencyLevel + "'!";
151
+ this._orderedInitializers[dependencyLevel].push({definition: definition, processor: processor, callOnce: callOnce});
152
+ },
153
+
154
+ processInitializers: function(){
155
+ for(var i = this._orderedInitializers.size() - 1; i >= 0; i--){
156
+ var initializers = $(this._orderedInitializers[i]);
157
+ var toDelete = [];
158
+ initializers.each(function(i, v){
159
+ // log(v.definition.name);
160
+ v.processor(v.definition);
161
+ if(v.callOnce) toDelete.push(i);
162
+ });
163
+ $(toDelete.reverse()).each(function(){
164
+ initializers.splice(this, this + 1);
165
+ });
166
+ }
167
+ },
168
+
169
+ _processOnceForEveryInitializer: function(definition) {
170
+ var count = 0
171
+ $(definition.query).each(function(){
172
+ var e = $(this);
173
+ if(!e.hasClass(definition.name)){ // if(!e.data(definition.name)){
174
+ count = count + 1;
175
+ e.addClass(definition.name); // e.data(definition.name, true);
176
+ definition.initializer.apply($(this));
177
+ }
178
+ });
179
+ // log(definition.name + ', ' + definition.query + ': ' + $(definition.query).size() + '/' + count)
180
+ },
181
+
182
+ _processOnceAfterUpdateInitializer: function(definition){
183
+ definition.initializer();
184
+ },
185
+
186
+ _processAfterUpdateInitializer: function(definition){
187
+ definition.initializer();
188
+ }
189
+ });
190
+
191
+ $(function(){
192
+ $.processInitializers();
193
+ });
194
+ $(document).ajaxSuccess(function(){
195
+ $.processInitializers();
196
+ });
197
+
198
+
199
+ //
200
+ // AJAX
201
+ //
202
+ $.ajaxSetup({
203
+ authenticity_token: $.authenticity_token,
204
+ type: "script",
205
+ dataType: "script",
206
+ format: 'js'
207
+ });
208
+
209
+
210
+ //
211
+ // dataAttr
212
+ //
213
+ $.fn.extend({
214
+ dataAttr: function(name, value) {
215
+ var attr_name = 'data-' + name;
216
+ if(value){
217
+ this.attr(attr_name, value);
218
+ }else{
219
+ return this.attr(attr_name);
220
+ }
221
+ }
222
+ });
223
+
224
+
225
+ //
226
+ // JS for CSS
227
+ //
228
+ $.extend({
229
+ // Should be overrided by actual js for css refresh
230
+ refresh_js_css: function(){}
231
+ });
232
+
233
+
234
+ //
235
+ // link_to
236
+ //
237
+ $.fn.extend({
238
+ link_to: function(options) {
239
+ options = $.extend({url: $(this).attr('href'), method: 'get'}, options);
240
+ options.method = options.method.toLowerCase();
241
+ // if(options.method == 'put' || options.method == 'delete') options.method = 'post';
242
+ try{
243
+ if(options.ajax){
244
+ var data = {
245
+ _method: options.method,
246
+ target: $(this).identify()
247
+ };
248
+ if(options.method != 'get') data.authenticity_token = $.authenticity_token;
249
+ $.ajax({
250
+ data: $.param(data),
251
+ dataType: 'script',
252
+ type: options.method,
253
+ url: options.url
254
+ });
255
+ }else{
256
+ var url = $(this).attr('href');
257
+ var form = $("<form method='POST'>").attr("action", options.url);
258
+ var params = {'authenticity_token': $.authenticity_token, '_method': options.method}
259
+ $.each(params, function(name, value) {
260
+ $("<input type='hidden'>").attr("name", name).attr("value", value).appendTo(form);
261
+ });
262
+ form.appendTo("body");
263
+ form.submit();
264
+ }
265
+ }catch(e){console.log(e)};
266
+ }
267
+ });
268
+ // it doesn't works
269
+ // $(document).ajaxError(function (e, r, o, e) {
270
+ // console.log(e);
271
+ // });
272
+
273
+
274
+ //
275
+ // Helpers
276
+ //
277
+ // AJAX for autosubmitting changes
278
+ $.callOnceForEvery('autosubmit', '._autosubmit', function() {
279
+ var e = $(this);
280
+ e.bind('change', function(){
281
+ $.post(e.dataAttr('action'), {value: e.val(), target: e.identify()})
282
+ });
283
+ });
@@ -0,0 +1,9 @@
1
+ require 'crystal/html'
2
+
3
+ crystal.after :environment do
4
+ dir = File.dirname(__FILE__)
5
+ crystal.ensure_public_symlink "crystal_jquery", "#{dir}/crystal_jquery/public/crystal_jquery"
6
+ end
7
+
8
+ require 'crystal_jquery/jquery_helper'
9
+ Crystal::ControllerContext.include Crystal::JQueryHelper
data/readme.md ADDED
@@ -0,0 +1 @@
1
+ # jQuery client for Crystal framework
data/spec/spec.opts ADDED
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --format progress
3
+ --loadby mtime
4
+ --reverse
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jquery_client
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Alexey Petrushin
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-11 00:00:00 +04:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: crystal
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ description:
36
+ email:
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files: []
42
+
43
+ files:
44
+ - Rakefile
45
+ - readme.md
46
+ - lib/crystal_jquery/jquery_helper.rb
47
+ - lib/crystal_jquery/public/crystal_jquery/jquery.crystal.css
48
+ - lib/crystal_jquery/public/crystal_jquery/jquery.crystal.js
49
+ - lib/crystal_jquery.rb
50
+ - spec/spec.opts
51
+ has_rdoc: true
52
+ homepage: http://github.com/alexeypetrushin/jquery_client
53
+ licenses: []
54
+
55
+ post_install_message:
56
+ rdoc_options: []
57
+
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ hash: 3
66
+ segments:
67
+ - 0
68
+ version: "0"
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ hash: 3
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ requirements: []
79
+
80
+ rubyforge_project:
81
+ rubygems_version: 1.3.7
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: jQuery client for Crystal Framework
85
+ test_files: []
86
+