Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save maximspokoiny/34ad60ad90944f8a80c6fc093873a807 to your computer and use it in GitHub Desktop.
Save maximspokoiny/34ad60ad90944f8a80c6fc093873a807 to your computer and use it in GitHub Desktop.
Fix js_composer element render function
/**
* Convert html into correct element
* @param html
*/
html2element: function(html) {
var attributes = {},
$template;
if (_.isString(html)) {
this.template = _.template(html);
$template = $(this.template(this.model.toJSON(), vc.templateOptions.default).trim());
} else {
this.template = html;
$template = $(this.template(this.model.toJSON(), vc.templateOptions.default).trim());
}
_.each($template.get(0).attributes, function(attr) {
attributes[attr.name] = attr.value;
});
this.$el.attr(attributes).html($template.html());
this.setContent();
this.renderContent();
},
render: function() {
var $shortcode_template_el = $('#vc_shortcode-template-' + this.model.get('shortcode'));
if ($shortcode_template_el.is('script')) {
this.html2element(_.template($shortcode_template_el.html()));
} else {
var params = this.model.get('params');
$.ajax({
type: 'POST',
url: window.ajaxurl,
data: {
action: 'wpb_get_element_backend_html',
data_element: this.model.get('shortcode'),
data_width: _.isUndefined(params.width) ? '1/1' : params.width,
_vcnonce: window.vcAdminNonce
},
dataType: 'html',
context: this
}).done(function(html) {
this.html2element(html);
});
}
this.model.view = this;
this.$controls_buttons = this.$el.find('.vc_controls > :first');
return this;
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment