From: Chuck Scott Date: Tue, 19 Mar 2019 16:39:36 +0000 (-0400) Subject: Started using Script Registry for enqueing script and style files X-Git-Tag: v1.4.0^2~1 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=5d52c2f683e85ae7032c061905db182a905ecb8a;p=WP-Plugins%2Fglm-member-db-registrations.git Started using Script Registry for enqueing script and style files Added registry lists for admin and front-end in setup dir Added a number of scripts and styles to using registry. --- diff --git a/defines.php b/defines.php index 8d34438..d8f52c0 100644 --- a/defines.php +++ b/defines.php @@ -1,6 +1,6 @@ wpdb, $this->config); - wp_enqueue_style( - 'foundation', - GLM_MEMBERS_REGISTRATIONS_PLUGIN_BASE_URL . '/css/foundation.css', - null, - '1.0' - ); - // Check for option submitted if (isset($_REQUEST['option']) && $_REQUEST['option'] != '') { $option = $_REQUEST['option']; diff --git a/models/front/registrations/checkout.php b/models/front/registrations/checkout.php index dd13273..469a79a 100755 --- a/models/front/registrations/checkout.php +++ b/models/front/registrations/checkout.php @@ -72,7 +72,7 @@ class GlmMembersFront_registrations_checkout extends GlmRegCartSupport array( 'jquery' ), - GLM_MEMBERS_PLUGIN_VERSION + GLM_MEMBERS_REGISTRATIONS_PLUGIN_VERSION ); wp_enqueue_script('glm-members-reg-front-mask'); diff --git a/models/front/registrations/registration.php b/models/front/registrations/registration.php index 14fe2d8..bca56df 100755 --- a/models/front/registrations/registration.php +++ b/models/front/registrations/registration.php @@ -55,27 +55,24 @@ $Misc = new GlmDataRegistrationsMisc($this->wpdb, $this->config); $misc = $Misc->getEntry(1); - // Setup scripts array for needed js files. - $scripts = array( - 'regApp' => 'js/frontRegApp.js', - ); - - // Loop through our scripts array and register them. - foreach ( $scripts as $scriptName => $scriptPath ) { - wp_register_script( - $scriptName, - GLM_MEMBERS_REGISTRATIONS_PLUGIN_URL . $scriptPath, - array( 'jquery', 'backbone', 'underscore' ), - '1.0', - true - ); + /* + * Enqueue required scripts + */ + // Select frontRegApp.js script to be enqueued + glmScriptRegistry::select( glmScriptType::Script, 'RegApp' ); + + // If we're using Leaflet - Enqueue Leaflet scripts and styles + if ( $this->config['settings']['selected_map_interface'] == 1 ) { + glmScriptRegistry::select( glmScriptType::Style, 'Leaflet' ); + glmScriptRegistry::select( glmScriptType::Script, 'Leaflet' ); + glmScriptRegistry::select( glmScriptType::Style, 'LeafletControlLoading' ); + glmScriptRegistry::select( glmScriptType::Script, 'LeafletControlLoading' ); } - // Load Backbone.sj and jQuery. - wp_enqueue_script( array( 'backbone', 'jquery' ) ); - // Load our scripts. - wp_enqueue_script( array_keys( $scripts ) ); - $regEvent = array(); + // If we're using Google Maps - Enqueue Google Maps script + if ( $this->config['settings']['selected_map_interface'] == 2 ) { + glmScriptRegistry::select( glmScriptType::Script, 'GoogleMapsAPI' ); + } // Get any provided option if (isset($_REQUEST['option'])) { @@ -419,6 +416,12 @@ ); $attendeeFieldsJSON = json_encode($attendeeFields, JSON_NUMERIC_CHECK); + // Select scripts to enqueue + if ( $this->config['settings']['selected_map_interface'] ) { + + } + + // echo "
".print_r($registrants,1)."
"; // Compile template data @@ -429,7 +432,7 @@ 'haveCart' => $haveCart, 'haveRegEvent' => $haveRegEvent, 'regEvent' => $regEvent, - 'standAlone' => ($regEvent.event == 0), + 'standAlone' => ($regEvent['event'] == 0), 'regEventFirstTime' => $regEventFirstTime, 'thisJsUrl' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_URL . '/js', 'regEventJSON' => json_encode( $event, JSON_NUMERIC_CHECK ), diff --git a/readme.txt b/readme.txt index 645ad0c..74eb78d 100755 --- a/readme.txt +++ b/readme.txt @@ -25,6 +25,10 @@ e.g. 1. Activate the plugin through the 'Plugins' menu in WordPress == Changelog == += (pending) = +***** NOTE: NEED TO SET REQUIRED MAIN PLUGIN TO NEXT NEW VERSION DUE TO ADDING SCRIPT REGISTRY ****** +* Now enqueueing most scripts and styles through new Script Registry. + = 1.3.1 = * Update database to version 1.0.4 * Added management flags for showing and requiring Organization and Title attendee fields. diff --git a/setup/registerAdminScriptStyle.php b/setup/registerAdminScriptStyle.php new file mode 100644 index 0000000..26ee514 --- /dev/null +++ b/setup/registerAdminScriptStyle.php @@ -0,0 +1,75 @@ + + * @copyright 2019 Gaslight Media + * @license Gaslight Media + * @version SVN: $Id$ + * @link <> + */ + +/** + * This file registers scripts and styles with the glmScriptRegistry. + * + * Scripts and Styles are added to the registry to ensure consistancy and avoid duplication. + * This process only lists them in the registry. A further step of calling the enqueue() + * method in the running model is required to have the needed scripts and styles passed + * to WordPress to have them enqueued. The expection to that is when including an "enqueue" + * parameter below that indicates that the scirpt should always be enqueued. + * + * The parameters below are what can be included. For more information on these parameters see + * classes/sciptRegistry.php in the main plugin. When these are loaded a check will be made to + * make sure there's no duplicate 'handle' or 'src' strings. The exception for 'handle' is that + * it may be the same for a matching script and style (the plugin slug and type prefix the + * 'handle' provided below to make them actually unique). + * + * int type Required type enumerated (see glmScriptType above) + * string handle Required handle (name) for this script (no spaces or punctuation) + * Handles must be unique for a particular type + * A matching script and style may have the same handle + * string src Required source URL of script + * array deps Optional array of handles for scripts this script depends on + * boolean in_footer Optional flag for enqueue before tag + * string media Optional media types for styles (i.e. 'all', 'print', 'screen'...) + * array attrs Optional tag attribute name/value pairs to be included in tag + * string plugin Required plugin slug + * string version Required plugin version for cache-busting + * boolean enqueue Optional flag, if true always enqueue this + * + * Please identify the file in the comment area using the URL or application. + * + * NOTE: The $config array is available in the context of this file. You need to refer + * to a config item in a way similar to this... + * + * $config['settings']['google_maps_api_key'] + * + * Example - Please add multi-line comment above each with script src for reference + * + * glmScriptRegistry::add( + * [ + * 'type' => glmScriptType::Script, + * 'handle' => 'RegApp', + * 'src' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_URL . '/js/frontRegApp.js', + * 'deps' => array( + * 'jquery', + * 'backbone', + * 'underscore' + * ), + * 'in_footer' => true, + * 'attrs' => array( + * 'integrity' => 'sha512-tAGcCfR4Sc5ZP5ZoVz0quoZDYX5aCtEm/eu1KhSLj2c9eFrylXZknQYmxUssFaVJKvvc0dJQixhGjG2yXWiV9Q==', + * 'crossorigin' => '' + * ), + * 'plugin' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG, + * 'version' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_VERSION + * ] ); + * + * NOTE: DO NOT PLACE ANY SCRIPT OR STYLE FILE TAGS INTO VIEW. SELECT THEM IN THE MODEL + * USING THIS REGISTRY ONLY. + */ + diff --git a/setup/registerFrontScriptStyle.php b/setup/registerFrontScriptStyle.php new file mode 100644 index 0000000..b3189d9 --- /dev/null +++ b/setup/registerFrontScriptStyle.php @@ -0,0 +1,92 @@ + + * @copyright 2019 Gaslight Media + * @license Gaslight Media + * @version SVN: $Id$ + * @link <> + */ + +/** + * This file registers scripts and styles with the glmScriptRegistry. + * + * Scripts and Styles are added to the registry to ensure consistancy and avoid duplication. + * This process only lists them in the registry. A further step of calling the enqueue() + * method in the running model is required to have the needed scripts and styles passed + * to WordPress to have them enqueued. The expection to that is when including an "enqueue" + * parameter below that indicates that the scirpt should always be enqueued. + * + * The parameters below are what can be included. For more information on these parameters see + * classes/sciptRegistry.php in the main plugin. When these are loaded a check will be made to + * make sure there's no duplicate 'handle' or 'src' strings. The exception for 'handle' is that + * it may be the same for a matching script and style (the plugin slug and type prefix the + * 'handle' provided below to make them actually unique). + * + * int type Required type enumerated (see glmScriptType above) + * string handle Required handle (name) for this script (no spaces or punctuation) + * Handles must be unique for a particular type + * A matching script and style may have the same handle + * string src Required source URL of script + * array deps Optional array of handles for scripts this script depends on + * boolean in_footer Optional flag for enqueue before tag + * string media Optional media types for styles (i.e. 'all', 'print', 'screen'...) + * array attrs Optional tag attribute name/value pairs to be included in tag + * string plugin Required plugin slug + * string version Required plugin version for cache-busting + * boolean enqueue Optional flag, if true always enqueue this + * + * Please identify the file in the comment area using the URL or application. + * + * NOTE: The $config array is available in the context of this file. You need to refer + * to a config item in a way similar to this... + * + * $config['settings']['google_maps_api_key'] + * + * Example - Please add multi-line comment above each with script src for reference + * + * glmScriptRegistry::add( + * [ + * 'type' => glmScriptType::Script, + * 'handle' => 'RegApp', + * 'src' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_URL . '/js/frontRegApp.js', + * 'deps' => array( + * 'jquery', + * 'backbone', + * 'underscore' + * ), + * 'in_footer' => true, + * 'attrs' => array( + * 'integrity' => 'sha512-tAGcCfR4Sc5ZP5ZoVz0quoZDYX5aCtEm/eu1KhSLj2c9eFrylXZknQYmxUssFaVJKvvc0dJQixhGjG2yXWiV9Q==', + * 'crossorigin' => '' + * ), + * 'plugin' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG, + * 'version' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_VERSION + * ] ); + * + * NOTE: DO NOT PLACE ANY SCRIPT OR STYLE FILE TAGS INTO VIEW. SELECT THEM IN THE MODEL + * USING THIS REGISTRY ONLY. + */ + +/* + * {registrations}/js/frontRegApp.js + */ +glmScriptRegistry::add( + [ + 'type' => glmScriptType::Script, + 'handle' => 'RegApp', + 'src' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_URL . '/js/frontRegApp.js', + 'deps' => array( + 'jquery', + 'backbone', + 'underscore' + ), + 'in_footer' => true, + 'plugin' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG, + 'version' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_VERSION + ] ); diff --git a/views/front/registrations/registration.html b/views/front/registrations/registration.html index 8e54f41..3179a15 100755 --- a/views/front/registrations/registration.html +++ b/views/front/registrations/registration.html @@ -2,14 +2,7 @@ {* Underscore Templates for the Event Registration App *} {* Template for Logged in Account *} -{if $settings.selected_map_interface == 1} - - - - -{/if} {if $settings.selected_map_interface == 2} - {/if}