From e9bb1c8090c7f4fb8c705cc083b4613bc89d894e Mon Sep 17 00:00:00 2001 From: Kartik Mistry Date: Thu, 10 Jul 2014 10:10:49 +0000 Subject: [PATCH] Beautify code using js-beautify tool --- SelectedTextnotification.js | 217 +++++++++++++++++++----------------- background.js | 116 +++++++++---------- 2 files changed, 176 insertions(+), 157 deletions(-) diff --git a/SelectedTextnotification.js b/SelectedTextnotification.js index 02a6fa0..05ecb72 100644 --- a/SelectedTextnotification.js +++ b/SelectedTextnotification.js @@ -1,214 +1,230 @@ var GujaratiLexicon = { - selectedWord:'', - curDictOpt:'', - curLanguage:'', - mousePosX:'', - mousePosY:'', - curDictTypeName:[{"0" : ["Eng-Guj"] }, - {"1" : ["Guj-Guj","Guj-Eng"]}, - {"2" : ["Hin-Guj"] } + selectedWord: '', + curDictOpt: '', + curLanguage: '', + mousePosX: '', + mousePosY: '', + curDictTypeName: [ { + "0": [ "Eng-Guj" ] + }, + { + "1": [ "Guj-Guj", "Guj-Eng" ] + }, + { + "2": [ "Hin-Guj" ] + } ], - init:function(){ + init: function () { //Intiliaze Event Handler - if(document) { + if ( document ) { document.onkeydown = GujaratiLexicon.handelKeyPress; - document.body.addEventListener('dblclick',GujaratiLexicon.selectedWordNotification,false); - document.body.addEventListener('click', GujaratiLexicon.removeDictBubble,false); + document.body.addEventListener( 'dblclick', GujaratiLexicon.selectedWordNotification, false ); + document.body.addEventListener( 'click', GujaratiLexicon.removeDictBubble, false ); //document.body.onclick = removeDictBubble; GujaratiLexicon.getCurDictOpt(); } }, - getCurDictOpt : function(){ /*Get Current Dictionary Option and Set it to Global Dictionary Variable (curDictOpt)*/ - chrome.extension.sendMessage({getDictOpt: true}, function(response) { - GujaratiLexicon.curDictOpt = response.curDictOpt; - //console.log( this.curDictOpt ); - }); + getCurDictOpt: function () { /*Get Current Dictionary Option and Set it to Global Dictionary Variable (curDictOpt)*/ + chrome.extension.sendMessage( { + getDictOpt: true + }, function ( response ) { + GujaratiLexicon.curDictOpt = response.curDictOpt; + //console.log( this.curDictOpt ); + } ); }, - setCurDictOpt : function( dict ){ - chrome.extension.sendMessage({setDictOpt: dict }, function(response) { - }); + setCurDictOpt: function ( dict ) { + chrome.extension.sendMessage( { + setDictOpt: dict + }, function ( response ) {} ); }, - selectedWordNotification : function(event){ - if(window.getSelection().toString().trim() !== "") { + selectedWordNotification: function ( event ) { + if ( window.getSelection().toString().trim() !== "" ) { GujaratiLexicon.selectedWord = window.getSelection().toString().trim(); } - GujaratiLexicon.curLanguage = GujaratiLexicon.wordLangIndentification(GujaratiLexicon.selectedWord); /*Indentify Word Language*/ + GujaratiLexicon.curLanguage = GujaratiLexicon.wordLangIndentification( GujaratiLexicon.selectedWord ); /*Indentify Word Language*/ - if( $('#GujaratiLexicon').length === 0 ) { + if ( $( '#GujaratiLexicon' ).length === 0 ) { GujaratiLexicon.mousePosX = event.pageX; GujaratiLexicon.mousePosY = event.pageY; } - if( GujaratiLexicon.curLanguage !== false ) { - GujaratiLexicon.curDictType = GujaratiLexicon.dictionarySelection(GujaratiLexicon.curLanguage); - GujaratiLexicon.renderBubble( GujaratiLexicon.mousePosX , GujaratiLexicon.mousePosY , GujaratiLexicon.selectedWord, GujaratiLexicon.curLanguage, "Searching . . ." ); + if ( GujaratiLexicon.curLanguage !== false ) { + GujaratiLexicon.curDictType = GujaratiLexicon.dictionarySelection( GujaratiLexicon.curLanguage ); + GujaratiLexicon.renderBubble( GujaratiLexicon.mousePosX, GujaratiLexicon.mousePosY, GujaratiLexicon.selectedWord, GujaratiLexicon.curLanguage, "Searching . . ." ); GujaratiLexicon.getDictTranslation(); } }, - handelKeyPress : function( event ){ - if( event.keyCode == 27 ) { + handelKeyPress: function ( event ) { + if ( event.keyCode == 27 ) { GujaratiLexicon.removeDictBubble(); } }, - removeDictBubble : function(){ - if( $('#GujaratiLexicon') ) { - $('#GujaratiLexicon').remove(); + removeDictBubble: function () { + if ( $( '#GujaratiLexicon' ) ) { + $( '#GujaratiLexicon' ).remove(); } }, - wordLangIndentification : function( tempWord ){ - if( tempWord === "" ) { + wordLangIndentification: function ( tempWord ) { + if ( tempWord === "" ) { return false; } //test for English Language - if( /^[a-zA-Z]*$/.test(tempWord) ) { - return 0; + if ( /^[a-zA-Z]*$/.test( tempWord ) ) { + return 0; } //test for Gujarati Language - else if( /^[\u0A80-\u0AFF]*$/.test(tempWord) ) { + else if ( /^[\u0A80-\u0AFF]*$/.test( tempWord ) ) { return 1; } //test for Hindi Language - else if( /^[\u0900-\u097F]*$/.test(tempWord) ) { + else if ( /^[\u0900-\u097F]*$/.test( tempWord ) ) { return 2; - } - - else { + } else { return false; } }, - dictionarySelection : function( language ){ - if(language === 1) { + dictionarySelection: function ( language ) { + if ( language === 1 ) { return GujaratiLexicon.curDictOpt; - } - else { + } else { return language + ".0"; } }, - getDictTranslation : function( ){ - chrome.extension.sendMessage({SW: GujaratiLexicon.curDictType + GujaratiLexicon.selectedWord }, function(response) { + getDictTranslation: function () { + chrome.extension.sendMessage( { + SW: GujaratiLexicon.curDictType + GujaratiLexicon.selectedWord + }, function ( response ) { //GujaratiLexicon.renderBubble( GujaratiLexicon.mousePosX , GujaratiLexicon.mousePosY , GujaratiLexicon.selectedWord , GujaratiLexicon.curLanguage , response.TW ); - - if(GujaratiLexicon.curLanguage === 0) - { - $('#GujaratiLexicon #GLXBubblePronunciation').text(response.PRONUNCIATION); + + if ( GujaratiLexicon.curLanguage === 0 ) { + $( '#GujaratiLexicon #GLXBubblePronunciation' ).text( response.PRONUNCIATION ); } - - $('#GujaratiLexicon #GLXBubbleTranslatedWord').text(response.TW); - }); + $( '#GujaratiLexicon #GLXBubbleTranslatedWord' ).text( response.TW ); + + } ); }, - renderBubble : function (mouseX, mouseY, word, wordLanguage, meaning){ + renderBubble: function ( mouseX, mouseY, word, wordLanguage, meaning ) { GujaratiLexicon.removeDictBubble(); - divContainer=document.createElement('div'); + divContainer = document.createElement( 'div' ); - $('html').append(divContainer); + $( 'html' ).append( divContainer ); divContainer.id = 'GujaratiLexicon'; divContainer.className = 'arrow_box'; - divContainer.style.top = mouseY + 10+ 'px'; - divContainer.style.left = mouseX - 140 + 'px'; + divContainer.style.top = mouseY + 10 + 'px'; + divContainer.style.left = mouseX - 140 + 'px'; - divGLXBubbleSelectedWord = document.createElement('div'); + divGLXBubbleSelectedWord = document.createElement( 'div' ); divGLXBubbleSelectedWord.id = 'GLXBubbleSelectedWord'; divGLXBubbleSelectedWord.innerHTML = word; divGLXBubbleSelectedWord.className = 'selectedWord'; - $('#GujaratiLexicon').append(divGLXBubbleSelectedWord); + $( '#GujaratiLexicon' ).append( divGLXBubbleSelectedWord ); var tempSpanString = ""; - for( var i =0; i < GujaratiLexicon.curDictTypeName[wordLanguage][wordLanguage].length ; i++ ) - { - tempSpanString += "" + GujaratiLexicon.curDictTypeName[wordLanguage][wordLanguage][i] + ""; + for ( var i = 0; i < GujaratiLexicon.curDictTypeName[ wordLanguage ][ wordLanguage ].length; i++ ) { + tempSpanString += "" + GujaratiLexicon.curDictTypeName[ wordLanguage ][ wordLanguage ][ i ] + ""; } - $('#GLXBubbleSelectedWord').html( word + tempSpanString ); + $( '#GLXBubbleSelectedWord' ).html( word + tempSpanString ); - if( $('#GLXBubbleSelectedWord span').length > 1 ) - { - $('#GLXBubbleSelectedWord span:first').bind( "click" , GujaratiLexicon.setGujGuj); - $('#GLXBubbleSelectedWord span:last').bind( "click" , GujaratiLexicon.setGujEng); + if ( $( '#GLXBubbleSelectedWord span' ).length > 1 ) { + $( '#GLXBubbleSelectedWord span:first' ).bind( "click", GujaratiLexicon.setGujGuj ); + $( '#GLXBubbleSelectedWord span:last' ).bind( "click", GujaratiLexicon.setGujEng ); - $('#GLXBubbleSelectedWord span').css({ 'cursor' : 'hand' , 'cursor': 'pointer', 'color' : 'blue'}); + $( '#GLXBubbleSelectedWord span' ).css( { + 'cursor': 'hand', + 'cursor': 'pointer', + 'color': 'blue' + } ); - if( GujaratiLexicon.curDictType === "1.1" ) { - $('#GLXBubbleSelectedWord span:first').css({'font-weight' : 'bold'}); + if ( GujaratiLexicon.curDictType === "1.1" ) { + $( '#GLXBubbleSelectedWord span:first' ).css( { + 'font-weight': 'bold' + } ); } - if( GujaratiLexicon.curDictType === "1.2" ) { - $('#GLXBubbleSelectedWord span:last').css({'font-weight' : 'bold'}); + if ( GujaratiLexicon.curDictType === "1.2" ) { + $( '#GLXBubbleSelectedWord span:last' ).css( { + 'font-weight': 'bold' + } ); } } - if(GujaratiLexicon.curLanguage === 0) - { - divGLXBubblePronunciation = document.createElement('div'); + if ( GujaratiLexicon.curLanguage === 0 ) { + divGLXBubblePronunciation = document.createElement( 'div' ); divGLXBubblePronunciation.id = 'GLXBubblePronunciation'; - divGLXBubblePronunciation.innerHTML = ""; + divGLXBubblePronunciation.innerHTML = ""; divGLXBubblePronunciation.className = 'pronunciation'; - $('#GujaratiLexicon').append(divGLXBubblePronunciation); + $( '#GujaratiLexicon' ).append( divGLXBubblePronunciation ); } - divGLXBubbleTranslatedWord = document.createElement('div'); + divGLXBubbleTranslatedWord = document.createElement( 'div' ); divGLXBubbleTranslatedWord.id = 'GLXBubbleTranslatedWord'; - divGLXBubbleTranslatedWord.innerHTML = meaning; + divGLXBubbleTranslatedWord.innerHTML = meaning; divGLXBubbleTranslatedWord.className = 'traslatedWord'; - $('#GujaratiLexicon').append(divGLXBubbleTranslatedWord); + $( '#GujaratiLexicon' ).append( divGLXBubbleTranslatedWord ); - divGLXHyperLink = document.createElement('div'); + divGLXHyperLink = document.createElement( 'div' ); divGLXHyperLink.id = 'GLXHyperLink'; - $('#GujaratiLexicon').append(divGLXHyperLink); + $( '#GujaratiLexicon' ).append( divGLXHyperLink ); divGLXHyperLink.className = 'gujaratiLexiconLink'; - divGLXHyperLink.innerHTML = "" + "Powered By:" + " GujaratiLexicon " + ""; + divGLXHyperLink.innerHTML = "" + "Powered By:" + " GujaratiLexicon " + ""; - divCloseButton = document.createElement('div'); + divCloseButton = document.createElement( 'div' ); divCloseButton.id = 'GLXCloseButton'; - var imageSource = chrome.extension.getURL("/glxCloseButton.png"); + var imageSource = chrome.extension.getURL( "/glxCloseButton.png" ); - $('#GujaratiLexicon').append(divCloseButton); + $( '#GujaratiLexicon' ).append( divCloseButton ); divCloseButton.className = 'closeButton'; - $('#GLXCloseButton').css('background-image','url('+ imageSource +')'); - $('#GLXCloseButton').bind("click", GujaratiLexicon.removeDictBubble ); + $( '#GLXCloseButton' ).css( 'background-image', 'url(' + imageSource + ')' ); + $( '#GLXCloseButton' ).bind( "click", GujaratiLexicon.removeDictBubble ); - $('html #GujaratiLexicon #GLXBubbleTranslatedWord').bind('dblclick' , GujaratiLexicon.selectedWordNotification); + $( 'html #GujaratiLexicon #GLXBubbleTranslatedWord' ).bind( 'dblclick', GujaratiLexicon.selectedWordNotification ); }, - setGujGuj : function( ){ - GujaratiLexicon.setCurDictOpt("1.1"); + setGujGuj: function () { + GujaratiLexicon.setCurDictOpt( "1.1" ); GujaratiLexicon.curDictType = "1.1"; - if( GujaratiLexicon.curDictType === "1.1" ) { - $('#GLXBubbleSelectedWord span:first').css({'font-weight' : 'bold'}); + if ( GujaratiLexicon.curDictType === "1.1" ) { + $( '#GLXBubbleSelectedWord span:first' ).css( { + 'font-weight': 'bold' + } ); } - GujaratiLexicon.renderBubble( GujaratiLexicon.mousePosX , GujaratiLexicon.mousePosY , GujaratiLexicon.selectedWord, GujaratiLexicon.curLanguage, "Searching . . ." ); + GujaratiLexicon.renderBubble( GujaratiLexicon.mousePosX, GujaratiLexicon.mousePosY, GujaratiLexicon.selectedWord, GujaratiLexicon.curLanguage, "Searching . . ." ); GujaratiLexicon.getDictTranslation(); }, - setGujEng : function(){ - GujaratiLexicon.setCurDictOpt("1.2"); + setGujEng: function () { + GujaratiLexicon.setCurDictOpt( "1.2" ); GujaratiLexicon.curDictType = "1.2"; - if( GujaratiLexicon.curDictType === "1.2" ) { - $('#GLXBubbleSelectedWord span:last').css({'font-weight' : 'bold'}); + if ( GujaratiLexicon.curDictType === "1.2" ) { + $( '#GLXBubbleSelectedWord span:last' ).css( { + 'font-weight': 'bold' + } ); } GujaratiLexicon.renderBubble( GujaratiLexicon.mousePosX, GujaratiLexicon.mousePosY, GujaratiLexicon.selectedWord, GujaratiLexicon.curLanguage, "Searching . . ." ); @@ -219,4 +235,3 @@ var GujaratiLexicon = { }; GujaratiLexicon.init(); - diff --git a/background.js b/background.js index fc2dcfb..5421d79 100644 --- a/background.js +++ b/background.js @@ -1,21 +1,21 @@ -function getDictionaryOption(){ - return $('#dict').text(); +function getDictionaryOption() { + return $( '#dict' ).text(); } -function setDictonayOption( option ){ - $('#dict').text(option); +function setDictonayOption( option ) { + $( '#dict' ).text( option ); } -function XmlHTTPRequest( URL, callback ){ +function XmlHTTPRequest( URL, callback ) { var xhr = new XMLHttpRequest(); - xhr.open("GET", URL, false); + xhr.open( "GET", URL, false ); - xhr.onreadystatechange = function() { + xhr.onreadystatechange = function () { - if (xhr.readyState == 4 && xhr.status==200) { - //document.getElementById("add").innerHTML = xhr.responseText; - callback(xhr.responseText); - } + if ( xhr.readyState == 4 && xhr.status == 200 ) { + //document.getElementById("add").innerHTML = xhr.responseText; + callback( xhr.responseText ); + } }; @@ -24,67 +24,71 @@ function XmlHTTPRequest( URL, callback ){ } function composeURL( dictType, selectedWord ) { - if( dictType === "0.0" ) { + if ( dictType === "0.0" ) { return "http://www.gujaratilexicon.com/dictionary/EG/" + selectedWord; - } - else if( dictType === "1.1" ) { + } else if ( dictType === "1.1" ) { return "http://www.gujaratilexicon.com/dictionary/GG/" + selectedWord; - } - else if( dictType === "1.2" ) { + } else if ( dictType === "1.2" ) { return "http://www.gujaratilexicon.com/dictionary/GE/" + selectedWord; - } - else if(dictType === "2.0") { + } else if ( dictType === "2.0" ) { return "http://www.gujaratilexicon.com/dictionary/HG/" + selectedWord; } } -function sendTranslation( responsehandler, selectedWord, exactWordInWebPage, pronunciation, finalTranslation ) { - if(finalTranslation !== "") { - if(selectedWord.toLowerCase() === exactWordInWebPage.split(' ').join('')) { - responsehandler({ TW: finalTranslation, - PRONUNCIATION : pronunciation }); - } - else { - responsehandler({TW: "No Exact Match Found.!!"}); +function sendTranslation( responsehandler, selectedWord, exactWordInWebPage, pronunciation, finalTranslation ) { + if ( finalTranslation !== "" ) { + if ( selectedWord.toLowerCase() === exactWordInWebPage.split( ' ' ).join( '' ) ) { + responsehandler( { + TW: finalTranslation, + PRONUNCIATION: pronunciation + } ); + } else { + responsehandler( { + TW: "No Exact Match Found.!!" + } ); } - } - else { - responsehandler({TW: "Not Found.!!"}); + } else { + responsehandler( { + TW: "Not Found.!!" + } ); } } chrome.extension.onMessage.addListener( - function( request, sender, sendResponse ) { - if(request.getDictOpt) { - sendResponse({ curDictOpt: getDictionaryOption() }); - } - else if( request.setDictOpt ) { - setDictonayOption(request.setDictOpt); - sendResponse({Not: "null"}); - } + function ( request, sender, sendResponse ) { + if ( request.getDictOpt ) { + sendResponse( { + curDictOpt: getDictionaryOption() + } ); + } else if ( request.setDictOpt ) { + setDictonayOption( request.setDictOpt ); + sendResponse( { + Not: "null" + } ); + } - if(request.SW) { - var tempDictAndWord = request.SW; - // var dictionaryType = parseInt(tempDictAndWord[0]); + if ( request.SW ) { + var tempDictAndWord = request.SW; + // var dictionaryType = parseInt(tempDictAndWord[0]); - //if(dictionaryType === 1) - { - var tempSelectedWord = tempDictAndWord.substr(3, tempDictAndWord.length); - dictionaryType = tempDictAndWord.substr(0 , 3); - } + //if(dictionaryType === 1) + { + var tempSelectedWord = tempDictAndWord.substr( 3, tempDictAndWord.length ); + dictionaryType = tempDictAndWord.substr( 0, 3 ); + } - var URL = composeURL(dictionaryType, tempSelectedWord); + var URL = composeURL( dictionaryType, tempSelectedWord ); - XmlHTTPRequest(URL, function(tempWebpage) { - document.getElementById('ab').innerHTML = tempWebpage; - var selectAllMetaTag = $('#ab meta'); - var exactWordInWebpage = $('#ab #details .rc_border .wordbox h1').text(); - var pronunciation = $( $('#details .rc_border table tbody td')[2] ).text(); - var finalTranslation = selectAllMetaTag[1]["content"]; + XmlHTTPRequest( URL, function ( tempWebpage ) { + document.getElementById( 'ab' ).innerHTML = tempWebpage; + var selectAllMetaTag = $( '#ab meta' ); + var exactWordInWebpage = $( '#ab #details .rc_border .wordbox h1' ).text(); + var pronunciation = $( $( '#details .rc_border table tbody td' )[ 2 ] ).text(); + var finalTranslation = selectAllMetaTag[ 1 ][ "content" ]; - sendTranslation( sendResponse , tempSelectedWord , exactWordInWebpage , pronunciation, finalTranslation ); - }); + sendTranslation( sendResponse, tempSelectedWord, exactWordInWebpage, pronunciation, finalTranslation ); + } ); - } + } -}); + } );