redditor 0.1.5 → 0.1.6

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.
@@ -1,199 +0,0 @@
1
-
2
- <% content_for :js do %>
3
-
4
- <%= javascript_include_tag "fileapi/config", "fileapi/FileAPI.min", "fileapi/FileAPI.id3.js", "fileapi/FileAPI.exif.js", "fileapi/tmpl" %>
5
-
6
- <%= stylesheet_link_tag "fileapi/fileapi" %>
7
-
8
- <script id="b-file-ejs" type="text/ejs">
9
- <div id="file-<%%=FileAPI.uid(file)%>" class="js-file b-file b-file_<%%=file.type.split('/')[0]%>">
10
- <div class="js-left b-file__left">
11
- <img src="<%%=icon[file.type.split('/')[0]]||icon.def%>" width="32" height="32" style="margin: 2px 0 0 3px"/>
12
- </div>
13
- <div class="b-file__right">
14
- <div><a class="js-name b-file__name"><%%=file.name%></a></div>
15
- <div class="js-info b-file__info">size: <%%=(file.size/FileAPI.KB).toFixed(2)%> KB</div>
16
- <div class="js-progress b-file__bar" style="display: none">
17
- <div class="b-progress"><div class="js-bar b-progress__bar"></div></div>
18
- </div>
19
- </div>
20
- <i class="js-abort b-file__abort" title="abort">&times;</i>
21
- </div>
22
- </script>
23
-
24
- <script id="b-layer-ejs" type="text/ejs">
25
- <div class="b-layer">
26
- <div class="b-layer__h1"><%%=file.name%></div>
27
- <div class="js-img b-layer__img"></div>
28
- <div class="b-layer__info">
29
- <%%
30
- FileAPI.each(info, function(val, key){
31
- if( Object.prototype.toString.call(val) == '[object Object]' ){
32
- var sub = '';
33
- FileAPI.each(val, function (val, key){ sub += '<div>'+key+': '+val+'</div>'; });
34
- if( sub ){
35
- %><%%=key%><div style="margin: 0 0 5px 20px;"><%%=sub%></div><%%
36
- }
37
- } else {
38
- %>
39
- <div><%%=key%>: <%%=val%></div>
40
- <%%
41
- }
42
- });
43
- %>
44
- </div>
45
- </div>
46
- </script>
47
-
48
-
49
- <script type="text/javascript">
50
- jQuery(function ($){
51
- if( !(FileAPI.support.cors || FileAPI.support.flash) ){
52
- $('#oooops').show();
53
- $('#buttons-panel').hide();
54
- }
55
-
56
- $(document).on('mouseenter mouseleave', '.b-button', function (evt){
57
- $(evt.currentTarget).toggleClass('b-button_hover', evt.type == 'mouseenter');
58
- });
59
-
60
-
61
- if( FileAPI.support.dnd ){
62
- $('#drag-n-drop').show();
63
- $(document).dnd(function (over){
64
- $('#drop-zone').toggle(over);
65
- }, function (files){
66
- onFiles(files);
67
- });
68
- }
69
-
70
-
71
- $(document).on('change', 'input[type="file"]', function (evt){
72
- var files = FileAPI.getFiles(evt);
73
- onFiles.call(this, files);
74
- FileAPI.reset(evt.currentTarget);
75
- });
76
-
77
-
78
- var FU = {
79
- icon: {
80
- def: '//cdn1.iconfinder.com/data/icons/CrystalClear/32x32/mimetypes/unknown.png'
81
- , image: '//cdn1.iconfinder.com/data/icons/humano2/32x32/apps/synfig_icon.png'
82
- , audio: '//cdn1.iconfinder.com/data/icons/august/PNG/Music.png'
83
- , video: '//cdn1.iconfinder.com/data/icons/df_On_Stage_Icon_Set/128/Video.png'
84
- },
85
-
86
- files: [],
87
- index: 0,
88
- active: false,
89
-
90
- add: function (file){
91
- FU.files.push(file);
92
-
93
- if( /^image/.test(file.type) ){
94
- FileAPI.Image(file).preview(35).rotate('auto').get(function (err, img){
95
- if( !err ){
96
- FU._getEl(file, '.js-left')
97
- .addClass('b-file__left_border')
98
- .html(img)
99
- ;
100
- }
101
- });
102
- }
103
- },
104
-
105
- getFileById: function (id){
106
- var i = FU.files.length;
107
- while( i-- ){
108
- if( FileAPI.uid(FU.files[i]) == id ){
109
- return FU.files[i];
110
- }
111
- }
112
- },
113
-
114
- start: function (context){
115
- if( !FU.active && (FU.active = FU.files.length > FU.index) ){
116
- FU._upload(FU.files[FU.index], context);
117
- }
118
- },
119
-
120
- abort: function (id){
121
- var file = this.getFileById(id);
122
- if( file.xhr ){
123
- file.xhr.abort();
124
- }
125
- },
126
-
127
- _getEl: function (file, sel){
128
- var $el = $('#file-'+FileAPI.uid(file));
129
- return sel ? $el.find(sel) : $el;
130
- },
131
-
132
- _upload: function (file, context){
133
- if( file ){
134
- file.xhr = FileAPI.upload({
135
- url: FU.uploadUrl,
136
- data: {"content_block_id": FU.contentBlockId},
137
- dataType: "script", // forced respond is script!!
138
- headers: {
139
- 'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
140
- },
141
- files: {
142
- file: file
143
- },
144
- upload: function (){
145
- FU._getEl(file).addClass('b-file_upload');
146
- FU._getEl(file, '.js-progress')
147
- .css({ opacity: 0 }).show()
148
- .animate({ opacity: 1 }, 100)
149
- ;
150
- },
151
- progress: function (evt){
152
- FU._getEl(file, '.js-bar').css('width', evt.loaded/evt.total*100+'%');
153
- },
154
- complete: function (err, xhr){
155
- setTimeout(xhr.response, 10)
156
- var state = err ? 'error' : 'done';
157
-
158
- FU._getEl(file).removeClass('b-file_upload');
159
- FU._getEl(file, '.js-progress').animate({ opacity: 0 }, 200, function (){ $(this).hide() });
160
- FU._getEl(file, '.js-info').append(', <b class="b-file__'+state+'">'+(err ? (xhr.statusText || err) : state)+'</b>');
161
-
162
- FU.index++;
163
- FU.active = false;
164
-
165
- FU.start(context);
166
- }
167
- });
168
- }
169
- }
170
- };
171
-
172
- function onFiles(files){
173
- var context = this; // input, на который нажали
174
- var $Queue = $('<div class="upload-area" />').appendTo($(this).closest("dd"));
175
-
176
-
177
- FU.uploadUrl = $(context).data("url");
178
- FU.contentBlockId = $(context).closest("dd").attr("id").replace(/\D/gi,"");
179
-
180
- FileAPI.each(files, function (file){
181
- if( file.size >= 25*FileAPI.MB ){
182
- alert('Sorrow.\nMax size 25MB')
183
- }
184
- else if( file.size === void 0 ){
185
- $('#oooops').show();
186
- $('#buttons-panel').hide();
187
- }
188
- else {
189
- $Queue.append(tmpl($('#b-file-ejs').html(), { file: file, icon: FU.icon }));
190
-
191
- FU.add(file);
192
- FU.start(context);
193
- }
194
- });
195
- }
196
- }); // ready
197
- </script>
198
-
199
- <% end %>