% if (config('always_encrypt')) {
<%=l 'always_encrypt' %>
% }
% if (defined(stash('short'))) {
% if (defined(stash('short'))) {
% }
% # Display image informations
% my $url = index_url(1).stash('short');
<%= stash('filename') %>
<%=l 'tweet_it' %>
% my $delete_url = url_for('delete', {short => stash('real_short'), token => stash('token')})->to_abs();
- <%= link_to $url => begin %> <%= $url %> <%= end %>
- <%= link_to $url.'?dl' => begin %> <%= $url.'?dl' %> <%= end %>
- <%= link_to $url.'?t' => begin %> <%= $url.'?t' %> <%= end %>
- <%= link_to $delete_url => begin %> <%= $delete_url %> <%= end %>
% # Delay modification form
% my $modify_url = url_for('modify', {short => stash('real_short'), token => stash('token')})->to_abs();
% }
% if (defined(flash('success'))) {
<%== flash('success') %>
% }
% if (defined(flash('msg'))) {
<%=l 'some-bad' %>
<%= flash('filename') %> <%= flash('msg') %>
% }
'
+thumb
+'
'
+msg.filename
+''
+tw_url(msg.short)
+'
- '
+link(msg.short, '')
+'
- '
+link(msg.short, 'dl')
+'
- '
+link(msg.short, 't')
+'
- '
+link(msg.real_short, '', msg.token)
+'
'
+'
';
} else {
return '
<%=l 'some-bad' %>
'
+msg.filename
+"
"
+msg.msg
+'
';
}
}
function bindddz(firstview, deleteday) {
$('#drag-and-drop-zone').dmUploader({
url: '<%== index_url %>',
dataType: 'json',
allowedTypes: 'image/*',
maxFileSize: <%= $max_file_size %>,
onNewFile: function(id, file){
$(".messages").append('
');
},
onUploadProgress: function(id, percent){
var percentStr = ' '+percent+'%';
$('#'+id).prop('aria-valuenow', percent);
$('#'+id).prop('style', 'width: '+percent+'%;');
$('#'+id+'-text').html(percentStr);
},
onUploadSuccess: function(id, data){
$('#'+id+'-div').remove();
$(".messages").append(build_message(data.success, data.msg));
},
onUploadError: function(id, message){
$(".messages").append(build_message(false, ''));
},
onFileSizeError: function(file){
$(".messages").append(build_message(false, { filename: file.name, msg: '<%= l('file_too_big', $max_file_size) %>'}));
}
});
}
function upload_url() {
var val = $("#lutim-file-url").val();
if (val !== undefined && val !== "") {
$("#lutim-file-url").prop('disabled', 'disabled');
$(".hidden-spin").css('display', 'block');
console.log(val);
$.ajax({
url : '<%== index_url %>',
type : "POST",
data : {
'lutim-file-url' : val,
'format' : 'json',
'first-view' : ($("#first-view").prop('checked')) ? 1 : 0,
'crypt' : ($("#crypt").prop('checked')) ? 1 : 0,
'delete-day' : $("#delete-day").val()
},
success: function(data) {
$(".messages").append(build_message(data.success, data.msg));
if (data.success) {
$("#lutim-file-url").val('');
}
},
error: function() {
$(".messages").append(build_message(false, ''));
},
complete: function() {
$("#lutim-file-url").prop('disabled', '');
$(".hidden-spin").css('display', 'none');
}
});
} else {
console.log("fhdsjnf");
}
}
function fileUpload(file) {
var fd = new FormData();
fd.append('file', file);
fd.append('format', 'json');
fd.append('first-view', ($("#first-view").prop('checked')) ? 1 : 0);
fd.append('crypt', ($("#crypt").prop('checked')) ? 1 : 0);
fd.append('delete-day', ($("#delete-day").val()));
$(".messages").append('
');
// Ajax Submit
$.ajax({
url: '<%== index_url %>',
type: 'POST',
dataType: 'json',
data: fd,
cache: false,
contentType: false,
processData: false,
forceSync: false,
xhr: function(){
var xhrobj = $.ajaxSettings.xhr();
if(xhrobj.upload){
xhrobj.upload.addEventListener('progress', function(event) {
var percent = 0;
var position = event.loaded || event.position;
var total = event.total || e.totalSize;
if(event.lengthComputable){
percent = Math.ceil(position / total * 100);
}
var percentStr = ' '+percent+'%';
$('#1').prop('aria-valuenow', percent);
$('#1').prop('style', 'width: '+percent+'%;');
$('#1-text').html(percentStr);
}, false);
}
return xhrobj;
},
success: function (data, message, xhr){
$('#1-div').remove();
$(".messages").append(build_message(data.success, data.msg));
},
error: function (xhr, status, errMsg){
$(".messages").append(build_message(false, ''));
},
});
}
window.onload = function() {
if (navigator.mozSetMessageHandler !== undefined) {
navigator.mozSetMessageHandler('activity', function handler(activityRequest) {
var activityName = activityRequest.source.name;
if (activityName == 'share') {
activity = activityRequest;
blob = activity.source.data.blobs[0];
fileUpload(blob);
}
});
}
};
$('document').ready(function() {
var firstview = ($("#first-view").prop('checked')) ? 1 : 0;
var deleteday = ($("#delete-day").prop('checked')) ? 1 : 0;
bindddz(firstview, deleteday);
$("#file-url-button").on("click", upload_url);
$('#lutim-file-url').keydown( function(e) {
var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
if(key == 13) {
e.preventDefault();
upload_url();
}
});
});
% end