err_supply 0.1.10 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ce3d99b223e895b683ab96c99cf77a07f1890a5a
4
- data.tar.gz: 06da79c2db3d7dfeb5cb2f22acc2369a28fbfdea
3
+ metadata.gz: 43b07a58a27ef4bfaaea935f09990cfb3e271f4f
4
+ data.tar.gz: 1e5e224eb76058586d0c3ca850ef94d41d29de7f
5
5
  SHA512:
6
- metadata.gz: 3f92242346c102906174e7cb110acf4203a77b51ef389cf6e81e46f319ea7e685ef0584e42ede71cef8b2e7f8abd32f6608676061164fd2aa03a2176845ed0b0
7
- data.tar.gz: cdfdb6ddd83621c30ea6ba1027d64a179e338a5580918fd705c9cd14a1322a77139038f7da0817c202200f48c539147a3574fdc9fa1da140421564ab669819db
6
+ metadata.gz: 14ec0bfe4fad3df32041bdb6cc7135c4c9006ca5a59995c7f1f06bc96dab98c0bedb3d95ec530f530729bda8e977aa8eecb9a6fc8f7a59b3b352db6e4d6f887e
7
+ data.tar.gz: 06a5f8eb14ee3d4af61dfe38de4e1b4e302aae57dcc3098775e75ef4806f5e04d172f8276c91334a40dbea62478a5ef5d16a6afe8947361bb83c7916a564cfb8
@@ -0,0 +1,92 @@
1
+ //= require jquery.qtip
2
+
3
+ /*
4
+ ErrSupply Twitter Bootstrap3 Adapter
5
+ Copyright (c) 2014 Coroutine LLC
6
+ Licensed under the MIT license
7
+ */
8
+ jQuery(function($) {
9
+ $("form").on("err_supply:loaded", function(event, errors) {
10
+
11
+ // define how errors are applied to dom elements
12
+ var applyFn = function(error_hash) {
13
+ var unmatched = {};
14
+ var errors = error_hash || {};
15
+ var error;
16
+ var content;
17
+ var $field;
18
+ var position;
19
+
20
+ for (var id in errors) {
21
+ error = errors[id];
22
+ if (error && error.messages && error.messages.length) {
23
+
24
+ content = '<ul class="err_supply">';
25
+ for (var i = 0, n = error.messages.length; i < n; i++) {
26
+ content += '<li>' + error.label + " " + error.messages[i] + '</li>';
27
+ };
28
+ content += '</ul>';
29
+
30
+ $field = $('#' + id);
31
+ options = {}
32
+ if ($field.offset()) {
33
+
34
+ // determine position
35
+ if (($field.offset().left + $field.outerWidth() + 300) < $(window).width()) {
36
+ position = 'right';
37
+ }
38
+ else {
39
+ position = 'left';
40
+ };
41
+
42
+ // add class
43
+ $field.addClass('error');
44
+
45
+ // add popover
46
+ console.log(content);
47
+ $field.popover({
48
+ html: true,
49
+ placement: position,
50
+ trigger: 'focus',
51
+ content: content
52
+ });
53
+ }
54
+ else {
55
+ unmatched[id] = error;
56
+ };
57
+ };
58
+ };
59
+
60
+ return unmatched;
61
+ };
62
+
63
+ // get reference to form firing event
64
+ var $form = $(this);
65
+
66
+ // find all contained elements with a style of error and remove the class.
67
+ // this is typically more important for ajax submissions. html submissions
68
+ // tend not to have this problem.
69
+ $form.find('.error').removeClass('error');
70
+
71
+ // hide all fields that have been explicitly destroyed. when an html submission
72
+ // has errors, the _destroy value renders as true rather than 1, which may or may not
73
+ // causes destroyed sets to be visible after the reload. here, we scan for both
74
+ // values and hide any containing div.fields elements.
75
+ $form.find('input:hidden[id$=_destroy]').filter('[value=true], [value=1]').closest('.fields').hide();
76
+
77
+ // apply errors to dom elements
78
+ var unmatched_errors = applyFn(errors) || {};
79
+
80
+ // publish unmatched errors, in case view cares about that
81
+ $form.trigger('err_supply:unmatched', unmatched_errors);
82
+
83
+ // move focus to first field with error (or first field)
84
+ var $focus_field = ($form.find('.error').size() > 0) ?
85
+ $form.find('.error').filter(':first') :
86
+ $form.find(':not(.filter) :input:visible:enabled:first');
87
+ $focus_field.focus()
88
+
89
+ // cancel event
90
+ return false;
91
+ });
92
+ });
@@ -1,3 +1,3 @@
1
1
  module ErrSupply
2
- VERSION = '0.1.10'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: err_supply
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Coroutine
@@ -9,34 +9,34 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-08 00:00:00.000000000 Z
12
+ date: 2014-02-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - '>='
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
20
  version: 3.0.0
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - '>='
25
+ - - ">="
26
26
  - !ruby/object:Gem::Version
27
27
  version: 3.0.0
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: rspec
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - '>='
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
34
  version: 2.0.0
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - '>='
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: 2.0.0
42
42
  description: Simple, beautiful error messages for Rails. Err_supply unpacks and rekeys
@@ -50,12 +50,13 @@ executables: []
50
50
  extensions: []
51
51
  extra_rdoc_files: []
52
52
  files:
53
- - .gitignore
54
- - .specification
53
+ - ".gitignore"
54
+ - ".specification"
55
55
  - Gemfile
56
56
  - README.md
57
57
  - Rakefile
58
58
  - err_supply.gemspec
59
+ - lib/assets/javascripts/err_supply-bootstrap.js
59
60
  - lib/assets/javascripts/err_supply.js
60
61
  - lib/err_supply.rb
61
62
  - lib/err_supply/controller_helpers.rb
@@ -71,19 +72,18 @@ require_paths:
71
72
  - lib
72
73
  required_ruby_version: !ruby/object:Gem::Requirement
73
74
  requirements:
74
- - - '>='
75
+ - - ">="
75
76
  - !ruby/object:Gem::Version
76
77
  version: '0'
77
78
  required_rubygems_version: !ruby/object:Gem::Requirement
78
79
  requirements:
79
- - - '>='
80
+ - - ">="
80
81
  - !ruby/object:Gem::Version
81
82
  version: '0'
82
83
  requirements: []
83
84
  rubyforge_project:
84
- rubygems_version: 2.0.3
85
+ rubygems_version: 2.2.1
85
86
  signing_key:
86
87
  specification_version: 4
87
88
  summary: Simple, beautiful error messages for Rails.
88
89
  test_files: []
89
- has_rdoc: