Множественное вольерное перо

У меня проблема с интеграцией Aviary Feather. В моем javascript мне нужно использовать Feathers следующим образом:

// Aviary init
var featherProductEditor = new Aviary.Feather({
  apiKey: 'myapykey',
  apiVersion: 3,
  theme: 'dark',
  tools: 'all',
  appendTo: '',
  onSave: function(imageID, newURL) {
    // Do things for featherProductEditor
    console.log('featherProductEditor');
    // Close the editor
    featherProductEditor.close();
  }
});

// Aviary init
var featherContentBlockEditor = new Aviary.Feather({
  apiKey: 'myapykey',
  apiVersion: 3,
  theme: 'light',
  tools: 'all',
  appendTo: '',
  onSave: function(imageID, newURL) {
    // Do things for featherContentBlockEditor
    console.log('featherContentBlockEditor');
    // Close the editor
    featherContentBlockEditor.close();
  }
});

Тогда я зову двух Перьев

featherProductEditor.launch({ ....

и

featherContentBlockEditor.launch({ ....

но единственный вызываемый обратный вызов "onSave*:" является вторым из "featherContentBlockEditor" var

Почему? Как я могу это решить?


person albertopriore    schedule 06.06.2014    source источник
comment
Пробовали ли вы вызывать обратные вызовы onError или onReady вместо onSave?   -  person T.S.    schedule 12.06.2014
comment
Да я уже пробовал, onError ничего не возвращает. OnReady всегда вызывает инициализацию второго пера.   -  person albertopriore    schedule 12.06.2014
comment
Что вы предоставляете в x.launch({ ...? Поскольку этот объект является переопределением конфигурации, было бы неплохо узнать, что там.   -  person Ingmars    schedule 18.06.2014


Ответы (3)


Что касается вашего первого вопроса, почему только второй onSave называется ?

Внутри Aviary Web SDK хранит конфигурацию пера в AV.launchData, а AV является псевдонимом глобальной переменной Aviary. Это фрагмент кода из функции Aviary.Feather:

AV.Feather = function (config) {
    ...
    AV.launchData = AV.util.extend(AV.baseConfig, config);
    ...
}

Итак, это означает, что конфигурация featherContentBlockEditor переопределит конфигурацию featherProductEditor.

Вы можете убедиться в этом, добавив AV.launchData.onSave() после создания каждого пера.

Что касается вашего второго вопроса, как я могу решить эту проблему?

Нет, без взлома SDK нельзя. Вот как работает Aviary Web SDK, определите только один экземпляр Aviary.Feather на страницу.

person merlin    schedule 19.06.2014

Как вы можете решить эту проблему?

Вы можете использовать imageID, чтобы определить, какой экземпляр Aviary вызвал событие onSave.

  onSave: function(imageID, newURL) {
    if(imageID === 'productImg') {
      // Do things for featherFeatureEditor
      console.log('featherProductEditor');
    } else {
      // Do things for featherContentBlockEditor
      console.log('featherContentBlockEditor');
    }
    // Close the editor
    featherContentBlockEditor.close();
  }

Используйте image:'productImg' для конфигураций запуска образа вашего продукта.

person Laurence Lord    schedule 11.09.2015

У вас может быть только один экземпляр редактора Aviary на данной странице, но вы можете повторно использовать его, вызвав:

  editor.close(true); // passing true forces an immediate close without triggering shutdown animation
  editor.launch({ image: new_id, url: new_url });
person ari    schedule 30.10.2014