sizzlemctwizzle / GM_config

A lightweight, reusable, cross-browser graphical settings framework for inclusion in user scripts.

Home Page:https://github.com/sizzlemctwizzle/GM_config/wiki

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Strange issue with Unit Test

Martii opened this issue · comments

@sizzlemctwizzle

Hmmm...

Somewhere between 0f041ec and 136d28c the CSS on the Unit Test seems to have messed up. The form is all over the place. When I do the raw on 0f041e it's fine... but when I do your merge commit at 136d28 it messes up on page refresh.


OUJS-1 seems unaffected btw.

Here's the OUJS diff between these two consecutive commits (manual check for GH integrity):

--- /libs/Marti/GM_config_(test)/source@+010d533
+++ /libs/Marti/GM_config_(test)/source
@@ -165,12 +165,34 @@
 
         for (let id in fields) {
           var field = fields[id];
+          var fieldExists = false;
 
+          if (config.fields[id]) {
+            fieldExists = true;
+          }
+
           // for each field definition create a field object
-          if (field)
+          if (field) {
+            if (config.isOpen && fieldExists) {
+                config.fields[id].remove();
+            }
+
             config.fields[id] = new GM_configField(field, stored[id], id,
               customTypes[field.type], configId);
-          else if (config.fields[id]) delete config.fields[id];
+
+            // Add field to open frame
+            if (config.isOpen) {
+              config.fields[id].wrapper = config.fields[id].toNode();
+              config.frameSection.appendChild(config.fields[id].wrapper);
+            }
+          } else if (!field && fieldExists) {
+            // Remove field from open frame
+            if (config.isOpen) {
+              config.fields[id].remove();
+            }
+
+            delete config.fields[id];
+          }
         }
 
         config.isInit = true;
@@ -227,9 +249,13 @@
           className: 'config_header block center'
         }, config.title));
 
+        var secNum = 0; // Section count
         // Append elements
-        var section = bodyWrapper,
-            secNum = 0; // Section count
+        var section = bodyWrapper.appendChild(create('div', {
+          className: 'section_header_holder',
+          id: configId + '_section_' + (++secNum)
+        }));
+        
 
         // loop through fields
         for (let id in fields) {
@@ -262,6 +288,8 @@
           // Create field elements and append to current section
           section.appendChild((field.wrapper = field.toNode()));
         }
+        
+        config.frameSection = section;
 
         // Add save and close buttons
         bodyWrapper.appendChild(create('div',
@@ -521,6 +549,7 @@
       : (name, value) => localStorage.setItem(name, value);
     let log = typeof GM_log !== 'undefined' ? GM_log : console.log;
 
+    var GM = Object.create(null);
     GM.getValue = promisify(getValue);
     GM.setValue = promisify(setValue);
     GM.log = promisify(log);
@@ -530,7 +559,7 @@
   construct.prototype.parser = JSON.parse;
   construct.prototype.getValue = GM.getValue;
   construct.prototype.setValue = GM.setValue;
-  construct.prototype.log = GM.log || console.log;
+  construct.prototype.log = GM.log;
 
   // Passthrough frontends for new and old usage
   let config = function () {
@@ -870,4 +899,4 @@
     }
     return true;
   }
-};
+};
\ No newline at end of file

and GH's:

0f041ec...136d28c

This is likely caused by ab5451f. Although I'm not sure how I messed this up. Figured out a solution: only create a default section if no section is created.