Luke Plant avatar Luke Plant committed 58b005c

Made 'New row' and 'New column' work as toggles.

Also cleaned up some related OAOO violations.

Comments (0)

Files changed (1)

semanticeditor/media/semanticeditor/javascript/wymeditor/plugins/semantic/wymeditor.semantic.js

 
 PresentationControls.prototype.has_command = function(sect_id, command) {
     // Returns true if the section has the command before it.
-    // For section 'p_1' command 'newrow', we just need to check
-    // for the existence of 'newrow_p_1'.
-    return (this.presentation_info[command.name + "_" + sect_id] != undefined);
+    return (this.presentation_info[this.command_block_id(sect_id, command)] != undefined);
 }
 
 PresentationControls.prototype.next_id = function(tagName) {
     this.update_classlist_item(btn, style);
 };
 
+PresentationControls.prototype.command_block_id = function(sect_id, command) {
+    // Returns the ID to use for a command block that appears before
+    // section sect_id for a given command.  This is also the key used
+    // in this.presentation_info
+    return command.name + "_" + sect_id;
+}
+
 PresentationControls.prototype.insert_command_block = function(sect_id, command) {
     // There is some custom logic about the different commands here i.e.
     // that newrow should appear before newcol.
         elem = elem.prev();
     }
     elem.before(newelem);
-    var new_id = command.name + "_" + sect_id; // duplication with update_command_blocks
+    var new_id = this.command_block_id(sect_id, command);
     newelem.attr('id', new_id);
     return new_id;
 };
     }
     // newrow and newcol are the only commands at the moment.
     // We handle both using inserted blocks
-    var new_id = this.insert_command_block(sect_id, command);
-    this.register_section(new_id);
-    this.presentation_info[new_id].push(command);
-    this.update_style_display(new_id);
+    if (this.has_command(sect_id, command)) {
+        // remove it.
+        var id = this.command_block_id(sect_id, command);
+        jQuery(this.wym._doc).find('#' + id).remove();
+        delete this.presentation_info[id];
+    } else {
+        var new_id = this.insert_command_block(sect_id, command);
+        this.register_section(new_id);
+        this.presentation_info[new_id].push(command);
+        this.update_style_display(new_id);
+    }
     this.update_classlist_item(btn, command);
 };
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.