/* global fusionAllElements, FusionPageBuilderElements */
/* eslint no-unused-vars: 0 */
var FusionPageBuilder = FusionPageBuilder || {};
( function() {
jQuery( document ).ready( function() {
// Counter flip box view
FusionPageBuilder.fusion_flip_box = FusionPageBuilder.ChildElementView.extend( {
/**
* Runs during render() call.
*
* @since 2.0
* @return {void}
*/
onRender: function() {
if ( 'undefined' !== typeof this.model.attributes.selectors ) {
this.model.attributes.selectors[ 'class' ] += ' ' + this.className;
this.setElementAttributes( this.$el, this.model.attributes.selectors );
}
},
/**
* Runs after view DOM is patched.
*
* @since 2.0
* @return {void}
*/
afterPatch: function() {
if ( 'undefined' !== typeof this.model.attributes.selectors ) {
this.model.attributes.selectors[ 'class' ] += ' ' + this.className;
this.setElementAttributes( this.$el, this.model.attributes.selectors );
}
// Using non debounced version for smoothness.
this.refreshJs();
},
/**
* Modify template attributes.
*
* @since 2.0
* @param {Object} atts - The attributes.
* @return {Object}
*/
filterTemplateAtts: function( atts ) {
var computedAtts;
atts.usingDynamicParent = this.isParentHasDynamicContent( atts.parentValues );
if ( atts.usingDynamicParent ) {
atts.values.usingDynamicParent = true;
}
computedAtts = this.computeAtts( atts.values );
atts.cid = this.model.get( 'cid' );
atts.parent = this.model.get( 'parent' );
atts.flipBoxShortcodeBackBox = computedAtts.flipBoxShortcodeBackBox;
atts.flipBoxAttributes = computedAtts.flipBoxAttributes;
atts.flipBoxShortcodeFrontBox = computedAtts.flipBoxShortcodeFrontBox;
atts.icon_output = computedAtts.icon_output;
atts.title_front_output = computedAtts.title_front_output;
atts.title_back_output = computedAtts.title_back_output;
atts.icon_output = computedAtts.icon_output;
return atts;
},
/**
* Builds attributes.
*
* @since 2.0
* @param {Object} values - The values.
* @return {Object}
*/
computeAtts: function( values ) {
var parent = this.model.get( 'parent' ),
parentModel = FusionPageBuilderElements.find( function( model ) {
return model.get( 'cid' ) == parent;
} ),
parentValues = 'undefined' !== typeof parentModel ? jQuery.extend( true, {}, fusionAllElements.fusion_flip_boxes.defaults, _.fusionCleanParameters( parentModel.get( 'params' ) ) ) : {},
params = this.model.get( 'params' ),
style = '',
flipBoxAttributes = '',
flipBoxShortcode,
flipBoxShortcodeIcon = {
'aria-hidden': 'true'
},
iconOutput = '',
animations = '',
titleTag = '',
flipBoxShortcodeGrafix = '',
flipBoxShortcodeHeadingFront = '',
titleFrontOutput = '',
flipBoxShortcodeHeadingBack = '',
flipBoxShortcodeBackBox = '',
titleBackOutput = '',
frontInner = '',
columns = '',
flipBoxShortcodeFrontBox,
atts,
alpha;
values.border_size = _.fusionValidateAttrValue( values.border_size, 'px' );
values.border_radius = _.fusionValidateAttrValue( values.border_radius, 'px' );
// Case when image is set on parent element and icon on child element.
if ( ( 'undefined' === typeof params.image || '' === params.image ) && ( 'undefined' !== typeof params.icon && '' !== params.icon ) ) {
values.image = '';
}
// Backwards compatibility for when we had image width and height params.
if ( 'undefined' !== typeof params.image_width && params.image_width ) {
values.image_width = params.image_width;
} else {
values.image_width = values.image_max_width;
}
values.image_width = _.fusionValidateAttrValue( values.image_width, '' );
if ( 'undefined' !== typeof values.image && ( '' !== values.image || '' !== values.image_id ) ) {
if ( -1 === parseInt( values.image_width ) ) {
values.image_width = '35';
}
values.image_height = values.image_width;
} else {
values.image_width = '' === values.image_width ? '35' : values.image_width;
values.image_height = '35';
}
if ( 'round' === values.border_radius ) {
values.border_radius = '50%';
}
style = '';
iconOutput = '';
titleFrontOutput = '';
titleBackOutput = '';
flipBoxAttributes = {
class: 'fusion-flip-box',
tabindex: 0
};
flipBoxAttributes[ 'class' ] += ' flip-' + values.flip_direction;
if ( values.animation_type ) {
flipBoxAttributes = _.fusionAnimations( values, flipBoxAttributes );
}
if ( values.image && '' !== values.image ) {
iconOutput = '';
} else if ( values.icon ) {
if ( values.image ) {
flipBoxShortcodeIcon[ 'class' ] = 'image';
} else if ( values.icon ) {
flipBoxShortcodeIcon[ 'class' ] = _.fusionFontAwesome( values.icon );
}
if ( values.icon_flip ) {
flipBoxShortcodeIcon[ 'class' ] += ' fa-flip-' + values.icon_flip;
}
if ( values.icon_rotate ) {
flipBoxShortcodeIcon[ 'class' ] += ' fa-rotate-' + values.icon_rotate;
}
if ( 'yes' === values.icon_spin ) {
flipBoxShortcodeIcon[ 'class' ] += ' fa-spin';
}
iconOutput = '';
}
if ( '' !== iconOutput ) {
flipBoxShortcodeGrafix = {
class: 'flip-box-grafix'
};
if ( ! values.image ) {
if ( 'yes' === values.circle ) {
flipBoxShortcodeGrafix[ 'class' ] += ' flip-box-circle';
} else {
flipBoxShortcodeGrafix[ 'class' ] += ' flip-box-no-circle';
}
} else {
flipBoxShortcodeGrafix[ 'class' ] += ' flip-box-image';
}
iconOutput = '