I'm trying to get file drag and drop in firefox and am taking baby steps to start. Right now, I'm just trying to drag some files in to a dropzone and get a list of the files dropped. At this point, I don't want to do anything with the files yet.
When I drag a file (in this case an image, but the same thing happens regardless of the file type) from finder to the dropzone, I can see the dragenter and dragexit events firing. When I drop the file in to the dropzone, the drop event is not firing. What happens instead is that the browser opens the image on it's own (e.g, the address is showing file://path/to/my/image.png).
My javascript looks like this:
dropbox = document.getElementById("standard_file_dropzone");
dropbox.addEventListener("dragenter", function(){console.log('standard enter');}, false);
dropbox.addEventListener("dragexit", function(){console.log('standard exit');}, false);
dropbox.addEventListener("dragover", $.noop, false);
dropbox.addEventListener("drop", function ( event ) {
console.log('standard dropped');
event.stopPropagation();
event.preventDefault();
if(( typeof event.dataTransfer.files !== 'undefined' ) &&
( event.dataTransfer.files.length > 0 )) {
console.dir( event.dataTransfer.files );
}
return false;
}, false);
My HTML looks like this:
<div id="standard_file_dropzone" style="height:150px; width:150px; border:solid;">
Standard Drop Files Here
</div>
So I'm wondering what I'm doing wrong here? There doesn't seem to be anything (at least obvious to me) wrong with the above code. The dragenter/exit events are firing, why isn't the drop event? Why is the browser trying to open the file itself?
One thing to note, when I open my page in Chrome, this is working as expected so this is a Firefox specific issue.
thnx,
Christoph
The issue was using $.noop as the dragover handler. Replacing it with a function which actually stops propagation and the bubbling, it started working as expected.
I'm such an idiot sometimes. :p
Related
Let me preface this by saying I want a spinner...
I don't necessarily care whether it loads when the page first starts up, or later. The problem I'm experiencing also doesn't seem to care, as I've tried it both ways.
Right this moment, I don't declare it at the top of the page. Because I have a lot of visualization stuff going on, I start that up and immediately pass some info to the spinner (which also starts it up):
google.load('visualization', '1', {packages:['controls'], callback: initializeTables});
function initializeTables() {
provideInfo("loading proficiencies (Step 1/12)");
//etc... }
function provideInfo(text) {
$.mobile.loading( "show", {
text: text,
textVisible: true
});
}
So that starts... fine... ish...
The problem is that there's actually two spinners started when that starts - one in front, one behind. Because the one in front is slightly offset from the one behind, I can see both.
If I later call:
$.mobile.loading( "hide" );
It only hides the front one, not the back one.
I've found I can hide both by saying:
$(".ui-loader").hide();
Which is great. But, I'd like to not see two in the first place. I've tried to puzzle out the jquery mobile documentation page, to no avail (it also mentions a "global method docs" but I haven't been able to find that link):
//This does not work:
$( ".ui-loader" ).loader( "option", "text", "Loading Page..." );
//Nor does this:
$( "#notify_div" ).loader( "show" );
$( "#notify_div" ).loader( "option", "text", "Loading Page..." );
Anyone know how to get it all into one spinner, or why it's loading two?
Sadly, the current JQM documentation is for the 1.5 version which hasn't be released yet. You need to look directly at the source code of the 1.4.5 version.
There is a JQM default which is showing the spinner when a page is loading. You can override this behavior at JQM initialization.
<script type="application/javascript" src="js/jquery-2.2.4.js"></script>
<script>
$(document).on("mobileinit", function () {
$.mobile.changePage.defaults.showLoadMsg = false;
});
</script>
<script type="application/javascript" src="js/jquery.mobile-1.4.5.js"></script>
If You look at line 5847 of the JQM uncompressed source code, You will find all the configurable settings for that.
Moreover, just for the sake of completeness, there is another setting where You can tell JQM to not show the spinner for already cached pages. Just look at line 5122 of the JQM uncompressed source code:
// This delay allows loads that pull from browser cache to
// occur without showing the loading message.
loadMsgDelay: 50
Hope this help.
I have events working fine in Chrome and IE10 for Google Maps (APIv3) and RichMarkers. Problem is, the same code borks on Firefox19 with event undefined. So, this code works on Chrome and IE10...
google.maps.event.addListener( marker, 'mouseover', function(event) {
console.log(event);
});
But not on Firefox. Interestingly, attaching a CLICK event to the map object does work as you'd expect. The event object is visible within the called function in all browsers. So, does anyone have any idea as to how to fix this? I really need to pass the event object onwards as I have funcs that use it for positioning and so on.
Normally, I'd get around this using jQuery to attach the events, but this is not an option here.
Cheers
CT
There is no mouseover-event : http://google-maps-utility-library-v3.googlecode.com/svn/trunk/richmarker/docs/reference.html
Apply the mouseover-event to the content of the marker(the content must be a node)
I just noticed something weird in my app.
I have a "save" button that triggers this function:
var saveFile:File = File.desktopDirectory.resolvePath(nameOfProject+".uct");
saveFile.browseForSave("Save as");
saveFile.addEventListener(Event.SELECT, saveFileToSystem);
When clicked, it display the "browse for save" window with a suggested name file.
Now I've noticed that when exporting, installing and running the app, when I click the button for the first time everything it's ok, but when I clicked again the location looks like this:
The "where" field is the same file....? And even if I click save, it doesn't save. The strange stuff is that this is not happening while testing my app in Flash Builder.
Any hint?
I did the workaround above, and it seems to do the trick. Code is something like this:
var saveFile:File = File.documentsDirectory.resolvePath("output.file");
var tempMovedAway:File = File.applicationStorageDirectory.resolvePath("temp.temp");
currentFileRenamedForAirBug = picker.clone();
currentFileRenamedForAirBug.moveTo(tempMovedAway), true);
saveFile.addEventListener(Event.SELECT, function():void {
tempMovedAway.deleteFile();
} );
saveFile.addEventListener(Event.CANCEL, function():void {
tempMovedAway.moveTo(currentFileRenamedForAirBug);
});
saveFile.browseForSave("save file");
// MUST be sure to call saveFile.browseForSave, or you risk losing an existing file.
You can wrap this lot in checks for the Air runtime (NativeApplication.nativeApplication.runtimeVersion) and Mac-only, to avoid doing this any more than necessary.
Also, if your file save code could rely on making changes to an existing file (rather than creating an entirely new one), you'll need to tweak this a bit.
Does anyone know of a method to trigger a click on an element with mootools at the dom level?
foo.fireEvent('click') will, for instance, only fire events added by mootools, which is not very helpful for this particular application.
Here's a fiddle with a toy example - you can see that clicking the top button will fire off both event handler functions, while trying to use the lower button to trigger a click will only fire off the 2nd function.
http://jsfiddle.net/Tc4Bv/
Any help would be appreciated - thanks!
modern browsers have an Element.click method available, so you could try something like this:
Element.implement({
synteticClick: function() {
var click = 'click';
(this[click] && !(this[click]())) || this.dispatchEvent(new Event(click));
return this;
}
});
http://jsfiddle.net/dimitar/LUPYK/
works/tested in latest FF, Chrome, also IE9 and IE9 in IE7 mode (compat).
keep in mind that the event object may be basic, i.e. lacking clientX/Y etc - so it very much depends on what you do at the other side...
I have a Maven Jetty project with JSPs using JavaScript. I want to be able to highlight parts of a canvas corresponding to the dragged image's size.
When I look at my JSP by simply opening it in the browser everything works as expected but when I start the Jetty Server with the goal jetty:run the ID of the dragged object is not being set or cannot be retrieved from the transferData of the event.
The relevant code: All draggable images have a unique ID. On drag start I set the ID of the dragged image on the event's transferData like this:
function dragShipFromTable(event) {
event.dataTransfer.setData("id",event.target.id);
}
When the image is dragged over the canvas I call the following function
function allowDrop(event) {
event.preventDefault();
var id = event.dataTransfer.getData("id");
var img = document.getElementById(id);
// Do the highlighting stuff
....
}
The problem is that when the server is started and I do the above action then in allowDrop(event) the ID of the dragged image is not being retrieved from the transferData. It is undefined and therefore the highlighting fails. This is not the case when simply opening the JSP as a File.
Well I kind of found the answer to my own question. First of all the setData method on the dataTransfer object only allows certain formats as first parameter. I interpreted it as an associative array but this is not the case. So it should be
event.dataTransfer.setData("text/plain", id);
event.dataTransfer.getData("text/plain");
to set and retrieve the id correctly.
But in the end everything failed due to chrome as there is a bug in Chrome which prevents me from using dataTransfer as intended (see How do you get the selected items from a dragstart event in Chrome? Is dataTransfer.getData broken? ).
I now use global variables to store the information I need. And still I am wondering why everything worked fine when the page was displayed as a file instead of as a response from the webserver.