1

我正在使用最新版本的 TinyMCE,并且我想在用户单击插入图像时集成 Google Drive Picker。

从 TinyMCE 文档中,我看到我应该使用file_browser_callback参数,但我遇到了几个问题。首先,我设法附加了谷歌选择器,但插入图像弹出窗口停留在顶部,我无法选择文件。即使我解决了这个问题,如何从 Google Picker 回调函数中设置文本框值?下面你可以看到我的代码,Google Picker 代码非常标准,所以我不会粘贴它。

var picker;

tinymce.init({
    //other init parameters...
    file_browser_callback: function(field_name, url, type, win) {
        picker.setVisible(true);
        win.document.getElementById(field_name).value = 'my browser value';
    }
});

function createPicker() {
    // Here I build the Picker...
    // var picker = ...
}

function pickerCallback(data) {
    //TODO: Find a way to set textbox value with the URL of the Image selected from Drive
}

在此处输入图像描述

4

1 回答 1

1

我认为您可以在调用时隐藏模式createPicker()

function createPicker() {
  document.getElementById('modal_id').style.display = 'none';
  // your picker code here!
}

然后在收到回调后将其显示回来,即pickerCallback(data)

function pickerCallback(data) {
  document.getElementById('modal_id').style.display = 'block';
  var url = 'nothing';
  if (data[google.picker.Response.ACTION] == google.picker.Action.PICKED) {
    var doc = data[google.picker.Response.DOCUMENTS][0];
    url = doc[google.picker.Document.URL];
  }
  // set the input text value with the URL:
  document.getElementById('source_input_id').value = url;
}

更改modal_id为您的模式的 div id 和source_input_id您的源输入字段的 id。

于 2014-10-09T19:29:01.783 回答