';
}
}
// Update the data object.
this._data.html = html.html();
this._data.scriptsStyles = scriptsStyles;
},
/**
* Adds the new HTML to the page.
*
* @since 1.7
* @access private
* @method _addNewHTML
*/
_addNewHTML: function()
{
var siblings;
// Add HTML for a partial refresh.
if ( this._data.partial ) {
// If data.nodeParent is present, we have a new node.
if ( this._data.nodeParent ) {
// Get sibling rows.
if ( this._data.nodeParent.hasClass( 'fl-builder-content' ) ) {
siblings = this._data.nodeParent.find( '.fl-row' );
}
// Get sibling column groups.
else if ( this._data.nodeParent.hasClass( 'fl-row-content' ) ) {
siblings = this._data.nodeParent.find( ' > .fl-col-group' );
}
// Get sibling modules.
else {
siblings = this._data.nodeParent.find( ' > .fl-col-group, > .fl-module' );
}
// Add the new node.
if ( 0 === siblings.length || siblings.length == this._data.nodePosition ) {
this._data.nodeParent.append( this._data.html );
}
else {
siblings.eq( this._data.nodePosition ).before( this._data.html );
}
}
// We must be refreshing an existing node.
else {
this._content.after( this._data.html );
this._content.remove();
}
}
// Add HTML for a full refresh.
else {
this._content.append( this._data.html );
}
},
/**
* Removes unnecessary JS and CSS assets from the layout.
*
* @since 1.7
* @access private
* @method _cleanAssets
*/
_cleanNewAssets: function()
{
var nodeId = null,
self = this;
// Remove duplicate assets from _data.html.
this._data.html = this._removeDuplicateAssets( this._data.html );
// Remove duplicate assets from _data.scriptsStyles.
if ( this._data.scriptsStyles && '' !== this._data.scriptsStyles ) {
this._data.scriptsStyles = this._removeDuplicateAssets( this._data.scriptsStyles );
}
// Remove all partial JS and CSS if this is a full render.
if ( ! this._data.partial ) {
$( '#fl-builder-partial-refresh-js' ).remove();
$( '.fl-builder-node-scripts-styles' ).remove();
}
// Else, remove assets that aren't needed.
else {
$( '.fl-builder-node-scripts-styles' ).each( function() {
if ( self._data.html.indexOf( 'fl-node-' + $( this ).data( 'node' ) ) > -1 ) {
$( this ).remove();
}
} );
}
},
/**
* Removes JS and CSS that is already on the page
* from the provided HTML content.
*
* @since 1.7
* @access private
* @method _removeDuplicateAssets
* @param {String} html The HTML content to remove assets from.
* @return {String} The cleaned HTML content.
*/
_removeDuplicateAssets: function( html )
{
var cleaned = $( '
' + html + '
' ),
src = '',
script = null,
href = '',
link = null,
loc = window.location,
origin = loc.protocol + '//' + loc.hostname + ( loc.port ? ':' + loc.port : '' );
// Remove duplicate scripts.
cleaned.find( 'script' ).each( function() {
src = $( this ).attr( 'src' );
if ( 'undefined' != typeof src ) {
src = src.replace( origin, '' );
script = $( 'script[src*="' + src + '"]' );
if ( script.length > 0 ) {
$( this ).remove();
}
}
});
// Remove duplicate links.
cleaned.find( 'link' ).each( function() {
href = $( this ).attr( 'href' );
if ( 'undefined' != typeof href ) {
href = href.replace( origin, '' );
link = $( 'link[href*="' + href + '"]' );
if ( link.length > 0 ) {
$( this ).remove();
}
}
});
return cleaned.html();
},
/**
* Adds the new scripts and styles to the page.
*
* @since 1.7
* @access private
* @method _addNewScriptsStyles
*/
_addNewScriptsStyles: function()
{
if ( this._data.scriptsStyles && '' !== this._data.scriptsStyles ) {
this._body.append( this._data.scriptsStyles );
}
},
/**
* Adds the new layout JS to the page.
*
* @since 1.7
* @access private
* @method _addNewJS
*/
_addNewJS: function()
{
setTimeout( $.proxy( function() {
if ( this._newJs ) {
this._head.append( this._newJs );
}
}, this ), 50 );
},
/**
* Called when the render has been completed.
*
* @since 1.7
* @access private
* @method _complete
*/
_complete: function()
{
FLBuilder._setupEmptyLayout();
FLBuilder._highlightEmptyCols();
FLBuilder._initDropTargets();
FLBuilder._initSortables();
FLBuilder._resizeLayout();
FLBuilder._initMediaElements();
FLBuilderLayout.init();
FLBuilderResponsiveEditing.refreshPreview();
this._body.height( 'auto' );
}
};
})(jQuery);