2013-06-02 00:38:23 +00:00
|
|
|
define([
|
|
|
|
"jquery",
|
|
|
|
"underscore",
|
2013-06-22 23:48:57 +00:00
|
|
|
"classes/Provider",
|
2013-06-02 00:38:23 +00:00
|
|
|
"core",
|
2013-06-10 21:22:32 +00:00
|
|
|
"providers/gplusProvider"
|
2013-06-22 23:48:57 +00:00
|
|
|
], function($, _, Provider, core) {
|
2013-06-02 00:38:23 +00:00
|
|
|
|
|
|
|
var mediaImporter = {};
|
|
|
|
|
|
|
|
// Create a map with providerId: providerModule
|
|
|
|
var providerMap = _.chain(arguments).map(function(argument) {
|
2013-06-22 23:48:57 +00:00
|
|
|
return argument instanceof Provider && [
|
2013-06-02 00:38:23 +00:00
|
|
|
argument.providerId,
|
|
|
|
argument
|
|
|
|
];
|
|
|
|
}).compact().object().value();
|
|
|
|
|
|
|
|
core.onReady(function() {
|
|
|
|
_.each(providerMap, function(provider) {
|
|
|
|
// Import image action links (if any)
|
|
|
|
$(".action-import-image-" + provider.providerId).click(function() {
|
|
|
|
// Take the insertLinkCallback from core module
|
|
|
|
var insertLinkCallback = core.insertLinkCallback;
|
|
|
|
// Unset it to be sure core module will not call it
|
|
|
|
core.insertLinkCallback = undefined;
|
|
|
|
provider.importImage(function(error, imageLink) {
|
|
|
|
if(error) {
|
|
|
|
insertLinkCallback(null);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
insertLinkCallback(imageLink || null);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return mediaImporter;
|
|
|
|
});
|