// Generated by CoffeeScript 1.6.3
jQuery(document).ready(function($) {
var MediaFrame;
window.mpp_selectImage = function(id, aff_link) {
var a, m, s;
if (aff_link == null) {
aff_link = false;
}
m = wp.media.editor.get(wpActiveEditor);
m.setState('insert');
m.content.mode('browse');
m.views._views[".media-frame-content"][0].views._views[""][1].collection.props.set({
ignore: +(new Date())
});
s = m.state('insert').get('selection');
s.reset([]);
a = wp.media.attachment(id);
return a.fetch({
success: function(model, response, options) {
return s.add(a);
}
});
};
if (!(typeof wp !== "undefined" && wp !== null ? wp.media : void 0)) {
return;
}
window.mpp_syncSearch = {
sync: true,
search: '',
filters: ['mpp_search_filter_photo']
};
window.add_stock_photo = false;
$('.add-stock-photo').on('click', function() {
window.add_stock_photo = true;
return $('.insert-media').trigger('click');
});
wp.media.controller.MPP = wp.media.controller.State.extend({
initialize: function() {
return this;
},
refresh: function() {
return this.frame.toolbar.get().refresh();
},
_renderTitle: function(view) {
return view.$el.html(this.get('headerTitle'));
},
_renderMenu: function(view) {
var menuItem, priority, title;
menuItem = view.get('menuItem');
title = this.get('title');
priority = this.get('priority');
if (!menuItem) {
menuItem = {
html: title
};
}
if (priority) {
menuItem.priority = priority;
}
return view.set(this.id, menuItem);
}
});
wp.media.view.MPP = wp.media.View.extend({
template: wp.media.template('mpp-content'),
initialize: function() {
return this.module = this.options.module;
},
render: function() {
return this;
}
});
wp.media.view.Toolbar.MPP = wp.media.view.Toolbar.extend({
initialize: function() {
return wp.media.view.Toolbar.prototype.initialize.apply(this, arguments);
},
refresh: function() {
var $img_logo, iframe, module, state, _i, _len, _ref;
wp.media.view.Toolbar.prototype.refresh.apply(this, arguments);
state = this.controller.state();
_ref = Plugin123RF.modules;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
module = _ref[_i];
if (state.id === 'mpp-' + module.name) {
this.secondary.$el.html(wp.media.template('mpp-loader'));
window.mpp_loader = this.secondary.$el.find('.mpp_loader');
$img_logo = $('').attr('src', module.logo).css('margin-top', '13px');
this.primary.$el.html($img_logo);
iframe = this.controller.$el.find('.mpp-iframe-' + module.name);
if (iframe.length > 0) {
iframe[0].contentWindow.mpp_checkStatus();
}
}
}
return this;
}
});
MediaFrame = wp.media.view.MediaFrame.Post;
return wp.media.view.MediaFrame.Post = MediaFrame.extend({
initialize: function() {
var module, _i, _j, _len, _len1, _ref, _ref1, _results,
_this = this;
_ref = Plugin123RF.modules;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
module = _ref[_i];
delete wp.media.view.settings.tabs[module.name];
}
MediaFrame.prototype.initialize.apply(this, arguments);
this.on('deactivate', function() {
var iframe, _j, _len1, _ref1;
_ref1 = Plugin123RF.modules;
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
module = _ref1[_j];
if (_this.state().id === 'mpp-' + module.name) {
iframe = _this.$el.find('.mpp-iframe-' + module.name);
if (iframe.length > 0) {
window.mpp_syncSearch = iframe[0].contentWindow.mpp_syncSearch();
}
}
}
return _this.$el.find('.mpp-frame-content').hide();
});
this.on('activate', function() {
return window.mpp_currentState = _this.state().id;
});
this.on('open', function() {
var id;
id = 'mpp-Plugin123RF_depositphotos';
if (_this.states.where({
id: id
}).length > 0 && window.add_stock_photo) {
window.add_stock_photo = false;
return _this.setState(id);
}
});
_ref1 = Plugin123RF.modules;
_results = [];
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
module = _ref1[_j];
this.states.remove(this.states.where({
id: 'iframe:' + module.name
}));
this.states.add([
new wp.media.controller.MPP({
id: 'mpp-' + module.name,
menu: 'default',
content: 'mpp-' + module.name,
toolbar: 'mpp-' + module.name,
title: '
' + module.title + (module["new"] ? '' + Plugin123RF.text["new"] + '' : ''),
headerTitle: '
' + module.title + (module["new"] ? '' + Plugin123RF.text["new"] + '' : ''),
priority: 200,
type: 'link'
})
]);
this.on('content:render:mpp-' + module.name, _.bind(this.moduleContent, this, module));
_results.push(this.on('toolbar:create:mpp-' + module.name, this.createToolbar, this));
}
return _results;
},
moduleContent: function(module) {
var content, def_content, iframe, view;
this.$el.addClass('hide-router');
if (!this.$el.find('.mpp-frame-content-' + module.name).length) {
iframe = '';
def_content = this.$el.find('.media-frame-content');
content = $('