barryvdh / laravel-elfinder

elFinder bundle for Laravel
738 stars 169 forks source link

standalonepopup setting show mimes #132

Open gzai opened 8 years ago

gzai commented 8 years ago

In view when using standalonepopup

        <script type="text/javascript">
        var mimes = ["image/jpeg", "application/msword"];
        </script>

if views elfinder set to publish resources/views/vendor/elfinder/standalonepopup.php

or views elfinder not set to publish vendor/barryvdh/laravel-elfinder/resources/views/standalonepopup.php

update source code

        var mimes = ( typeof window.parent.mimes !== 'undefined' ) ? window.parent.mimes : []; // <-- new code
        var elf = $('#elfinder').elfinder({
            // set your elFinder options here
            <?php if($locale){ ?>
                lang: '<?= $locale ?>', // locale
            <?php } ?>
            customData: { 
                _token: '<?= csrf_token() ?>'
            },
            url: '<?= route("elfinder.connector") ?>',  // connector URL
            dialog: {width: 900, modal: true, title: 'Select a file'},
            resizable: false,
            commandsOptions: {
                getfile: {
                    oncomplete: 'destroy'
                }
            },
            onlyMimes: mimes, // <-- new code
            getFileCallback: function (file) {
                window.parent.processSelectedFile(file.path, '<?= $input_id?>');
                parent.jQuery.colorbox.close();
            }
        }).elfinder('instance');
gzai commented 8 years ago

if in one view have 2 or more input standalonepopup, and each popup wants to have specific mimes added data-mimes and want to use alot of mimes use comma


<a href="javascript:void(0)" class="popup_selector" data-inputid="input_image" data-mimes="image">Select Image</a>

<a href="javascript:void(0)" class="popup_selector" data-inputid="input_video" data-mimes="video">Select Video</a>

<a href="javascript:void(0)" class="popup_selector" data-inputid="input_file" data-mimes="application/msword,application/excel">Select File</a>

update asset elfinder in public : public/packages/barryvdh/elfinder/js/standalonepupup.js


   var mimes = []; // <-- new code
   $(document).on('click','.popup_selector',function (event) {
       event.preventDefault();
       var updateID = $(this).attr('data-inputid'); // Btn id clicked
       var elfinderUrl = '/elfinder/popup/';
       var _mimes = ( typeof $(this).attr('data-mimes') !== 'undefined' ) ? $(this).attr('data-mimes') : ''; // <-- new code
       mimes = ( _mimes == '' ) ? [] : _mimes.replace(/\s/g, '').split(","); // <-- new code

       // trigger the reveal modal with elfinder inside
       var triggerUrl = elfinderUrl + updateID;
       $.colorbox({
           href: triggerUrl,
           fastIframe: true,
           iframe: true,
           width: '70%',
           height: '50%'
       });

   });
   // function to update the file selected by elfinder
   function processSelectedFile(filePath, requestingField) {
       $('#' + requestingField).val(filePath).trigger('change');
   }

if views elfinder set to publish resources/views/vendor/elfinder/standalonepopup.php

or views elfinder not set to publish vendor/barryvdh/laravel-elfinder/resources/views/standalonepopup.php


        var mimes = ( typeof window.parent.mimes !== 'undefined' ) ? window.parent.mimes : []; // <-- new code

        var elf = $('#elfinder').elfinder({
            // set your elFinder options here
            <?php if($locale){ ?>
                lang: '<?= $locale ?>', // locale
            <?php } ?>
            customData: { 
                _token: '<?= csrf_token() ?>'
            },
            url: '<?= route("elfinder.connector") ?>',  // connector URL
            dialog: {width: 900, modal: true, title: 'Select a file'},
            resizable: false,
            commandsOptions: {
                getfile: {
                    oncomplete: 'destroy'
                }
            },
            onlyMimes: mimes, // <-- new code
            getFileCallback: function (file) {
                window.parent.processSelectedFile(file.path, '<?= $input_id?>');
                parent.jQuery.colorbox.close();
            }
        }).elfinder('instance');