Commits

Luke Plant committed 396ad8f

Made update of class list and command list immediate.

  • Participants
  • Parent commits aa32b13

Comments (0)

Files changed (2)

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

     // command_dict: a dictionary mapping command name to PresentationInfo object.
     this.command_dict = {};
 
+    // the tagName of the current block level element being edited.
+    this.current_tag_name = "";
+
+    // Need to sync with presentation.py
+    this.blockdef_selector = "h1,h2,h3,h4,h5,h6,p,ol,ul,blockquote,li,div,pre";
+
     this.setup_controls(jQuery(wym._bvox).find(".wym_area_bottom"));
 }
 
                                    self.clean_html();
                                    return false;
                                });
-    jQuery(this.wym._doc).bind("keyup", function(evt) {
-                                   self.doc_keyup(evt);
-                               });
+    jQuery(this.wym._doc)
+        .bind("keyup", function(evt) {
+                  // this style of binding give doc_keyup
+                  // access to 'this' PresentationControl
+                  self.doc_keyup(evt);
+              })
+        .bind("mouseup", function(evt) {
+                  self.doc_mouseup(evt);
+              });
 
     // Insert rewriting of HTML before the WYMeditor updates the textarea.
     jQuery(this.wym._options.updateSelector)
     // for our styling to work. It's possible that multiple 'p' elements can be inserted
     // for one keyup event, so we handle that. This appears to happen for any
     // elements that are created by pressing 'Enter'
+
+    // We also need to update the disable/enabled state of the classlist and commandlist
     var self = this;
     var wym = self.wym;
+    var container = jQuery(wym.selected()).parentsOrSelf(this.blockdef_selector);
     if (evt.keyCode == 13 && !evt.shiftKey) {
-        var container = jQuery(wym.selected()).parentsOrSelf("p,li");
         if (container.is("p[id],li[id]")) {
             // Need to clear id on all elem's with that id except the first.
             // (hoping that jQuery will return them in document order, which it
                      });
         }
     }
+    this.update_classlist_item_all(container);
+};
+
+PresentationControls.prototype.doc_mouseup = function(evt) {
+    this.update_classlist_item_all();
+};
+
+PresentationControls.prototype.update_classlist_item_all = function(cur_container) {
+    var self = this;
+    if (cur_container == undefined) {
+        // For speed
+        cur_container = jQuery(this.wym.selected()).parentsOrSelf(this.blockdef_selector);
+    }
+    var node = cur_container.get(0);
+    if (node != undefined && node.tagName != this.current_tag_name) {
+        // if current tagName has changed, might need to update list
+        this.current_tag_name = node.tagName;
+        // Sets enabled/disabled on all items in classlist and commands
+        var pairs = [[this.available_styles, this.classlist],
+                     [this.commands, this.commandlist]];
+
+        for (var i = 0; i < pairs.length; i++) {
+            var styles = pairs[i][0];
+            var btncontainer = pairs[i][1];
+            btncontainer.find("a").each(function(k) {
+                                            self.update_classlist_item(jQuery(this), styles[k]);
+                                        });
+        }
+    }
+
 
 };
 
         return;
     };
     var prev = node.previousSibling;
-    if (prev && prev.tagName.toLowerCase() == 'div') {
+    if (prev != undefined && prev.tagName != undefined && prev.tagName.toLowerCase() == 'div') {
         // command divs are like <div id="newrow_p_1" class="newrow">
         // check we've got a command div.
         var className = prev.className;

semanticeditor/utils/presentation.py

 technical_blockdef = set(['h1','h2','h3','h4','h5','h6', 'p', 'ol', 'ul', 'blockquote']) # according to HTML4
 additional_blockdef = set(['li']) # li really act like block elements
 blockdef = technical_blockdef | additional_blockdef
-blockdef_selector = ",".join(blockdef)
+blockdef_selector = ",".join(blockdef) # need to sync with wymeditor.semantic.js
 headingdef = set(['h1','h2','h3','h4','h5','h6'])
 preview_blockdef = technical_blockdef