Alexander Nazarov (nfokz) wrote in changelog,
Alexander Nazarov
nfokz
changelog

[livejournal] r22629: LJSUP-13085: RTE - edit image dialog

Committer: anazarov
LJSUP-13085: RTE - edit image dialog
U   trunk/htdocs/js/ck/plugins/livejournal/plugin.js
Modified: trunk/htdocs/js/ck/plugins/livejournal/plugin.js
===================================================================
--- trunk/htdocs/js/ck/plugins/livejournal/plugin.js	2012-08-13 12:07:07 UTC (rev 22628)
+++ trunk/htdocs/js/ck/plugins/livejournal/plugin.js	2012-08-13 12:16:31 UTC (rev 22629)
@@ -786,15 +786,32 @@
 
 				editor.addCommand(button, {
 					exec: function (editor, fromDoubleClick) {
-						var selected = editor.getSelection().getSelectedElement();
+						var selected = editor.getSelection();
+
+						selected = selected? selected.getSelectedElement() : null;
 						selectedImage = selected;
-							
+
 						if (selected) {
 							var parent = selected && selected.getParent(),
 								hasParentLink = parent.getName() === 'a',
 								parentLink = hasParentLink && parent,
-								parentHref = hasParentLink && parent.getAttribute('href');
+								parentHref = hasParentLink && parent.getAttribute('href'),
+								natural = {};
 
+							if ('naturalWidth' in selected.$) {
+								natural.width = selected.$.naturalWidth;
+								natural.height = selected.$.naturalHeight;
+							} else {
+								// IE 8 or lower
+								var img = new Image();
+								img.src = selected.$.src;
+
+								natural = {
+									width: img.width,
+									height: img.height
+								};
+							}
+
 							editor.rteButton(button, 'editpic', {
 								picData: {
 									url: selected.getAttribute('src'),
@@ -803,6 +820,9 @@
 									width: selected.getAttribute('width') || selected.$.width,
 									height: selected.getAttribute('height') || selected.$.height,
 
+									defaultWidth: natural.width,
+									defaultHeight: natural.height,
+
 									link: parentHref || "",
 									blank: (hasParentLink? !!parentLink.getAttribute('target') : true),
 

Tags: anazarov, js, livejournal, nfokz
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments