mera 0.1.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.
Files changed (2) hide show
  1. data/lib/assets/javascripts/mera.js +9 -0
  2. metadata +61 -0
@@ -0,0 +1,9 @@
1
+ /**
2
+ *
3
+ * My Easy Rails Ajax
4
+ * Open under GPL (General Public License)
5
+ * Author Richard Hutta 2012
6
+ *
7
+ */
8
+
9
+ $(function(){$.mera=function(options){$('a[data-skip-mera]').mera(options)};jQuery.fn.mera=function(options){$location=location.pathname;$absoluteUrl=location.href;$this=$(this);$default={before:function(){$('body').hide()},after:function(){$('body').fadeIn()},error:function(){window.location.replace('/404.html')},confirme:function(question){return confirm(question)},compress:true,autoload:true};$options=$.extend({},$default,options);$this.click(function(){window.location.href=$(this).attr('href')});$('a:not([data-remote=true])').click(function(){var hrefMera=$(this).attr('href');if($(this).attr('data-method')!==undefined){$.rails.handleMethodRemote($(this))}else{$.rails.handleRemote($(this))}history.pushState({url:$location},document.title,hrefMera);return false});$('form:not([data-remote=true])').on('submit',function(){$.rails.handleRemote($(this));return false});$(window).bind('popstate',function(event){if(location.href!==$absoluteUrl){window.location.replace(location.href)}});if($.inArray('state',$.event.props)<0){$.event.props.push('state')}$(window).on('ajax:beforeSend',function(event,xhr,settings){$options.before();xhr.setRequestHeader('X-Mera','enabled')});$(window).on('ajax:success',function(event,data,status){$.meraUpdater(data);$options.after()});$.meraUpdater=function(data){var resBody=data.split(/.*<body.*>.*/)[1].split(/.*<\/body>.*/)[0];var resHead=data.split(/.*<head.*>.*/)[1].split(/.*<\/head>.*/)[0];if($options.compress){resBody=$.whiteSpaceRemover(resBody);resHead=$.whiteSpaceRemover(resHead)}if($options.autoload){$('head').html(resHead)}else{if(!$.isHeadSame(resHead)){$('head').html(resHead)}}$('body').html(resBody)};$.whiteSpaceRemover=function(data){data=data.replace(/ /g,'');data=data.replace(/\n/g,'');data=$.trim(data);return data};$.isHeadSame=function(head){var ident="head link, head meta, head script";return $(ident).count==$(ident,$(head)).count};$.rails.handleMethodRemote=function(link){var href=$.rails.href(link),method=link.data('method'),target=link.attr('target'),confirmLink=link.attr('data-confirm'),csrf_token=$('meta[name=csrf-token]').attr('content'),csrf_param=$('meta[name=csrf-param]').attr('content'),form=$('<form method="post" action="'+href+'"></form>'),metadata_input='<input name="_method" value="'+method+'" type="hidden" />';if(csrf_param!==undefined&&csrf_token!==undefined){metadata_input+='<input name="'+csrf_param+'" value="'+csrf_token+'" type="hidden" />'}if(target){form.attr('target',target)}form.hide().append(metadata_input).appendTo('body');if(confirmLink!==undefined&&$options.confirme(confirmLink)){$.rails.handleRemote(form)}}}});
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mera
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Richard Hutta
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: jquery-rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description:
31
+ email: huttarichard@gmail.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - lib/assets/javascripts/mera.js
37
+ homepage:
38
+ licenses: []
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubyforge_project:
57
+ rubygems_version: 1.8.24
58
+ signing_key:
59
+ specification_version: 3
60
+ summary: My Easy Rails Ajax && Ruby on Rails 3.1 +
61
+ test_files: []