mera 0.1.6 → 0.1.7
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.
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mera
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.7
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -34,7 +34,6 @@ extensions: []
|
|
|
34
34
|
extra_rdoc_files: []
|
|
35
35
|
files:
|
|
36
36
|
- lib/assets/javascripts/mera.js
|
|
37
|
-
- lib/assets/javascripts/mera.min.js
|
|
38
37
|
- lib/mera.rb
|
|
39
38
|
homepage:
|
|
40
39
|
licenses: []
|
|
@@ -1,9 +0,0 @@
|
|
|
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)}}}});
|