Commits

Cat's Eye Technologies committed 2cf3435

Add .click_start(), .click_stop(), for better button management.

  • Participants
  • Parent commits 19f7dc4

Comments (0)

Files changed (2)

File src/yoob/controller.js

                 this.controls[key] = value;
             }
         }
+        if (this.controls.stop) {
+            this.controls.stop.disabled = true;
+        }
 
         var keys = ["source", "display"];
         for (var i in keys) {
             if (typeof value === 'string') {
                 value = document.getElementById(value);
             }
-            if (value !== undefined) {
+            if (value) {
                 this[key] = value;
             }
         }
         if (typeof speed === 'string') {
             speed = document.getElementById(speed);
         }
-        if (speed !== undefined) {
+        if (speed) {
             this.speed = speed;
             speed.value = this.delay;
             var $this = this;
     };
 
     this.click_load = function(e) {
-        this.stop();
+        this.click_stop();
         this.load(this.source.value);
         if (this.controls.edit) this.controls.edit.style.display = "inline";
         if (this.controls.load) this.controls.load.style.display = "none";
         if (this.controls.start) this.controls.start.disabled = false;
         if (this.controls.step) this.controls.step.disabled = false;
-        if (this.controls.stop) this.controls.stop.disabled = false;
+        if (this.controls.stop) this.controls.stop.disabled = true;
         if (this.display) this.display.style.display = "block";
         if (this.source) this.source.style.display = "none";
     };
     };
 
     this.click_edit = function(e) {
-        this.stop();
+        this.click_stop();
         if (this.controls.edit) this.controls.edit.style.display = "none";
         if (this.controls.load) this.controls.load.style.display = "inline";
         if (this.controls.start) this.controls.start.disabled = true;
         if (this.source) this.source.style.display = "block";
     };
 
+    this.click_start = function(e) {
+        this.start();
+        if (this.controls.start) this.controls.start.disabled = true;
+        if (this.controls.step) this.controls.step.disabled = false;
+        if (this.controls.stop) this.controls.stop.disabled = false;
+    };
+
     this.start = function() {
         if (this.intervalId !== undefined)
             return;
         this.intervalId = setInterval(function() { $this.step(); }, this.delay);
     };
 
+    this.click_stop = function(e) {
+        this.stop();
+        if (this.controls.stop && this.controls.stop.disabled) {
+            return;
+        }
+        if (this.controls.start) this.controls.start.disabled = false;
+        if (this.controls.step) this.controls.step.disabled = false;
+        if (this.controls.stop) this.controls.stop.disabled = true;
+    };
+
     this.stop = function() {
         if (this.intervalId === undefined)
             return;

File src/yoob/example-manager.js

         this.selectElem.options.add(opt);
         var $this = this;
         this.reactTo[id] = callback || function(id) {
-            $this.controller.stop(); // in case it is currently running
+            $this.controller.click_stop(); // in case it is currently running
             $this.controller.loadSourceFromHTML(
               document.getElementById(id).innerHTML
             );