Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only load gigya libraries when actually needed. #76

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions gigya/gigya.module
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,5 @@ function gigya_page_attachments(array &$attachments) {

\Drupal::moduleHandler()->alter('gigya_lang', $lang);
$attachments['#attached']['drupalSettings']['gigya']['lang'] = $lang;

// Add Library.
$attachments['#attached']['library'][] = 'gigya/drupalGigya';
}
}
}
10 changes: 9 additions & 1 deletion gigya_raas/gigya_raas.libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@ gigyaRaas:
- core/jquery.cookie
- core/drupal
- core/drupalSettings
- core/drupal.ajax
- core/drupal.ajax
- gigya/drupalGigya

customScreenSets:
version: VERSION
js:
js/customScreenSets.js: {}
dependencies:
- gigya_raas/gigyaRaas
33 changes: 1 addition & 32 deletions gigya_raas/gigya_raas.module
Original file line number Diff line number Diff line change
Expand Up @@ -83,37 +83,6 @@ function gigya_raas_page_attachments(array &$attachments) {
Drupal::moduleHandler()->alter('gigya_raas_profile_settings', $raas_profile);
$attachments['#attached']['drupalSettings']['gigya']['raas']['profile'] = $raas_profile;
}

/* Load screen-set config into front-end for custom screen-set in UI blocks functionality */
$custom_screensets = array();
/** @var BlockInterface[] $blocks; */
$blocks = Block::loadMultiple();
foreach ($blocks as $key => $block) {
$settings = $block->get('settings');
if ($settings['id'] == 'gigya_raas_custom_screenset') {
$custom_screensets[] = $settings;
}
}
$screenset_config = (array)json_decode(Drupal::config('gigya_raas.screensets')->get('gigya.custom_screensets'));
foreach ($screenset_config as $key => $screenset) {
if (isset($screenset->remove))
unset($screenset->remove);
$screenset = (array)$screenset;
$screenset_config[$screenset['desktop']] = $screenset;
unset($screenset_config[$key]);
}
foreach ($custom_screensets as $key => $screenset) {
if (!empty($screenset_config[$screenset['desktop_screenset']])) {
$custom_screensets[$key]['sync_data'] = $screenset_config[$screenset['desktop_screenset']]['sync'];
if (!empty($screenset_config[$screenset['desktop_screenset']]['mobile']))
$custom_screensets[$key]['mobile_screenset'] = $screenset_config[$screenset['desktop_screenset']]['mobile'];
else
$custom_screensets[$key]['mobile_screenset'] = $screenset_config[$screenset['desktop_screenset']]['desktop'];
}
}
$attachments['#attached']['drupalSettings']['gigya']['raas']['customScreenSets'] = $custom_screensets;

$attachments['#attached']['library'][] = 'gigya_raas/gigyaRaas';
}
}
}
Expand Down Expand Up @@ -272,4 +241,4 @@ function gigya_raas_mail($key, &$message, $params) {

$message['subject'] = t($params['subject'], array(), $options);
$message['body'][] = $params['message'];
}
}
62 changes: 62 additions & 0 deletions gigya_raas/js/customScreenSets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* @file
* Handles custom screen sets.
*/

(function ($, Drupal, drupalSettings) {

Drupal.behaviors.gigyaRaasCustomScreenSets = {
attach: function (context, settings) {
window.onGigyaServiceReady = function () {
for (var id in drupalSettings.gigya.raas.customScreenSets) {
var custom_screenset = drupalSettings.gigya.raas.customScreenSets[id];
if (typeof custom_screenset.display_type !== 'undefined') {
var screenset_params = {
screenSet: custom_screenset.desktop_screenset,
mobileScreenSet: custom_screenset.mobile_screenset
};
if (parseInt(custom_screenset.sync_data) === 1)
screenset_params['onAfterSubmit'] = processFieldMapping;

if (custom_screenset.display_type === 'popup') {
$('#' + custom_screenset.link_id)
.once('gigya-raas')
.click(popupClickListener);
}
else if (custom_screenset.display_type === 'embed') {
screenset_params['containerID'] = custom_screenset.container_id;
gigya.accounts.showScreenSet(screenset_params);
}
}
}
};

var popupClickListener = function (e) {
var id = $(this).closest('.gigya-custom-screenset').attr('id');
var custom_screenset = drupalSettings.gigya.raas.customScreenSets[id];
var screenset_params = {
screenSet: custom_screenset.desktop_screenset,
mobileScreenSet: custom_screenset.mobile_screenset
};
e.preventDefault();
gigya.accounts.showScreenSet(screenset_params);
drupalSettings.gigya.raas.linkId = $(this).attr('id');
};

var processFieldMapping = function (data) {
var gigyaData = {
UID: data.response.UID,
UIDSignature: data.response.UIDSignature,
signatureTimestamp: data.response.signatureTimestamp
};
var ajaxSettings = {
url: drupalSettings.path.baseUrl + 'gigya/raas-process-fieldmapping',
submit: { gigyaData: gigyaData }
};
var myAjaxObject = Drupal.ajax(ajaxSettings);
myAjaxObject.execute();
};
}
};

})(jQuery, Drupal, drupalSettings);
55 changes: 0 additions & 55 deletions gigya_raas/js/gigyaRaas.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,60 +220,6 @@ var getUrlPrefix = function () {
}
};

/**
* @property gigya.accounts.showScreenSet
* @property drupalSettings.gigya.raas.customScreenSets
*/
var initCustomScreenSet = function () {
if (drupalSettings.gigya.enableRaaS) {
var customScreenSets = drupalSettings.gigya.raas.customScreenSets;

/**
* @property custom_screenset.display_type
* @property custom_screenset.link_id
* @property custom_screenset.container_id
* @property custom_screenset.desktop_screenset
* @property custom_screenset.mobile_screenset
* @property custom_screenset.sync_data
*/
customScreenSets.forEach(function (custom_screenset) {
if (typeof custom_screenset.display_type !== 'undefined') {
var screenset_params = {
screenSet: custom_screenset.desktop_screenset,
mobileScreenSet: custom_screenset.mobile_screenset
};
if (parseInt(custom_screenset.sync_data) === 1)
screenset_params['onAfterSubmit'] = processFieldMapping;

if (custom_screenset.display_type === 'popup') {
$('#' + custom_screenset.link_id).once('gigya-raas').click(function (e) {
e.preventDefault();
gigya.accounts.showScreenSet(screenset_params);
drupalSettings.gigya.raas.linkId = $(this).attr('id');
});
} else if (custom_screenset.display_type === 'embed') {
screenset_params['containerID'] = custom_screenset.container_id;
gigya.accounts.showScreenSet(screenset_params);
}
}
});
}
};

var processFieldMapping = function (data) {
var gigyaData = {
UID: data.response.UID,
UIDSignature: data.response.UIDSignature,
signatureTimestamp: data.response.signatureTimestamp
};
var ajaxSettings = {
url: getUrlPrefix() + 'gigya/raas-process-fieldmapping',
submit: {gigyaData: gigyaData}
};
var myAjaxObject = Drupal.ajax(ajaxSettings);
myAjaxObject.execute();
};

var init = function() {
if (drupalSettings.gigya.enableRaaS) {
gigyaHelper.addGigyaFunctionCall('accounts.addEventHandlers', {
Expand Down Expand Up @@ -304,7 +250,6 @@ var getUrlPrefix = function () {
gigyaHelper.runGigyaCmsInit();
initLoginUI();
initRaaS();
initCustomScreenSet();
};
init();
}
Expand Down
10 changes: 10 additions & 0 deletions gigya_raas/src/Plugin/Block/GigyaRaasCustomScreenset.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ public function build() {
'#display_type' => $config['display_type'],
'#container_id' => $config['container_id'],
'#screenset' => $screenset_params,
'#attached' => [
'library' => ['gigya_raas/customScreenSets'],
'drupalSettings' => [
'gigya' => [
'raas' => [
'customScreenSets' => [$config['container_id'] => $config],
],
],
],
],
];
return $build;
}
Expand Down
5 changes: 4 additions & 1 deletion gigya_raas/src/Plugin/Block/GigyaRaasLogin.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ class GigyaRaasLogin extends BlockBase {
public function build() {
$build['block'] = array(
'#theme' => 'gigya_raas_login_block',
'#showDiv' => \Drupal::currentUser()->isAnonymous()
'#showDiv' => \Drupal::currentUser()->isAnonymous(),
'#attached' => [
'library' => ['gigya_raas/gigyaRaas'],
],
);
$this->setConfigurationValue('label_display', 'hidden');

Expand Down
5 changes: 4 additions & 1 deletion gigya_raas/src/Plugin/Block/GigyaRaasProfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ class GigyaRaasProfile extends BlockBase {
public function build() {
$build['block'] = array(
'#theme' => 'gigya_raas_profile_block',
'#showDiv' => \Drupal::currentUser()->isAuthenticated()
'#showDiv' => \Drupal::currentUser()->isAuthenticated(),
'#attached' => [
'library' => ['gigya_raas/gigyaRaas'],
],
);
return $build;
}
Expand Down
5 changes: 4 additions & 1 deletion gigya_raas/src/Plugin/Block/GigyaRaasRegister.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ class GigyaRaasRegister extends BlockBase {
public function build() {
$build['block'] = array(
'#theme' => 'gigya_raas_register_block',
'#showDiv' => \Drupal::currentUser()->isAnonymous()
'#showDiv' => \Drupal::currentUser()->isAnonymous(),
'#attached' => [
'library' => ['gigya_raas/gigyaRaas'],
],
);
return $build;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @ingroup themeable
*/
#}
<div id="{% if container_id %}{{ container_id }}{% endif %}">
<div class="gigya-custom-screenset" id="{% if container_id %}{{ container_id }}{% endif %}">
{% if display_type == 'popup' %}
<span class="gigya-raas">
{% if link['popup'] %}
Expand All @@ -17,4 +17,4 @@
{{ container_id }}
{% else %}
{% endif %}
</div>
</div>