adapter
3 days ago
index.html
3 days ago
inspector.js
3 days ago
mediamanager.js
3 days ago
vikappointments.js
3 days ago
wizard.js
3 days ago
mediamanager.js
131 lines
| 1 | var VAP_SELECTED_FIELD = null; |
| 2 | var VAP_TMP_FILES = []; |
| 3 | var VAP_MEDIA_FOLDER = ''; |
| 4 | |
| 5 | jQuery(function() { |
| 6 | jQuery('#media-manager-save').on('click', vapMediaDismissHandler); |
| 7 | }); |
| 8 | |
| 9 | function vapMediaDismissHandler() { |
| 10 | // get previous value |
| 11 | var oldVal = jQuery(VAP_SELECTED_FIELD).mediamanager('val'); |
| 12 | |
| 13 | // update media field |
| 14 | jQuery(VAP_SELECTED_FIELD).mediamanager('val', VAP_TMP_FILES); |
| 15 | |
| 16 | // get new value |
| 17 | var newVal = jQuery(VAP_SELECTED_FIELD).mediamanager('val'); |
| 18 | |
| 19 | // trigger change event if the value changed |
| 20 | if (JSON.stringify(oldVal) != JSON.stringify(newVal)) { |
| 21 | jQuery(VAP_SELECTED_FIELD).trigger('change'); |
| 22 | } |
| 23 | |
| 24 | // dispose modal |
| 25 | vapMediaCloseJModal(); |
| 26 | |
| 27 | // unset selected field |
| 28 | VAP_SELECTED_FIELD = null; |
| 29 | // empty selected files list |
| 30 | VAP_TMP_FILES = []; |
| 31 | } |
| 32 | |
| 33 | function vapMediaStartPreview(id, path) { |
| 34 | // get selected images |
| 35 | var images = jQuery(id).mediamanager('val'); |
| 36 | |
| 37 | if (!images || images.length == 0) { |
| 38 | return false; |
| 39 | } |
| 40 | |
| 41 | if (!path) { |
| 42 | path = VAP_MEDIA_FOLDER; |
| 43 | } |
| 44 | |
| 45 | if (Array.isArray(images)) { |
| 46 | images = images.map(function(image) { |
| 47 | return path + image; |
| 48 | }); |
| 49 | } else { |
| 50 | images = path + images; |
| 51 | } |
| 52 | |
| 53 | // start preview |
| 54 | vapOpenModalImage(images); |
| 55 | } |
| 56 | |
| 57 | jQuery.fn.mediamanager = function(method, data) { |
| 58 | if (typeof method === 'undefined') { |
| 59 | method = 'open'; |
| 60 | } |
| 61 | |
| 62 | if (method.match(/^(val|value)$/i)) { |
| 63 | // check if the field supports multiple selection |
| 64 | var multiple = jQuery(this).attr('multiple') ? true : false; |
| 65 | // extract field name |
| 66 | var name = jQuery(this).data('name'); |
| 67 | // set value if 2nd argument is defined |
| 68 | if (typeof data !== 'undefined') { |
| 69 | // check if multiple |
| 70 | if (multiple) { |
| 71 | jQuery(this).siblings('input[type="hidden"][name="' + name + '"]').remove(); |
| 72 | |
| 73 | // no selection by default |
| 74 | var text = ''; |
| 75 | |
| 76 | if (data && data.length) { |
| 77 | if (!Array.isArray(data)) { |
| 78 | data = [data]; |
| 79 | } |
| 80 | |
| 81 | for (var i = 0; i < data.length; i++) { |
| 82 | jQuery('<input type="hidden" name="' + name + '" value="' + data[i] + '" />').insertBefore(this); |
| 83 | } |
| 84 | |
| 85 | if (data.length == 1) { |
| 86 | // text = Joomla.JText._('VAP_DEF_N_SELECTED_1'); |
| 87 | text = data[0]; |
| 88 | } else { |
| 89 | text = Joomla.JText._('VAP_DEF_N_SELECTED').replace(/%d/, data.length); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | jQuery(this).val(text); |
| 94 | } else { |
| 95 | if (Array.isArray(data)) { |
| 96 | data = data.length ? data.shift() : null; |
| 97 | } |
| 98 | |
| 99 | jQuery(this).val(data); |
| 100 | } |
| 101 | |
| 102 | return this; |
| 103 | } |
| 104 | |
| 105 | // retrieve field value |
| 106 | if (multiple) { |
| 107 | var tmp = []; |
| 108 | jQuery(this).siblings('input[type="hidden"][name="' + name + '"]').each(function() { |
| 109 | tmp.push(jQuery(this).val()); |
| 110 | }); |
| 111 | return tmp; |
| 112 | } |
| 113 | |
| 114 | return jQuery(this).val(); |
| 115 | } |
| 116 | // check if we should open the dialog |
| 117 | else if (method.match(/^(open|show)$/i)) { |
| 118 | vapMediaOpenJModal(this, data ? data : null); |
| 119 | } |
| 120 | // check if we should dismiss the dialog |
| 121 | else if (method.match(/^(close|dismiss|hide)$/i)) { |
| 122 | vapMediaCloseJModal(); |
| 123 | } |
| 124 | // check if we should display the preview |
| 125 | else if (method.match(/^preview$/i)) { |
| 126 | vapMediaStartPreview(this, data ? data : null); |
| 127 | } |
| 128 | |
| 129 | return this; |
| 130 | } |
| 131 |