Nicolas Froidure avatar Nicolas Froidure committed 62e56b9

Enabled sending image in a text field as DataURI

Comments (0)

Files changed (5)

chrome/canimage/content/canimage.js

 	this._fSelX=-1;
 	this._fSelY=-1;
 	this._eventHandlers=new Array();
-	this.localeProperties = document.getElementById("canimage-properties");
 	};
 CanImageUI.prototype.init = function ()
 	{
 		window.parent.myBBComposerManager.canimageDisplay();
 		}
 	this.canvas=document.getElementById('canImageCanvas');
+	// Getting locales
+	this.localeProperties = document.getElementById("canimage-properties");
 	// Buttons events
 	document.getElementById('canImageOpenFile').addEventListener('command', this.newEventHandler(this,this.openFromFile), false);
 	document.getElementById('canImageOpenClipboard').addEventListener('command', this.newEventHandler(this,this.openFromClipboard), false);
 	// Menupopups events
 	document.getElementById('canImagePagePopup').addEventListener('popupshowing', this.newEventHandler(this,this.displayImagesMenupopup), false);
 	document.getElementById('canImageInputPopup').addEventListener('popupshowing', this.newEventHandler(this,this.displayInputsMenupopup), false);
+	document.getElementById('canImageFieldPopup').addEventListener('popupshowing', this.newEventHandler(this,this.displayFieldsMenupopup), false);
 	// Editor buttons events
 	document.getElementById('canImageZoomIn').addEventListener('command', this.newEventHandler(this,this.editorEventHandler), false);
 	document.getElementById('canImageZoomOut').addEventListener('command', this.newEventHandler(this,this.editorEventHandler), false);
 	else
 		alert(this.localeProperties.getString('extensions.canimage@elitwork.com.no_image'));
 	}
+CanImageUI.prototype.sendToField = function (hEvent)
+	{
+	if(this.editor)
+		{
+		hEvent.target.linkedInput.value=this.canvas.toDataURL("image/png");
+		}
+	else
+		alert(this.localeProperties.getString('extensions.canimage@elitwork.com.no_image'));
+	}
 CanImageUI.prototype.sendToClipboardBmp = function (hEvent)
 	{
 	if(this.editor)
 			}
 		}
 	}
+
+CanImageUI.prototype.displayFieldsMenupopup = function (hEvent)
+	{
+	var menupopup=hEvent.target;
+	if(menupopup==document.getElementById('canImageFieldPopup'))
+		{
+		while(menupopup.firstChild)
+			menupopup.removeChild(menupopup.firstChild);
+		for (var i = window.parent.gBrowser.browsers.length-1; i>=0; i--)
+			{
+			var browser = window.parent.gBrowser.getBrowserAtIndex(i);
+			if(browser.contentDocument)
+				{
+				var inputs=browser.contentDocument.getElementsByTagName('input');
+				var keepedInputs=[];
+				for(var j=inputs.length-1; j>=0; j--)
+					{
+					if(inputs[j].hasAttribute('type')&&inputs[j].getAttribute('type')=='text')
+						keepedInputs.push(inputs[j]);
+					}
+				var inputs=browser.contentDocument.getElementsByTagName('textarea');
+				for(var j=inputs.length-1; j>=0; j--)
+					{
+					keepedInputs.push(inputs[j]);
+					}
+				var j = keepedInputs.length-1;
+				if(j>=0)
+					{
+					var menu = document.createElement('menu');
+					var subMenupopup = document.createElement('menupopup');
+					menu.setAttribute('label',browser.contentDocument.title);
+					for (j; j>=0; j--)
+						{
+						var menuitem = document.createElement('menuitem');
+						var label='';
+						if(keepedInputs[j].hasAttribute('id'))
+							{
+							var labels=browser.contentDocument.getElementsByTagName('label');
+							for(var k=labels.length-1; k>=0; k--)
+								{
+								if(labels[k].hasAttribute('for')&&labels[k].getAttribute('for')==keepedInputs[j].getAttribute('id'))
+									{
+									label=labels[k].textContent;
+									}
+								}
+							}
+						menuitem.setAttribute('label','#'+j+(label?' '+label:(keepedInputs[j].hasAttribute('name')?' '+keepedInputs[j].getAttribute('name'):'')));
+						menuitem.addEventListener('command', this.newEventHandler(this,this.sendToField), false);
+						menuitem.linkedInput=keepedInputs[j];
+						subMenupopup.appendChild(menuitem);
+						}
+					menu.appendChild(subMenupopup);
+					menupopup.appendChild(menu);
+					}
+				}
+			}
+		if(!menupopup.firstChild)
+			{
+			var menuitem = document.createElement('menuitem');
+			menuitem.setAttribute('label',this.localeProperties.getString('extensions.canimage@elitwork.com.no_fields_in_tabs'));
+			menupopup.appendChild(menuitem);
+			}
+		}
+	}
 // Editor gestion functions
 CanImageUI.prototype.openImageEditor = function (image)
 	{

chrome/canimage/content/canimage.xul

 			<toolbarbutton id="canImageSave" label="&canimage.toolbar.save;" tooltiptext="&canimage.toolbar.save.ttt;"></toolbarbutton>
 			<toolbarbutton label="&canimage.toolbar.insert;" tooltiptext="&canimage.toolbar.insert.ttt;" type="menu">
 				<menupopup>
-					<menu label="&canimage.toolbar.insert.input;" tooltiptext="&canimage.toolbar.insert.input.ttt;" id="bbcomposer-pasteas-context">
+					<menu label="&canimage.toolbar.insert.input;" tooltiptext="&canimage.toolbar.insert.input.ttt;">
 						<menupopup id="canImageInputPopup">
 						</menupopup>
 					</menu>
+					<menu label="&canimage.toolbar.insert.field;" tooltiptext="&canimage.toolbar.insert.field.ttt;">
+						<menupopup id="canImageFieldPopup">
+						</menupopup>
+					</menu>
 				</menupopup>
 			</toolbarbutton>
 			<toolbarbutton label="&canimage.toolbar.send;" tooltiptext="&canimage.toolbar.send.ttt;" type="menu">

chrome/canimage/locale/en-US/canimage-content.dtd

 <!ENTITY canimage.toolbar.insert.ttt "Insert into opened tab">
 <!ENTITY canimage.toolbar.insert.input "File inputs">
 <!ENTITY canimage.toolbar.insert.input.ttt "Insert image into a file input">
+<!ENTITY canimage.toolbar.insert.field "Text inputs (DataURI)">
+<!ENTITY canimage.toolbar.insert.field.ttt "Insert image as DataURI into a text input">
 <!ENTITY canimage.toolbar.send "Send">
 <!ENTITY canimage.toolbar.send.ttt "Send image to">
 <!ENTITY canimage.toolbar.send.clipboardasbmp "Clipboard (bitmap)">

chrome/canimage/locale/fr-FR/canimage-content.dtd

 <!ENTITY canimage.toolbar.insert.ttt "Insérer dans une page ouverte">
 <!ENTITY canimage.toolbar.insert.input "Champs fichier">
 <!ENTITY canimage.toolbar.insert.input.ttt "Insérer l'image dans un champs de formulaire">
+<!ENTITY canimage.toolbar.insert.field "Champs texte (DataURI)">
+<!ENTITY canimage.toolbar.insert.field.ttt "Insérer l'image dans un champs texte en tant que DataURI">
 <!ENTITY canimage.toolbar.send "Envoyer">
 <!ENTITY canimage.toolbar.send.ttt "Envoyer vers une destination">
 <!ENTITY canimage.toolbar.send.clipboardasbmp "Presse papier (bitmap)">
 
   <RDF:Description RDF:about="urn:mozilla:install-manifest"
                    em:id="canimage@elitwork.com"
-                   em:version="0.1.4"
+                   em:version="0.1.5"
                    em:name="CanImage"
                    em:creator="Nicolas FROIDURE"
                    em:homepageURL="http://bbcomposer.elitwork.com"
   <RDF:Description RDF:about="rdf:#$arpP13"
                    em:id="{ec8030f7-c20a-464f-9b0e-13a3a9e97384}"
                    em:minVersion="1.0"
-                   em:maxVersion="4.0b7" />
+                   em:maxVersion="5.*" />
 </RDF:RDF>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.