[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kupu-checkins
Subject:    [kupu-checkins] r44423 - in kupu/trunk/kupu: common default
From:       duncan () codespeak ! net
Date:       2007-06-22 10:44:39
Message-ID: 20070622104439.37A8D80D8 () code0 ! codespeak ! net
[Download RAW message or body]

Author: duncan
Date: Fri Jun 22 12:44:38 2007
New Revision: 44423

Modified:
   kupu/trunk/kupu/common/kupubasetools.js
   kupu/trunk/kupu/common/kupudrawers.js
   kupu/trunk/kupu/common/kupudrawerstyles.css
   kupu/trunk/kupu/common/kupuhelpers.js
   kupu/trunk/kupu/default/drawers.kupu
   kupu/trunk/kupu/plone/kupu_plone_layer/kupu_wysiwyg_support.html
Log:
Added a 'manage anchors' tab to the anchor drawer so you can add/remove anchors \
without having to link to them on the same page.

Modified: kupu/trunk/kupu/common/kupubasetools.js
==============================================================================
--- kupu/trunk/kupu/common/kupubasetools.js	(original)
+++ kupu/trunk/kupu/common/kupubasetools.js	Fri Jun 22 12:44:38 2007
@@ -2874,10 +2874,33 @@
     return paras;
 };
 
-proto.getAnchor = function(node) {
-    /* Returns the anchor for a node, creating one if reqd. */
+proto.getAnchorsInUse = function() {
+    var doc = this.editor.getInnerDocument();
+    var anchors = doc.getElementsByTagName('a');
+    var inuse = {};
+    for (var i = 0; i < anchors.length; i++) {
+        var m = (/(.*)(#.*)$/.exec(anchors[i].href));
+        /* TODO: filter out external links */
+        if (m) { inuse[m[2]] = 1; };
+    }
+    return inuse;
+}
+
+proto.removeAnchor = function(node) {
+    var anchors = node.getElementsByTagName('a');
+    if (anchors.length > 0) {
+        var anchor = anchors[0];
+        anchor.removeAttribute('name');
+        if (anchor.href) return;
+        anchor.parentNode.removeChild(anchor);
+    };
+}
+proto.getAnchor = function(node, ifexists) {
+    /* Returns the anchor for a node, creating one if reqd. unless
+     * ifexists is set*/
     var anchors = node.getElementsByTagName('a');
     if (anchors.length > 0) return anchors[0].name;
+    if (ifexists) return;
 
     var anchor = Sarissa.getText(node, true).strip().truncate(40).
         replace(/[^\w]+/g, '-').toLowerCase().replace(/-$/,'') || 'anchor';

Modified: kupu/trunk/kupu/common/kupudrawers.js
==============================================================================
--- kupu/trunk/kupu/common/kupudrawers.js	(original)
+++ kupu/trunk/kupu/common/kupudrawers.js	Fri Jun 22 12:44:38 2007
@@ -1581,7 +1581,10 @@
         this.tool.fillStyleSelect(this.style2);
         this.tool.fillStyleSelect(this.ostyle);
     };
-    this.getMode = function() {
+    this.getMode = function() { /* tab 0, 1, or 2 */
+        if (/kupu-ins-bm/.test(this.panel.className)) return 0;
+        if (/kupu-anchor/.test(this.panel.className)) return 1;
+        return 2;
         return !!(/kupu-ins-bm/.test(this.panel.className));
     };
 
@@ -1589,7 +1592,10 @@
         var nodes = this.paralist.getElementsByTagName('input');
         var state = this.checkall.checked;
         for (var i = 0; i < nodes.length; i++) {
-            nodes[i].checked = state;
+            var n = nodes[i];
+            if (n.type=="checkbox" && !n.disabled) {
+                nodes[i].checked = state;
+            };
         };
     };
 
@@ -1601,9 +1607,9 @@
 
         this.styleNames = ['', ''];
 
-        var isSingle = this.getMode();
+        var mode = this.getMode();
         var s = ['', ''];
-        for (var idx=0; idx < (isSingle?1:2); idx++) {
+        for (var idx=0; idx < (mode==2?2:1); idx++) {
             var sel = this['style'+(idx+1)];
             var i = sel.selectedIndex;
             if (i >= 0) {
@@ -1612,21 +1618,43 @@
             }
         }
 
+        if (mode==1) {
+            var inuse = this.tool.getAnchorsInUse();
+        }
         var paras = (this.nodelist = this.tool.grubParas(s[0], s[1]));
         for (var i = 0; i < paras.length; i++) {
             var node = paras[i][0];
             var text = Sarissa.getText(node, true).strip().truncate(60);
             if (!text) continue;
             var content = document.createTextNode(text);
-
+            var anchor = '';
+            if (mode==1) {
+                anchor = this.tool.getAnchor(node, true);
+                if (anchor) {
+                    anchor = '#'+anchor;
+                }
+            }
+            var checked;
+            switch (mode) {
+                case 0: checked = i==0; break;
+                case 1: checked = !!anchor; break;
+                case 2: checked = this.checkall.checked; break;
+            }
             var control = el('input', {
-                'type': isSingle?"radio":"checkbox",
-                'checked': isSingle?i==0:this.checkall.checked,
-                'name': "kupu-bm-paralist"});
-
-            var div = el('div',
-                { 'className': "kupu-bm-level" + paras[i][1] },
-                [el('label', [control, el('span', [content])])]);
+                'type': (mode==0)?"radio":"checkbox",
+                checked: checked, title:'hello',
+                name: "kupu-bm-paralist"});
+            if (anchor && inuse && inuse[anchor]) {
+                control.disabled = true;
+            }
+
+            var inner = [control, el('span', [content])];
+            if (anchor) {
+                inner.push(el('a', {href:anchor, \
className:'kupu-anchor-link',onclick:'return false;', +                    \
title:_('Right click to copy link')}, [anchor])); +            };
+            var div = el('div', {className: "kupu-bm-level" + paras[i][1] },
+                [el('label', inner)]);
             
             this.paralist.appendChild(div);
         };
@@ -1637,27 +1665,30 @@
         this.focusElement();
     };
     this.save = function() {
-        var isSingle = this.getMode();
+        var mode = this.getMode();
         var selected = this.paralist.getElementsByTagName('input');
         var ed = this.editor;
         
         ed.resumeEditing();
 
-        if (!isSingle) {
+        if (mode==2) {
             var toc = ed.newElement('ul');
         };
         var lvl1=0, lvl2=0;
         for (var i = 0; i < selected.length; i++) {
+            var nodeinfo = this.nodelist[i];
+            var node = nodeinfo[0];
+            var level = nodeinfo[1];
             if (selected[i].checked) {
-                var nodeinfo = this.nodelist[i];
-                var node = nodeinfo[0];
-                var level = nodeinfo[1];
                 var a = this.tool.getAnchor(node);
                 var caption = Sarissa.getText(node, true).strip().truncate(140);
-                if (isSingle) {
+                switch (mode) {
+                case 0:
                     this.tool.createLink('#'+a, null, null, null, caption);
                     break;
-                } else {
+                case 1:
+                    break;
+                case 2:
                     /* Insert TOC entry here */
                     var number;
                     if (level==0) {
@@ -1678,10 +1709,15 @@
                         }
                         toc.lastChild.appendChild(li);
                     };
+                    break;
                 };
+            } else {
+                if (mode==1) {
+                    this.tool.removeAnchor(node);
+                }
             };
         };
-        if (!isSingle && toc.firstChild) {
+        if (mode==2 && toc.firstChild) {
             var o = this.ostyle.selectedIndex;
             if (o > 0) {
                 var ostyle = this.ostyle.options[o].value.split('|');

Modified: kupu/trunk/kupu/common/kupudrawerstyles.css
==============================================================================
--- kupu/trunk/kupu/common/kupudrawerstyles.css	(original)
+++ kupu/trunk/kupu/common/kupudrawerstyles.css	Fri Jun 22 12:44:38 2007
@@ -296,8 +296,10 @@
   opacity:0.5;
   filter:alpha(opacity=50);
 }
-.kupu-ins-bm #kupu-bm-sel2, .kupu-ins-bm .kupu-bm-heading,
-.kupu-ins-bm .kupu-bm-helptoc,.kupu-toc .kupu-bm-helpanchor,
+.kupu-ins-bm .hide-ins-bm, .kupu-anchor .hide-anchor, .kupu-toc .hide-toc {
+  display: none;
+}
+
 .image-dimensions {
   display: none;
 }
@@ -348,3 +350,6 @@
     padding: 1px 0px 1px 16px;
     font-style: italic;
 }
+a.kupu-anchor-link {
+    margin-left: 1em;
+}

Modified: kupu/trunk/kupu/common/kupuhelpers.js
==============================================================================
--- kupu/trunk/kupu/common/kupuhelpers.js	(original)
+++ kupu/trunk/kupu/common/kupuhelpers.js	Fri Jun 22 12:44:38 2007
@@ -96,7 +96,11 @@
         if (arg.length===undefined) {
             if (!_SARISSA_IS_IE) {
                 for (var attr in arg) {
-                    node[attr] = arg[attr];
+                    if (/^on/.test(attr)) {
+                        node.setAttribute(attr, arg[attr]);
+                    } else {
+                        node[attr] = arg[attr];
+                    };
                 };
             };
         } else {

Modified: kupu/trunk/kupu/default/drawers.kupu
==============================================================================
--- kupu/trunk/kupu/default/drawers.kupu	(original)
+++ kupu/trunk/kupu/default/drawers.kupu	Fri Jun 22 12:44:38 2007
@@ -276,6 +276,7 @@
       <div class="kupu-panels kupu-ins-bm">
          <ul class="kupu-tabs">
             <li class="kupu-ins-bm selected"><a href="#" i18n:translate="">Link to \
anchor</a></li> +            <li class="kupu-anchor"><a href="#" \
                i18n:translate="">Manage Anchors</a></li>
             <li class="kupu-toc"><a href="#" i18n:translate="">Table of \
contents</a></li>  </ul>
         <table class="kupu-tabbed">
@@ -284,8 +285,8 @@
               <select id="kupu-bm-sel1" size="10"> </select>
             </td>
             <td rowspan="2">
-              <div class="kupu-bm-heading">
-                <div style="float:right">
+              <div class="kupu-bm-heading hide-ins-bm">
+                <div style="float:right" class="hide-anchor">
                   <label i18n:translate="" for="kupu-bm-outcls">
                     Table style
                   </label>
@@ -293,7 +294,7 @@
                     <option value="" i18n:translate="">Normal</option>
                   </select>
                 </div>
-                <div style="float:right">
+                <div style="float:right" class="hide-anchor">
                   <label i18n:translate="" for="kupu-bm-number">
                     Numbering
                   </label>
@@ -305,17 +306,22 @@
                 <input type="checkbox" checked="checked" id="kupu-bm-checkall"/>
               </div>
               <div class="kupu-bm-paras">&#xa0;</div>
-              <div class="kupu-bm-helpanchor" i18n_translate="create_anchor_help">
+              <div class="kupu-bm-helpanchor hide-anchor hide-toc" \
                i18n_translate="create_anchor_link_help">
                 Select a paragraph style then choose a paragraph and Ok to insert a \
link to that location.  </div>
-              <div class="kupu-bm-helptoc" i18n_translate="create_toc_help">
+              <div class="kupu-bm-helptoc hide-ins-bm hide-anchor" \
                i18n_translate="create_toc_help">
                 Select one or two paragraph styles, then Ok to insert a table of \
contents.  </div>
+              <div class="hide-ins-bm hide-toc" i18n_translate="create_anchor_help">
+                Anchors are created for checked paragraphs and
+                removed for unchecked paragraphs when you press Ok.
+                Anchors in use on this page may not be deleted.
+              </div>
             </td>
           </tr>
           <tr>
-            <td>
-              <select id="kupu-bm-sel2" size="1">
+            <td class="hide-ins-bm hide-anchor">
+              <select id="kupu-bm-sel2" size="1" class="hide-ins-bm hide-anchor">
                 <option value="" i18n:translate="">(optional 2nd style)</option>
               </select>
             </td>

Modified: kupu/trunk/kupu/plone/kupu_plone_layer/kupu_wysiwyg_support.html
==============================================================================
--- kupu/trunk/kupu/plone/kupu_plone_layer/kupu_wysiwyg_support.html	(original)
+++ kupu/trunk/kupu/plone/kupu_plone_layer/kupu_wysiwyg_support.html	Fri Jun 22 \
12:44:38 2007 @@ -16,7 +16,7 @@
     <!--$Id: toolboxes.kupu 37754 2007-02-01 17:24:29Z yuppie $-->
     <!--$Id: colorchooser.kupu 35491 2006-12-08 15:41:49Z duncan $-->
     <!--$Id: save.kupu 9520 2005-02-26 16:30:23Z duncan $-->
-    <!--$Id: drawers.kupu 43634 2007-05-25 13:45:36Z duncan $-->
+    <!--$Id: drawers.kupu 43895 2007-05-30 13:42:40Z duncan $-->
     <!--$Id: include.kupu 39202 2007-02-19 12:06:45Z duncan $-->
     <!--$Id: wire.kupu 25247 2006-04-03 11:23:02Z fschulze $-->
     <!--$Id: head.kupu 34332 2006-11-07 14:50:40Z duncan $-->
@@ -241,7 +241,7 @@
                            Link the highlighted text to this URL:
                         </span>
                      </div>
-                     <input class="kupu-toolbox-st kupu-linkdrawer-input" \
type="text" onkeypress="return HandleDrawerEnter(event, 'linkdrawer-preview');" \
onchange="return HandleDrawerEnter(event, 'linkdrawer-preview');"/> +                 \
<input class="kupu-toolbox-st kupu-linkdrawer-input" type="text" onkeypress="return \
HandleDrawerEnter(event, 'linkdrawer-preview');"/>  </td>
                   <td class="kupu-preview-button">
                      <button class="kupu-dialog-button" type="button" \
id="linkdrawer-preview" onclick="drawertool.current_drawer.preview()" \
i18n:translate="">Preview</button> @@ -401,6 +401,7 @@
       <div class="kupu-panels kupu-ins-bm">
          <ul class="kupu-tabs">
             <li class="kupu-ins-bm selected"><a href="#" i18n:translate="">Link to \
anchor</a></li> +            <li class="kupu-anchor"><a href="#" \
                i18n:translate="">Manage Anchors</a></li>
             <li class="kupu-toc"><a href="#" i18n:translate="">Table of \
contents</a></li>  </ul>
         <table class="kupu-tabbed">
@@ -409,8 +410,8 @@
               <select id="kupu-bm-sel1" size="10"> </select>
             </td>
             <td rowspan="2">
-              <div class="kupu-bm-heading">
-                <div style="float:right">
+              <div class="kupu-bm-heading hide-ins-bm">
+                <div style="float:right" class="hide-anchor">
                   <label i18n:translate="" for="kupu-bm-outcls">
                     Table style
                   </label>
@@ -418,7 +419,7 @@
                     <option value="" i18n:translate="">Normal</option>
                   </select>
                 </div>
-                <div style="float:right">
+                <div style="float:right" class="hide-anchor">
                   <label i18n:translate="" for="kupu-bm-number">
                     Numbering
                   </label>
@@ -430,17 +431,22 @@
                 <input type="checkbox" checked="checked" id="kupu-bm-checkall"/>
               </div>
               <div class="kupu-bm-paras">&#160;</div>
-              <div class="kupu-bm-helpanchor" i18n_translate="create_anchor_help">
+              <div class="kupu-bm-helpanchor hide-anchor hide-toc" \
                i18n_translate="create_anchor_link_help">
                 Select a paragraph style then choose a paragraph and Ok to insert a \
link to that location.  </div>
-              <div class="kupu-bm-helptoc" i18n_translate="create_toc_help">
+              <div class="kupu-bm-helptoc hide-ins-bm hide-anchor" \
                i18n_translate="create_toc_help">
                 Select one or two paragraph styles, then Ok to insert a table of \
contents.  </div>
+              <div class="hide-ins-bm hide-toc" i18n_translate="create_anchor_help">
+                Anchors are created for checked paragraphs and
+                removed for unchecked paragraphs when you press Ok.
+                Anchors in use on this page may not be deleted.
+              </div>
             </td>
           </tr>
           <tr>
-            <td>
-              <select id="kupu-bm-sel2" size="1">
+            <td class="hide-ins-bm hide-anchor">
+              <select id="kupu-bm-sel2" size="1" class="hide-ins-bm hide-anchor">
                 <option value="" i18n:translate="">(optional 2nd style)</option>
               </select>
             </td>


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic