Created
September 5, 2008 09:09
-
-
Save tothda/8944 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// TODO: | |
// * sztaki off még nem működik | |
// * a megjelenő ablak legyen draggable és resizeable (jQuery UI) | |
// * a kijelölt szavak szótövesítése, és a szótő lekérdezése a szótárból (pl. többes számú főneveknél, vagy ing-es igéknél jól jöhet) | |
noun_type_sztaki_states = new CmdUtils.NounType("SztakiStates", ["on", "off"]); | |
var dictionaryWindowStyle = "<style> \ | |
#sztaki_results { \ | |
color: black; \ | |
position: fixed; \ | |
top: 40px; \ | |
left: 40px; \ | |
width: 200px; \ | |
height: 300px; \ | |
background-color: yellow; \ | |
font-size: 11px; \ | |
font-family: \"Lucida Grande\"; \ | |
padding: 10px; \ | |
-moz-border-radius: 10px; \ | |
opacity: .80; \ | |
z-index: 100; \ | |
text-align: left; \ | |
} \ | |
#sztaki_results h3 { \ | |
font-size: 12px; \ | |
font-weight: bold; \ | |
border-bottom: 1px solid black; \ | |
margin: 0 \ | |
} \ | |
#sztaki_results ul { \ | |
padding-left: 0px; \ | |
margin: 5px 0; \ | |
} \ | |
#sztaki_results ul li { \ | |
list-style-type: none; \ | |
padding: 1px; \ | |
} \ | |
</style>"; | |
var dictionaryWindowTemplate = "<div id=\"sztaki_results\"> \ | |
<h3>${englishWord}</h3> \ | |
<ul> \ | |
{for w in words } \ | |
<li>${w}</li> \ | |
{/for} \ | |
</ul> \ | |
</div>"; | |
CmdUtils.CreateCommand({ | |
name: "sztaki", | |
homepage: "http://hiperkocka.hu/", | |
author: { name: "Tóth Dávid", email: "tothda@gmail.com" }, | |
license: "GPL", | |
description: "Sztaki szótár kliens", | |
help: "A \"sztaki on\" paranccsal bekapcsolva, egy kis ablak jelenik meg a weboldalon. Ezután ha egy angol szóra duplán kattintunk, a program lekérdez a Sztaki szótárból, és az eredményt az ablakba teszi.", | |
icon: "http://szotar.sztaki.hu/favicon.ico", | |
takes: { | |
"state": noun_type_sztaki_states | |
}, | |
inserWindowStyle: function() { | |
var body = context.focusedWindow.document.body; | |
jQuery(body).append(dictionaryWindowStyle); | |
}, | |
translate: function() { | |
var word = CmdUtils.getSelection(); | |
var dictUrl = 'http://szotar.sztaki.hu/dict_search.php'; | |
var params = { | |
L: "ENG:HUN:EngHunDict", | |
M: "3", | |
E: "1", | |
T: "0", | |
C: "0", | |
A: "0", | |
P: "0", | |
O: "HUN", | |
in_bookmarklet: "1", | |
W: word | |
}; | |
jQuery.get(dictUrl, params, | |
function(data) { | |
var result | |
var tempElement = CmdUtils.getHiddenWindow().document.createElementNS("http://www.w3.org/1999/xhtml", "div"); | |
tempElement.innerHTML = data; | |
var result = jQuery(tempElement).find('#result .normtext a'); | |
var resultElems = jQuery(tempElement).find('#result .normtext a').get(); | |
var words = jQuery.map(resultElems, function(e) {return jQuery(e).html();}); | |
var body = context.focusedWindow.document.body; | |
jQuery("#sztaki_results", body).html(CmdUtils.renderTemplate(dictionaryWindowTemplate, {words: words, englishWord:word})); | |
} | |
); | |
}, | |
execute: function(state) { | |
var body = context.focusedWindow.document.body; | |
var resultsDiv = jQuery(body).append("<div id='sztaki_results'>Szótár lekérdezés eredmények:</div>"); | |
this.inserWindowStyle(); | |
if (state.text == "off") { | |
body.removeEventListener("dblclick", this.translate, false); | |
return; | |
} | |
jQuery(body).bind("dblclick", this, this.translate); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment