Class: IRuby::Input::File
Instance Method Summary
collapse
Methods inherited from Label
#widget_label
Methods inherited from Widget
builder, #content, #widget_css, #widget_display, #widget_join
Instance Method Details
46
47
48
49
50
51
52
53
54
|
# File 'lib/iruby/input/file.rb', line 46
def widget_html
widget_label do
input(
type: 'file',
:'data-iruby-key' => @key,
class: 'form-control iruby-file'
)
end
end
|
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/iruby/input/file.rb', line 25
def widget_js
<<-JS
$('.iruby-file').change(function() {
var input = $(this);
$.grep($(this).prop('files'), function(file) {
var reader = new FileReader();
reader.addEventListener("load", function(event) {
input.data('iruby-value', {
name: input.val(),
data: event.target.result
});
});
reader.readAsDataURL(file);
});
});
JS
end
|