2014-01-19 13:45:22 +01:00
|
|
|
/*
|
|
|
|
* upload-selection.js - makes upload fields in post form more compact
|
2014-01-19 14:03:07 +01:00
|
|
|
* https://github.com/vichan-devel/Tinyboard/blob/master/js/upload-selection.js
|
2014-01-19 13:45:22 +01:00
|
|
|
*
|
|
|
|
* Released under the MIT license
|
|
|
|
* Copyright (c) 2014 Marcin Łabanowski <marcin@6irc.net>
|
|
|
|
*
|
|
|
|
* Usage:
|
|
|
|
* $config['additional_javascript'][] = 'js/jquery.min.js';
|
2014-01-29 22:05:59 +01:00
|
|
|
* //$config['additional_javascript'][] = 'js/wpaint.js';
|
2014-01-19 13:45:22 +01:00
|
|
|
* $config['additional_javascript'][] = 'js/upload-selection.js';
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2013-08-17 22:56:22 +02:00
|
|
|
$(function(){
|
|
|
|
var enabled_file = true;
|
|
|
|
var enabled_url = $("#upload_url").length > 0;
|
|
|
|
var enabled_embed = $("#upload_embed").length > 0;
|
2014-01-29 22:05:59 +01:00
|
|
|
var enabled_oekaki = typeof window.oekaki != "undefined";
|
2013-08-17 22:56:22 +02:00
|
|
|
|
|
|
|
var disable_all = function() {
|
|
|
|
$("#upload").hide();
|
2014-06-12 20:01:16 +02:00
|
|
|
$("[id^=upload_file]").hide();
|
|
|
|
$(".file_separator").hide();
|
2013-08-17 22:56:22 +02:00
|
|
|
$("#upload_url").hide();
|
|
|
|
$("#upload_embed").hide();
|
2014-04-30 16:27:24 +02:00
|
|
|
$(".add_image").hide();
|
2015-03-31 06:50:05 +02:00
|
|
|
$(".dropzone-wrap").hide();
|
2013-08-17 23:26:46 +02:00
|
|
|
|
2014-06-12 20:01:16 +02:00
|
|
|
$('[id^=upload_file]').each(function(i, v) {
|
|
|
|
$(v).val('');
|
|
|
|
});
|
|
|
|
|
2013-08-17 23:26:46 +02:00
|
|
|
if (enabled_oekaki) {
|
2014-01-29 22:05:59 +01:00
|
|
|
if (window.oekaki.initialized) {
|
|
|
|
window.oekaki.deinit();
|
2013-08-17 23:26:46 +02:00
|
|
|
}
|
|
|
|
}
|
2013-08-17 22:56:22 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
enable_file = function() {
|
|
|
|
disable_all();
|
|
|
|
$("#upload").show();
|
2015-03-31 06:50:05 +02:00
|
|
|
$(".dropzone-wrap").show();
|
2014-06-12 20:01:16 +02:00
|
|
|
$(".file_separator").show();
|
|
|
|
$("[id^=upload_file]").show();
|
2014-04-30 16:27:24 +02:00
|
|
|
$(".add_image").show();
|
2013-08-17 22:56:22 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
enable_url = function() {
|
|
|
|
disable_all();
|
|
|
|
$("#upload").show();
|
|
|
|
$("#upload_url").show();
|
|
|
|
|
|
|
|
$('label[for="file_url"]').html(_("URL"));
|
|
|
|
};
|
|
|
|
|
|
|
|
enable_embed = function() {
|
|
|
|
disable_all();
|
|
|
|
$("#upload_embed").show();
|
|
|
|
};
|
|
|
|
|
|
|
|
enable_oekaki = function() {
|
|
|
|
disable_all();
|
2013-08-17 23:26:46 +02:00
|
|
|
|
2014-01-29 22:05:59 +01:00
|
|
|
window.oekaki.init();
|
2013-08-17 22:56:22 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
if (enabled_url || enabled_embed || enabled_oekaki) {
|
|
|
|
$("<tr><th>"+_("Select")+"</th><td id='upload_selection'></td></tr>").insertBefore("#upload");
|
|
|
|
var my_html = "<a href='javascript:void(0)' onclick='enable_file(); return false;'>"+_("File")+"</a>";
|
|
|
|
if (enabled_url) {
|
|
|
|
my_html += " / <a href='javascript:void(0)' onclick='enable_url(); return false;'>"+_("Remote")+"</a>";
|
|
|
|
}
|
|
|
|
if (enabled_embed) {
|
|
|
|
my_html += " / <a href='javascript:void(0)' onclick='enable_embed(); return false;'>"+_("Embed")+"</a>";
|
|
|
|
}
|
|
|
|
if (enabled_oekaki) {
|
|
|
|
my_html += " / <a href='javascript:void(0)' onclick='enable_oekaki(); return false;'>"+_("Oekaki")+"</a>";
|
2013-08-17 23:31:50 +02:00
|
|
|
|
|
|
|
$("#confirm_oekaki_label").hide();
|
2013-08-17 22:56:22 +02:00
|
|
|
}
|
|
|
|
$("#upload_selection").html(my_html);
|
|
|
|
|
|
|
|
enable_file();
|
|
|
|
}
|
|
|
|
});
|