aerogel-media 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +14 -0
  6. data/Rakefile +1 -0
  7. data/aerogel-media.gemspec +26 -0
  8. data/app/helpers/README.md +7 -0
  9. data/app/helpers/image_tag.rb +26 -0
  10. data/app/routes/README.md +7 -0
  11. data/assets/README.md +1 -0
  12. data/assets/javascripts/aerogel-media.js.coffee +4 -0
  13. data/assets/javascripts/aerogel-media/enable-fancybox.js.coffee +36 -0
  14. data/assets/javascripts/aerogel-media/smart-file-input.js.coffee +132 -0
  15. data/assets/stylesheets/aerogel-media.css.scss +2 -0
  16. data/assets/stylesheets/aerogel-media/smart-file-input.css.scss +12 -0
  17. data/assets/vendor/fancybox2.css.scss +1 -0
  18. data/assets/vendor/fancybox2.js.coffee +1 -0
  19. data/assets/vendor/fancybox2/blank.gif +0 -0
  20. data/assets/vendor/fancybox2/fancybox_loading.gif +0 -0
  21. data/assets/vendor/fancybox2/fancybox_loading@2x.gif +0 -0
  22. data/assets/vendor/fancybox2/fancybox_overlay.png +0 -0
  23. data/assets/vendor/fancybox2/fancybox_sprite.png +0 -0
  24. data/assets/vendor/fancybox2/fancybox_sprite@2x.png +0 -0
  25. data/assets/vendor/fancybox2/helpers/fancybox_buttons.png +0 -0
  26. data/assets/vendor/fancybox2/helpers/jquery.fancybox-buttons.css +97 -0
  27. data/assets/vendor/fancybox2/helpers/jquery.fancybox-buttons.js +122 -0
  28. data/assets/vendor/fancybox2/helpers/jquery.fancybox-media.js +199 -0
  29. data/assets/vendor/fancybox2/helpers/jquery.fancybox-thumbs.css +55 -0
  30. data/assets/vendor/fancybox2/helpers/jquery.fancybox-thumbs.js +162 -0
  31. data/assets/vendor/fancybox2/jquery.fancybox.css +274 -0
  32. data/assets/vendor/fancybox2/jquery.fancybox.js +2020 -0
  33. data/assets/vendor/fancybox2/jquery.fancybox.pack.js +46 -0
  34. data/config/README.md +3 -0
  35. data/config/development/.keep +0 -0
  36. data/config/production/.keep +0 -0
  37. data/db/model/README.md +1 -0
  38. data/db/seed/README.md +1 -0
  39. data/db/seed/development/.keep +0 -0
  40. data/db/seed/production/.keep +0 -0
  41. data/db/seed/seed.template +42 -0
  42. data/lib/aerogel/media.rb +19 -0
  43. data/lib/aerogel/media/core.rb +46 -0
  44. data/lib/aerogel/media/field_types.rb +61 -0
  45. data/lib/aerogel/media/model.rb +60 -0
  46. data/lib/aerogel/media/uploaded_file.rb +15 -0
  47. data/lib/aerogel/media/version.rb +5 -0
  48. data/locales/aerogel-forms.en.yml +8 -0
  49. data/locales/aerogel-forms.ru.yml +8 -0
  50. data/locales/models.en.yml +14 -0
  51. data/locales/models.ru.yml +13 -0
  52. data/public/README.md +1 -0
  53. data/rake/README.md +3 -0
  54. data/views/README.md +1 -0
  55. data/views/form_builder/standard/field_media-file.erb +48 -0
  56. data/views/form_builder/standard/field_media-image.erb +50 -0
  57. metadata +155 -0
@@ -0,0 +1,122 @@
1
+ /*!
2
+ * Buttons helper for fancyBox
3
+ * version: 1.0.5 (Mon, 15 Oct 2012)
4
+ * @requires fancyBox v2.0 or later
5
+ *
6
+ * Usage:
7
+ * $(".fancybox").fancybox({
8
+ * helpers : {
9
+ * buttons: {
10
+ * position : 'top'
11
+ * }
12
+ * }
13
+ * });
14
+ *
15
+ */
16
+ (function ($) {
17
+ //Shortcut for fancyBox object
18
+ var F = $.fancybox;
19
+
20
+ //Add helper object
21
+ F.helpers.buttons = {
22
+ defaults : {
23
+ skipSingle : false, // disables if gallery contains single image
24
+ position : 'top', // 'top' or 'bottom'
25
+ tpl : '<div id="fancybox-buttons"><ul><li><a class="btnPrev" title="Previous" href="javascript:;"></a></li><li><a class="btnPlay" title="Start slideshow" href="javascript:;"></a></li><li><a class="btnNext" title="Next" href="javascript:;"></a></li><li><a class="btnToggle" title="Toggle size" href="javascript:;"></a></li><li><a class="btnClose" title="Close" href="javascript:;"></a></li></ul></div>'
26
+ },
27
+
28
+ list : null,
29
+ buttons: null,
30
+
31
+ beforeLoad: function (opts, obj) {
32
+ //Remove self if gallery do not have at least two items
33
+
34
+ if (opts.skipSingle && obj.group.length < 2) {
35
+ obj.helpers.buttons = false;
36
+ obj.closeBtn = true;
37
+
38
+ return;
39
+ }
40
+
41
+ //Increase top margin to give space for buttons
42
+ obj.margin[ opts.position === 'bottom' ? 2 : 0 ] += 30;
43
+ },
44
+
45
+ onPlayStart: function () {
46
+ if (this.buttons) {
47
+ this.buttons.play.attr('title', 'Pause slideshow').addClass('btnPlayOn');
48
+ }
49
+ },
50
+
51
+ onPlayEnd: function () {
52
+ if (this.buttons) {
53
+ this.buttons.play.attr('title', 'Start slideshow').removeClass('btnPlayOn');
54
+ }
55
+ },
56
+
57
+ afterShow: function (opts, obj) {
58
+ var buttons = this.buttons;
59
+
60
+ if (!buttons) {
61
+ this.list = $(opts.tpl).addClass(opts.position).appendTo('body');
62
+
63
+ buttons = {
64
+ prev : this.list.find('.btnPrev').click( F.prev ),
65
+ next : this.list.find('.btnNext').click( F.next ),
66
+ play : this.list.find('.btnPlay').click( F.play ),
67
+ toggle : this.list.find('.btnToggle').click( F.toggle ),
68
+ close : this.list.find('.btnClose').click( F.close )
69
+ }
70
+ }
71
+
72
+ //Prev
73
+ if (obj.index > 0 || obj.loop) {
74
+ buttons.prev.removeClass('btnDisabled');
75
+ } else {
76
+ buttons.prev.addClass('btnDisabled');
77
+ }
78
+
79
+ //Next / Play
80
+ if (obj.loop || obj.index < obj.group.length - 1) {
81
+ buttons.next.removeClass('btnDisabled');
82
+ buttons.play.removeClass('btnDisabled');
83
+
84
+ } else {
85
+ buttons.next.addClass('btnDisabled');
86
+ buttons.play.addClass('btnDisabled');
87
+ }
88
+
89
+ this.buttons = buttons;
90
+
91
+ this.onUpdate(opts, obj);
92
+ },
93
+
94
+ onUpdate: function (opts, obj) {
95
+ var toggle;
96
+
97
+ if (!this.buttons) {
98
+ return;
99
+ }
100
+
101
+ toggle = this.buttons.toggle.removeClass('btnDisabled btnToggleOn');
102
+
103
+ //Size toggle button
104
+ if (obj.canShrink) {
105
+ toggle.addClass('btnToggleOn');
106
+
107
+ } else if (!obj.canExpand) {
108
+ toggle.addClass('btnDisabled');
109
+ }
110
+ },
111
+
112
+ beforeClose: function () {
113
+ if (this.list) {
114
+ this.list.remove();
115
+ }
116
+
117
+ this.list = null;
118
+ this.buttons = null;
119
+ }
120
+ };
121
+
122
+ }(jQuery));
@@ -0,0 +1,199 @@
1
+ /*!
2
+ * Media helper for fancyBox
3
+ * version: 1.0.6 (Fri, 14 Jun 2013)
4
+ * @requires fancyBox v2.0 or later
5
+ *
6
+ * Usage:
7
+ * $(".fancybox").fancybox({
8
+ * helpers : {
9
+ * media: true
10
+ * }
11
+ * });
12
+ *
13
+ * Set custom URL parameters:
14
+ * $(".fancybox").fancybox({
15
+ * helpers : {
16
+ * media: {
17
+ * youtube : {
18
+ * params : {
19
+ * autoplay : 0
20
+ * }
21
+ * }
22
+ * }
23
+ * }
24
+ * });
25
+ *
26
+ * Or:
27
+ * $(".fancybox").fancybox({,
28
+ * helpers : {
29
+ * media: true
30
+ * },
31
+ * youtube : {
32
+ * autoplay: 0
33
+ * }
34
+ * });
35
+ *
36
+ * Supports:
37
+ *
38
+ * Youtube
39
+ * http://www.youtube.com/watch?v=opj24KnzrWo
40
+ * http://www.youtube.com/embed/opj24KnzrWo
41
+ * http://youtu.be/opj24KnzrWo
42
+ * http://www.youtube-nocookie.com/embed/opj24KnzrWo
43
+ * Vimeo
44
+ * http://vimeo.com/40648169
45
+ * http://vimeo.com/channels/staffpicks/38843628
46
+ * http://vimeo.com/groups/surrealism/videos/36516384
47
+ * http://player.vimeo.com/video/45074303
48
+ * Metacafe
49
+ * http://www.metacafe.com/watch/7635964/dr_seuss_the_lorax_movie_trailer/
50
+ * http://www.metacafe.com/watch/7635964/
51
+ * Dailymotion
52
+ * http://www.dailymotion.com/video/xoytqh_dr-seuss-the-lorax-premiere_people
53
+ * Twitvid
54
+ * http://twitvid.com/QY7MD
55
+ * Twitpic
56
+ * http://twitpic.com/7p93st
57
+ * Instagram
58
+ * http://instagr.am/p/IejkuUGxQn/
59
+ * http://instagram.com/p/IejkuUGxQn/
60
+ * Google maps
61
+ * http://maps.google.com/maps?q=Eiffel+Tower,+Avenue+Gustave+Eiffel,+Paris,+France&t=h&z=17
62
+ * http://maps.google.com/?ll=48.857995,2.294297&spn=0.007666,0.021136&t=m&z=16
63
+ * http://maps.google.com/?ll=48.859463,2.292626&spn=0.000965,0.002642&t=m&z=19&layer=c&cbll=48.859524,2.292532&panoid=YJ0lq28OOy3VT2IqIuVY0g&cbp=12,151.58,,0,-15.56
64
+ */
65
+ (function ($) {
66
+ "use strict";
67
+
68
+ //Shortcut for fancyBox object
69
+ var F = $.fancybox,
70
+ format = function( url, rez, params ) {
71
+ params = params || '';
72
+
73
+ if ( $.type( params ) === "object" ) {
74
+ params = $.param(params, true);
75
+ }
76
+
77
+ $.each(rez, function(key, value) {
78
+ url = url.replace( '$' + key, value || '' );
79
+ });
80
+
81
+ if (params.length) {
82
+ url += ( url.indexOf('?') > 0 ? '&' : '?' ) + params;
83
+ }
84
+
85
+ return url;
86
+ };
87
+
88
+ //Add helper object
89
+ F.helpers.media = {
90
+ defaults : {
91
+ youtube : {
92
+ matcher : /(youtube\.com|youtu\.be|youtube-nocookie\.com)\/(watch\?v=|v\/|u\/|embed\/?)?(videoseries\?list=(.*)|[\w-]{11}|\?listType=(.*)&list=(.*)).*/i,
93
+ params : {
94
+ autoplay : 1,
95
+ autohide : 1,
96
+ fs : 1,
97
+ rel : 0,
98
+ hd : 1,
99
+ wmode : 'opaque',
100
+ enablejsapi : 1
101
+ },
102
+ type : 'iframe',
103
+ url : '//www.youtube.com/embed/$3'
104
+ },
105
+ vimeo : {
106
+ matcher : /(?:vimeo(?:pro)?.com)\/(?:[^\d]+)?(\d+)(?:.*)/,
107
+ params : {
108
+ autoplay : 1,
109
+ hd : 1,
110
+ show_title : 1,
111
+ show_byline : 1,
112
+ show_portrait : 0,
113
+ fullscreen : 1
114
+ },
115
+ type : 'iframe',
116
+ url : '//player.vimeo.com/video/$1'
117
+ },
118
+ metacafe : {
119
+ matcher : /metacafe.com\/(?:watch|fplayer)\/([\w\-]{1,10})/,
120
+ params : {
121
+ autoPlay : 'yes'
122
+ },
123
+ type : 'swf',
124
+ url : function( rez, params, obj ) {
125
+ obj.swf.flashVars = 'playerVars=' + $.param( params, true );
126
+
127
+ return '//www.metacafe.com/fplayer/' + rez[1] + '/.swf';
128
+ }
129
+ },
130
+ dailymotion : {
131
+ matcher : /dailymotion.com\/video\/(.*)\/?(.*)/,
132
+ params : {
133
+ additionalInfos : 0,
134
+ autoStart : 1
135
+ },
136
+ type : 'swf',
137
+ url : '//www.dailymotion.com/swf/video/$1'
138
+ },
139
+ twitvid : {
140
+ matcher : /twitvid\.com\/([a-zA-Z0-9_\-\?\=]+)/i,
141
+ params : {
142
+ autoplay : 0
143
+ },
144
+ type : 'iframe',
145
+ url : '//www.twitvid.com/embed.php?guid=$1'
146
+ },
147
+ twitpic : {
148
+ matcher : /twitpic\.com\/(?!(?:place|photos|events)\/)([a-zA-Z0-9\?\=\-]+)/i,
149
+ type : 'image',
150
+ url : '//twitpic.com/show/full/$1/'
151
+ },
152
+ instagram : {
153
+ matcher : /(instagr\.am|instagram\.com)\/p\/([a-zA-Z0-9_\-]+)\/?/i,
154
+ type : 'image',
155
+ url : '//$1/p/$2/media/?size=l'
156
+ },
157
+ google_maps : {
158
+ matcher : /maps\.google\.([a-z]{2,3}(\.[a-z]{2})?)\/(\?ll=|maps\?)(.*)/i,
159
+ type : 'iframe',
160
+ url : function( rez ) {
161
+ return '//maps.google.' + rez[1] + '/' + rez[3] + '' + rez[4] + '&output=' + (rez[4].indexOf('layer=c') > 0 ? 'svembed' : 'embed');
162
+ }
163
+ }
164
+ },
165
+
166
+ beforeLoad : function(opts, obj) {
167
+ var url = obj.href || '',
168
+ type = false,
169
+ what,
170
+ item,
171
+ rez,
172
+ params;
173
+
174
+ for (what in opts) {
175
+ if (opts.hasOwnProperty(what)) {
176
+ item = opts[ what ];
177
+ rez = url.match( item.matcher );
178
+
179
+ if (rez) {
180
+ type = item.type;
181
+ params = $.extend(true, {}, item.params, obj[ what ] || ($.isPlainObject(opts[ what ]) ? opts[ what ].params : null));
182
+
183
+ url = $.type( item.url ) === "function" ? item.url.call( this, rez, params, obj ) : format( item.url, rez, params );
184
+
185
+ break;
186
+ }
187
+ }
188
+ }
189
+
190
+ if (type) {
191
+ obj.href = url;
192
+ obj.type = type;
193
+
194
+ obj.autoHeight = false;
195
+ }
196
+ }
197
+ };
198
+
199
+ }(jQuery));
@@ -0,0 +1,55 @@
1
+ #fancybox-thumbs {
2
+ position: fixed;
3
+ left: 0;
4
+ width: 100%;
5
+ overflow: hidden;
6
+ z-index: 8050;
7
+ }
8
+
9
+ #fancybox-thumbs.bottom {
10
+ bottom: 2px;
11
+ }
12
+
13
+ #fancybox-thumbs.top {
14
+ top: 2px;
15
+ }
16
+
17
+ #fancybox-thumbs ul {
18
+ position: relative;
19
+ list-style: none;
20
+ margin: 0;
21
+ padding: 0;
22
+ }
23
+
24
+ #fancybox-thumbs ul li {
25
+ float: left;
26
+ padding: 1px;
27
+ opacity: 0.5;
28
+ }
29
+
30
+ #fancybox-thumbs ul li.active {
31
+ opacity: 0.75;
32
+ padding: 0;
33
+ border: 1px solid #fff;
34
+ }
35
+
36
+ #fancybox-thumbs ul li:hover {
37
+ opacity: 1;
38
+ }
39
+
40
+ #fancybox-thumbs ul li a {
41
+ display: block;
42
+ position: relative;
43
+ overflow: hidden;
44
+ border: 1px solid #222;
45
+ background: #111;
46
+ outline: none;
47
+ }
48
+
49
+ #fancybox-thumbs ul li img {
50
+ display: block;
51
+ position: relative;
52
+ border: 0;
53
+ padding: 0;
54
+ max-width: none;
55
+ }
@@ -0,0 +1,162 @@
1
+ /*!
2
+ * Thumbnail helper for fancyBox
3
+ * version: 1.0.7 (Mon, 01 Oct 2012)
4
+ * @requires fancyBox v2.0 or later
5
+ *
6
+ * Usage:
7
+ * $(".fancybox").fancybox({
8
+ * helpers : {
9
+ * thumbs: {
10
+ * width : 50,
11
+ * height : 50
12
+ * }
13
+ * }
14
+ * });
15
+ *
16
+ */
17
+ (function ($) {
18
+ //Shortcut for fancyBox object
19
+ var F = $.fancybox;
20
+
21
+ //Add helper object
22
+ F.helpers.thumbs = {
23
+ defaults : {
24
+ width : 50, // thumbnail width
25
+ height : 50, // thumbnail height
26
+ position : 'bottom', // 'top' or 'bottom'
27
+ source : function ( item ) { // function to obtain the URL of the thumbnail image
28
+ var href;
29
+
30
+ if (item.element) {
31
+ href = $(item.element).find('img').attr('src');
32
+ }
33
+
34
+ if (!href && item.type === 'image' && item.href) {
35
+ href = item.href;
36
+ }
37
+
38
+ return href;
39
+ }
40
+ },
41
+
42
+ wrap : null,
43
+ list : null,
44
+ width : 0,
45
+
46
+ init: function (opts, obj) {
47
+ var that = this,
48
+ list,
49
+ thumbWidth = opts.width,
50
+ thumbHeight = opts.height,
51
+ thumbSource = opts.source;
52
+
53
+ //Build list structure
54
+ list = '';
55
+
56
+ for (var n = 0; n < obj.group.length; n++) {
57
+ list += '<li><a style="width:' + thumbWidth + 'px;height:' + thumbHeight + 'px;" href="javascript:jQuery.fancybox.jumpto(' + n + ');"></a></li>';
58
+ }
59
+
60
+ this.wrap = $('<div id="fancybox-thumbs"></div>').addClass(opts.position).appendTo('body');
61
+ this.list = $('<ul>' + list + '</ul>').appendTo(this.wrap);
62
+
63
+ //Load each thumbnail
64
+ $.each(obj.group, function (i) {
65
+ var href = thumbSource( obj.group[ i ] );
66
+
67
+ if (!href) {
68
+ return;
69
+ }
70
+
71
+ $("<img />").load(function () {
72
+ var width = this.width,
73
+ height = this.height,
74
+ widthRatio, heightRatio, parent;
75
+
76
+ if (!that.list || !width || !height) {
77
+ return;
78
+ }
79
+
80
+ //Calculate thumbnail width/height and center it
81
+ widthRatio = width / thumbWidth;
82
+ heightRatio = height / thumbHeight;
83
+
84
+ parent = that.list.children().eq(i).find('a');
85
+
86
+ if (widthRatio >= 1 && heightRatio >= 1) {
87
+ if (widthRatio > heightRatio) {
88
+ width = Math.floor(width / heightRatio);
89
+ height = thumbHeight;
90
+
91
+ } else {
92
+ width = thumbWidth;
93
+ height = Math.floor(height / widthRatio);
94
+ }
95
+ }
96
+
97
+ $(this).css({
98
+ width : width,
99
+ height : height,
100
+ top : Math.floor(thumbHeight / 2 - height / 2),
101
+ left : Math.floor(thumbWidth / 2 - width / 2)
102
+ });
103
+
104
+ parent.width(thumbWidth).height(thumbHeight);
105
+
106
+ $(this).hide().appendTo(parent).fadeIn(300);
107
+
108
+ }).attr('src', href);
109
+ });
110
+
111
+ //Set initial width
112
+ this.width = this.list.children().eq(0).outerWidth(true);
113
+
114
+ this.list.width(this.width * (obj.group.length + 1)).css('left', Math.floor($(window).width() * 0.5 - (obj.index * this.width + this.width * 0.5)));
115
+ },
116
+
117
+ beforeLoad: function (opts, obj) {
118
+ //Remove self if gallery do not have at least two items
119
+ if (obj.group.length < 2) {
120
+ obj.helpers.thumbs = false;
121
+
122
+ return;
123
+ }
124
+
125
+ //Increase bottom margin to give space for thumbs
126
+ obj.margin[ opts.position === 'top' ? 0 : 2 ] += ((opts.height) + 15);
127
+ },
128
+
129
+ afterShow: function (opts, obj) {
130
+ //Check if exists and create or update list
131
+ if (this.list) {
132
+ this.onUpdate(opts, obj);
133
+
134
+ } else {
135
+ this.init(opts, obj);
136
+ }
137
+
138
+ //Set active element
139
+ this.list.children().removeClass('active').eq(obj.index).addClass('active');
140
+ },
141
+
142
+ //Center list
143
+ onUpdate: function (opts, obj) {
144
+ if (this.list) {
145
+ this.list.stop(true).animate({
146
+ 'left': Math.floor($(window).width() * 0.5 - (obj.index * this.width + this.width * 0.5))
147
+ }, 150);
148
+ }
149
+ },
150
+
151
+ beforeClose: function () {
152
+ if (this.wrap) {
153
+ this.wrap.remove();
154
+ }
155
+
156
+ this.wrap = null;
157
+ this.list = null;
158
+ this.width = 0;
159
+ }
160
+ }
161
+
162
+ }(jQuery));