javascript - Permitting moving only of <img>s within contentEditable <div> -


i struggling achieve desired behaviour div marked contenteditable. wish allow user move img around within div , maintained inline, not let them resize or otherwise modify img. should otherwise able modify text within div.

the default browser behaviour may seen below, img being able both moved , resized drag-handles:

<html>   <head>     <title></title>     <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>   </head>   <body>      <div id="edit" contenteditable="true">       here text, , <img src="http://img841.imageshack.us/img841/1747/imagead.png" /> image     </div>    </body> </html> 

i have been playing around various client scripts attempt achieve desired functionality, each combination attempt seems run difficulty. can achieve ultimate lockdown with:

<script type="text/javascript">   $(document).ready(function() {     $('img', '#edit').each(function (i, item) {       item.contenteditable = false;       $(item).bind('mousedown', function (e) {         e.preventdefault();       });       if ($.browser.msie) {         item.oncontrolselect = function () { return false; }       }     });   }); </script> 

but although prevents element duplication (a problem had in firefox) , resizing using drag handles (in ie), not possible move img @ all.

update: guys, closest have got far is:

<script type="text/javascript">   $(document).ready(function() {     $('img', '#edit').each(function (i, item) {       attachevents(item);     });      if ($.browser.mozilla) {       document.execcommand("enableobjectresizing", false, false);     }   });    function attachevents(item) {     if ($.browser.msie) {       item.attachevent('onresizestart', function (e) {          e.returnvalue = false;        }, false);       item.attachevent('ondragend', function (e) {          // cannot ie rebind moved item (toelement or similar not available until ie9 when using addeventlistener)         attachevents(e.srcelement);       }, false);     }      if ($.browser.opera) {       // doesn't seem work @ in opera 11     }   } </script> 

but 2 remaining problems complete lack of support in opera (something can live with) , problem of how rebind events ondragend in ie.

can else assist?

you implement draggable effect using jquery ui on img.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -