/** * functions for stylesheet file/color attachments */ var themeProperties = (function() { /** * @var number the total attached files for this stylesheet */ var attachedCount = 0; /** * attach event handlers * * @return void */ function init() { for (var i = 0; i < attachedCount; ++i) { $("#delete_img_" + i).on('click', removeAttachmentBox); } $("#new_specific_file").on('click', addAttachmentBox); } /** * allow external setup * * @param string the count at load time * @return void */ function setup(count) { attachedCount = count || 0; } /** * create a new blank attachment box * * @param object the event * @return void */ function addAttachmentBox(e) { e.preventDefault(); var next_count = Number(attachedCount) + 1, contents = "
\n\n\n\n\n\n\n\n\n\n
\""" + file_lang_string + "  
\n
\n
\n
\n
\n" + specific_actions_desc_lang_string + "\n\n\n\n\n
\n
\n
\n
\n
\n"; // if this is the first attachment, create the first if (!$("#attach_box_" + attachedCount).attr('id')) { $("#attach_1").html(contents).show(); } else { $("#attach_box_" + attachedCount).html(contents).show(); } checkAction('action_' + attachedCount); if ($("#attached_form_" + attachedCount)) { $("#delete_img_" + attachedCount).on('click', removeAttachmentBox); } ++attachedCount; } /** * remove an entire attachment box * * @param object the event * @return void */ function removeAttachmentBox(e) { var idArray, id; idArray = e.currentTarget.id.split('_'); if (!idArray.length) { return; } id = idArray[idArray.length - 1]; e.preventDefault(); if (confirm(delete_confirm_lang_string) == true) { $("#attached_form_" + id).remove(); } } $(init); // the only public method return { setup: setup, }; })();