mera 0.1.7 → 0.1.8

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 +29 -21
  2. metadata +2 -2
@@ -9,8 +9,14 @@
9
9
 
10
10
  $(function(){
11
11
 
12
- $.mera = function(options){
13
- $('a[data-skip-mera]').mera(options);
12
+ $.mera = {
13
+ init: function(options){
14
+ return $('a[data-skip-mera]').mera(options);
15
+ },
16
+
17
+ version: function(){
18
+ return "0.1.8";
19
+ }
14
20
  };
15
21
 
16
22
  jQuery.fn.mera = function(options) {
@@ -24,13 +30,14 @@ $(function(){
24
30
  $default = {
25
31
  before : function(){$('body').hide();},
26
32
  after : function(){$('body').fadeIn();},
27
- error : function(){window.location.replace('/404.html')},
33
+ error : function(xhr, status, error){alert(error);},
28
34
  confirme : function(question){return confirm(question);},
29
- compress: true,
30
- autoload: true
35
+ compress: true
31
36
  };
32
37
  //get user options
33
38
  $options = $.extend({}, $default, options);
39
+ //get if data-update-only
40
+ $dataUpdateOnly = false;
34
41
 
35
42
  $this.click(function(){
36
43
  window.location.href = $(this).attr('href');
@@ -38,7 +45,7 @@ $(function(){
38
45
 
39
46
  //handle a click
40
47
  $('a:not([data-remote=true])').click(function(){
41
- var hrefMera = $(this).attr('href');
48
+ var hrefMera = $(this).attr('href');
42
49
 
43
50
  if($(this).attr('data-method') !== undefined){
44
51
  $.rails.handleMethodRemote($(this));
@@ -77,6 +84,10 @@ $(function(){
77
84
  $options.after();
78
85
  });
79
86
 
87
+ $(window).on('ajax:error', function(event, xhr, status, error) {
88
+ $options.error(xhr, status, error);
89
+ });
90
+
80
91
  $.meraUpdater = function(data){
81
92
  var resBody = data.split(/.*<body.*>.*/)[1].split(/.*<\/body>.*/)[0];
82
93
  var resHead = data.split(/.*<head.*>.*/)[1].split(/.*<\/head>.*/)[0];
@@ -86,14 +97,7 @@ $(function(){
86
97
  resHead = $.whiteSpaceRemover(resHead);
87
98
  }
88
99
 
89
- if($options.autoload){
90
- $('head').html(resHead);
91
- } else {
92
- if(!$.isHeadSame(resHead)){
93
- $('head').html(resHead);
94
- }
95
- }
96
-
100
+ $('head').html(resHead);
97
101
  $('body').html(resBody);
98
102
  };
99
103
 
@@ -105,11 +109,6 @@ $(function(){
105
109
  return data;
106
110
  };
107
111
 
108
- $.isHeadSame = function(head) {
109
- var ident = "head link, head meta, head script";
110
- return $(ident).count == $(ident, $(head)).count;
111
- };
112
-
113
112
  $.rails.handleMethodRemote = function(link) {
114
113
  var href = $.rails.href(link),
115
114
  method = link.data('method'),
@@ -128,10 +127,19 @@ $(function(){
128
127
 
129
128
  form.hide().append(metadata_input).appendTo('body');
130
129
 
131
- if(confirmLink !== undefined && $options.confirme(confirmLink)){
130
+ if(confirmLink !== undefined ){
131
+ if($options.confirme(confirmLink)){
132
+ $.rails.handleRemote(form);
133
+ }
134
+ } else {
132
135
  $.rails.handleRemote(form);
133
136
  }
134
- }
137
+ };
135
138
 
136
139
  };
137
140
  });
141
+
142
+ $(document).ready(function(){
143
+ $.mera.init();
144
+ });
145
+
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.7
4
+ version: 0.1.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-16 00:00:00.000000000 Z
12
+ date: 2012-09-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jquery-rails