stand-alone-button.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. (function( $ ){
  2. $.fn.filemanager = function(type, options) {
  3. type = type || 'file';
  4. this.on('click', function(e) {
  5. var route_prefix = (options && options.prefix) ? options.prefix : '/filemanager';
  6. var target_input = $('#' + $(this).data('input'));
  7. var target_preview = $('#' + $(this).data('preview'));
  8. window.open(route_prefix + '?type=' + type, 'FileManager', 'width=900,height=600');
  9. window.SetUrl = function (items) {
  10. var file_path = items.map(function (item) {
  11. return item.url;
  12. }).join(',');
  13. // set the value of the desired input to image url
  14. target_input.val('').val(file_path).trigger('change');
  15. // clear previous preview
  16. target_preview.html('');
  17. // set or change the preview image src
  18. items.forEach(function (item) {
  19. target_preview.append(
  20. $('<img>').css('height', '5rem').attr('src', item.thumb_url)
  21. );
  22. });
  23. // trigger change event
  24. target_preview.trigger('change');
  25. };
  26. return false;
  27. });
  28. }
  29. })(jQuery);