2

Using AppJS (http://appjs.org/) which basically gives NodeJS a webkit window to work with. I am attempting to harness the drag and drop event for files and URLs to be used in my code.

The short code for the drag and drop can be found here: https://github.com/appjs/appjs/wiki/HTML5:-Drag-&-Drop-from-Desktop

The code I have used to create the window:

var app_window = appjs.createWindow({
  width  : 200,
  height : 200,
  showChrome : true, //display as standard os window with max/min/close buttons
  alpha: false,
  autoResize: true,  //adjust window size automatically according to content.
  resizable: true,   //allow user resize of window
  margin: 0,
  disableSecurity:true, //turn off security restrictions.
  showResizeGrip:false, //show/hide the resize grip.
  name:'Drag and Drop',   //undocumented parameter
  opacity:1,
  fullscreen:false,
  topmost:true
});


the event handler code:

var window_drop = function(event) { // this code never fires.
  event.preventDefault();
  console.log('drop event');
};


and the code I have set for firing the event:

app_window.on('ready', function() {
  app_window.require = require;
  app_window.process = process;
  app_window.module = module;
  app_window.console = console;

  app_window.frame.show();
  app_window.frame.center();

  app_window.addEventListener("drop", window_drop);
});

Specs: I am running NodeJS 32 bit (required by AppJS) on Mac OSX Lion.
I know that AppJS is in it's infancy but this should work.

What could be the problem? Why is the event never fired?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Levi Roberts
  • 1,277
  • 3
  • 22
  • 44
  • What do you have @ client side? Perhaps you block it. – Ron van der Heijden Apr 22 '13 at 12:18
  • There is no "client side" as this is not a traditional server. The only "client side" I think you could be referring to is the index.html page that AppJS loads into webkit, which is blank for the most part except a – Levi Roberts Apr 22 '13 at 12:20
  • Yes, there is a client side, The server `app.js` and the folder `content`. You have client side and server side javascript. But reading that comment means you have no javascript at your client side. – Ron van der Heijden Apr 22 '13 at 12:26
  • Could you paste you whole full `app.js` file? Not just parts – Ron van der Heijden Apr 22 '13 at 12:28
  • This IS the whole file except the appjs include part. var appjs = require('appjs'); appjs.serveFilesFrom(__dirname + '/content'); I just separated it into sections for easy reading. – Levi Roberts Apr 22 '13 at 12:30
  • When I use your code, my application won't even start up. Because its missing the `icons: __dirname + '/content/icons',` part. – Ron van der Heijden Apr 22 '13 at 13:04
  • You have to use the given app.sh file that's included in AppJS. The app starts up fine. I have another project running smoothly with exactly the same setup. The problem here is that the event just simply doesn't get fired. – Levi Roberts Apr 22 '13 at 13:10

1 Answers1

0

I'm not entirely sure why your method isn't working, but try the method I use (and it works):-

In your main html, add the script tag there and then attach your drop event inside the app-ready event as shown below:

addEventListener('app-ready', function(e){
    window.addEventListener("drop", window_drop);
    window.dispatchEvent(new Event('app-done'));
});
Irfan
  • 1,758
  • 3
  • 24
  • 32