Laravel文件管理器独立的iframe输入

时间:2018-08-09 20:11:27

标签: laravel iframe

我不知道如何找不到任何示例,就像以前没有人使用过。.

我想在iframe中打开文件管理器,然后在图片上单击以插入图片网址以进行输入。他们的示例打开了新窗口...

我正在使用laravel文件管理器独立按钮来更改头像图像,但是通过他们的文档,我可以这样做:

<div class="input-group">
       <span class="input-group-btn">
         <a id="lfm" data-input="thumbnail" data-preview="holder" class="btn btn-primary">
           <i class="fa fa-picture-o"></i> Choose
         </a>
       </span>
       <input id="thumbnail" class="form-control" type="text" name="filepath">
     </div>
     <img id="holder" style="margin-top:15px;max-height:100px;">

并致电$('#lfm').filemanager('image');

可以使用,但是会打开新窗口,因为它是.filemanager()

(function( $ ){

  $.fn.filemanager = function(type, options) {
    type = type || 'file';

    this.on('click', function(e) {
      var route_prefix = (options && options.prefix) ? options.prefix : '/laravel-filemanager';
      localStorage.setItem('target_input', $(this).data('input'));
      localStorage.setItem('target_preview', $(this).data('preview'));
      window.open(route_prefix + '?type=' + type, 'FileManager', 'width=900,height=600');
      window.SetUrl = function (url, file_path) {
          //set the value of the desired input to image url
          var target_input = $('#' + localStorage.getItem('target_input'));
          target_input.val(file_path).trigger('change');

          //set or change the preview image src
          var target_preview = $('#' + localStorage.getItem('target_preview'));
          target_preview.attr('src', url).trigger('change');
      };
      return false;
    });
  }

})(jQuery);

现在更改:

window.open(route_prefix + '?type=' + type, 'FileManager', 'width=900,height=600');

收件人:

$('iframe').attr('src', route_prefix + '?type=' + type);

是否可以根据需要将Filemanager附加到iframe,但是当我单击iframe中的图像时,它会在新标签页中打开图像,因为它正在设置新的url但跳过了脚本?

我想我可以在iframe中打开图片网址,但不是...

您也许知道该怎么做?

谢谢

1 个答案:

答案 0 :(得分:0)

我找到了满足我需求的答案,虽然还没有完成,但可以根据需要进行操作:

从vendor /..../ js文件夹中打开script.js,并在您使用任何编辑器(cke,mce等)查找/ else语句的情况下更改useFIle函数,如果没有,则直接打开图片在新窗口中。

我删除了该选项并添加了它:

// parent.document.getElementById(field_name).value = url;
    var target_input = parent.document.getElementById(localStorage.getItem('target_input'));
    target_input.value = url;

    //set or change the preview image src
    var target_preview = parent.document.getElementById(localStorage.getItem('target_preview'));
    target_preview.src = url;

从我的问题中,您可以看到jquery-plugin,用于将laravel-filemanager打开到iframe中并向本地存储添加元素。

我用iframe中localstorage的元素在输入中附加了url,并在holder中显示了图像。

现在,我将对此进行一些更改,因为我不想离开该脚本,因为该脚本用于该URL上的完整经理页面。我将在uri中添加另一个字段,以便可以说该网址由iframe打开,默认情况下使用someOtherFUnction而不是useFile函数。