/*global redux_change, redux, redux_typography_ajax, WebFont */
/**
* Typography
* Dependencies: google.com, jquery, select2
* Feature added by: Dovy Paukstys - http://simplerain.com/
* Date: 06.14.2013
*
* Rewrite: Kevin Provance (kprovance)
* Date: May 25, 2014,
* And again on: April 4, 2017, for v4.0
*/
(function ( $ ) {
'use strict';
let selVals = [];
let isSelecting = false;
redux.field_objects = redux.field_objects || {};
redux.field_objects.typography = redux.field_objects.typography || {};
redux.field_objects.typography.init = function ( selector ) {
selector = $.redux.getSelector( selector, 'typography' );
$( selector ).each(
function () {
const el = $( this );
let parent = el;
if ( ! el.hasClass( 'redux-field-container' ) ) {
parent = el.parents( '.redux-field-container:first' );
}
if ( parent.is( ':hidden' ) ) {
return;
}
el.each(
function () {
// Init each typography field.
$( this ).find( '.redux-typography-container' ).each(
function () {
const el = $( this );
let parent = el;
let key;
let obj;
let prop;
let fontData;
let val;
let xx;
let reduxTypography;
let family = $( this ).find( '.redux-typography-family' );
const familyData = family.data( 'value' );
let data = [{id: 'none', text: 'none'}];
const thisID = $( this ).find( '.redux-typography-family' ).parents( '.redux-container-typography:first' ).data( 'id' );
let usingGoogleFonts = $( '#' + thisID + ' .redux-typography-google' ).val();
// Set up data array.
const buildData = [];
const fontKids = [];
// User included fonts?
let isUserFonts = $( '#' + thisID + ' .redux-typography-font-family' ).data( 'user-fonts' );
if ( ! el.hasClass( 'redux-field-container' ) ) {
parent = el.parents( '.redux-field-container:first' );
}
if ( parent.is( ':hidden' ) ) {
return;
}
if ( parent.hasClass( 'redux-field-init' ) ) {
parent.removeClass( 'redux-field-init' );
} else {
return;
}
if ( undefined === familyData ) {
family = $( this );
} else if ( '' !== familyData ) {
$( family ).val( familyData );
}
isUserFonts = isUserFonts ? 1 : 0;
// Google font isn't in use?
usingGoogleFonts = usingGoogleFonts ? 1 : 0;
// If custom fonts, push onto array.
if ( undefined !== redux.customfonts ) {
buildData.push( redux.customfonts );
}
// If typekit fonts, push onto array.
if ( undefined !== redux.typekitfonts ) {
buildData.push( redux.typekitfonts );
}
// If standard fonts, push onto array.
if ( undefined !== redux.stdfonts && 0 === isUserFonts ) {
buildData.push( redux.stdfonts );
}
// If user fonts, pull from localize and push into array.
if ( 1 === isUserFonts ) {
//