/* global FusionPageBuilderElements, fusionAllElements */ var FusionPageBuilder = FusionPageBuilder || {}; ( function() { jQuery( document ).ready( function() { // Counter box child View FusionPageBuilder.fusion_counter_box = FusionPageBuilder.ChildElementView.extend( { /** * Runs after view DOM is patched. * * @since 2.0 * @return {void} */ afterPatch: function() { this._refreshJs(); if ( 'undefined' !== typeof this.model.attributes.selectors ) { this.model.attributes.selectors[ 'class' ] += ' ' + this.className; this.setElementAttributes( this.$el, this.model.attributes.selectors ); } }, /** * 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 ); } }, /** * Modify template attributes. * * @since 2.0 * @param {Object} atts - The attributes. * @return {Object} */ filterTemplateAtts: function( atts ) { var counterBoxContainer, elementContent = atts.values.element_content, parent = this.model.get( 'parent' ), parentModel = FusionPageBuilderElements.find( function( model ) { return model.get( 'cid' ) == parent; } ), parentValues = jQuery.extend( true, {}, fusionAllElements.fusion_counters_box.defaults, _.fusionCleanParameters( parentModel.get( 'params' ) ) ), counterBoxShortcodeContent, counterWrapper; // Validate values and extras. this.validateValues( atts.values, atts.params ); this.validateParentValues( parentValues ); counterBoxContainer = this.buildContainerAtts(); counterWrapper = this.buildCounterWrapper( atts.values, parentValues ); counterBoxShortcodeContent = this.buildContentAttr(); this.setSelectors( atts.values, parentValues ); // Reset attribute objet. atts = {}; // Create attribute objects. atts.counterBoxContainer = counterBoxContainer; atts.counterWrapper = counterWrapper; atts.counterBoxShortcodeContent = counterBoxShortcodeContent; // Any extras that need passed on. atts.cid = this.model.get( 'cid' ); atts.parent = parent; atts.output = elementContent; return atts; }, /** * Modifies values. * * @since 2.0 * @param {Object} values - The values. * @param {Object} params - The parameters. * @return {void} */ validateValues: function( values, params ) { values = jQuery.extend( true, {}, fusionAllElements.fusion_counter_box.defaults, _.fusionCleanParameters( params ) ); values.value = values.value.replace( ',', '.' ); values[ 'float' ] = values.value.split( '.' ); if ( 'undefined' !== typeof values[ 'float' ][ 1 ] ) { values.decimals = values[ 'float' ][ 1 ].length; } }, /** * Modifies parent values. * * @since 2.0 * @param {Object} parentValues - The parent values. * @return {void} */ validateParentValues: function( parentValues ) { parentValues.title_size = _.fusionValidateAttrValue( parentValues.title_size, '' ); parentValues.icon_size = _.fusionValidateAttrValue( parentValues.icon_size, '' ); parentValues.body_size = _.fusionValidateAttrValue( parentValues.body_size, '' ); parentValues.columns = Math.min( 6, parentValues.columns ); }, /** * Builds attributes. * * @since 2.0 * @return {Object} */ buildContainerAtts: function() { var counterBoxContainer = { class: 'counter-box-container' }; return counterBoxContainer; }, /** * Builds the HTML for the wrapper element. * * @since 2.0 * @param {Object} values - The values. * @param {Object} parentValues - The parent element values. * @return {string} */ buildCounterWrapper: function( values, parentValues ) { var unitOutput = values.unit ? '' + values.unit + '' : '', initValue = ( 'up' === values.direction ) ? 0 : values.value, iconOutput = '', decimals = 0, counter, selectedIcon, counterBoxShortcodeCounter, counterBoxShortcodeCounterContainer, counterBoxShortcodeIcon, decimalsValue; values.value = values.value.replace( ',', '.' ); decimalsValue = values.value.split( '.' ); if ( 'undefined' !== typeof decimalsValue[ 1 ] ) { decimals = decimalsValue[ 1 ].length; } // counterBoxShortcodeCounter Attributes. counterBoxShortcodeCounter = { class: 'display-counter', 'data-value': values.value, 'data-delimiter': values.delimiter, 'data-direction': values.direction, 'data-decimals': decimals }; // Make value editable. counterBoxShortcodeCounter = _.fusionInlineEditor( { cid: this.model.get( 'cid' ), param: 'value', toolbar: false, 'disable-return': true, 'disable-extra-spaces': true }, counterBoxShortcodeCounter ); counter = '' + initValue + ''; if ( values.icon || parentValues.icon ) { selectedIcon = ( values.icon ) ? values.icon : parentValues.icon; counterBoxShortcodeIcon = { class: 'counter-box-icon fontawesome-icon ' + _.fusionFontAwesome( selectedIcon ), 'aria-hidden': 'true' }; iconOutput = ''; } counter = ( 'prefix' === values.unit_pos ) ? iconOutput + unitOutput + counter : iconOutput + counter + unitOutput; // counterBoxShortcodeCounterContainer Atributes. counterBoxShortcodeCounterContainer = { class: 'content-box-percentage content-box-counter' }; return '