redditor 0.1.0 → 0.1.1

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,35 +0,0 @@
1
- // Simple JavaScript Templating
2
- // John Resig - http://ejohn.org/ - MIT Licensed
3
- (function (){
4
- var cache = {};
5
-
6
- this.tmpl = function tmpl(str, data){
7
- // Figure out if we're getting a template, or if we need to
8
- // load the template - and be sure to cache the result.
9
- var fn = !/\W/.test(str) ?
10
- cache[str] = cache[str] ||
11
- tmpl(document.getElementById(str).innerHTML) :
12
-
13
- // Generate a reusable function that will serve as a template
14
- // generator (and which will be cached).
15
- new Function("obj",
16
- "var p=[],print=function(){p.push.apply(p,arguments);};" +
17
-
18
- // Introduce the data as local variables using with(){}
19
- "with(obj){p.push('" +
20
-
21
- // Convert the template into pure JavaScript
22
- str
23
- .replace(/[\r\t\n]/g, " ")
24
- .split("<%").join("\t")
25
- .replace(/((^|%>)[^\t]*)'/g, "$1\r")
26
- .replace(/\t=(.*?)%>/g, "',$1,'")
27
- .split("\t").join("');")
28
- .split("%>").join("p.push('")
29
- .split("\r").join("\\'")
30
- + "');}return p.join('');");
31
-
32
- // Provide some basic currying to the user
33
- return data ? fn(data) : fn;
34
- };
35
- })();
@@ -1,139 +0,0 @@
1
- window.FU =
2
- config:
3
- maxFileSizeMB: 10
4
- messages:
5
- error: "Ошибка"
6
- done: "Загружено"
7
- data: ->
8
- icon:
9
- image: "//cdn1.iconfinder.com/data/icons/humano2/32x32/apps/synfig_icon.png"
10
-
11
- files: []
12
- index: 0
13
- active: false
14
-
15
- add: (file) ->
16
- FU.files.push file
17
- if /^image/.test(file.type)
18
- FileAPI.Image(file).preview(35).rotate("auto").get (err, img) ->
19
- FU._getEl(file, ".js-left").addClass("b-file__left_border").html img unless err
20
-
21
- getFileById: (id) ->
22
- i = FU.files.length
23
- return FU.files[i] if FileAPI.uid(FU.files[i]) is id while i--
24
-
25
- start: ->
26
- FU._upload FU.files[FU.index] if not FU.active and (FU.active = FU.files.length > FU.index)
27
-
28
- abort: (id) ->
29
- file = @getFileById(id)
30
- file.xhr.abort() if file.xhr
31
-
32
- _getEl: (file, sel) ->
33
- $el = $("#file-" + FileAPI.uid(file))
34
- (if sel then $el.find(sel) else $el)
35
-
36
- _upload: (file) ->
37
- if file
38
- FileAPI.upload(
39
- url: FU.config.uploadUrl+"?authenticity_token=#{encodeURIComponent($("meta[name=\"csrf-token\"]").attr("content"))}"
40
- data: FU.config.data()
41
- dataType: "script"
42
-
43
- files:
44
- file: file
45
-
46
- upload: ->
47
- FU._getEl(file).addClass "b-file_upload"
48
- FU._getEl(file, ".js-progress").css(opacity: 0).show().animate
49
- opacity: 1
50
- , 100
51
-
52
- progress: (evt) ->
53
- FU._getEl(file, ".js-bar").css "width", evt.loaded / evt.total * 100 + "%"
54
-
55
- complete: (err, xhr) ->
56
- setTimeout(xhr.responseText, 10)
57
-
58
- state = (if err then "error" else "done")
59
- FU._getEl(file).removeClass "b-file_upload"
60
- FU._getEl(file, ".js-progress").animate
61
- opacity: 0
62
- , 200, ->
63
- $(@).hide().closest("div.js-file").delay(1000).fadeOut 200, ->
64
- $(@).remove()
65
-
66
- FU._getEl(file, ".js-info").append ", <b class=\"b-file__" + state + "\">" + ((if err then (xhr.statusText or err) else FU.config.messages[state])) + "</b>"
67
- FU.index++
68
- FU.active = false
69
- FU.start()
70
- )
71
-
72
- template: '<div id="file-<%=FileAPI.uid(file)%>" class="js-file b-file b-file_<%=file.type.split("/")[0]%>">
73
- <div class="js-left b-file__left">
74
- <img src="<%=icon[file.type.split("/")[0]]||icon.def%>" width="32" height="32" style="margin: 2px 0 0 3px"/>
75
- </div>
76
- <div class="b-file__right">
77
- <div class="js-name b-file__name"><%=file.name%></div>
78
- <div class="js-info b-file__info">Размер: <%=(file.size/FileAPI.KB).toFixed(2)%> KB</div>
79
- <div class="js-progress b-file__bar" style="display: none">
80
- <div class="b-progress"><div class="js-bar b-progress__bar"></div></div>
81
- </div>
82
- </div>
83
- <i class="js-abort b-file__abort" title="abort">&times;</i>
84
- </div>'
85
-
86
-
87
- window.onFiles = (files, context) ->
88
- $context = $(context)
89
- if uploadUrl = $context.data("upload-url")
90
- FU.config.uploadUrl = uploadUrl
91
-
92
- if contentBlockId = $context.data("content-block-id")
93
- FU.config.data = ->
94
- REDDE.redditor.parameterizationForm $context.closest("dd")
95
- else
96
- FU.config.data = ->
97
-
98
- FileAPI.each files, (file) ->
99
- if file.size >= FU.config.maxFileSizeMB * FileAPI.MB
100
- alert "Sorrow.\nMax size #{FU.config.maxFileSizeMB}MB"
101
- else if file.size is undefined
102
- $("#oooops").show()
103
- $("#buttons-panel").hide()
104
- else
105
- $("#preview").append tmpl(window.FU.template,
106
- file: file
107
- icon: FU.icon
108
- )
109
- FU.add file
110
- FU.start()
111
-
112
- $ ->
113
- unless FileAPI.support.cors or FileAPI.support.flash
114
- $("<div />",
115
- class: "alert"
116
- html: "Увы, ваш браузер не поддерживает html5 и flash, поэтому смотреть тут нечего, а iframe не даёт всей красоты :]"
117
- ).insertAfter "#page-header" # если загрузка не поддерживается, то выводим сообщение
118
- $('#buttons-panel').hide()
119
-
120
-
121
- if FileAPI.support.dnd
122
- $('#drag-n-drop').show() #выводим текст с сообщение что работает dnd
123
- $(document).dnd (over) ->
124
- $('#drop-zone').toggleClass "active", over #Если кто-то перетащил файлы в браузер подсвечиваем область в которую их можно бросить
125
- return
126
- , ->
127
- $('#drop-zone').dnd (over) ->
128
- return
129
- , (files) ->
130
- onFiles files, this
131
- return
132
-
133
- $(document).on 'change', 'input[type="file"][name="files"]', (evt) ->
134
- files = FileAPI.getFiles(evt)
135
- onFiles(files, this)
136
- FileAPI.reset(evt.currentTarget)
137
- return
138
-
139
- return