joeyoverlay.js.svn-base

来自「Joey is j2me client server application f」· SVN-BASE 代码 · 共 1,413 行 · 第 1/3 页

SVN-BASE
1,413
字号
/* ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * * The contents of this file are subject to the Mozilla Public License Version * 1.1 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is Joey Mozilla Project. * * The Initial Developer of the Original Code is * Doug Turner <dougt@meer.net>. * Portions created by the Initial Developer are Copyright (C) 2007 * the Initial Developer. All Rights Reserved. * * Contributor(s): * Marcio Galli  * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), * in which case the provisions of the GPL or the LGPL are applicable instead * of those above. If you wish to allow use of your version of this file only * under the terms of either the GPL or the LGPL, and not to allow others to * use your version of this file under the terms of the MPL, indicate your * decision by deleting the provisions above and replace them with the notice * and other provisions required by the GPL or the LGPL. If you do not delete * the provisions above, a recipient may use your version of this file under * the terms of any one of the MPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */var g_joey_data;var g_joey_content_type;var g_joey_title;var g_joey_url;var g_joey_isfile;var g_joey_media_url  = null;var g_joey_media_type = null;var g_joey_areaWindow = null;var g_joey_gBrowser = null;                // presents the main browser, used by the joey_feed code.var g_joey_browserStatusHandler = null;    // to track onloction changes in the above browser ( tab browser ) element.var g_joey_statusUpdateObject = null;      // the proxy object to deal with UI var g_joey_bundleElement = null;var g_joey_mediaContentTypes = ['flv','mov','wmv','avi','mpeg','mp3','wav']; function joeyString(ref) {     return g_joey_bundleElement.getString(ref);}/*  * Event listeners associated to the joeyOverlay app  */window.addEventListener("load", joeyStartup, false);var gImageSource;function joey_listener() {}joey_listener.prototype ={    onProgressChange: function (current, total)    {        g_joey_statusUpdateObject.tellStatus("upload", current, total);    },    onStatusChange: function (action, status)    {        if (action == "login")        {            if (status == 0)            {                g_joey_statusUpdateObject.loginStatus("login","completed");            }            else if (status == -1 )            {                g_joey_statusUpdateObject.loginStatus("login","failed");                var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]                                        .getService(Components.interfaces.nsIPromptService);                var result = prompts.confirm(null, joeyString("loginFailedShort"), joeyString("loginFailedQuestion"));                if (result == true)                {                    // Clear the username and password and try again.                    clearLoginData();                    setTimeout(uploadDataFromGlobals, 500); // give enough time for us to leave the busy check                }            }            return;        }        if (action == "upload")        {            if (status == 1) {                g_joey_statusUpdateObject.tellStatus("upload",null,null,"completed");            }             else {                            g_joey_statusUpdateObject.tellStatus("upload",null,null,"failed");                 var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]                                        .getService(Components.interfaces.nsIPromptService);                prompts.alert(null, joeyString("uploadFailed"), joeyString("uploadFailed"));            }            return;        }    },    QueryInterface: function (iid)    {        if (iid.equals(Components.interfaces.mocoJoeyListener) ||            iid.equals(Components.interfaces.nsISupports))            return this;                Components.returnCode = Components.results.NS_ERROR_NO_INTERFACE;        return null;    },};function uploadDataFromGlobals(){    // marcio    try {                             var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]                                .getService(Components.interfaces.nsIPromptService);                var titleObject = {value: g_joey_title}; // default the username to user        var psvc = Components.classes["@mozilla.org/preferences-service;1"]                         .getService(Components.interfaces.nsIPrefBranch);        var askState = psvc.getBoolPref("joey.askForTitle");             if(askState == true ) {                    var check = {value: askState};  // default the checkbox to true                        var result = prompts.prompt(null, joeyString("promptTitle.windowTitle"),                                                            joeyString("promptTitle.label"),                                                           titleObject,                                                           joeyString("promptTitle.prefQuestion"),                                                            check);                        if(result) {                g_joey_title = titleObject.value;            }                                    psvc.setBoolPref("joey.askForTitle",check.value);                                       }                                   } catch (i) { joeyDumpToConsole(i) }    var joey = Components.classes["@mozilla.com/joey;1"]                         .createInstance(Components.interfaces.mocoJoey);        joey.setListener(new joey_listener());    	if (g_joey_isfile)	{		joey.uploadFile(g_joey_title,                        g_joey_url,                        g_joey_file,                        g_joey_content_type);	}	else	{	    joey.uploadData(g_joey_title,                        g_joey_url,                        g_joey_data,                        g_joey_content_type);	}}function joeyOnMouseDown(e){	if (e.which == 3) 	{		var target = e.target;		var classname = e.target.toString();		if (classname.match(/ImageElement/))        {			// Simpler, but probably less efficient syntax: target.src;			var hie = target.QueryInterface(Components.interfaces.nsIDOMHTMLImageElement);			if (hie != null)				// show menu item:				setImageSource(hie);			else				setImageSource(null);		}         else        {            setImageSource(null);        }                var selectedRange=g_joey_gBrowser.selectedBrowser.contentDocument.getSelection();        if( selectedRange && selectedRange.toString() ) {           document.getElementById("joey_selectedText").hidden=false;        } else {          document.getElementById("joey_selectedText").hidden=true;        }    }}function setImageSource(imageElement){	if (imageElement != null)		gImageSource = imageElement.src;	else		gImageSource = null;        try     {        	var menuItem = document.getElementById('joey_selectedImage');	    menuItem.setAttribute("hidden", gImageSource == null ? "true" : "false");    }     catch (e) {}}function replaceAll( str, from, to ){    // regular expression faster?        var idx = str.indexOf( from );        while ( idx > -1 ) {        str = str.replace( from, to );        idx = str.indexOf( from );    }        return str;}function joey_launchCloudSite() {	g_joey_gBrowser.loadURI(getJoeyServerURL()+"/uploads");}function joey_selectedText() {    var focusedWindow = document.commandDispatcher.focusedWindow;    var selection = focusedWindow.getSelection().toString();        selection = replaceAll(selection, "\t", "\r\n");        var file = Components.classes["@mozilla.org/file/directory_service;1"]                         .getService(Components.interfaces.nsIProperties)                         .get("TmpD", Components.interfaces.nsIFile);    file.append("joey-selected-text.tmp");    file.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0664);    // file is nsIFile, data is a string    var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"]                             .createInstance(Components.interfaces.nsIFileOutputStream);    // use 0x02 | 0x10 to open file for appending.    foStream.init(file, 0x02 | 0x08 | 0x20, 0664, 0); // write, create, truncate    foStream.write(selection, selection.length);    foStream.close();    g_joey_file = file;    g_joey_isfile = true;    g_joey_content_type = "text/plain";    g_joey_title = focusedWindow.document.title;    g_joey_url  = focusedWindow.location.href;    uploadDataFromGlobals(false);}function joey_selected(){	if (gImageSource)		return joey_selectedImage();        var focusedWindow = document.commandDispatcher.focusedWindow;    var selection = focusedWindow.getSelection().toString();    	if (selection != null || selection != "")		return joey_selectedText();    	joey_selectedArea();}function joey_feed(){    /* We can detect which type of feed and send additional information      * as well, such as the title. On the other hand, the feed title      * may change, so that could be something chechec ( and refreshed )      * on the server      */        var feedLocation = g_joey_gBrowser.mCurrentBrowser.feeds[0].href;        g_joey_data = feedLocation;    g_joey_isfile = false;    g_joey_content_type = "rss-source/text";    g_joey_title = "Feed / We can put a title in it with one more client call. ";    g_joey_url  = feedLocation;    uploadDataFromGlobals(false);}// Check XUL statusbar itemfunction joey_launchPopup() {  joeySetCurrentFeed();  document.getElementById('joeyStatusPopup').showPopup(document.getElementById('joeyStatusButton'),-1,-1,'popup','topright', 'bottomright')}/* FIXME to be as an instance */function getMediaCallback(content_type, file){	if (length>0)    {         joeyDumpToConsole("Download successful... (" + content_type + ")");                g_joey_statusUpdateObject.tellStatus("download",null,null,"completed");                g_joey_content_type = content_type;        g_joey_file = file;        uploadDataFromGlobals(false);        return;	}    else {            /* This should become failed? */                g_joey_statusUpdateObject.tellStatus("download",null,null,"failed");        joeyDumpToConsole("Problem downloading media to joey!\n");    }}function JoeyStatusUpdateClass() {  /* We have now the XUL stack with elements in it.    * A background Layer and the top layer for    * the label.    */   this.progressElement   = document.getElementById("joeyProgressLayer");  this.progressBoxObject = document.getBoxObjectFor(document.getElementById("joeyStatusTeller"));  }/*  * UI Wrapper / Deals with the UI  * ------- * TODO: Need to work with multiple instances */JoeyStatusUpdateClass.prototype = {	/*  	 * We have to separate the login information from the      * loading status processes      */	    loginStatus: function (aMode,aAdVerb)    {	},    tellStatus:function(verb,from,to,adverb)     {        var value;         var percentage = parseInt((from/to)*parseInt(this.progressBoxObject.width));        // account for roundoff error that we have been seeing.        if (percentage > 100)            percentage = 100;                if (verb == "upload")         {            // value = "Uploading... ("+from+"/"+to+")";            value = joeyString("uploading") + "(" + percentage + "%)";        }        else        {            if (from==to)            {                // this might not be entirely true... basically, at ths point we are waiting to upload...                value = joeyString("loggingin");             }            else             {                // value = "Downloading... ("+from+"/"+to+")";                value = joeyString("downloading") + "("+percentage+"%)";              }        }           if(verb =="upload") {              this.progressElement.width=percentage;        } else {              if(verb =="download") {                percentage = this.progressBoxObject.width - percentage;                this.progressElement.width=percentage;              }         }         document.getElementById("joeyStatusTeller").value=value;                /* adverb */               if(adverb=="completed") {            this.progressElement.width=0;            if(verb=="download") {                 document.getElementById("joeyStatusTeller").value=joeyString("downloadCompleted");            }             if(verb=="upload") {                 document.getElementById("joeyStatusTeller").value=joeyString("uploadCompleted");            }             /* Dougt timer status cleanup */            setTimeout("document.getElementById('joeyStatusTeller').value=''", 600);        }        if(adverb == "failed") {            if(verb=="download") {                 document.getElementById("joeyStatusTeller").value=joeyString("downloadFailed");            }             if(verb=="upload") {                 document.getElementById("joeyStatusTeller").value=joeyString("uploadFailed");            }             /* Dougt timer status cleanup */            setTimeout("document.getElementById('joeyStatusTeller').value=''", 600);        }                      }    }/*  * This is nice for the Download + Progress functional */ function JoeyMediaFetcherStreamListener(aCallbackFunc){  this.mCallbackFunc = aCallbackFunc;}JoeyMediaFetcherStreamListener.prototype = {  mStream: null,  mContentType : null,  

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?