To main page | Opera Unite HowTo'sStatic images, client-side scriptsYou can create a "magic" directory: ./public_htmleverything inside that directory is given out as a static file (@ Artemy Tregubenko →) Other Methods1. You need to use opera.io.webserver.shareFile(file, path) from here →.2. Uniteness has a easier way to deal with this. URLs([ 'js','static' ]);3. Yusef has something called sharedDirectory (unfortunately didn't figure out how to properly call it and it seems like there's a bug inside, so I converted it into a function): // From Yusef (modified) function shareDirectory( dir, rootPath ) { dir.refresh(); for( var i = 0, file; file = dir[i]; i++ ) { if( file.path[file.path.lastIndexOf('/')+1]==='.' ) { continue; } if( file.isDirectory ) { shareDirectory( file, rootPath ); } else if( file.isFile ) { var path = file.path.slice( rootPath.length ); opera.io.webserver.shareFile( file, file.path.replace(/^\/[^\/]+/, '') ); } } } function shareStatic(dir) { public_html = opera.io.filesystem. mountSystemDirectory('application').resolve( '/'+dir+'/' ); shareDirectory( public_html, public_html.path ); }; Using Yusef's function: Define it, when you define URLs: window.onload = function () { webserver = opera.io.webserver if (webserver) { webserver.addEventListener('_index', start_page, false); staticDirectory('imgs'); staticDirectory('docs/js'); }; };Now ./imgs/ and ./docs/js directory (and any subdirectories) will be served as-is (imgs as imgs). Serving ImagesIf your URLs are always http://...operaunite/appname/smth (if you don't know - then you probably are using URLs this way):function start_page(r) { var o = r.connection.response; o.write('<img src="imgs/my_image.jpg">'); Serving Images (more complex way)If you use deeper URLs, then you need to use webserver.currentServicePath to form image URLs like so "/service_name/imgs/my_image.jpg":function start_page(r) { var o = r.connection.response; o.write('<img src="' + webserver.currentServicePath + 'imgs/my_image.jpg">');This will serve image "my_image.jpg" from your "imgs" directory under root directory (where your config.xml is). ./config.xml ./index.html ./imgs/my_image.jpg Serving client-side scriptsIf you have:./config.xml ./js/jquery.jsand you want to make sure user uses "/js/jquery.js" script, you need to: function start_page(r) { var o = r.connection.response; o.write('<script src="' + webserver.currentServicePath + 'scripts/jquery.js">'); ExplanationThere is a variable:opera.io.webserver.currentServicePathIf your app name is "/application/" this variable contains a relative path to your app, like so: /application/ | Last updated
|