avgrund_to 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,40 @@
1
+ = AvgrundTo
2
+
3
+ Wraps hakim's awesome Avgrund reimagining of the modal window into a Rails Engine.
4
+
5
+ I've had to make a few adjustments to make it work with scrollable content (the original sets the body to overflow:hideden, preventing scrolling).
6
+
7
+ To use, you'll have to add the class "avgrund-contents" to the block container you'd like to blur (usually the div that's the immediate child of body).
8
+
9
+ Then you'll need to require avgrund in application.js
10
+
11
+ //= require avgrund_to/modal
12
+ //= require avgrund_to/avgrund
13
+
14
+ Same with your application.css
15
+
16
+ *= require avgrund
17
+
18
+ Then you'll need to render the partial for the modal in your layout file
19
+
20
+ <%= render 'avgrund_to/modal' %>
21
+
22
+ Then you just use the helper method avgrund_to the same way you'd use link_to
23
+
24
+ <%= avgrund_to 'Edit', shipment, {:class=>'btn btn-primary'}, "Edit Shipment #{shipment.order_number.upcase}" %>
25
+
26
+ You'll need to edit your controller to accept the .text format (behavior inherited from isieo's modal-me Rails Engine, from which this gem was inspired)
27
+
28
+ def show
29
+ @shipment = Shipment.unscoped.find(params[:id].downcase)
30
+
31
+ respond_to do |format|
32
+ format.html # show.html.erb
33
+ format.json { render json: @shipment }
34
+ format.text { render 'show', formats: [:html], layout: false }
35
+ end
36
+ end
37
+
38
+ And that's it :)
39
+
40
+ The gem is very rough and raw, and I'm sure there are lots of ways to improve it (it's yet another modal window plugin after all). Suggestions and feedback are welcome, please use the Issue Tracker for them.
data/Rakefile ADDED
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'AvgrundTo'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ #APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
24
+ #load 'rails/tasks/engine.rake'
25
+
26
+
27
+
28
+ Bundler::GemHelper.install_tasks
29
+
30
+ # require 'rake/testtask'
31
+
32
+ # Rake::TestTask.new(:test) do |t|
33
+ # t.libs << 'lib'
34
+ # t.libs << 'test'
35
+ # t.pattern = 'test/**/*_test.rb'
36
+ # t.verbose = false
37
+ # end
38
+
39
+
40
+ task :default => :test
@@ -0,0 +1,76 @@
1
+ /*!
2
+ * avgrund 0.1
3
+ * http://lab.hakim.se/avgrund
4
+ * MIT licensed
5
+ *
6
+ * Copyright (C) 2012 Hakim El Hattab, http://hakim.se
7
+ */
8
+ jQuery(function(){
9
+
10
+ var container = document.documentElement,
11
+ popup = document.querySelector( '.avgrund-popup' ),
12
+ cover = document.querySelector( '.avgrund-cover' ),
13
+ currentState = null;
14
+
15
+ //Added draggable popup
16
+ $( ".avgrund-popup" ).draggable({ cursor: "move" });
17
+
18
+ container.className = container.className.replace( /\s+$/gi, '' ) + ' avgrund-ready';
19
+
20
+ // Deactivate on ESC
21
+ function onDocumentKeyUp( event ) {
22
+ if( event.keyCode === 27 ) {
23
+ deactivate();
24
+ }
25
+ }
26
+
27
+ // Deactivate on click outside
28
+ function onDocumentClick( event ) {
29
+ if( event.target === cover ) {
30
+ deactivate();
31
+ }
32
+ }
33
+
34
+ function activate( state, pos ) {
35
+
36
+ document.addEventListener( 'keyup', onDocumentKeyUp, false );
37
+ document.addEventListener( 'click', onDocumentClick, false );
38
+
39
+ removeClass( popup, currentState );
40
+ addClass( popup, 'no-transition' );
41
+ addClass( popup, state );
42
+
43
+ setTimeout( function() {
44
+ removeClass( popup, 'no-transition' );
45
+ addClass( container, 'avgrund-active' );
46
+ }, 0 );
47
+
48
+ currentState = state;
49
+ }
50
+
51
+ function deactivate() {
52
+ document.removeEventListener( 'keyup', onDocumentKeyUp, false );
53
+ document.removeEventListener( 'click', onDocumentClick, false );
54
+
55
+ removeClass( container, 'avgrund-active' );
56
+ }
57
+
58
+ function disableBlur() {
59
+ addClass( document.documentElement, 'no-blur' );
60
+ }
61
+
62
+ function addClass( element, name ) {
63
+ element.className = element.className.replace( /\s+$/gi, '' ) + ' ' + name;
64
+ }
65
+
66
+ function removeClass( element, name ) {
67
+ element.className = element.className.replace( name, '' );
68
+ }
69
+
70
+ window.avgrund = {
71
+ activate: activate,
72
+ deactivate: deactivate,
73
+ disableBlur: disableBlur
74
+ }
75
+
76
+ })();
@@ -0,0 +1,13 @@
1
+ jQuery(function(){
2
+ jQuery('a[data-avgrund-url*=]').prop('href','#');
3
+ jQuery('a[data-avgrund-url*=]').click(function(){
4
+ avgrund.activate('', this);
5
+ jQuery.ajax({url: $(this).data('avgrund-url'),
6
+ success: function(data){
7
+ jQuery('.modal-body').html(data);
8
+ },
9
+ async: true
10
+ });
11
+ return false;
12
+ });
13
+ });
@@ -0,0 +1,122 @@
1
+ html,
2
+ body {
3
+ height: 100%;
4
+ }
5
+
6
+ .avgrund-active .avgrund-contents {
7
+ -webkit-transform: scale( 0.9 );
8
+ -moz-transform: scale( 0.9 );
9
+ -ms-transform: scale( 0.9 );
10
+ -o-transform: scale( 0.9 );
11
+ transform: scale( 0.9 );
12
+ }
13
+
14
+ .avgrund-cover {
15
+ position: fixed;
16
+ width: 100%;
17
+ height: 100%;
18
+ top: 0;
19
+ left: 0;
20
+ z-index: 1;
21
+ visibility: hidden;
22
+ opacity: 0;
23
+ background: rgba( 0, 0, 0, 0.5 );
24
+ }
25
+ .avgrund-active .avgrund-cover {
26
+ visibility: visible;
27
+ opacity: 1;
28
+ }
29
+
30
+ .avgrund-contents {
31
+ position: relative;
32
+ padding: 20px;
33
+ height: 100%;
34
+ margin: auto;
35
+ }
36
+ .avgrund-active .avgrund-contents {
37
+ -webkit-filter: blur(2px);
38
+ -moz-filter: blur(2px);
39
+ -ms-filter: blur(2px);
40
+ -o-filter: blur(2px);
41
+ filter: blur(2px);
42
+
43
+ }
44
+ .no-blur.avgrund-active .avgrund-contents {
45
+ -webkit-filter: none;
46
+ -moz-filter: none;
47
+ -ms-filter: none;
48
+ -o-filter: none;
49
+ filter: none;
50
+ }
51
+
52
+ .avgrund-popup {
53
+ position: fixed;
54
+ width: 640px;
55
+ height: 600px;
56
+ margin: -330px 0 0 -320px;
57
+ visibility: hidden;
58
+ opacity: 0;
59
+ z-index: 2;
60
+ padding: 20px;
61
+ top: 50%;
62
+ left: 50%;
63
+
64
+ background: white;
65
+ box-shadow: 0px 0px 20px rgba( 0, 0, 0, 0.6 );
66
+ border-radius: 3px;
67
+
68
+ -webkit-transform: scale( 0.8 );
69
+ -moz-transform: scale( 0.8 );
70
+ -ms-transform: scale( 0.8 );
71
+ -o-transform: scale( 0.8 );
72
+ transform: scale( 0.8 );
73
+ }
74
+ .avgrund-active .avgrund-popup {
75
+ visibility: visible;
76
+ opacity: 1;
77
+
78
+ -webkit-transform: scale( 1 );
79
+ -moz-transform: scale( 1 );
80
+ -ms-transform: scale( 1 );
81
+ -o-transform: scale( 1 );
82
+ transform: scale( 1 );
83
+ }
84
+ .avgrund-popup.stack {
85
+ -webkit-transform: scale( 1.5 );
86
+ -moz-transform: scale( 1.5 );
87
+ -ms-transform: scale( 1.5 );
88
+ -o-transform: scale( 1.5 );
89
+ transform: scale( 1.5 );
90
+ }
91
+ .avgrund-active .avgrund-popup.stack {
92
+ -webkit-transform: scale( 1.1 );
93
+ -moz-transform: scale( 1.1 );
94
+ -ms-transform: scale( 1.1 );
95
+ -o-transform: scale( 1.1 );
96
+ transform: scale( 1.1 );
97
+ }
98
+
99
+ .avgrund-ready body,
100
+ .avgrund-ready .avgrund-contents,
101
+ .avgrund-ready .avgrund-popup,
102
+ .avgrund-ready .avgrund-cover {
103
+ -webkit-transform-origin: 50% 50%;
104
+ -moz-transform-origin: 50% 50%;
105
+ -ms-transform-origin: 50% 50%;
106
+ -o-transform-origin: 50% 50%;
107
+ transform-origin: 50% 50%;
108
+
109
+ -webkit-transition: 0.3s all cubic-bezier(0.250, 0.460, 0.450, 0.940);
110
+ -moz-transition: 0.3s all cubic-bezier(0.250, 0.460, 0.450, 0.940);
111
+ -ms-transition: 0.3s all cubic-bezier(0.250, 0.460, 0.450, 0.940);
112
+ -o-transition: 0.3s all cubic-bezier(0.250, 0.460, 0.450, 0.940);
113
+ transition: 0.3s all cubic-bezier(0.250, 0.460, 0.450, 0.940);
114
+
115
+ }
116
+ .avgrund-ready .avgrund-popup.no-transition {
117
+ -webkit-transition: none;
118
+ -moz-transition: none;
119
+ -ms-transition: none;
120
+ -o-transition: none;
121
+ transition: none;
122
+ }
@@ -0,0 +1,22 @@
1
+ module AvgrundToHelper
2
+
3
+ def avgrund_to(*args, &block)
4
+ if block_given?
5
+ options = args.first || {}
6
+ html_options = args.second
7
+ modal_title = args.third
8
+ avgrund_to(capture(&block), options, html_options)
9
+ else
10
+ name = args[0]
11
+ options = args[1] || {}
12
+ html_options = args[2]
13
+
14
+
15
+ options = url_for(options) unless options.kind_of? String
16
+
17
+ html_options['data-avgrund-url'] = "#{options}.text"
18
+ return link_to(name, options, html_options)
19
+ end
20
+ end
21
+
22
+ end
@@ -0,0 +1,7 @@
1
+ <div class="avgrund-cover"></div>
2
+
3
+ <div class="avgrund-popup" id="avgrund-modal">
4
+ <div class="modal-body">
5
+ <button onclick="avgrund.deactivate();">Close</button>
6
+ </div>
7
+ </div>
data/lib/avgrund_to.rb ADDED
@@ -0,0 +1,4 @@
1
+ require "avgrund_to/engine"
2
+
3
+ module AvgrundTo
4
+ end
@@ -0,0 +1,5 @@
1
+ module AvgrundTo
2
+ class Engine < ::Rails::Engine
3
+ engine_name 'avgrund_to'
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module AvgrundTo
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :avgrund_to do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: avgrund_to
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tristan
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '3.1'
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: '3.1'
30
+ - !ruby/object:Gem::Dependency
31
+ name: jquery-rails
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Wraps hakim's awesome Avgrund reimagining of the modal window into a
47
+ Rails Engine
48
+ email:
49
+ - tristan.gomez@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - app/assets/javascripts/avgrund_to/avgrund.js
55
+ - app/assets/javascripts/avgrund_to/modal.js
56
+ - app/assets/stylesheets/avgrund.css
57
+ - app/helpers/avgrund_to_helper.rb
58
+ - app/views/avgrund_to/_modal.html.erb
59
+ - lib/avgrund_to/engine.rb
60
+ - lib/avgrund_to/version.rb
61
+ - lib/avgrund_to.rb
62
+ - lib/tasks/avgrund_to_tasks.rake
63
+ - MIT-LICENSE
64
+ - Rakefile
65
+ - README.rdoc
66
+ homepage: https://github.com/parasquid/avgrund_to.git
67
+ licenses: []
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ segments:
79
+ - 0
80
+ hash: 3923213717211686162
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ segments:
88
+ - 0
89
+ hash: 3923213717211686162
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 1.8.24
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: Wraps hakim's awesome Avgrund reimagining of the modal window into a Rails
96
+ Engine
97
+ test_files: []