%PDF- %PDF-
| Direktori : /dom645759/wp-content/plugins/fusion-builder/front-end/views/elements/ |
| Current File : /dom645759/wp-content/plugins/fusion-builder/front-end/views/elements/view-popover.js |
/* global FusionPageBuilderApp, fusionAllElements */
var FusionPageBuilder = FusionPageBuilder || {};
( function() {
jQuery( document ).ready( function() {
// Tooltip View
FusionPageBuilder.fusion_popover = FusionPageBuilder.ElementView.extend( {
/**
* Runs before view DOM is patched.
*
* @since 2.0
* @return {void}
*/
beforePatch: function() {
var $popover = jQuery( '#fb-preview' )[ 0 ].contentWindow.jQuery( this.$el.find( '[data-toggle~="popover"]' ) );
$popover.removeData();
$popover.remove();
if ( jQuery( '#fb-preview' )[ 0 ].contentWindow.jQuery( '.fusion-popover-' + this.model.get( 'cid' ) ).length ) {
jQuery( '#fb-preview' )[ 0 ].contentWindow.jQuery( '.fusion-popover-' + this.model.get( 'cid' ) ).remove();
}
},
/**
* Runs after view DOM is patched.
*
* @since 2.0
* @return {void}
*/
afterPatch: function() {
this._refreshJs();
},
/**
* Modify template attributes.
*
* @since 2.0
* @param {Object} atts - The attributes.
* @return {Object}
*/
filterTemplateAtts: function( atts ) {
var attributes = {};
this.values = atts.values;
attributes.attr = this.computeAttr( atts.values );
attributes.cid = this.model.get( 'cid' );
attributes.parent = this.model.get( 'parent' );
attributes.inline = 'undefined' !== typeof atts.inlineElement;
attributes.content = atts.values.element_content;
attributes.label = window.fusionAllElements[ this.model.get( 'element_type' ) ].name;
attributes.icon = window.fusionAllElements[ this.model.get( 'element_type' ) ].icon;
attributes.popover = atts.values.popover;
return attributes;
},
/**
* Builds attributes.
*
* @since 2.0
* @param {Object} values - The values.
* @return {Object}
*/
computeAttr: function( values ) {
var cssVars = [
'bordercolor',
'title_bg_color',
'textcolor',
'bordercolor',
'content_bg_color'
],
cid = this.model.get( 'cid' ),
atts = {
class: 'fusion-popover popover-' + cid,
'data-style': this.getCssVarsForOptions( cssVars )
},
popoverContent = values.content;
this.values.arrow_color = 'bottom' !== this.values.placement ? this.values.content_bg_color : this.values.title_bg_color;
if ( '' !== this.values.arrow_color ) {
atts[ 'data-style' ] += '--awb-arrowcolor:' + this.values.arrow_color + ';';
}
if ( 'default' === values.placement ) {
values.placement = fusionAllElements.fusion_popover.defaults.placement;
}
if ( '' !== values[ 'class' ] ) {
atts[ 'class' ] += ' ' + values[ 'class' ];
}
if ( '' !== values.id ) {
atts.id = values.id;
}
try {
if ( popoverContent && '' !== popoverContent && FusionPageBuilderApp.base64Encode( FusionPageBuilderApp.base64Decode( popoverContent ) ) === popoverContent ) {
popoverContent = FusionPageBuilderApp.base64Decode( popoverContent );
}
} catch ( error ) {
console.log( error ); // jshint ignore:line
}
// Resolve inline {dynamic_data} tokens in the popover body. The shared inline-DD pipeline
// in view-base.js skips raw_textarea options, so handle them here for this specific param.
if ( 'string' === typeof popoverContent && '' !== popoverContent && -1 !== popoverContent.indexOf( '{' ) ) {
const tokens = popoverContent.match( /\{.*?\}/g );
if ( tokens && tokens.length ) {
const self = this;
_.each( tokens, function( token ) {
const tokenValue = FusionPageBuilderApp.dynamicValues.getValue( { 'data': token } );
if ( tokenValue && 'object' === typeof tokenValue && 'function' === typeof tokenValue.then ) {
tokenValue.then( function() {
if ( tokenValue.responseJSON && null !== tokenValue.responseJSON.content ) {
self.reRender();
}
} );
} else if ( 'undefined' !== typeof tokenValue && false !== tokenValue ) {
popoverContent = popoverContent.split( token ).join( tokenValue );
}
} );
}
}
atts[ 'data-animation' ] = values.animation;
atts[ 'data-class' ] = 'fusion-popover-' + cid;
atts[ 'data-delay' ] = values.delay;
atts[ 'data-placement' ] = values.placement.toLowerCase();
atts[ 'data-title' ] = values.title;
atts[ 'data-toggle' ] = 'popover';
atts[ 'data-trigger' ] = values.trigger;
// The popover box renders this as markup: sanitize it like the PHP render does.
values.popover = _.awbKsesPost( popoverContent );
return atts;
}
} );
} );
}( jQuery ) );