// ---------------------------------------------------------------------------- // SundayMorning - A jQuery Plugin to translate content // v 1.0 Beta // Dual licensed under the MIT and GPL licenses. // ---------------------------------------------------------------------------- // Copyright (C) 2009 Jay Salvat // http://sundaymorning.jaysalvat.com/ // ---------------------------------------------------------------------------- // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. // ---------------------------------------------------------------------------- (function($) { $.sundayMorning = function(text, settings, callback) { var settings = $.extend({}, $.sundayMorning.defaults, settings); translate(settings, function(settings) { getGoogleTranslation(text, settings, function(response) { callback(response); }); }); }; // ------------------------------------------------------ $.fn.sundayMorningReset = function() { return this.each(function() { $(this).unbind('.sundayMorning'); }); } $.fn.sundayMorning = function(settings) { var settings = $.extend({}, $.sundayMorning.defaults, settings); return this.each(function() { var $$ = $(this); var text = $$.html(); var originalText = text; var originalLang = (settings.source == '') ? getSource($$) : settings.source; if (settings.source == '') { settings.source = getSource($$); } if (settings.trigger) { //$$.unbind('.sundayMorning'); $$.bind(settings.trigger+'.sundayMorning', function(evt) { if (settings.ctrlKey != evt.ctrlKey) { return false; } if (settings.shiftKey != evt.shiftKey) { return false; } settings.menuLeft = evt.pageX; settings.menuTop = evt.pageY; if (settings.destination != '') { if (settings.source == settings.destination) { return false; } if (getSource($$) == settings.destination) { $$.fadeTo('fast', 1.1, function() { $$.html(originalText); $$.attr('lang', originalLang); $$.fadeTo('fast', 1); }); return false; } } translate(settings, function(settings) { contentReplacement($$, text, settings) }); evt.preventDefault(); evt.stopPropagation(); }); } else { translate(settings, function(settings) { contentReplacement($$, text, settings) }); } }); }; // ------------------------------------------------------ $.fn.sundayMorningDetection = function(callback) { var settings = $.sundayMorning.defaults; return this.each(function() { var $$ = $(this); var text = $$.text(); getGoogleDetection(text, settings, function(response) { callback(response); }); }); }; $.sundayMorningDetection = function(text, callback) { var settings = $.sundayMorning.defaults; getGoogleDetection(text, settings, function(response) { callback(response); }); }; // ------------------------------------------------------ $.fn.sundayMorningBubble = function(settings) { var settings = $.extend({}, $.sundayMorning.defaults, settings); return this.each(function() { var $$ = $(this); //$$.unbind('.sundayMorning'); $$.bind('dblclick.sundayMorning', function(evt) { if (settings.ctrlKey != evt.ctrlKey) { return false; } if (settings.shiftKey != evt.shiftKey) { return false; } if (window.getSelection) { var text = window.getSelection(); } else if (document.getSelection) { var text = document.getSelection(); } else { var text = document.selection.createRange().text; } text = text.toString(); if (text.replace(/\W|\d/g, '') == '') { return false; } settings.menuLeft = menuLeft = evt.pageX; settings.menuTop = menuTop = evt.pageY; translate(settings, function(settings) { getGoogleTranslation(text, settings, function(response) { var bubble; bubble = $('