Jelajahi Sumber

Add initialized flag

Denis K 8 tahun lalu
induk
melakukan
2c3c9685cc
2 mengubah file dengan 22 tambahan dan 8 penghapusan
  1. 8 0
      jet/static/jet/css/_header.scss
  2. 14 8
      jet/static/jet/js/src/features/themes.js

+ 8 - 0
jet/static/jet/css/_header.scss

@@ -203,3 +203,11 @@
     }
   }
 }
+
+.theme-chooser {
+  display: none;
+
+  &.initialized {
+    display: block;
+  }
+}

+ 14 - 8
jet/static/jet/js/src/features/themes.js

@@ -5,12 +5,16 @@ var $ = require('jquery');
 var Themes = function() { };
 
 Themes.prototype = {
-    moveChooser: function() {
-        var $chooser = $('.theme-chooser').detach();
-        $('.user-tools-welcome-msg').after($chooser);
+    moveChooser: function($chooser) {
+        $chooser
+            .detach()
+            .insertAfter($('.user-tools-welcome-msg'))
+            .addClass('initialized');
     },
-    initChooser: function() {
-        $('.choose-theme').on('click', function (e) {
+    initChooser: function($chooser) {
+        var $links = $chooser.find('.choose-theme');
+
+        $links.on('click', function (e) {
             e.preventDefault();
             
             var $link = $(this);
@@ -45,14 +49,16 @@ Themes.prototype = {
                     .remove();
             });
 
-            $('.choose-theme').removeClass('selected');
+            $links.removeClass('selected');
             $link.addClass('selected');
         });
     },
     run: function() {
+        var $chooser = $('.theme-chooser');
+
         try {
-            this.moveChooser();
-            this.initChooser();
+            this.moveChooser($chooser);
+            this.initChooser($chooser);
         } catch (e) {
             console.error(e, e.stack);
         }