angular-ui-select2-rails 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 57910819d2a3e3dbb60b6ae53522e917d430f35d
4
+ data.tar.gz: 3bcddc7f46b2b678457266afe5611a5c845469df
5
+ SHA512:
6
+ metadata.gz: 8e4108bd2aab052bd980b709e73b0132dbb3f1258f04dcd0e5ede80b87ccaa87ba8dbcdd1ba814a1f7eea691506a327339858a67b08f1a1bde9a1537112e025f
7
+ data.tar.gz: 3415c814a61365b9d6a20c92940fdbdbe65ac3ddfc908709b48f761aec8fff0bf351c77bf38990b490d3c84afc3bd6a07b66efced8ad93f4aa4af551ef93223e
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in angular-ui-select2-rails.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Tymon Tobolski
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # Angular::Ui::Select2::Rails
2
+
3
+ [angular-ui-select2](https://github.com/angular-ui/ui-select2) packaged for Rails assets pipeline
4
+
5
+ ## Usage
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'angular-ui-select2-rails'
11
+ ```
12
+
13
+ Add the following directive to your Javascript manifest file (application.js):
14
+
15
+ ```js
16
+ //= require angular-ui-select2-rails
17
+ ```
18
+
19
+ Add the following directive to your CSS manifest file (application.css):
20
+
21
+ ```css
22
+ *= require angular-ui-select2-rails
23
+ ```
24
+
25
+
26
+ ## Contributing
27
+
28
+ 1. Fork it
29
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
30
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
31
+ 4. Push to the branch (`git push origin my-new-feature`)
32
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ desc "Fetch new version from https://raw.github.com/angular-ui/ui-select2/master/src/select2.js"
4
+ task :fetch do
5
+ source = "https://raw.github.com/angular-ui/ui-select2/master/src/select2.js"
6
+ target = "vendor/assets/javascripts/angular-ui-select2-original.js"
7
+ sh "curl #{source} > #{target}"
8
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'angular/ui/select2/rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "angular-ui-select2-rails"
8
+ spec.version = Angular::Ui::Select2::Rails::VERSION
9
+ spec.authors = ["Tymon Tobolski"]
10
+ spec.email = ["i@teamon.eu"]
11
+ spec.description = %q{angular-ui-select2 packaged for Rails assets pipeline}
12
+ spec.summary = %q{angular-ui-select2 packaged for Rails assets pipeline}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "jquery-rails"
22
+ spec.add_dependency "select2-rails"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ end
@@ -0,0 +1,9 @@
1
+ require "angular/ui/select2/rails/version"
2
+ require "jquery-rails"
3
+ require "select2-rails"
4
+
5
+ module Angular::Ui::Select2::Rails
6
+ class Engine < ::Rails::Engine
7
+ # Rails -> use vendor directory.
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Angular
2
+ module Ui
3
+ module Select2
4
+ module Rails
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,133 @@
1
+ /**
2
+ * Enhanced Select2 Dropmenus
3
+ *
4
+ * @AJAX Mode - When in this mode, your value will be an object (or array of objects) of the data used by Select2
5
+ * This change is so that you do not have to do an additional query yourself on top of Select2's own query
6
+ * @params [options] {object} The configuration options passed to $.fn.select2(). Refer to the documentation
7
+ */
8
+ angular.module('ui.select2', []).value('uiSelect2Config', {}).directive('uiSelect2', ['uiSelect2Config', '$timeout', function (uiSelect2Config, $timeout) {
9
+ var options = {};
10
+ if (uiSelect2Config) {
11
+ angular.extend(options, uiSelect2Config);
12
+ }
13
+ return {
14
+ require: '?ngModel',
15
+ compile: function (tElm, tAttrs) {
16
+ var watch,
17
+ repeatOption,
18
+ repeatAttr,
19
+ isSelect = tElm.is('select'),
20
+ isMultiple = (tAttrs.multiple !== undefined);
21
+
22
+ // Enable watching of the options dataset if in use
23
+ if (tElm.is('select')) {
24
+ repeatOption = tElm.find('option[ng-repeat], option[data-ng-repeat]');
25
+
26
+ if (repeatOption.length) {
27
+ repeatAttr = repeatOption.attr('ng-repeat') || repeatOption.attr('data-ng-repeat');
28
+ watch = jQuery.trim(repeatAttr.split('|')[0]).split(' ').pop();
29
+ }
30
+ }
31
+
32
+ return function (scope, elm, attrs, controller) {
33
+ // instance-specific options
34
+ var opts = angular.extend({}, options, scope.$eval(attrs.uiSelect2));
35
+
36
+ if (isSelect) {
37
+ // Use <select multiple> instead
38
+ delete opts.multiple;
39
+ delete opts.initSelection;
40
+ } else if (isMultiple) {
41
+ opts.multiple = true;
42
+ }
43
+
44
+ if (controller) {
45
+ // Watch the model for programmatic changes
46
+ controller.$render = function () {
47
+ if (isSelect) {
48
+ elm.select2('val', controller.$viewValue);
49
+ } else {
50
+ if (isMultiple) {
51
+ if (!controller.$viewValue) {
52
+ elm.select2('data', []);
53
+ } else if (angular.isArray(controller.$viewValue)) {
54
+ elm.select2('data', controller.$viewValue);
55
+ } else {
56
+ elm.select2('val', controller.$viewValue);
57
+ }
58
+ } else {
59
+ if (angular.isObject(controller.$viewValue)) {
60
+ elm.select2('data', controller.$viewValue);
61
+ } else if (!controller.$viewValue) {
62
+ elm.select2('data', null);
63
+ } else {
64
+ elm.select2('val', controller.$viewValue);
65
+ }
66
+ }
67
+ }
68
+ };
69
+
70
+ // Watch the options dataset for changes
71
+ if (watch) {
72
+ scope.$watch(watch, function (newVal, oldVal, scope) {
73
+ if (!newVal) return;
74
+ // Delayed so that the options have time to be rendered
75
+ $timeout(function () {
76
+ elm.select2('val', controller.$viewValue);
77
+ // Refresh angular to remove the superfluous option
78
+ elm.trigger('change');
79
+ });
80
+ });
81
+ }
82
+
83
+ if (!isSelect) {
84
+ // Set the view and model value and update the angular template manually for the ajax/multiple select2.
85
+ elm.bind("change", function () {
86
+ if (scope.$$phase) return;
87
+ scope.$apply(function () {
88
+ angular.extend(controller.$viewValue, elm.select2('data'));
89
+ });
90
+ });
91
+
92
+ if (opts.initSelection) {
93
+ var initSelection = opts.initSelection;
94
+ opts.initSelection = function (element, callback) {
95
+ initSelection(element, function (value) {
96
+ controller.$setViewValue(value);
97
+ callback(value);
98
+ });
99
+ };
100
+ }
101
+ }
102
+ }
103
+
104
+ attrs.$observe('disabled', function (value) {
105
+ elm.select2(value && 'disable' || 'enable');
106
+ });
107
+
108
+ if (attrs.ngMultiple) {
109
+ scope.$watch(attrs.ngMultiple, function(newVal) {
110
+ elm.select2(opts);
111
+ });
112
+ }
113
+
114
+ // Set initial value since Angular doesn't
115
+ //elm.val(scope.$eval(attrs.ngModel));
116
+
117
+ // Initialize the plugin late so that the injected DOM does not disrupt the template compiler
118
+ $timeout(function () {
119
+ elm.select2(opts);
120
+
121
+ // Set initial value - I'm not sure about this but it seems to need to be there
122
+ elm.val(controller.$viewValue);
123
+ // important!
124
+ controller.$render();
125
+
126
+ // Not sure if I should just check for !isSelect OR if I should check for 'tags' key
127
+ if (!opts.initSelection && !isSelect)
128
+ controller.$setViewValue(elm.select2('data'));
129
+ });
130
+ };
131
+ }
132
+ };
133
+ }]);
@@ -0,0 +1,3 @@
1
+ //= require jquery
2
+ //= require select2
3
+ //= require angular-ui-select2-original
@@ -0,0 +1,6 @@
1
+ /*
2
+ * This is just a proxy to leaflet-rails gem stylesheets
3
+ * to make require consistent inside rails app
4
+ *
5
+ *= require select2
6
+ */
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: angular-ui-select2-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tymon Tobolski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jquery-rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: select2-rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: angular-ui-select2 packaged for Rails assets pipeline
70
+ email:
71
+ - i@teamon.eu
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - angular-ui-select2-rails.gemspec
82
+ - lib/angular-ui-select2-rails.rb
83
+ - lib/angular/ui/select2/rails/version.rb
84
+ - vendor/assets/javascripts/angular-ui-select2-original.js
85
+ - vendor/assets/javascripts/angular-ui-select2.js
86
+ - vendor/assets/stylesheets/angular-ui-select2.css
87
+ homepage: ''
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.0.0
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: angular-ui-select2 packaged for Rails assets pipeline
111
+ test_files: []
112
+ has_rdoc: