%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-table.js |
/* global AWBTable, AWBTableEditor, fusionAllElements */
/* eslint-disable dot-notation */
/* eslint no-unused-vars: ["error", {"args": "none"}] */
var FusionPageBuilder = FusionPageBuilder || {};
( function() {
jQuery( document ).ready( function() {
// Table Element View.
FusionPageBuilder.fusion_table = FusionPageBuilder.ElementView.extend( {
/**
* Tables saved without a style carry it only in the class of their wrapper div.
* Set it, so the Table Style option shows the style the table has.
*
* @since 3.17
* @return {void}
*/
onInit: function() {
var params = this.model.get( 'params' );
if ( 'undefined' === typeof params.fusion_table_type || '' === params.fusion_table_type ) {
params.fusion_table_type = this.getTableStyle( params, 'string' === typeof params.element_content ? params.element_content : '' );
}
},
/**
* Modify template attributes.
*
* Renders the table as FusionSC_FusionTable::render() does.
*
* @since 2.0
* @param {Object} atts - The attributes.
* @return {Object}
*/
filterTemplateAtts: function( atts ) {
var values = jQuery.extend( true, {}, fusionAllElements.fusion_table.defaults, _.fusionCleanParameters( jQuery.extend( {}, atts.params ) ) ),
content = 'string' === typeof values.element_content ? values.element_content : '',
style = this.getTableStyle( values, content ),
stack = this.stackBreakpoint( values ),
table = this.unwrapContent( content ),
caption = table.match( /<caption\b[^>]*>([\s\S]*?)<\/caption>/i ),
captionText;
captionText = caption ? jQuery( '<div>' ).html( caption[ 1 ].replace( /\[[^\]]*\]/g, '' ) ).text().replace( /\s+/g, ' ' ).trim() : '';
if ( 'undefined' !== typeof AWBTable ) {
table = AWBTable.enhance( table, {
labels: '' !== stack,
tableClass: this.tableClass( values, style, stack )
} );
}
return {
cid: this.model.get( 'cid' ),
element_content: '<div ' + _.fusionGetAttributes( this.buildAttr( values, style, stack, captionText ) ) + '>' + table + '</div>'
};
},
/**
* Gets the style of the table, as FusionSC_FusionTable::get_table_style().
*
* @since 3.17
* @param {Object} values - The params.
* @param {string} content - The element content.
* @return {string}
*/
getTableStyle: function( values, content ) {
var style = 'undefined' !== typeof values.fusion_table_type ? String( values.fusion_table_type ) : '',
match;
if ( '' === style ) {
match = content.match( /^\s*<div\b[^>]*\bclass="[^"]*\btable-([12])\b/i );
style = match ? match[ 1 ] : '';
}
return -1 !== [ 'default', '1', '2' ].indexOf( style ) ? style : 'default';
},
/**
* Removes the wrapper div saved around the table; the element renders its own.
*
* @since 3.17
* @param {string} content - The element content.
* @return {string}
*/
unwrapContent: function( content ) {
var match;
content = content.trim();
match = content.match( /^<div\b[^>]*>([\s\S]*)<\/div>$/i );
return match && -1 !== match[ 1 ].toLowerCase().indexOf( '<table' ) ? match[ 1 ] : content;
},
/**
* The breakpoint below which the rows stack, or empty when the table scrolls, as FusionSC_FusionTable::get_stack_breakpoint().
*
* @since 3.17
* @param {Object} values - The params.
* @return {string}
*/
stackBreakpoint: function( values ) {
if ( 'stack' !== values.responsive_mode ) {
return '';
}
return 'medium' === values.stack_breakpoint ? 'medium' : 'small';
},
/**
* The classes of the table element, as FusionSC_FusionTable::get_table_classes().
*
* @since 3.17
* @param {Object} values - The params.
* @param {string} style - The table style.
* @param {string} stack - The stack breakpoint, empty when the table scrolls.
* @return {string}
*/
tableClass: function( values, style, stack ) {
var classes = [ 'awb-table__table' ];
if ( stack ) {
classes.push( 'awb-table__table--stack-' + stack );
}
// The design options only apply to the Custom style; the others are complete designs.
if ( 'default' !== style ) {
return classes.join( ' ' );
}
if ( 'rows' === values.alternate ) {
classes.push( 'awb-table__table--alternate-rows' );
}
// Typography rules only apply when set, so other tables keep the theme's.
[ 'header', 'cell' ].forEach( function( prefix ) {
var params = [ 'fusion_font_family_' + prefix + '_font', prefix + '_font_size', prefix + '_line_height', prefix + '_letter_spacing', prefix + '_text_transform' ];
if ( params.some( function( param ) {
return values[ param ];
} ) ) {
classes.push( 'awb-table__table--' + prefix + '-typography' );
}
} );
return classes.join( ' ' );
},
/**
* Builds attributes.
*
* @since 2.0
* @param {Object} values - The values object.
* @param {string} style - The table style.
* @param {string} stack - The stack breakpoint, empty when the table scrolls.
* @param {string} captionText - The caption as plain text.
* @return {Object}
*/
buildAttr: function( values, style, stack, captionText ) {
var className = 'table-' + style + ' awb-table',
attr;
// The original styles keep their table-1/table-2 classes.
if ( 'default' === style ) {
className = 'awb-table awb-table--style-default';
if ( -1 !== [ 'all', 'horizontal', 'rows', 'outer', 'none' ].indexOf( values.borders ) ) {
className += ' awb-table--borders-' + values.borders;
}
}
attr = _.fusionVisibilityAtts( values.hide_on_mobile, {
class: className + ( stack ? ' awb-table--stack-' + stack : '' ),
style: this.getStyleVars( values, style )
} );
// Scrolling tables are a region keyboard users can focus and scroll.
if ( ! stack ) {
attr.role = 'region';
attr.tabindex = '0';
attr[ 'aria-label' ] = captionText || ( 'undefined' !== typeof AWBTableEditor ? AWBTableEditor.t( 'table', 'Table' ) : 'Table' );
}
attr = _.fusionAnimations( values, attr );
if ( '' !== values[ 'class' ] ) {
attr[ 'class' ] += ' ' + values[ 'class' ];
}
if ( '' !== values.id ) {
attr.id = values.id;
}
return attr;
},
/**
* Get the css style vars, as FusionSC_FusionTable::get_style_vars().
*
* @since 3.9
* @param {Object} values - The params.
* @param {string} style - The table style.
* @return {string}
*/
getStyleVars: function( values, style ) {
var cssCustomVars = {},
units = [ 'border_size', 'border_radius_top_left', 'border_radius_top_right', 'border_radius_bottom_right', 'border_radius_bottom_left', 'header_font_size', 'header_letter_spacing', 'cell_font_size', 'cell_letter_spacing' ];
this.values = values;
[ 'top', 'right', 'bottom', 'left' ].forEach( function( side ) {
if ( values[ 'margin_' + side ] ) {
cssCustomVars[ 'margin_' + side ] = _.fusionGetValueWithUnit( values[ 'margin_' + side ] );
}
} );
// Stacked rows, in every style.
if ( values.stack_gap ) {
cssCustomVars.table_stack_gap = parseFloat( values.stack_gap ) + 'px';
}
// The Design tab only applies to the Custom style.
if ( 'default' === style ) {
[ 'top', 'right', 'bottom', 'left' ].forEach( function( side ) {
[ '', '_medium', '_small' ].forEach( function( size ) {
units.push( 'cell_padding_' + side + size );
} );
} );
[ 'border_color', 'header_color', 'header_bg_color', 'cell_color', 'cell_bg_color', 'alternate_color', 'alternate_bg_color', 'footer_color', 'footer_bg_color' ].forEach( function( param ) {
if ( values[ param ] ) {
cssCustomVars[ 'table_' + param ] = values[ param ];
}
} );
units.forEach( function( param ) {
if ( values[ param ] ) {
cssCustomVars[ 'table_' + param ] = _.fusionGetValueWithUnit( values[ param ] );
}
} );
[ 'header_line_height', 'header_text_transform', 'cell_line_height', 'cell_text_transform' ].forEach( function( param ) {
if ( values[ param ] ) {
cssCustomVars[ 'table_' + param ] = values[ param ];
}
} );
[ 'header', 'cell' ].forEach( function( prefix ) {
_.each( _.fusionGetFontStyle( prefix + '_font', values, 'object' ), function( value, property ) {
cssCustomVars[ 'table_' + prefix + '_' + property.replace( '-', '_' ) ] = value;
} );
} );
}
return this.getCustomCssVars( cssCustomVars );
}
} );
} );
}( jQuery ) );