Browse Source

turns out we don't need babel afterall

sisyphus
Dustin Falgout 9 years ago
parent
commit
38d1bd7d4b
  1. 4
      themes/antergos/index.html
  2. 132
      themes/antergos/js/greeter-compiled.js
  3. 2
      themes/antergos/js/greeter-compiled.js.map
  4. 141
      themes/antergos/js/greeter.js

4
themes/antergos/index.html

@ -53,7 +53,7 @@
<!-- Theme JavaScript --> <!-- Theme JavaScript -->
<script type="text/javascript" src="js/translations.js"></script> <script type="text/javascript" src="js/translations.js"></script>
<script type="text/javascript" src="js/greeter-compiled.js"></script> <script type="text/javascript" src="js/greeter.js"></script>
</head> </head>
@ -94,7 +94,7 @@
<div class="row"> <div class="row">
<div class="col-md-6 col-md-offset-3"> <div class="col-md-6 col-md-offset-3">
<!-- Login Dialog --> <!-- Login Dialog -->
<div id="login" class="panel panel-default login-box fade"> <div id="login" class="panel panel-default login-box">
<div class="panel-heading text-center"> <div class="panel-heading text-center">
<span class="pull-left"> <span class="pull-left">
<img src="img/antergos.png" data-greeter-config="logo" alt="Antergos"/> <img src="img/antergos.png" data-greeter-config="logo" alt="Antergos"/>

132
themes/antergos/js/greeter-compiled.js

@ -30,7 +30,8 @@
* This is used to access our classes from within jQuery callbacks. * This is used to access our classes from within jQuery callbacks.
*/ */
var _self = null, var _self = null,
_bg_self = null; _bg_self = null,
_util = null;
/** /**
* Capitalize a string. * Capitalize a string.
@ -44,9 +45,14 @@ String.prototype.capitalize = function () {
/** /**
* This is the base class for the theme's components. * This is the base class for the theme's components.
*/ */
class GreeterThemeComponent { class AntergosThemeUtils {
constructor() { constructor() {
if (null !== _util) {
return _util;
}
_util = this;
this.debug = true; this.debug = true;
this.lang = window.navigator.language.split('-')[0].toLowerCase(); this.lang = window.navigator.language.split('-')[0].toLowerCase();
this.translations = window.ant_translations; this.translations = window.ant_translations;
@ -79,7 +85,7 @@ class GreeterThemeComponent {
cache_get() { cache_get() {
var key = `ant`; var key = `ant`;
for (var _len = arguments.length, key_parts = Array(_len), _key = 0; _key < _len; _key++) { for (var _len = arguments.length, key_parts = new Array(_len), _key = 0; _key < _len; _key++) {
key_parts[_key] = arguments[_key]; key_parts[_key] = arguments[_key];
} }
@ -99,7 +105,7 @@ class GreeterThemeComponent {
cache_set(value) { cache_set(value) {
var key = `ant`; var key = `ant`;
for (var _len2 = arguments.length, key_parts = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { for (var _len2 = arguments.length, key_parts = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
key_parts[_key2 - 1] = arguments[_key2]; key_parts[_key2 - 1] = arguments[_key2];
} }
@ -119,17 +125,17 @@ class GreeterThemeComponent {
background_images_dir = ''; background_images_dir = '';
if ('undefined' !== typeof config) { if ('undefined' !== typeof config) {
if (this instanceof AntergosTheme) {
logo = config.get_str('branding', 'logo') || ''; logo = config.get_str('branding', 'logo') || '';
user_image = config.get_str('branding', 'user_image') || ''; user_image = config.get_str('branding', 'user_image') || '';
} else if (this instanceof AntergosBackgroundManager) {
background_images_dir = config.get_str('branding', 'background_images') || ''; background_images_dir = config.get_str('branding', 'background_images') || '';
if (background_images_dir) { if (background_images_dir) {
background_images = greeterutil.dirlist(background_images_dir) || []; background_images = greeterutil.dirlist(background_images_dir) || [];
} }
if (background_images.length) { if (background_images && background_images.length) {
let images = []; var images = [];
for (var file of background_images) { for (var file of background_images) {
if (file.match(/(png|PNG)|(jpg|JPEG)|(bmp|BMP)/)) { if (file.match(/(png|PNG)|(jpg|JPEG)|(bmp|BMP)/)) {
images.push(file); images.push(file);
@ -138,7 +144,6 @@ class GreeterThemeComponent {
background_images = images; background_images = images;
} }
} }
}
this.logo = logo; this.logo = logo;
this.user_image = user_image; this.user_image = user_image;
@ -150,23 +155,25 @@ class GreeterThemeComponent {
/** /**
* This class handles the theme's background switcher. * This class handles the theme's background switcher.
*/ */
class AntergosBackgroundManager extends GreeterThemeComponent { class AntergosBackgroundManager {
constructor() { constructor() {
super(); if (null !== _bg_self) {
if (null === _bg_self) { return _bg_self;
_bg_self = this;
} }
this.current_background = this.cache_get('background_manager', 'current_background'); _bg_self = this;
this.current_background = _util.cache_get('background_manager', 'current_background');
if (!this.background_images_dir.length || !this.background_images.length) { if (!_util.background_images_dir.length || !_util.background_images.length) {
this.log('AntergosBackgroundManager: [ERROR] No background images detected.'); this.log('AntergosBackgroundManager: [ERROR] No background images detected.');
$('.header').fadeTo(300, 0.5, function () { $('.header').fadeTo(300, 0.5, function () {
$('.header').css("background", '#000000'); $('.header').css("background", '#000000');
}).fadeTo(300, 1); }).fadeTo(300, 1);
} }
return _bg_self; return _bg_self;
} }
@ -175,53 +182,55 @@ class AntergosBackgroundManager extends GreeterThemeComponent {
// For backwards compatibility // For backwards compatibility
if (null !== localStorage.getItem('bgsaved') && '0' === localStorage.getItem('bgrandom')) { if (null !== localStorage.getItem('bgsaved') && '0' === localStorage.getItem('bgrandom')) {
this.current_background = localStorage.getItem('bgsaved'); this.current_background = localStorage.getItem('bgsaved');
this.cache_set(this.current_background, 'background_manager', 'current_background'); _util.cache_set(this.current_background, 'background_manager', 'current_background');
localStorage.removeItem('bgrandom'); localStorage.removeItem('bgrandom');
localStorage.removeItem('bgsaved'); localStorage.removeItem('bgsaved');
} else if ('0' === localStorage.getItem('bgrandom')) { } else {
if ('0' === localStorage.getItem('bgrandom')) {
this.current_background = this.get_random_image(); this.current_background = this.get_random_image();
this.cache_set('true', 'background_manager', 'random_background'); _util.cache_set('true', 'background_manager', 'random_background');
localStorage.removeItem('bgrandom'); localStorage.removeItem('bgrandom');
} }
} }
}
if (!this.current_background) { if (!this.current_background) {
// For current and future versions // For current and future versions
let current_background = this.cache_get('background_manager', 'current_background'), let current_background = _util.cache_get('background_manager', 'current_background'),
random_background = this.cache_get('background_manager', 'random_background'); random_background = _util.cache_get('background_manager', 'random_background');
if ('true' === random_background || !current_background) { if ('true' === random_background || !current_background) {
current_background = this.get_random_image(); current_background = this.get_random_image();
this.cache_set('true', 'background_manager', 'random_background'); _util.cache_set('true', 'background_manager', 'random_background');
} }
this.current_background = current_background; this.current_background = current_background;
this.cache_set(this.current_background, 'background_manager', 'current_background'); _util.cache_set(this.current_background, 'background_manager', 'current_background');
} }
this.do_background(); this.do_background();
} }
do_background() { do_background() {
if ('undefined' !== typeof this.current_background) {
$('.header').fadeTo(300, 0.5, function () { $('.header').fadeTo(300, 0.5, function () {
var tpl = `url(${ this.current_background })`; var tpl = `url(${ _bg_self.current_background })`;
$('.header').css("background-image", tpl); $('.header').css("background-image", tpl);
}).fadeTo(300, 1); }).fadeTo(300, 1);
} }
}
get_random_image() { get_random_image() {
var random_bg; var random_bg;
random_bg = Math.floor(Math.random() * this.background_images.length); random_bg = Math.floor(Math.random() * _util.background_images.length);
return this.background_images[random_bg]; return _util.background_images[random_bg];
} }
setup_background_thumbnails() { setup_background_thumbnails() {
if (this.background_images.length) { if (_util.background_images.length) {
for (var image_file of this.background_images) { $('[data-img="random"]').click(this.background_selected_handler);
for (var image_file of _util.background_images) {
var $link = $('<a href="#"><img>'), var $link = $('<a href="#"><img>'),
$img_el = $link.children('img'), $img_el = $link.children('img'),
tpl = `file://${ image_file }`; tpl = `file://${ image_file }`;
@ -238,11 +247,11 @@ class AntergosBackgroundManager extends GreeterThemeComponent {
var img = $(this).attr('data-img'); var img = $(this).attr('data-img');
if ('random' === img) { if ('random' === img) {
_bg_self.cache_set('true', 'background_manager', 'random_background'); _util.cache_set('true', 'background_manager', 'random_background');
img = _bg_self.get_random_image(); img = _bg_self.get_random_image();
} }
_bg_self.cache_set(img, 'background_manager', 'current_background'); _util.cache_set(img, 'background_manager', 'current_background');
_bg_self.current_background = img; _bg_self.current_background = img;
_bg_self.do_background(); _bg_self.do_background();
@ -252,13 +261,14 @@ class AntergosBackgroundManager extends GreeterThemeComponent {
/** /**
* This is the theme's main class object. It contains almost all the theme's logic. * This is the theme's main class object. It contains almost all the theme's logic.
*/ */
class AntergosTheme extends GreeterThemeComponent { class AntergosTheme {
constructor() { constructor() {
super(); if (null !== _self) {
if (null === _self) { return _self;
_self = this;
} }
_self = this;
this.tux = 'img/antergos-logo-user.png'; this.tux = 'img/antergos-logo-user.png';
this.user_list_visible = false; this.user_list_visible = false;
this.auth_pending = false; this.auth_pending = false;
@ -270,9 +280,10 @@ class AntergosTheme extends GreeterThemeComponent {
this.$actions_container = $("#actionsArea"); this.$actions_container = $("#actionsArea");
this.$msg_area_container = $('#statusArea'); this.$msg_area_container = $('#statusArea');
this.$msg_area = $('#showMsg'); this.$msg_area = $('#showMsg');
this.background_manager = new AntergosBackgroundManager();
this.background_manager = new AntergosBackgroundManager();
this.background_manager.initialize(); this.background_manager.initialize();
this.initialize(); this.initialize();
return _self; return _self;
@ -286,7 +297,6 @@ class AntergosTheme extends GreeterThemeComponent {
this.prepare_user_list(); this.prepare_user_list();
this.prepare_session_list(); this.prepare_session_list();
this.prepare_system_action_buttons(); this.prepare_system_action_buttons();
$("#login").addClass("in");
this.register_callbacks(); this.register_callbacks();
this.background_manager.setup_background_thumbnails(); this.background_manager.setup_background_thumbnails();
} }
@ -319,8 +329,8 @@ class AntergosTheme extends GreeterThemeComponent {
// Loop through the array of LightDMUser objects to create our user list. // Loop through the array of LightDMUser objects to create our user list.
for (var user of lightdm.users) { for (var user of lightdm.users) {
var last_session = this.cache_get('user', user.name, 'session'), var last_session = _util.cache_get('user', user.name, 'session'),
image_src = user.image.length ? user.image : this.user_image; image_src = user.image.length ? user.image : _util.user_image;
if (null === last_session) { if (null === last_session) {
// For backwards compatibility // For backwards compatibility
@ -330,10 +340,10 @@ class AntergosTheme extends GreeterThemeComponent {
// session. // session.
last_session = lightdm.default_session; last_session = lightdm.default_session;
} }
this.cache_set(last_session, 'user', user.name, 'session'); _util.cache_set(last_session, 'user', user.name, 'session');
} }
this.log(`Last session for ${ user.name } was: ${ last_session }`); _util.log(`Last session for ${ user.name } was: ${ last_session }`);
template = ` template = `
<a href="#" id="${ user.name }" class="list-group-item ${ user.name }" data-session="${ last_session }"> <a href="#" id="${ user.name }" class="list-group-item ${ user.name }" data-session="${ last_session }">
@ -361,7 +371,7 @@ class AntergosTheme extends GreeterThemeComponent {
var css_class = session.name.replace(/ /g, ''), var css_class = session.name.replace(/ /g, ''),
template; template;
this.log(`Adding ${ session.name } to the session list...`); _util.log(`Adding ${ session.name } to the session list...`);
template = ` template = `
<li> <li>
@ -404,7 +414,7 @@ class AntergosTheme extends GreeterThemeComponent {
} }
initialize_clock() { initialize_clock() {
var saved_format = this.cache_get('clock', 'time_format'), var saved_format = _util.cache_get('clock', 'time_format'),
format = null !== saved_format ? saved_format : 'LT'; format = null !== saved_format ? saved_format : 'LT';
moment.locale(window.navigator.languages); moment.locale(window.navigator.languages);
@ -429,8 +439,8 @@ class AntergosTheme extends GreeterThemeComponent {
} }
prepare_login_panel_header() { prepare_login_panel_header() {
var greeting = this.translations.greeting ? this.translations.greeting : 'Welcome!', var greeting = _util.translations.greeting ? _util.translations.greeting : 'Welcome!',
logo = '' !== this.logo ? this.logo : 'img/antergos.png'; logo = '' !== _util.logo ? _util.logo : 'img/antergos.png';
$('.welcome').text(greeting); $('.welcome').text(greeting);
$('#hostname').append(lightdm.hostname); $('#hostname').append(lightdm.hostname);
@ -438,19 +448,19 @@ class AntergosTheme extends GreeterThemeComponent {
} }
prepare_translations() { prepare_translations() {
if (!this.translations.hasOwnProperty(this.lang)) { if (!_util.translations.hasOwnProperty(this.lang)) {
for (var lang of window.navigator.languages) { for (var lang of window.navigator.languages) {
if (this.translations.hasOwnProperty(lang)) { if (_util.translations.hasOwnProperty(lang)) {
this.lang = lang; this.lang = lang;
break; break;
} }
} }
} }
if (!this.translations.hasOwnProperty(this.lang)) { if (!_util.translations.hasOwnProperty(this.lang)) {
this.lang = 'en'; this.lang = 'en';
} }
this.translations = this.translations[this.lang]; _util.translations = _util.translations[this.lang];
} }
/** /**
@ -462,7 +472,7 @@ class AntergosTheme extends GreeterThemeComponent {
$('[data-i18n]').each(function () { $('[data-i18n]').each(function () {
var key = $(this).attr('data-i18n'), var key = $(this).attr('data-i18n'),
html = $(this).html(), html = $(this).html(),
translated = _self.translations[key], translated = _util.translations[key],
new_html = html.replace('${i18n}', translated); new_html = html.replace('${i18n}', translated);
$(this).html(new_html); $(this).html(new_html);
@ -477,15 +487,15 @@ class AntergosTheme extends GreeterThemeComponent {
start_authentication(event) { start_authentication(event) {
var user_id = $(this).attr('id'), var user_id = $(this).attr('id'),
selector = `.${ user_id }`, selector = `.${ user_id }`,
user_session = _self.cache_get('user', user_id, 'session'); user_session = _util.cache_get('user', user_id, 'session');
if (_self.auth_pending || null !== _self.selected_user) { if (_self.auth_pending || null !== _self.selected_user) {
lightdm.cancel_authentication(); lightdm.cancel_authentication();
_self.log(`Authentication cancelled for ${ _self.selected_user }`); _util.log(`Authentication cancelled for ${ _self.selected_user }`);
_self.selected_user = null; _self.selected_user = null;
} }
_self.log(`Starting authentication for ${ user_id }.`); _util.log(`Starting authentication for ${ user_id }.`);
_self.selected_user = user_id; _self.selected_user = user_id;
// CSS hack to workaround webkit bug // CSS hack to workaround webkit bug
@ -495,7 +505,7 @@ class AntergosTheme extends GreeterThemeComponent {
$(selector).addClass('hovered').siblings().hide(); $(selector).addClass('hovered').siblings().hide();
$('.fa-toggle-down').hide(); $('.fa-toggle-down').hide();
_self.log(`Session for ${ user_id } is ${ user_session }`); _util.log(`Session for ${ user_id } is ${ user_session }`);
$(`[data-session-id="${ user_session }"]`).parent().trigger('click', this); $(`[data-session-id="${ user_session }"]`).parent().trigger('click', this);
@ -522,7 +532,7 @@ class AntergosTheme extends GreeterThemeComponent {
lightdm.cancel_authentication(); lightdm.cancel_authentication();
_self.log('Cancelled authentication.'); _util.log('Cancelled authentication.');
// CSS hack to work-around webkit bug // CSS hack to work-around webkit bug
if ($(_self.$user_list).children().length > 3) { if ($(_self.$user_list).children().length > 3) {
@ -543,17 +553,18 @@ class AntergosTheme extends GreeterThemeComponent {
*/ */
authentication_complete() { authentication_complete() {
var selected_session = $('.selected').attr('data-session-id'), var selected_session = $('.selected').attr('data-session-id'),
err_msg = _self.translations.auth_failed[_self.lang]; err_msg = _util.translations.auth_failed[_self.lang];
_self.auth_pending = false; _self.auth_pending = false;
_self.cache_set(selected_session, 'user', lightdm.authentication_user, 'session'); _util.cache_set(selected_session, 'user', lightdm.authentication_user, 'session');
$('#timerArea').hide(); $('#timerArea').hide();
if (lightdm.is_authenticated) { if (lightdm.is_authenticated) {
// The user entered the correct password. Let's log them in. // The user entered the correct password. Let's log them in.
$('body').fadeOut(1000); $('body').fadeOut(1000, () => {
lightdm.login(lightdm.authentication_user, selected_session); lightdm.login(lightdm.authentication_user, selected_session);
});
} else { } else {
// The user did not enter the correct password. Show error message. // The user did not enter the correct password. Show error message.
$('#statusArea').show(); $('#statusArea').show();
@ -598,7 +609,7 @@ class AntergosTheme extends GreeterThemeComponent {
var action = $(this).attr('id'), var action = $(this).attr('id'),
$modal = $('.modal'); $modal = $('.modal');
$modal.find('.btn-primary').text(_self.translations[action]).click(action, event => { $modal.find('.btn-primary').text(_util.translations[action]).click(action, event => {
$(this).off('click'); $(this).off('click');
lightdm[event.data](); lightdm[event.data]();
}); });
@ -650,7 +661,8 @@ class AntergosTheme extends GreeterThemeComponent {
* Initialize the theme once the window has loaded. * Initialize the theme once the window has loaded.
*/ */
$(window).load(() => { $(window).load(() => {
_self = new AntergosTheme(); new AntergosThemeUtils();
new AntergosTheme();
}); });
//# sourceMappingURL=greeter-compiled.js.map //# sourceMappingURL=greeter-compiled.js.map

2
themes/antergos/js/greeter-compiled.js.map

File diff suppressed because one or more lines are too long

141
themes/antergos/js/greeter.js

@ -31,7 +31,8 @@
* This is used to access our classes from within jQuery callbacks. * This is used to access our classes from within jQuery callbacks.
*/ */
var _self = null, var _self = null,
_bg_self = null; _bg_self = null,
_util = null;
/** /**
@ -51,9 +52,14 @@ String.prototype.capitalize = function() {
/** /**
* This is the base class for the theme's components. * This is the base class for the theme's components.
*/ */
class GreeterThemeComponent { class AntergosThemeUtils {
constructor() { constructor() {
if ( null !== _util ) {
return _util;
}
_util = this;
this.debug = true; this.debug = true;
this.lang = window.navigator.language.split( '-' )[ 0 ].toLowerCase(); this.lang = window.navigator.language.split( '-' )[ 0 ].toLowerCase();
this.translations = window.ant_translations; this.translations = window.ant_translations;
@ -85,9 +91,13 @@ class GreeterThemeComponent {
* *
* @param {...string} key_parts - Strings that are combined to form the key. * @param {...string} key_parts - Strings that are combined to form the key.
*/ */
cache_get( ...key_parts ) { cache_get() {
var key = `ant`; var key = `ant`;
for (var _len = arguments.length, key_parts = new Array(_len), _key = 0; _key < _len; _key++) {
key_parts[_key] = arguments[_key];
}
for ( var part of key_parts ) { for ( var part of key_parts ) {
key += `:${part}`; key += `:${part}`;
} }
@ -102,9 +112,13 @@ class GreeterThemeComponent {
* @param {string} value - The value to set. * @param {string} value - The value to set.
* @param {...string} key_parts - Strings that are combined to form the key. * @param {...string} key_parts - Strings that are combined to form the key.
*/ */
cache_set( value, ...key_parts ) { cache_set( value ) {
var key = `ant`; var key = `ant`;
for (var _len2 = arguments.length, key_parts = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
key_parts[_key2 - 1] = arguments[_key2];
}
for ( var part of key_parts ) { for ( var part of key_parts ) {
key += `:${part}`; key += `:${part}`;
} }
@ -119,18 +133,18 @@ class GreeterThemeComponent {
var logo = '', user_image = '', background_images = [], background_images_dir = ''; var logo = '', user_image = '', background_images = [], background_images_dir = '';
if ( 'undefined' !== typeof config ) { if ( 'undefined' !== typeof config ) {
if ( this instanceof AntergosTheme ) {
logo = config.get_str( 'branding', 'logo' ) || ''; logo = config.get_str( 'branding', 'logo' ) || '';
user_image = config.get_str( 'branding', 'user_image' ) || ''; user_image = config.get_str( 'branding', 'user_image' ) || '';
} else if ( this instanceof AntergosBackgroundManager ) {
background_images_dir = config.get_str( 'branding', 'background_images' ) || ''; background_images_dir = config.get_str( 'branding', 'background_images' ) || '';
if ( background_images_dir ) { if ( background_images_dir ) {
background_images = greeterutil.dirlist( background_images_dir ) || []; background_images = greeterutil.dirlist( background_images_dir ) || [];
} }
if (background_images.length) { if ( background_images && background_images.length ) {
let images = []; var images = [];
for ( var file of background_images ) { for ( var file of background_images ) {
if ( file.match( /(png|PNG)|(jpg|JPEG)|(bmp|BMP)/ ) ) { if ( file.match( /(png|PNG)|(jpg|JPEG)|(bmp|BMP)/ ) ) {
images.push( file ); images.push( file );
@ -138,7 +152,7 @@ class GreeterThemeComponent {
} }
background_images = images; background_images = images;
} }
}
} }
this.logo = logo; this.logo = logo;
@ -156,17 +170,18 @@ class GreeterThemeComponent {
/** /**
* This class handles the theme's background switcher. * This class handles the theme's background switcher.
*/ */
class AntergosBackgroundManager extends GreeterThemeComponent { class AntergosBackgroundManager {
constructor() { constructor() {
super(); if ( null !== _bg_self ) {
if ( null === _bg_self ) { return _bg_self;
_bg_self = this;
} }
this.current_background = this.cache_get( 'background_manager', 'current_background' ); _bg_self = this;
this.current_background = _util.cache_get( 'background_manager', 'current_background' );
if ( ! this.background_images_dir.length || ! this.background_images.length ) { if ( ! _util.background_images_dir.length || ! _util.background_images.length ) {
this.log( 'AntergosBackgroundManager: [ERROR] No background images detected.' ); this.log( 'AntergosBackgroundManager: [ERROR] No background images detected.' );
$( '.header' ).fadeTo( 300, 0.5, function() { $( '.header' ).fadeTo( 300, 0.5, function() {
@ -174,6 +189,7 @@ class AntergosBackgroundManager extends GreeterThemeComponent {
} ).fadeTo( 300, 1 ); } ).fadeTo( 300, 1 );
} }
return _bg_self; return _bg_self;
} }
@ -183,28 +199,30 @@ class AntergosBackgroundManager extends GreeterThemeComponent {
// For backwards compatibility // For backwards compatibility
if ( null !== localStorage.getItem( 'bgsaved' ) && '0' === localStorage.getItem( 'bgrandom' ) ) { if ( null !== localStorage.getItem( 'bgsaved' ) && '0' === localStorage.getItem( 'bgrandom' ) ) {
this.current_background = localStorage.getItem( 'bgsaved' ); this.current_background = localStorage.getItem( 'bgsaved' );
this.cache_set( this.current_background, 'background_manager', 'current_background' ); _util.cache_set( this.current_background, 'background_manager', 'current_background' );
localStorage.removeItem( 'bgrandom' ); localStorage.removeItem( 'bgrandom' );
localStorage.removeItem( 'bgsaved' ); localStorage.removeItem( 'bgsaved' );
} else if ( '0' === localStorage.getItem( 'bgrandom' ) ) { } else {
if ( '0' === localStorage.getItem( 'bgrandom' ) ) {
this.current_background = this.get_random_image(); this.current_background = this.get_random_image();
this.cache_set( 'true', 'background_manager', 'random_background' ); _util.cache_set( 'true', 'background_manager', 'random_background' );
localStorage.removeItem( 'bgrandom' ); localStorage.removeItem( 'bgrandom' );
} }
} }
}
if ( ! this.current_background ) { if ( ! this.current_background ) {
// For current and future versions // For current and future versions
let current_background = this.cache_get('background_manager', 'current_background' ), let current_background = _util.cache_get( 'background_manager', 'current_background' ),
random_background = this.cache_get('background_manager', 'random_background' ); random_background = _util.cache_get( 'background_manager', 'random_background' );
if ( 'true' === random_background || ! current_background ) { if ( 'true' === random_background || ! current_background ) {
current_background = this.get_random_image(); current_background = this.get_random_image();
this.cache_set( 'true', 'background_manager', 'random_background' ); _util.cache_set( 'true', 'background_manager', 'random_background' );
} }
this.current_background = current_background; this.current_background = current_background;
this.cache_set( this.current_background, 'background_manager', 'current_background' ); _util.cache_set( this.current_background, 'background_manager', 'current_background' );
} }
this.do_background(); this.do_background();
@ -212,26 +230,26 @@ class AntergosBackgroundManager extends GreeterThemeComponent {
do_background() { do_background() {
if ('undefined' !== typeof this.current_background) {
$( '.header' ).fadeTo( 300, 0.5, function() { $( '.header' ).fadeTo( 300, 0.5, function() {
var tpl = `url(${this.current_background})`; var tpl = `url(${_bg_self.current_background})`;
$( '.header' ).css( "background-image", tpl ); $( '.header' ).css( "background-image", tpl );
} ).fadeTo( 300, 1 ); } ).fadeTo( 300, 1 );
} }
}
get_random_image() { get_random_image() {
var random_bg; var random_bg;
random_bg = Math.floor( Math.random() * this.background_images.length ); random_bg = Math.floor( Math.random() * _util.background_images.length );
return this.background_images[ random_bg ]; return _util.background_images[ random_bg ];
} }
setup_background_thumbnails() { setup_background_thumbnails() {
if (this.background_images.length) { if ( _util.background_images.length ) {
for ( var image_file of this.background_images ) { $('[data-img="random"]').click(this.background_selected_handler);
for ( var image_file of _util.background_images ) {
var $link = $( '<a href="#"><img>' ), var $link = $( '<a href="#"><img>' ),
$img_el = $link.children( 'img' ), $img_el = $link.children( 'img' ),
tpl = `file://${image_file}`; tpl = `file://${image_file}`;
@ -249,11 +267,11 @@ class AntergosBackgroundManager extends GreeterThemeComponent {
var img = $( this ).attr( 'data-img' ); var img = $( this ).attr( 'data-img' );
if ( 'random' === img ) { if ( 'random' === img ) {
_bg_self.cache_set('true', 'background_manager', 'random_background' ); _util.cache_set( 'true', 'background_manager', 'random_background' );
img = _bg_self.get_random_image(); img = _bg_self.get_random_image();
} }
_bg_self.cache_set(img, 'background_manager', 'current_background' ); _util.cache_set( img, 'background_manager', 'current_background' );
_bg_self.current_background = img; _bg_self.current_background = img;
_bg_self.do_background(); _bg_self.do_background();
@ -268,13 +286,14 @@ class AntergosBackgroundManager extends GreeterThemeComponent {
/** /**
* This is the theme's main class object. It contains almost all the theme's logic. * This is the theme's main class object. It contains almost all the theme's logic.
*/ */
class AntergosTheme extends GreeterThemeComponent { class AntergosTheme {
constructor() { constructor() {
super(); if ( null !== _self ) {
if ( null === _self ) { return _self;
_self = this;
} }
_self = this;
this.tux = 'img/antergos-logo-user.png'; this.tux = 'img/antergos-logo-user.png';
this.user_list_visible = false; this.user_list_visible = false;
this.auth_pending = false; this.auth_pending = false;
@ -286,9 +305,10 @@ class AntergosTheme extends GreeterThemeComponent {
this.$actions_container = $( "#actionsArea" ); this.$actions_container = $( "#actionsArea" );
this.$msg_area_container = $( '#statusArea' ); this.$msg_area_container = $( '#statusArea' );
this.$msg_area = $( '#showMsg' ); this.$msg_area = $( '#showMsg' );
this.background_manager = new AntergosBackgroundManager();
this.background_manager = new AntergosBackgroundManager();
this.background_manager.initialize(); this.background_manager.initialize();
this.initialize(); this.initialize();
return _self; return _self;
@ -302,7 +322,6 @@ class AntergosTheme extends GreeterThemeComponent {
this.prepare_user_list(); this.prepare_user_list();
this.prepare_session_list(); this.prepare_session_list();
this.prepare_system_action_buttons(); this.prepare_system_action_buttons();
$( "#login" ).addClass( "in" );
this.register_callbacks(); this.register_callbacks();
this.background_manager.setup_background_thumbnails(); this.background_manager.setup_background_thumbnails();
} }
@ -336,8 +355,8 @@ class AntergosTheme extends GreeterThemeComponent {
// Loop through the array of LightDMUser objects to create our user list. // Loop through the array of LightDMUser objects to create our user list.
for ( var user of lightdm.users ) { for ( var user of lightdm.users ) {
var last_session = this.cache_get( 'user', user.name, 'session' ), var last_session = _util.cache_get( 'user', user.name, 'session' ),
image_src = user.image.length ? user.image : this.user_image; image_src = user.image.length ? user.image : _util.user_image;
if ( null === last_session ) { if ( null === last_session ) {
// For backwards compatibility // For backwards compatibility
@ -347,10 +366,10 @@ class AntergosTheme extends GreeterThemeComponent {
// session. // session.
last_session = lightdm.default_session; last_session = lightdm.default_session;
} }
this.cache_set( last_session, 'user', user.name, 'session' ); _util.cache_set( last_session, 'user', user.name, 'session' );
} }
this.log( `Last session for ${user.name} was: ${last_session}` ); _util.log( `Last session for ${user.name} was: ${last_session}` );
template = ` template = `
<a href="#" id="${user.name}" class="list-group-item ${user.name}" data-session="${last_session}"> <a href="#" id="${user.name}" class="list-group-item ${user.name}" data-session="${last_session}">
@ -380,7 +399,7 @@ class AntergosTheme extends GreeterThemeComponent {
var css_class = session.name.replace( / /g, '' ), var css_class = session.name.replace( / /g, '' ),
template; template;
this.log( `Adding ${session.name} to the session list...` ); _util.log( `Adding ${session.name} to the session list...` );
template = ` template = `
<li> <li>
@ -424,7 +443,7 @@ class AntergosTheme extends GreeterThemeComponent {
} }
initialize_clock() { initialize_clock() {
var saved_format = this.cache_get( 'clock', 'time_format' ), var saved_format = _util.cache_get( 'clock', 'time_format' ),
format = (null !== saved_format) ? saved_format : 'LT'; format = (null !== saved_format) ? saved_format : 'LT';
moment.locale( window.navigator.languages ); moment.locale( window.navigator.languages );
@ -451,8 +470,8 @@ class AntergosTheme extends GreeterThemeComponent {
prepare_login_panel_header() { prepare_login_panel_header() {
var greeting = (this.translations.greeting) ? this.translations.greeting : 'Welcome!', var greeting = (_util.translations.greeting) ? _util.translations.greeting : 'Welcome!',
logo = ( '' !== this.logo ) ? this.logo : 'img/antergos.png'; logo = ( '' !== _util.logo ) ? _util.logo : 'img/antergos.png';
$( '.welcome' ).text( greeting ); $( '.welcome' ).text( greeting );
$( '#hostname' ).append( lightdm.hostname ); $( '#hostname' ).append( lightdm.hostname );
@ -461,19 +480,19 @@ class AntergosTheme extends GreeterThemeComponent {
prepare_translations() { prepare_translations() {
if ( ! this.translations.hasOwnProperty( this.lang ) ) { if ( ! _util.translations.hasOwnProperty( this.lang ) ) {
for ( var lang of window.navigator.languages ) { for ( var lang of window.navigator.languages ) {
if ( this.translations.hasOwnProperty( lang ) ) { if ( _util.translations.hasOwnProperty( lang ) ) {
this.lang = lang; this.lang = lang;
break; break;
} }
} }
} }
if ( ! this.translations.hasOwnProperty( this.lang ) ) { if ( ! _util.translations.hasOwnProperty( this.lang ) ) {
this.lang = 'en'; this.lang = 'en';
} }
this.translations = this.translations[ this.lang ]; _util.translations = _util.translations[ this.lang ];
} }
@ -486,7 +505,7 @@ class AntergosTheme extends GreeterThemeComponent {
$( '[data-i18n]' ).each( function() { $( '[data-i18n]' ).each( function() {
var key = $( this ).attr( 'data-i18n' ), var key = $( this ).attr( 'data-i18n' ),
html = $( this ).html(), html = $( this ).html(),
translated = _self.translations[ key ], translated = _util.translations[ key ],
new_html = html.replace( '${i18n}', translated ); new_html = html.replace( '${i18n}', translated );
$( this ).html( new_html ); $( this ).html( new_html );
@ -502,15 +521,15 @@ class AntergosTheme extends GreeterThemeComponent {
start_authentication( event ) { start_authentication( event ) {
var user_id = $( this ).attr( 'id' ), var user_id = $( this ).attr( 'id' ),
selector = `.${user_id}`, selector = `.${user_id}`,
user_session = _self.cache_get( 'user', user_id, 'session' ); user_session = _util.cache_get( 'user', user_id, 'session' );
if ( _self.auth_pending || null !== _self.selected_user ) { if ( _self.auth_pending || null !== _self.selected_user ) {
lightdm.cancel_authentication(); lightdm.cancel_authentication();
_self.log( `Authentication cancelled for ${_self.selected_user}` ); _util.log( `Authentication cancelled for ${_self.selected_user}` );
_self.selected_user = null; _self.selected_user = null;
} }
_self.log( `Starting authentication for ${user_id}.` ); _util.log( `Starting authentication for ${user_id}.` );
_self.selected_user = user_id; _self.selected_user = user_id;
// CSS hack to workaround webkit bug // CSS hack to workaround webkit bug
@ -520,7 +539,7 @@ class AntergosTheme extends GreeterThemeComponent {
$( selector ).addClass( 'hovered' ).siblings().hide(); $( selector ).addClass( 'hovered' ).siblings().hide();
$( '.fa-toggle-down' ).hide(); $( '.fa-toggle-down' ).hide();
_self.log( `Session for ${user_id} is ${user_session}` ); _util.log( `Session for ${user_id} is ${user_session}` );
$( `[data-session-id="${user_session}"]` ).parent().trigger( 'click', this ); $( `[data-session-id="${user_session}"]` ).parent().trigger( 'click', this );
@ -548,7 +567,7 @@ class AntergosTheme extends GreeterThemeComponent {
lightdm.cancel_authentication(); lightdm.cancel_authentication();
_self.log( 'Cancelled authentication.' ); _util.log( 'Cancelled authentication.' );
// CSS hack to work-around webkit bug // CSS hack to work-around webkit bug
if ( $( _self.$user_list ).children().length > 3 ) { if ( $( _self.$user_list ).children().length > 3 ) {
@ -571,17 +590,18 @@ class AntergosTheme extends GreeterThemeComponent {
*/ */
authentication_complete() { authentication_complete() {
var selected_session = $( '.selected' ).attr( 'data-session-id' ), var selected_session = $( '.selected' ).attr( 'data-session-id' ),
err_msg = _self.translations.auth_failed[ _self.lang ]; err_msg = _util.translations.auth_failed[ _self.lang ];
_self.auth_pending = false; _self.auth_pending = false;
_self.cache_set( selected_session, 'user', lightdm.authentication_user, 'session' ); _util.cache_set( selected_session, 'user', lightdm.authentication_user, 'session' );
$( '#timerArea' ).hide(); $( '#timerArea' ).hide();
if ( lightdm.is_authenticated ) { if ( lightdm.is_authenticated ) {
// The user entered the correct password. Let's log them in. // The user entered the correct password. Let's log them in.
$('body').fadeOut(1000); $( 'body' ).fadeOut( 1000, () => {
lightdm.login( lightdm.authentication_user, selected_session ); lightdm.login( lightdm.authentication_user, selected_session );
} );
} else { } else {
// The user did not enter the correct password. Show error message. // The user did not enter the correct password. Show error message.
$( '#statusArea' ).show(); $( '#statusArea' ).show();
@ -626,7 +646,7 @@ class AntergosTheme extends GreeterThemeComponent {
var action = $( this ).attr( 'id' ), var action = $( this ).attr( 'id' ),
$modal = $( '.modal' ); $modal = $( '.modal' );
$modal.find( '.btn-primary' ).text( _self.translations[ action ] ).click( action, ( event ) => { $modal.find( '.btn-primary' ).text( _util.translations[ action ] ).click( action, ( event ) => {
$( this ).off( 'click' ); $( this ).off( 'click' );
lightdm[ event.data ](); lightdm[ event.data ]();
} ); } );
@ -682,6 +702,7 @@ class AntergosTheme extends GreeterThemeComponent {
* Initialize the theme once the window has loaded. * Initialize the theme once the window has loaded.
*/ */
$( window ).load( () => { $( window ).load( () => {
_self = new AntergosTheme(); new AntergosThemeUtils();
new AntergosTheme();
} ); } );

Loading…
Cancel
Save