]> git.mjollnir.org Git - s9y.git/commitdiff
MAke image manager remember settings and return content at cursor position
authorgarvinhicking <garvinhicking>
Tue, 23 Aug 2005 11:03:09 +0000 (11:03 +0000)
committergarvinhicking <garvinhicking>
Tue, 23 Aug 2005 11:03:09 +0000 (11:03 +0000)
deployment/serendipity_editor.js
docs/NEWS
serendipity_admin_image_selector.php
serendipity_editor.js

index 5d246fe0cce5b6f0a39a33515021ed76feb73c14..d7dc0310e0c0da94c7e08da4109d29a8db2bd305 100644 (file)
@@ -143,7 +143,7 @@ function serendipity_imageSelector_addToElement (str, el)
 
 function serendipity_imageSelector_addToBody (str, textarea)
 {
-    document.forms['serendipityEntry']['serendipity['+ textarea +']'].value += str;
+       wrapSelection(document.forms['serendipityEntry']['serendipity['+ textarea +']'], str, '');
     document.forms['serendipityEntry']['serendipity['+ textarea +']'].focus();
 }
 
index 9e8051b20c25e276759bb09b459aa0b1d24d5063..22b92d52e35467374516526c730982f62e461216 100644 (file)
--- a/docs/NEWS
+++ b/docs/NEWS
@@ -3,6 +3,10 @@
 Version 0.9 ()
 ------------------------------------------------------------------------
 
+    * Make media insertion dialog remember settings (via Cookies) and
+      insert return of the media database on cursor position.
+      (garvinhicking)
+
     * Admin comment panels shows comments with their content and escaped HTML
       instead of stripping all HTML. Only summary, if longer than 200 characters
       will have stripped HTML because of otherwise invalid markup. (garvinhicking)
index 4ba43371e6ec45e24a8029e412a9872a6ca01cdc..26704063d3ceecda930044a1abf37569cf8f2612 100644 (file)
@@ -22,6 +22,20 @@ if (!isset($serendipity['GET']['step'])) {
     $serendipity['GET']['step']        = (isset($serendipity['POST']['step'])        ? $serendipity['POST']['step']        : '');
 }
 
+function ifRemember($name, $value, $isDefault = false, $att = 'checked') {
+    global $serendipity;
+    
+    if (!is_array($serendipity['COOKIE']) && !$isDefault) {
+        return false;
+    }
+    
+    if ((!is_array($serendipity['COOKIE']) && $isDefault) || 
+        (!isset($serendipity['COOKIE']['serendipity_' . $name]) && $isDefault) ||
+        (isset($serendipity['COOKIE']['serendipity_' . $name]) && $serendipity['COOKIE']['serendipity_' . $name] == $value)) {
+
+        return " $att=\"$att\" ";
+    }
+}
 ?>
 <html>
     <head>
@@ -37,6 +51,23 @@ if (!isset($serendipity['GET']['step'])) {
             expire.setTime(today.getTime() + (60*60*24*30));
             document.cookie = 'serendipity[' + name + ']='+escape(value) + ';expires=' + expire.toGMTString();
         }
+
+        function rememberOptions() {
+            el = document.getElementById('imageForm');
+            for (i = 0; i < el.elements.length; i++) {
+                elname = new String(el.elements[i].name);
+                elname = elname.replace(/\[/g, '_');
+                elname = elname.replace(/\]/g, '');
+                
+                if (el.elements[i].type == 'radio') {
+                    if (el.elements[i].checked) {
+                        SetCookie(elname, el.elements[i].value);
+                    }
+                } else if (typeof(el.elements[i].options) == 'object') {
+                    SetCookie(elname, el.elements[i].options[el.elements[i].selectedIndex].value);
+                }
+            }
+        }
     </script>
 <body id="serendipityAdminBodyImageSelector">
 
@@ -123,7 +154,7 @@ switch ($serendipity['GET']['step']) {
     <img align="right" src="<?php echo $imgsrc; ?>">
     <h1><?php printf(YOU_CHOSE, $file['name']); ?></h1>
     <p>
-        <form action="#" method="GET" name="serendipity[selForm]" onSubmit="serendipity_imageSelector_done()">
+        <form action="#" method="GET" id="imageForm" name="serendipity[selForm]" onsubmit="serendipity_imageSelector_done()">
             <div>
                 <?php serendipity_plugin_api::hook_event('frontend_image_selector_hiddenfields', $file); ?>
                 <input type="hidden" name="imgThumbWidth"  value="<?php echo $thumbWidth; ?>" />
@@ -142,24 +173,24 @@ switch ($serendipity['GET']['step']) {
 
                 <b><?php echo IMAGE_SIZE; ?>:</b>
                 <br />
-                <input id="radio_link_no" type="radio" name="serendipity[linkThumbnail]" value="no" checked="checked" /><label for="radio_link_no"><?php echo I_WANT_THUMB; ?></label><br />
-                <input id="radio_link_yes" type="radio" name="serendipity[linkThumbnail]" value="yes" /><label for="radio_link_yes"><?php echo I_WANT_BIG_IMAGE; ?></label><br />
+                <input id="radio_link_no" type="radio" name="serendipity[linkThumbnail]" value="no" <?php echo ifRemember('linkThumbnail', 'no', true); ?> /><label for="radio_link_no"><?php echo I_WANT_THUMB; ?></label><br />
+                <input id="radio_link_yes" type="radio" name="serendipity[linkThumbnail]" value="yes" <?php echo ifRemember('linkThumbnail', 'yes'); ?> /><label for="radio_link_yes"><?php echo I_WANT_BIG_IMAGE; ?></label><br />
                 <?php serendipity_plugin_api::hook_event('frontend_image_selector_imagesize', $file); ?>
                 <br />
 
                 <?php if (empty($serendipity['GET']['filename_only']) || $serendipity['GET']['filename_only'] != 'true') { ?>
                 <b><?php echo IMAGE_ALIGNMENT; ?>:</b>
                 <br />
-                <input type="radio" name="serendipity[align]" value="" />                       <img src="<?php echo serendipity_getTemplateFile('img/img_align_top.png') ?>"   vspace="5" /><br />
-                <input type="radio" name="serendipity[align]" value="left" checked="checked" /> <img src="<?php echo serendipity_getTemplateFile('img/img_align_left.png') ?>"  vspace="5" /><br />
-                <input type="radio" name="serendipity[align]" value="right" />                  <img src="<?php echo serendipity_getTemplateFile('img/img_align_right.png') ?>" vspace="5" /><br />
+                <input type="radio" name="serendipity[align]" <?php echo ifRemember('align', ''); ?>      value="" />                       <img src="<?php echo serendipity_getTemplateFile('img/img_align_top.png') ?>"   vspace="5" /><br />
+                <input type="radio" name="serendipity[align]" <?php echo ifRemember('align', 'left', true); ?>  value="left" /> <img src="<?php echo serendipity_getTemplateFile('img/img_align_left.png') ?>"  vspace="5" /><br />
+                <input type="radio" name="serendipity[align]" <?php echo ifRemember('align', 'right'); ?> value="right" />                  <img src="<?php echo serendipity_getTemplateFile('img/img_align_right.png') ?>" vspace="5" /><br />
                 <?php serendipity_plugin_api::hook_event('frontend_image_selector_imagealign', $file); ?>
                 <br />
 
                 <b><?php echo IMAGE_AS_A_LINK; ?>:</b>
                 <br />
-                <input id="radio_islink_yes" type="radio" name="serendipity[isLink]" checked="checked" /><label for="radio_islink_yes"> <?php echo I_WANT_NO_LINK; ?></label><br />
-                <input id="radio_islink_no"  type="radio" name="serendipity[isLink]" /><label for="radio_islink_no"> <?php echo I_WANT_IT_TO_LINK; ?></label>
+                <input id="radio_islink_yes" type="radio" name="serendipity[isLink]" value="yes" <?php echo ifRemember('isLink', 'yes', true); ?> /><label for="radio_islink_yes"> <?php echo I_WANT_NO_LINK; ?></label><br />
+                <input id="radio_islink_no"  type="radio" name="serendipity[isLink]" value="no" <?php  echo ifRemember('isLink', 'no'); ?> /><label for="radio_islink_no"> <?php echo I_WANT_IT_TO_LINK; ?></label>
                 <?php if ($file['hotlink']) { ?>
                 <input type="text"  name="serendipity[url]" size="30" value="<?php echo $file['path']; ?>" /><br />
                 <?php } else { ?>
@@ -178,7 +209,7 @@ switch ($serendipity['GET']['step']) {
                 <?php serendipity_plugin_api::hook_event('frontend_image_selector_more', $file); ?>
 
                 <input type="button" value="<?php echo BACK; ?>" onclick="history.go(-1);" />
-                <input type="button" value="<?php echo DONE; ?>" onclick="<?php echo $file['finishJSFunction']; ?>" />
+                <input type="button" value="<?php echo DONE; ?>" onclick="rememberOptions(); <?php echo $file['finishJSFunction']; ?>" />
                 <?php serendipity_plugin_api::hook_event('frontend_image_selector_submit', $file); ?>
             </div>
         </form>
@@ -244,4 +275,3 @@ switch ($serendipity['GET']['step']) {
 
 <?php
 /* vim: set sts=4 ts=4 expandtab : */
-?>
index 4918d3026c24c574f7454f8d7cf4bf31d4122ae2..c4ca8e6be33d5c4e095b9081caa28a4da690a5e6 100644 (file)
@@ -144,7 +144,7 @@ function serendipity_imageSelector_addToElement (str, el)
 
 function serendipity_imageSelector_addToBody (str, textarea)
 {
-    document.forms['serendipityEntry']['serendipity['+ textarea +']'].value += str;
+       wrapSelection(document.forms['serendipityEntry']['serendipity['+ textarea +']'], str, '');
     document.forms['serendipityEntry']['serendipity['+ textarea +']'].focus();
 }
 
@@ -219,6 +219,7 @@ function serendipity_imageSelector_done(textarea)
     if (self.opener.editorref) {
         self.opener.editorref.surroundHTML(block, '');
     } else {
+       
         self.opener.serendipity_imageSelector_addToBody(block, textarea);
     }