Skip to content

Commit

Permalink
= 1.5.8 =
Browse files Browse the repository at this point in the history
* Login JS script is now correctly enqueue and check for correct jQuery version to avoid theme conflicts
  • Loading branch information
unloqer-io committed May 10, 2017
1 parent 7014e7e commit ef2245e
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 17 deletions.
58 changes: 44 additions & 14 deletions assets/js/login.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,47 @@
/*
* Included when the site uses both UNLOQ and password login. This is used to perform the toggle.
* */
jQuery(function($) {
var $btn = $("#btnInitUnloq"),
$login = $("#login"),
$form = $login.find("form").first();
if($login.size() === 0 || $btn.size() === 0) {
// something went wrong.
console.error('UNLOQ Failed to initialize, the login form was no-where to be found.');
return;
(function() {
var JQUERY_INTEGRITY = 'sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=';
var JQUERY_URL = "https://code.jquery.com/jquery-1.12.4.min.js";

if (typeof window.jQuery === 'object' && window.jQuery && typeof window.jQuery.noConflict === 'function') {
loadPlugin(window.jQuery.noConflict());
} else {
var script = document.createElement('script');
script.onload = function() {
loadPlugin(jQuery.noConflict());
};
script.onerror = function() {
console.error('Could not load jQuery dependency');
};
script.integrity = JQUERY_INTEGRITY;
try {
script.setAttribute('integrity', JQUERY_INTEGRITY);
} catch (e) {
}
script.crossorigin = "anonymous";
try {
script.setAttribute('crossorigin', 'anonymous');
} catch (e) {
}
script.src = JQUERY_URL;
document.getElementsByTagName('head')[0].appendChild(script);
}
var PLUGIN_URL = $btn.attr("data-script"),
PLUGIN_THEME = $btn.attr("data-theme"),
PLUGIN_KEY = $btn.attr("data-key");
$btn.remove();

function loadPlugin($) {
var $btn = $("#btnInitUnloq"),
$login = $("#login"),
$form = $login.find("form").first();
if($login.size() === 0 || $btn.size() === 0) {
// something went wrong.
console.error('UNLOQ Failed to initialize, the login form was no-where to be found.');
return;
}
var PLUGIN_URL = $btn.attr("data-script"),
PLUGIN_THEME = $btn.attr("data-theme"),
PLUGIN_KEY = $btn.attr("data-key");
$btn.remove();
$form.wrap("<div class='tabs'></div>");
var $tabs = $form.parent();
$tabs.prepend('<div class="unloq-login-box"></div>');
Expand Down Expand Up @@ -54,8 +82,10 @@ jQuery(function($) {
$parent.addClass('password-active');
}
}

$tabs.on('click touchstart', '> .tab', onChange);
if($tabs.hasClass('unloq-active')) {
initialize();
initialize();
}
}
});
})();
5 changes: 4 additions & 1 deletion inc/class.util.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,12 @@ public static function register_js($name, $dep = null) {
if (!wp_script_is($name, 'registered')) {
wp_register_script($name, $url, $dep);
}
if (!wp_script_is($name, 'enqueued')) {
if(!wp_script_is($name, 'enqueued')) {
wp_enqueue_script($name);
}
if($dep != null && !wp_script_is($dep)) {
wp_enqueue_script($dep);
}
return $name;
}

Expand Down
3 changes: 3 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ For now, UNLOQ is available in English. Please consider helping translate UNLOQ.


== Changelog ==
= 1.5.8 =
* Login JS script is now correctly enqueue and check for correct jQuery version to avoid theme conflicts

= 1.5.7 =
* Fixed static declaration to use array() constructor

Expand Down
2 changes: 1 addition & 1 deletion templates/login.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<?php
// Login with UNLOQ or passwords
if ($unloq_type == "UNLOQ_PASS") {
UnloqUtil::register_js('login', array('jquery'));
UnloqUtil::register_js('login', 'jquery');
?>
<div id="btnInitUnloq" class="unloq-init" data-script="<?php echo UnloqApi::PLUGIN_LOGIN; ?>" data-theme="<?php echo $unloq_theme; ?>" data-key="<?php echo $unloq_api_key; ?>"></div>

Expand Down
2 changes: 1 addition & 1 deletion unloq.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
Plugin Name: UNLOQ.io authentication
Plugin URI: https://unloq.io
Version: 1.5.7
Version: 1.5.8
Author: UNLOQ.io
Description: Perform UNLOQ.io authentications with the click of a button
*/
Expand Down

0 comments on commit ef2245e

Please sign in to comment.