edit: autostart mode on #edit hash
[minimedit.git] / edit.js
diff --git a/edit.js b/edit.js
index 6f9211eea2f18f8863436634ddf18d35cb172516..164cc1ef9829a2add8472ebe617771bd99a90c70 100644 (file)
--- a/edit.js
+++ b/edit.js
@@ -56,6 +56,10 @@ CKEDITOR.on('instanceCreated', function (event) {
                        ['Bold', 'Italic', 'Underline', 'Strike', 'RemoveFormat', '-', 'Anchor', 'Link'],
                        ['HorizontalRule', 'Table', 'Image'],
                ];
+               config.toolbarCanCollapse = true;
+               config.floatSpacePreferRight = true;
+               config.floatSpaceDockedOffsetY = 0;
+               config.startupFocus = true;
 
                config.disableObjectResizing = true;
                document.execCommand('enableObjectResizing', false, false); // workaround in inline mode; ff bug?
@@ -72,8 +76,32 @@ CKEDITOR.on('instanceCreated', function (event) {
                });
        });
 
-var pagebody = document.getElementsByClassName('article')[0];
-pagebody.setAttribute('contenteditable', 'true');
+       CKEDITOR.disableAutoInline = true;
 
-document.body.className = 'edit';
+// add edit link to menu
+var pagebody = document.getElementsByClassName('static')[0];
+if (pagebody) {
+       var editlink = document.createElement('a');
+       editlink.style.cursor = 'pointer';
+       editlink.appendChild(document.createTextNode('Wijzig'));
+       editlink.onclick = function (e) {
+               var toggled = editlink.style.fontWeight;
+               editlink.style.fontWeight = toggled ? '' : 'bold';
+               pagebody.setAttribute('contenteditable', !toggled);
+               if (toggled) {
+                       for (name in CKEDITOR.instances) {
+                               CKEDITOR.instances[name].destroy()
+                       }
+               }
+               else {
+                       CKEDITOR.inline(pagebody);
+               }
+               document.body.className = toggled ? '' : 'edit';
+               return false;
+       };
+       if (window.location.hash == '#edit') {
+               editlink.onclick();
+       }
+       document.querySelector('header ul').appendChild(editlink);
+}