Created
May 8, 2016 19:30
-
-
Save maximspokoiny/34ad60ad90944f8a80c6fc093873a807 to your computer and use it in GitHub Desktop.
Fix js_composer element render function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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