first commit

This commit is contained in:
CHIEFSOFT\ameye
2023-12-28 16:20:07 -05:00
commit b114fdf4fa
5377 changed files with 1850677 additions and 0 deletions
@@ -0,0 +1,272 @@
module.exports = {
"env": {
"browser": true
},
"extends": "eslint:recommended",
"rules": {
"accessor-pairs": "error",
"array-bracket-newline": "off",
"array-bracket-spacing": "off",
"array-callback-return": "off",
"array-element-newline": "off",
"arrow-body-style": "error",
"arrow-parens": "error",
"arrow-spacing": "error",
"block-scoped-var": "off",
"block-spacing": "off",
"brace-style": "off",
"callback-return": "error",
"camelcase": "off",
"capitalized-comments": "off",
"class-methods-use-this": "error",
"comma-dangle": "off",
"comma-spacing": "off",
"comma-style": [
"error",
"last"
],
"complexity": "off",
"computed-property-spacing": "off",
"consistent-return": "off",
"consistent-this": "off",
"curly": "off",
"default-case": "off",
"dot-location": "off",
"dot-notation": "off",
"eol-last": "off",
"eqeqeq": "off",
"for-direction": "off",
"func-call-spacing": "off",
"func-name-matching": "error",
"func-names": [
"error",
"never"
],
"func-style": "off",
"function-paren-newline": "off",
"generator-star-spacing": "error",
"getter-return": "error",
"global-require": "off",
"guard-for-in": "off",
"handle-callback-err": "error",
"id-blacklist": "error",
"id-length": "off",
"id-match": "error",
"implicit-arrow-linebreak": "error",
"indent": "off",
"indent-legacy": "off",
"init-declarations": "off",
"jsx-quotes": "error",
"key-spacing": "off",
"keyword-spacing": "off",
"line-comment-position": "off",
"linebreak-style": "off",
"lines-around-comment": "off",
"lines-around-directive": "off",
"lines-between-class-members": "error",
"max-depth": "off",
"max-len": "off",
"max-lines": "off",
"max-nested-callbacks": "error",
"max-params": "off",
"max-statements": "off",
"max-statements-per-line": "off",
"multiline-comment-style": "off",
"multiline-ternary": "off",
"new-parens": "off",
"newline-after-var": "off",
"newline-before-return": "off",
"newline-per-chained-call": "off",
"no-alert": "error",
"no-array-constructor": "error",
"no-await-in-loop": "error",
"no-bitwise": "off",
"no-buffer-constructor": "error",
"no-caller": "error",
"no-catch-shadow": "off",
"no-confusing-arrow": "error",
"no-continue": "off",
"no-div-regex": "error",
"no-duplicate-imports": "error",
"no-else-return": "off",
"no-empty-function": "off",
"no-eq-null": "off",
"no-eval": "error",
"no-extend-native": "off",
"no-extra-bind": "error",
"no-extra-label": "error",
"no-extra-parens": "off",
"no-floating-decimal": "off",
"no-implicit-coercion": [
"error",
{
"boolean": false,
"number": false,
"string": false
}
],
"no-implicit-globals": "off",
"no-implied-eval": "error",
"no-inline-comments": "off",
"no-inner-declarations": [
"error",
"functions"
],
"no-invalid-this": "off",
"no-iterator": "error",
"no-label-var": "off",
"no-labels": "off",
"no-lone-blocks": "off",
"no-lonely-if": "off",
"no-loop-func": "error",
"no-magic-numbers": "off",
"no-mixed-operators": "off",
"no-mixed-requires": "error",
"no-multi-assign": "off",
"no-multi-spaces": "off",
"no-multi-str": "error",
"no-multiple-empty-lines": "off",
"no-native-reassign": "error",
"no-negated-condition": "off",
"no-negated-in-lhs": "error",
"no-nested-ternary": "off",
"no-new": "off",
"no-new-func": "error",
"no-new-object": "error",
"no-new-require": "error",
"no-new-wrappers": "error",
"no-octal-escape": "error",
"no-param-reassign": "off",
"no-path-concat": "error",
"no-plusplus": "off",
"no-process-env": "error",
"no-process-exit": "error",
"no-proto": "error",
"no-prototype-builtins": "off",
"no-restricted-globals": "error",
"no-restricted-imports": "error",
"no-restricted-modules": "error",
"no-restricted-properties": "error",
"no-restricted-syntax": "error",
"no-return-assign": "off",
"no-return-await": "error",
"no-script-url": "error",
"no-self-assign": [
"error",
{
"props": false
}
],
"no-self-compare": "off",
"no-sequences": "off",
"no-shadow": "off",
"no-shadow-restricted-names": "error",
"no-spaced-func": "off",
"no-sync": "error",
"no-tabs": "off",
"no-template-curly-in-string": "error",
"no-ternary": "off",
"no-throw-literal": "off",
"no-undef-init": "error",
"no-undefined": "error",
"no-underscore-dangle": "off",
"no-unmodified-loop-condition": "error",
"no-unneeded-ternary": [
"error",
{
"defaultAssignment": true
}
],
"no-unused-expressions": "off",
"no-use-before-define": "off",
"no-useless-call": "off",
"no-useless-computed-key": "error",
"no-useless-concat": "off",
"no-useless-constructor": "error",
"no-useless-rename": "error",
"no-useless-return": "off",
"no-var": "off",
"no-void": "off",
"no-warning-comments": "off",
"no-whitespace-before-property": "error",
"no-with": "error",
"nonblock-statement-body-position": [
"error",
"any"
],
"object-curly-newline": "off",
"object-curly-spacing": "off",
"object-property-newline": "off",
"object-shorthand": "off",
"one-var": "off",
"one-var-declaration-per-line": "off",
"operator-assignment": "off",
"operator-linebreak": [
"error",
"after"
],
"padded-blocks": "off",
"padding-line-between-statements": "error",
"prefer-arrow-callback": "off",
"prefer-const": "error",
"prefer-destructuring": "off",
"prefer-numeric-literals": "error",
"prefer-promise-reject-errors": "error",
"prefer-reflect": "off",
"prefer-rest-params": "off",
"prefer-spread": "off",
"prefer-template": "off",
"quote-props": "off",
"quotes": "off",
"radix": [
"error",
"always"
],
"require-await": "error",
"require-jsdoc": "off",
"rest-spread-spacing": "error",
"semi": "off",
"semi-spacing": "off",
"semi-style": [
"error",
"last"
],
"sort-imports": "error",
"sort-keys": "off",
"sort-vars": "off",
"space-before-blocks": "off",
"space-before-function-paren": "off",
"space-in-parens": "off",
"space-infix-ops": "off",
"space-unary-ops": "off",
"spaced-comment": "off",
"strict": "off",
"switch-colon-spacing": "off",
"symbol-description": "error",
"template-curly-spacing": "error",
"template-tag-spacing": "error",
"unicode-bom": [
"error",
"never"
],
"valid-jsdoc": "off",
"valid-typeof": [
"error",
{
"requireStringLiterals": false
}
],
"vars-on-top": "off",
"wrap-iife": "off",
"wrap-regex": "off",
"yield-star-spacing": "error",
"yoda": "off"
},
"globals": {
"wp": true,
"jQuery": true,
"_":true,
'FlatSkopeLocalizedData' : true,
'serverControlParams' : true
}
};
@@ -0,0 +1,136 @@
var CZRFlatSkopeModuleMths = CZRFlatSkopeModuleMths || {};
( function ( api, $, _ ) {
$.extend( CZRFlatSkopeModuleMths, {
// fired in module::initialize
scheduleSkopeReactions : function() {
var module = this;
// @params looks like :
// {
// newSkopes : newSkopes,
// previousSkopes : previousSkopes
// }
api.bind( 'active-skopes-updated', function( params ) {
console.log( 'active-skopes-updated', params, module.SKOPE_LEVEL );
params = _.extend( { newSkopes : {}, previousSkopes : {} }, params );
if ( ! _.has( params.newSkopes, module.SKOPE_LEVEL ) ) {
api.errorLog( 'active-skopes-updated => ' + module.SKOPE_LEVEL + ' was not found in the skope list' );
return;
} else {
module.isReady.then( function() {
// Always update the local skope-id in the pre-item
if ( module.preItem && ! _.isEmpty( module.preItem.czr_Input ) && module.preItem.czr_Input.has('skope-id') ) {
module.preItem.czr_Input( 'skope-id' )( params.newSkopes[ module.SKOPE_LEVEL ] );
}
// Print the contextual items only
//module.refreshContextualItems();
// Display the parent control when relevant
module.control.active( '_skope_not_set_' != params.newSkopes[ module.SKOPE_LEVEL ] );
});
// Print a bottom notification in all controls wrapper
//module.printSkopeInfoInControls();
}
});
},
//This method react to the skope change
// => reinstantiates all items based on the current collection
// refreshContextualItems : function() {
// var module = this;
// //Remove item views and instances
// module.czr_Item.each( function( _itm ) {
// if ( ! _.isEmpty( _itm.container ) && 0 < _itm.container.length ) {
// $.when( _itm.container.remove() ).done( function() {
// //Remove item instances
// module.czr_Item.remove( _itm.id );
// });
// } else {
// //Remove item instances
// module.czr_Item.remove( _itm.id );
// }
// });
// // Reset the item collection
// // => the collection listeners will be setup after populate, on 'items-collection-populated'
// var _collection_ = $.extend( true, [], module.itemCollection() );
// // reset the collection
// module.itemCollection = new api.Value( [] );
// module.populateSavedItemCollection( _collection_ );
// },
// // invoked when module.ready() and api.czr_activeSkopes updated
// printSkopeInfoInControls : function() {
// var module = this,
// _css_class_ = 'skp-note-for-' + module.SKOPE_LEVEL;
// //This = _ctrl_
// var mayBePrintAndSetupCtrlBottomNote = function() {
// var _ctrl_ = this,
// _skope_title_ = FlatSkopeLocalizedData.i18n[ 'this page' ];
// if ( 0 < _ctrl_.container.find( '.' + _css_class_ ).length )
// return;
// var currentSkopeObj = _.findWhere( api.czr_currentSkopesCollection(), { skope : module.SKOPE_LEVEL } );
// if ( ! _.isEmpty( currentSkopeObj ) ) {
// _skope_title_ = currentSkopeObj.ctx_title;
// }
// _ctrl_.container.append(
// $('<div>', {
// class: [ _css_class_ , 'skp-ctrl-bottom-note', 'czr-notice' ].join(' '),
// html : [
// FlatSkopeLocalizedData.i18n[ 'Can be customized for' ],
// '<span class="skp-focus-link"><u>' + _skope_title_ + '</u><span>'
// ].join(' ')
// })
// );
// api.CZR_Helpers.setupDOMListeners(
// [//toggles remove view alert
// {
// trigger : 'click keydown',
// selector : ['.' + _css_class_, '.skp-focus-link'].join(' '),
// name : _css_class_,
// //data = {
// // dom_el,
// // dom_event,
// // event,
// // model
// // }
// actions : function( data ) {
// data.dom_event.preventDefault();
// module.control.focus();
// }
// }//actions to execute
// ],
// { model: {}, dom_el:_ctrl_.container },//model + dom scope
// null //instance where to look for the cb methods
// );//api.CZR_Helpers.setupDOMListeners
// };//mayBePrintAndSetupCtrlBottomNote
// _.each( api.czr_skopeBase.getSkopableSettings(), function( settingData ) {
// //console.log('settingDATA', settingData );
// api.control.when( settingData.apiCtrlId, function( _ctrl_ ) {
// _ctrl_.deferred.embedded.then( function() {
// $.when( _ctrl_.container.find('.' + _css_class_ ).remove() ).done( function() {
// if ( module.weHaveASkope() ) {
// mayBePrintAndSetupCtrlBottomNote.call( _ctrl_ );
// }
// });
// });
// } );
// });
// }//printSkopeInfoInControls
});//extend
})( wp.customize , jQuery, _ );
@@ -0,0 +1,132 @@
//@global serverControlParams
var CZRSkopeBaseMths = CZRSkopeBaseMths || {};
(function ( api, $, _ ) {
$.extend( CZRSkopeBaseMths, {
initialize: function() {
var self = this;
///////////////////// DEFINITIONS /////////////////////
//Store the state of the first skope collection state
api.czr_initialSkopeCollectionPopulated = $.Deferred();
//the czr_skopeCollection stores all skopes instantiated by the user
//this collection is not updated directly
//=> it's updated on skope() instance change
api.czr_skopeCollection = new api.Value([]);//all available skope, including the current skopes
//the current skopes collection get updated each time the 'czr-new-skopes-synced' event is triggered on the api by the preview
api.czr_currentSkopesCollection = new api.Value([]);
//the currently active skopes
api.czr_activeSkopes = new api.Value( { local : '', group : ''} );
///////////////////// SKOPE COLLECTIONS SYNCHRONISATION AND LISTENERS /////////////////////
//LISTEN TO SKOPE SYNC => UPDATE SKOPE COLLECTION ON START AND ON EACH REFRESH
//the sent data look like :
//{
// czr_new_skopes : _wpCustomizeSettings.czr_new_skopes || [],
// isChangesetDirty : boolean
// }
api.bind( 'ready' , function() {
api.previewer.bind( 'czr-new-skopes-synced', function( skope_server_data ) {
if ( serverControlParams.isDevMode ) {
api.infoLog( 'API SKOPE SYNCED', skope_server_data );
}
// set the currently active stylesheet
if ( ! _.has( skope_server_data, 'czr_stylesheet') ) {
api.errorLog( "On 'czr-new-skopes-synced' : missing stylesheet in the server data" );
return;
}
api.czr_skopeBase.stylesheet = api.czr_skopeBase.stylesheet || new api.Value( api.settings.theme.stylesheet );
api.czr_skopeBase.stylesheet( skope_server_data.czr_stylesheet );
//api.consoleLog('czr-skopes-ready DATA', skope_server_data );
var preview = this,
previousSkopeCollection = api.czr_currentSkopesCollection();
//initialize skopes with the server sent skope_server_data
//if skope has not been initialized yet and the server sent wrong skope_server_data, then reject the skope ready promise()
if ( ! _.has( skope_server_data, 'czr_new_skopes') ) {
api.errorLog( "On 'czr-new-skopes-synced' : missing skopes in the server data" );
return;
}
// If no "group" skope has been sent, check if we should have one
// array( 'home', 'search', '404', 'date' ) <= have no group
if ( _.isEmpty( _.findWhere( skope_server_data.czr_new_skopes, { skope : 'group' } ) ) ){
var _local_ = _.findWhere( skope_server_data.czr_new_skopes, { skope : 'local' } );
if ( ! _.isEmpty( _local_ ) && ! _.contains( FlatSkopeLocalizedData.noGroupSkopeList, _local_.level ) ) {
api.errorLog( 'No group level skope sent while there should be one' );
}
}
//1) Updated the collection with normalized skopes => prepareSkopeForAPI + api.czr_currentSkopesCollection( collection )
//2) When the api.czr_currentSkopesCollection() Value is set => instantiates the missing skope
//3) Set the skope layout view when the skope embedded promise is resolved
if ( serverControlParams.isDevMode ) {
api.czr_skopeBase.updateSkopeCollection( skope_server_data.czr_new_skopes , preview.channel() );
} else {
try {
api.czr_skopeBase.updateSkopeCollection( skope_server_data.czr_new_skopes , preview.channel() );
} catch ( er ) {
console.log('UPDATE SKOPE COLLECTION ERROR', er);
return;
}
}
//@return void()
// => refresh skope notice below the skope switcher title
// => refresh bottom skope infos in the preview
// var _refreshSkopeInfosNotices = function() {
// console.log('REFRESH SKOPE TITLE IF NEEDED ?');
// //WRITE THE CURRENT SKOPE TITLE
// //self._writeCurrentSkopeTitle();
// };
//Always wait for the initial collection to be populated
api.czr_initialSkopeCollectionPopulated.then( function() {
//console.log('INITIAL SKOPE COLLECTION POPULATED');
if ( ! _.has( skope_server_data, 'czr_new_skopes' ) || _.isEmpty( skope_server_data.czr_new_skopes ) ) {
api.errorLog( 'Missing skope data after refresh', skope_server_data );
}
// set the local and group skope id
api.czr_activeSkopes( {
'local' : self.getSkopeProperty( 'skope_id', 'local' ),
'group' : self.getSkopeProperty( 'skope_id', 'group' )
});
// if ( ! _.isEmpty( previousSkopeCollection ) ) { //Rewrite the title when the local skope has changed
// var _prevLoc = _.findWhere( previousSkopeCollection , { skope : 'local' } ).opt_name,
// _newLoc =_.findWhere( skope_server_data.czr_new_skopes, { skope : 'local' } ).opt_name;
// if ( _newLoc !== _prevLoc ) {
// //REFRESH SKOPE INFOS IN TITLE AND PREVIEW FRAME
// _refreshSkopeInfosNotices();
// }
// }
});
});//api.previewer.bind
});//api.bind( 'ready'
//CURRENT SKOPE COLLECTION LISTENER
//The skope collection is set on 'czr-new-skopes-synced' triggered by the preview
//setup the callbacks of the skope collection update
//on init and on preview change : the collection of skopes is populated with new skopes
//=> instanciate the relevant skope object + render them
api.czr_currentSkopesCollection.bind( function( to, from ) {
return self.currentSkopesCollectionReact( to, from );
}, { deferred : true });
///////////////////// VARIOUS /////////////////////
//DECLARE THE LIST OF CONTROL TYPES FOR WHICH THE VIEW IS REFRESHED ON CHANGE
//self.refreshedControls = [ 'czr_cropped_image'];// [ 'czr_cropped_image', 'czr_multi_module', 'czr_module' ];
api.trigger( 'czr_skopeBase_initialized' );
}//initialize
});//$.extend()
})( wp.customize , jQuery, _);
@@ -0,0 +1,49 @@
//@global serverControlParams
var CZRSkopeBaseMths = CZRSkopeBaseMths || {};
( function ( api, $, _ ) {
$.extend( CZRSkopeBaseMths, {
//////////////////////////////////////////////////////////
/// <SKOPE HELPERSS>
// @return string
getSkopeProperty : function( what, skope_level ) {
what = what || 'skope_id';
skope_level = skope_level || 'local';
var _skope_data = _.findWhere( api.czr_currentSkopesCollection(), { skope : skope_level });
if ( _.isEmpty( _skope_data ) ){
// display an error message if local skope not found. Should always be defined.
if ( 'local' == skope_level ) {
api.errorLog( "getSkopeProperty => local skope missing, returning not_set" );
}
return "_skope_not_set_";//for example when trying to get a group skope_id in a context where there can't be a group skope like home or search.
} else if ( !_.has( _skope_data, what ) ) {
api.errorLog( "getSkopeProperty => " + what + " property does not exist" );
return "_skope_not_set_";
} else {
return _skope_data[ what ];
}
},
//@return string
firstToUpperCase : function( str ) {
return ! _.isString( str ) ? '' : str.substr(0, 1).toUpperCase() + str.substr(1);
}
// //@return string
// buildSkopeLink : function( skope_id ) {
// if ( ! api.czr_skope.has( skope_id ) ) {
// api.errorLog( 'buildSkopeLink : the requested skope id is not registered : ' + skope_id );
// return '';
// }
// var _link_title = [ serverControlParams.i18n.skope['Switch to scope'], api.czr_skope( skope_id )().title ].join(' : ');
// return [
// '<span class="czr-skope-switch" title=" ' + _link_title + '" data-skope-id="' + skope_id + '">',
// api.czr_skope( skope_id )().title,
// '</span>'
// ].join( '' );
// },
});//$.extend
})( wp.customize , jQuery, _ );
@@ -0,0 +1,132 @@
//@global serverControlParams
var CZRSkopeBaseMths = CZRSkopeBaseMths || {};
(function ( api, $, _ ) {
$.extend( CZRSkopeBaseMths, {
//Fired on 'czr-new-skopes-synced' triggered by the preview, each time the preview is refreshed.
//On a Save Action, api.czr_savedDirties has been populated =>
// 1) check if the server sends the same saved values
// 2) update the skope db properties with the latests saved ones
//
//A skope candidate is structured this way :
//{
// id:""
// long_title:"Site wide options"
// obj_id:""
// skope:"global"
// title:"Site wide options"
//}
//@see api_overrides
updateSkopeCollection : function( sent_collection ) {
var self = this,
_api_ready_collection = [];
//normalize each sent skopes
_.each( sent_collection, function( _skope ) {
var skope_candidate = $.extend( true, {}, _skope );//deep clone to avoid any shared references
_api_ready_collection.push( self.prepareSkopeForAPI( skope_candidate ) );
});
//set the new collection of current skopes
//=> this will instantiate the not instantiated skopes
api.czr_currentSkopesCollection( _api_ready_collection );
// set the group skope id
//console.log( "SKOPE COLLECTION UPDATED", api.czr_currentSkopesCollection() );
},
//@param skope_candidate
////A skope candidate is structured this way :
//{
// id:""
// long_title:"Site wide options"
// obj_id:""
// skope:"global"
// title:"Site wide options"
//}
prepareSkopeForAPI : function( skope_candidate ) {
if ( ! _.isObject( skope_candidate ) ) {
throw new Error('prepareSkopeForAPI : a skope must be an object to be API ready');
}
var api_ready_skope = skope_candidate;
_.each( FlatSkopeLocalizedData.defaultSkopeModel , function( _value, _key ) {
var _candidate_val = skope_candidate[_key];
switch( _key ) {
case 'title' :
if ( ! _.isString( _candidate_val ) ) {
throw new Error('prepareSkopeForAPI : a skope title property must a string');
}
api_ready_skope[_key] = _candidate_val;
break;
case 'long_title' :
if ( ! _.isString( _candidate_val ) ) {
throw new Error('prepareSkopeForAPI : a skope title property must a string');
}
api_ready_skope[_key] = _candidate_val;
break;
case 'ctx_title' :
if ( ! _.isString( _candidate_val ) ) {
throw new Error('prepareSkopeForAPI : a skope context title property must a string');
}
api_ready_skope[_key] = _candidate_val;
break;
case 'skope' :
if ( ! _.isString( _candidate_val ) || _.isEmpty( _candidate_val ) ) {
throw new Error('prepareSkopeForAPI : a skope "skope" property must a string not empty');
}
api_ready_skope[_key] = _candidate_val;
break;
case 'obj_id' :
if ( ! _.isString( _candidate_val ) ) {
throw new Error('prepareSkopeForAPI : invalid "obj_id" for skope ' + _candidate_val.skope );
}
api_ready_skope[_key] = _candidate_val;
break;
case 'skope_id' :
if ( ! _.isString( _candidate_val ) ) {
throw new Error('prepareSkopeForAPI : invalid "skope_key" for skope ' + _candidate_val.skope );
}
api_ready_skope[_key] = _candidate_val;
break;
case 'values' :
// if ( ! _.isString( _candidate_val ) ) {
// throw new Error('prepareSkopeForAPI : invalid "values" for skope ' + _candidate_val.skope );
// }
api_ready_skope[_key] = _candidate_val;
break;
default :
api_ready_skope[_key] = _candidate_val;
break;
}//switch
});
//Finally, generate the id and the title
api_ready_skope.id = api_ready_skope.skope + '_' + api_ready_skope.skope_id;
if ( ! _.isString( api_ready_skope.id ) || _.isEmpty( api_ready_skope.id ) ) {
throw new Error('prepareSkopeForAPI : a skope id must a string not empty');
}
if ( ! _.isString( api_ready_skope.title ) || _.isEmpty( api_ready_skope.title ) ) {
api_ready_skope.title = api_ready_skope.id;
api_ready_skope.long_title = api_ready_skope.id;
}
return api_ready_skope;
},
//cb of api.czr_currentSkopesCollection.callbacks
//fired in initialize
currentSkopesCollectionReact : function( to, from ) {
var dfd = $.Deferred();
//ON INITIAL COLLECTION POPULATE, RESOLVE THE DEFERRED STATE
//=> this way we can defer earlier actions.
//For example when autofocus is requested, the section might be expanded before the initial skope collection is sent from the preview.
if ( _.isEmpty( from ) && ! _.isEmpty( to ) ) {
api.czr_initialSkopeCollectionPopulated.resolve();
}
return dfd.resolve( 'changed' ).promise();
}//listenToSkopeCollection()
});//$.extend()
})( wp.customize , jQuery, _);
@@ -0,0 +1,13 @@
//@global serverControlParams
var CZRSkopeBaseMths = CZRSkopeBaseMths || {};
(function ( api, $ ) {
// Skope
$.extend( CZRSkopeBaseMths, api.Events );
var CZR_SkopeBase = api.Class.extend( CZRSkopeBaseMths );
// Schedule skope instantiation on api ready
// api.bind( 'ready' , function() {
// api.czr_skopeBase = new api.CZR_SkopeBase();
// });
api.czr_skopeBase = new CZR_SkopeBase();
})( wp.customize, jQuery );
@@ -0,0 +1,323 @@
//@global serverControlParams
var CZRSkopeBaseMths = CZRSkopeBaseMths || {};
(function ( api, $, _ ) {
$.extend( CZRSkopeBaseMths, {
initialize: function() {
var self = this;
///////////////////// DEFINITIONS /////////////////////
//Store the state of the first skope collection state
api.czr_initialSkopeCollectionPopulated = $.Deferred();
//the czr_skopeCollection stores all skopes instantiated by the user
//this collection is not updated directly
//=> it's updated on skope() instance change
api.czr_skopeCollection = new api.Value([]);//all available skope, including the current skopes
//the current skopes collection get updated each time the 'czr-new-skopes-synced' event is triggered on the api by the preview
api.czr_currentSkopesCollection = new api.Value([]);
//the currently active skopes
api.czr_activeSkopes = new api.Value( { local : '', group : ''} );
///////////////////// SKOPE COLLECTIONS SYNCHRONISATION AND LISTENERS /////////////////////
//LISTEN TO SKOPE SYNC => UPDATE SKOPE COLLECTION ON START AND ON EACH REFRESH
//the sent data look like :
//{
// czr_new_skopes : _wpCustomizeSettings.czr_new_skopes || [],
// isChangesetDirty : boolean
// }
api.bind( 'ready' , function() {
api.previewer.bind( 'czr-new-skopes-synced', function( skope_server_data ) {
if ( serverControlParams.isDevMode ) {
api.infoLog( 'API SKOPE SYNCED', skope_server_data );
}
// set the currently active stylesheet
if ( ! _.has( skope_server_data, 'czr_stylesheet') ) {
api.errorLog( "On 'czr-new-skopes-synced' : missing stylesheet in the server data" );
return;
}
api.czr_skopeBase.stylesheet = api.czr_skopeBase.stylesheet || new api.Value( api.settings.theme.stylesheet );
api.czr_skopeBase.stylesheet( skope_server_data.czr_stylesheet );
//api.consoleLog('czr-skopes-ready DATA', skope_server_data );
var preview = this,
previousSkopeCollection = api.czr_currentSkopesCollection();
//initialize skopes with the server sent skope_server_data
//if skope has not been initialized yet and the server sent wrong skope_server_data, then reject the skope ready promise()
if ( ! _.has( skope_server_data, 'czr_new_skopes') ) {
api.errorLog( "On 'czr-new-skopes-synced' : missing skopes in the server data" );
return;
}
// If no "group" skope has been sent, check if we should have one
// array( 'home', 'search', '404', 'date' ) <= have no group
if ( _.isEmpty( _.findWhere( skope_server_data.czr_new_skopes, { skope : 'group' } ) ) ){
var _local_ = _.findWhere( skope_server_data.czr_new_skopes, { skope : 'local' } );
if ( ! _.isEmpty( _local_ ) && ! _.contains( FlatSkopeLocalizedData.noGroupSkopeList, _local_.level ) ) {
api.errorLog( 'No group level skope sent while there should be one' );
}
}
//1) Updated the collection with normalized skopes => prepareSkopeForAPI + api.czr_currentSkopesCollection( collection )
//2) When the api.czr_currentSkopesCollection() Value is set => instantiates the missing skope
//3) Set the skope layout view when the skope embedded promise is resolved
if ( serverControlParams.isDevMode ) {
api.czr_skopeBase.updateSkopeCollection( skope_server_data.czr_new_skopes , preview.channel() );
} else {
try {
api.czr_skopeBase.updateSkopeCollection( skope_server_data.czr_new_skopes , preview.channel() );
} catch ( er ) {
console.log('UPDATE SKOPE COLLECTION ERROR', er);
return;
}
}
//@return void()
// => refresh skope notice below the skope switcher title
// => refresh bottom skope infos in the preview
// var _refreshSkopeInfosNotices = function() {
// console.log('REFRESH SKOPE TITLE IF NEEDED ?');
// //WRITE THE CURRENT SKOPE TITLE
// //self._writeCurrentSkopeTitle();
// };
//Always wait for the initial collection to be populated
api.czr_initialSkopeCollectionPopulated.then( function() {
//console.log('INITIAL SKOPE COLLECTION POPULATED');
if ( ! _.has( skope_server_data, 'czr_new_skopes' ) || _.isEmpty( skope_server_data.czr_new_skopes ) ) {
api.errorLog( 'Missing skope data after refresh', skope_server_data );
}
// set the local and group skope id
api.czr_activeSkopes( {
'local' : self.getSkopeProperty( 'skope_id', 'local' ),
'group' : self.getSkopeProperty( 'skope_id', 'group' )
});
// if ( ! _.isEmpty( previousSkopeCollection ) ) { //Rewrite the title when the local skope has changed
// var _prevLoc = _.findWhere( previousSkopeCollection , { skope : 'local' } ).opt_name,
// _newLoc =_.findWhere( skope_server_data.czr_new_skopes, { skope : 'local' } ).opt_name;
// if ( _newLoc !== _prevLoc ) {
// //REFRESH SKOPE INFOS IN TITLE AND PREVIEW FRAME
// _refreshSkopeInfosNotices();
// }
// }
});
});//api.previewer.bind
});//api.bind( 'ready'
//CURRENT SKOPE COLLECTION LISTENER
//The skope collection is set on 'czr-new-skopes-synced' triggered by the preview
//setup the callbacks of the skope collection update
//on init and on preview change : the collection of skopes is populated with new skopes
//=> instanciate the relevant skope object + render them
api.czr_currentSkopesCollection.bind( function( to, from ) {
return self.currentSkopesCollectionReact( to, from );
}, { deferred : true });
///////////////////// VARIOUS /////////////////////
//DECLARE THE LIST OF CONTROL TYPES FOR WHICH THE VIEW IS REFRESHED ON CHANGE
//self.refreshedControls = [ 'czr_cropped_image'];// [ 'czr_cropped_image', 'czr_multi_module', 'czr_module' ];
api.trigger( 'czr_skopeBase_initialized' );
}//initialize
});//$.extend()
})( wp.customize , jQuery, _);//@global serverControlParams
var CZRSkopeBaseMths = CZRSkopeBaseMths || {};
( function ( api, $, _ ) {
$.extend( CZRSkopeBaseMths, {
//////////////////////////////////////////////////////////
/// <SKOPE HELPERSS>
// @return string
getSkopeProperty : function( what, skope_level ) {
what = what || 'skope_id';
skope_level = skope_level || 'local';
var _skope_data = _.findWhere( api.czr_currentSkopesCollection(), { skope : skope_level });
if ( _.isEmpty( _skope_data ) ){
// display an error message if local skope not found. Should always be defined.
if ( 'local' == skope_level ) {
api.errorLog( "getSkopeProperty => local skope missing, returning not_set" );
}
return "_skope_not_set_";//for example when trying to get a group skope_id in a context where there can't be a group skope like home or search.
} else if ( !_.has( _skope_data, what ) ) {
api.errorLog( "getSkopeProperty => " + what + " property does not exist" );
return "_skope_not_set_";
} else {
return _skope_data[ what ];
}
},
//@return string
firstToUpperCase : function( str ) {
return ! _.isString( str ) ? '' : str.substr(0, 1).toUpperCase() + str.substr(1);
}
// //@return string
// buildSkopeLink : function( skope_id ) {
// if ( ! api.czr_skope.has( skope_id ) ) {
// api.errorLog( 'buildSkopeLink : the requested skope id is not registered : ' + skope_id );
// return '';
// }
// var _link_title = [ serverControlParams.i18n.skope['Switch to scope'], api.czr_skope( skope_id )().title ].join(' : ');
// return [
// '<span class="czr-skope-switch" title=" ' + _link_title + '" data-skope-id="' + skope_id + '">',
// api.czr_skope( skope_id )().title,
// '</span>'
// ].join( '' );
// },
});//$.extend
})( wp.customize , jQuery, _ );//@global serverControlParams
var CZRSkopeBaseMths = CZRSkopeBaseMths || {};
(function ( api, $, _ ) {
$.extend( CZRSkopeBaseMths, {
//Fired on 'czr-new-skopes-synced' triggered by the preview, each time the preview is refreshed.
//On a Save Action, api.czr_savedDirties has been populated =>
// 1) check if the server sends the same saved values
// 2) update the skope db properties with the latests saved ones
//
//A skope candidate is structured this way :
//{
// id:""
// long_title:"Site wide options"
// obj_id:""
// skope:"global"
// title:"Site wide options"
//}
//@see api_overrides
updateSkopeCollection : function( sent_collection ) {
var self = this,
_api_ready_collection = [];
//normalize each sent skopes
_.each( sent_collection, function( _skope ) {
var skope_candidate = $.extend( true, {}, _skope );//deep clone to avoid any shared references
_api_ready_collection.push( self.prepareSkopeForAPI( skope_candidate ) );
});
//set the new collection of current skopes
//=> this will instantiate the not instantiated skopes
api.czr_currentSkopesCollection( _api_ready_collection );
// set the group skope id
//console.log( "SKOPE COLLECTION UPDATED", api.czr_currentSkopesCollection() );
},
//@param skope_candidate
////A skope candidate is structured this way :
//{
// id:""
// long_title:"Site wide options"
// obj_id:""
// skope:"global"
// title:"Site wide options"
//}
prepareSkopeForAPI : function( skope_candidate ) {
if ( ! _.isObject( skope_candidate ) ) {
throw new Error('prepareSkopeForAPI : a skope must be an object to be API ready');
}
var api_ready_skope = skope_candidate;
_.each( FlatSkopeLocalizedData.defaultSkopeModel , function( _value, _key ) {
var _candidate_val = skope_candidate[_key];
switch( _key ) {
case 'title' :
if ( ! _.isString( _candidate_val ) ) {
throw new Error('prepareSkopeForAPI : a skope title property must a string');
}
api_ready_skope[_key] = _candidate_val;
break;
case 'long_title' :
if ( ! _.isString( _candidate_val ) ) {
throw new Error('prepareSkopeForAPI : a skope title property must a string');
}
api_ready_skope[_key] = _candidate_val;
break;
case 'ctx_title' :
if ( ! _.isString( _candidate_val ) ) {
throw new Error('prepareSkopeForAPI : a skope context title property must a string');
}
api_ready_skope[_key] = _candidate_val;
break;
case 'skope' :
if ( ! _.isString( _candidate_val ) || _.isEmpty( _candidate_val ) ) {
throw new Error('prepareSkopeForAPI : a skope "skope" property must a string not empty');
}
api_ready_skope[_key] = _candidate_val;
break;
case 'obj_id' :
if ( ! _.isString( _candidate_val ) ) {
throw new Error('prepareSkopeForAPI : invalid "obj_id" for skope ' + _candidate_val.skope );
}
api_ready_skope[_key] = _candidate_val;
break;
case 'skope_id' :
if ( ! _.isString( _candidate_val ) ) {
throw new Error('prepareSkopeForAPI : invalid "skope_key" for skope ' + _candidate_val.skope );
}
api_ready_skope[_key] = _candidate_val;
break;
case 'values' :
// if ( ! _.isString( _candidate_val ) ) {
// throw new Error('prepareSkopeForAPI : invalid "values" for skope ' + _candidate_val.skope );
// }
api_ready_skope[_key] = _candidate_val;
break;
default :
api_ready_skope[_key] = _candidate_val;
break;
}//switch
});
//Finally, generate the id and the title
api_ready_skope.id = api_ready_skope.skope + '_' + api_ready_skope.skope_id;
if ( ! _.isString( api_ready_skope.id ) || _.isEmpty( api_ready_skope.id ) ) {
throw new Error('prepareSkopeForAPI : a skope id must a string not empty');
}
if ( ! _.isString( api_ready_skope.title ) || _.isEmpty( api_ready_skope.title ) ) {
api_ready_skope.title = api_ready_skope.id;
api_ready_skope.long_title = api_ready_skope.id;
}
return api_ready_skope;
},
//cb of api.czr_currentSkopesCollection.callbacks
//fired in initialize
currentSkopesCollectionReact : function( to, from ) {
var dfd = $.Deferred();
//ON INITIAL COLLECTION POPULATE, RESOLVE THE DEFERRED STATE
//=> this way we can defer earlier actions.
//For example when autofocus is requested, the section might be expanded before the initial skope collection is sent from the preview.
if ( _.isEmpty( from ) && ! _.isEmpty( to ) ) {
api.czr_initialSkopeCollectionPopulated.resolve();
}
return dfd.resolve( 'changed' ).promise();
}//listenToSkopeCollection()
});//$.extend()
})( wp.customize , jQuery, _);//@global serverControlParams
var CZRSkopeBaseMths = CZRSkopeBaseMths || {};
(function ( api, $ ) {
// Skope
$.extend( CZRSkopeBaseMths, api.Events );
var CZR_SkopeBase = api.Class.extend( CZRSkopeBaseMths );
// Schedule skope instantiation on api ready
// api.bind( 'ready' , function() {
// api.czr_skopeBase = new api.CZR_SkopeBase();
// });
api.czr_skopeBase = new CZR_SkopeBase();
})( wp.customize, jQuery );
@@ -0,0 +1 @@
var CZRSkopeBaseMths=CZRSkopeBaseMths||{};!function(t,e,s){e.extend(CZRSkopeBaseMths,{initialize:function(){var r=this;t.czr_initialSkopeCollectionPopulated=e.Deferred(),t.czr_skopeCollection=new t.Value([]),t.czr_currentSkopesCollection=new t.Value([]),t.czr_activeSkopes=new t.Value({local:"",group:""}),t.bind("ready",function(){t.previewer.bind("czr-new-skopes-synced",function(e){if(serverControlParams.isDevMode&&t.infoLog("API SKOPE SYNCED",e),s.has(e,"czr_stylesheet")){t.czr_skopeBase.stylesheet=t.czr_skopeBase.stylesheet||new t.Value(t.settings.theme.stylesheet),t.czr_skopeBase.stylesheet(e.czr_stylesheet);t.czr_currentSkopesCollection();if(s.has(e,"czr_new_skopes")){if(s.isEmpty(s.findWhere(e.czr_new_skopes,{skope:"group"}))){var o=s.findWhere(e.czr_new_skopes,{skope:"local"});s.isEmpty(o)||s.contains(FlatSkopeLocalizedData.noGroupSkopeList,o.level)||t.errorLog("No group level skope sent while there should be one")}if(serverControlParams.isDevMode)t.czr_skopeBase.updateSkopeCollection(e.czr_new_skopes,this.channel());else try{t.czr_skopeBase.updateSkopeCollection(e.czr_new_skopes,this.channel())}catch(e){return void console.log("UPDATE SKOPE COLLECTION ERROR",e)}t.czr_initialSkopeCollectionPopulated.then(function(){s.has(e,"czr_new_skopes")&&!s.isEmpty(e.czr_new_skopes)||t.errorLog("Missing skope data after refresh",e),t.czr_activeSkopes({local:r.getSkopeProperty("skope_id","local"),group:r.getSkopeProperty("skope_id","group")})})}else t.errorLog("On 'czr-new-skopes-synced' : missing skopes in the server data")}else t.errorLog("On 'czr-new-skopes-synced' : missing stylesheet in the server data")})}),t.czr_currentSkopesCollection.bind(function(e,o){return r.currentSkopesCollectionReact(e,o)},{deferred:!0}),t.trigger("czr_skopeBase_initialized")}})}(wp.customize,jQuery,_);CZRSkopeBaseMths=CZRSkopeBaseMths||{};!function(t,e,s){e.extend(CZRSkopeBaseMths,{getSkopeProperty:function(e,o){e=e||"skope_id",o=o||"local";var r=s.findWhere(t.czr_currentSkopesCollection(),{skope:o});return s.isEmpty(r)?("local"==o&&t.errorLog("getSkopeProperty => local skope missing, returning not_set"),"_skope_not_set_"):s.has(r,e)?r[e]:(t.errorLog("getSkopeProperty => "+e+" property does not exist"),"_skope_not_set_")},firstToUpperCase:function(e){return s.isString(e)?e.substr(0,1).toUpperCase()+e.substr(1):""}})}(wp.customize,jQuery,_);CZRSkopeBaseMths=CZRSkopeBaseMths||{};!function(s,i,p){i.extend(CZRSkopeBaseMths,{updateSkopeCollection:function(e){var r=this,t=[];p.each(e,function(e){var o=i.extend(!0,{},e);t.push(r.prepareSkopeForAPI(o))}),s.czr_currentSkopesCollection(t)},prepareSkopeForAPI:function(t){if(!p.isObject(t))throw new Error("prepareSkopeForAPI : a skope must be an object to be API ready");var s=t;if(p.each(FlatSkopeLocalizedData.defaultSkopeModel,function(e,o){var r=t[o];switch(o){case"title":case"long_title":if(!p.isString(r))throw new Error("prepareSkopeForAPI : a skope title property must a string");s[o]=r;break;case"ctx_title":if(!p.isString(r))throw new Error("prepareSkopeForAPI : a skope context title property must a string");s[o]=r;break;case"skope":if(!p.isString(r)||p.isEmpty(r))throw new Error('prepareSkopeForAPI : a skope "skope" property must a string not empty');s[o]=r;break;case"obj_id":if(!p.isString(r))throw new Error('prepareSkopeForAPI : invalid "obj_id" for skope '+r.skope);s[o]=r;break;case"skope_id":if(!p.isString(r))throw new Error('prepareSkopeForAPI : invalid "skope_key" for skope '+r.skope);s[o]=r;break;case"values":default:s[o]=r}}),s.id=s.skope+"_"+s.skope_id,!p.isString(s.id)||p.isEmpty(s.id))throw new Error("prepareSkopeForAPI : a skope id must a string not empty");return p.isString(s.title)&&!p.isEmpty(s.title)||(s.title=s.id,s.long_title=s.id),s},currentSkopesCollectionReact:function(e,o){var r=i.Deferred();return p.isEmpty(o)&&!p.isEmpty(e)&&s.czr_initialSkopeCollectionPopulated.resolve(),r.resolve("changed").promise()}})}(wp.customize,jQuery,_);CZRSkopeBaseMths=CZRSkopeBaseMths||{};!function(e,o){jQuery.extend(CZRSkopeBaseMths,e.Events);var r=e.Class.extend(CZRSkopeBaseMths);e.czr_skopeBase=new r}(wp.customize);