משתמש:ערן/TranslationTool.js

מתוך ויקיפדיה, האנציקלופדיה החופשית

הערה: לאחר הפרסום, ייתכן שיהיה צורך לנקות את זיכרון המטמון (cache) של הדפדפן כדי להבחין בשינויים.

  • פיירפוקס / ספארי: להחזיק את המקש Shift בעת לחיצה על טעינה מחדש (Reload) או ללחוץ על צירוף המקשים Ctrl-F5 או Ctrl-R (במחשב מק: ⌘-R).
  • גוגל כרום: ללחוץ על צירוף המקשים Ctrl-Shift-R (במחשב מק: ⌘-Shift-R).
  • אינטרנט אקספלורר / אדג': להחזיק את המקש Ctrl בעת לחיצה על רענן (Refresh) או ללחוץ על צירוף המקשים Ctrl-F5.
  • אופרה: ללחוץ על Ctrl-F5.
/*
סקריפט עזר לתרגום. הסקריפט מאפשר להוסיף חלונית המקור שממנה מתרגמים לדף העריכה עצמו וחוסך עבודה עם שני טאבים/חלונות.
הערות:
*הכלי עובד היטב בפיירפוקס
*עובד באקספלורר רק כשלא מוגדר "קוד ויקי" (כלומר ניתן לצפות בערך, אך לא בקוד שלו). הסיבה היא שאקספלורר פותח את הקוד ויקי כקובץ להורדה... רעיונות לתיקון: אולי לעבוד עם הAPI...
הסקריפט נכתב על ידי [[משתמש:ערן]]
*/
if (wgAction == 'edit' || wgAction == 'submit')
	addOnloadHook(addTranslationButton);

 
function addTranslationButton(){
	if (!window.translationToolName) translationToolName= 'תרגום';
	var accesskey = window.translationToolKey || ''; 
	addSystemButton(translationToolName, popupTranslationTool, 'btnTranslationTool', 'תרגום', accesskey);
 
}

function addSystemButton(name, onclick, id, tooltip, accesskey){ 
	var wpDiff= document.getElementById('wpDiff');
	if (!wpDiff) return;
	var btn = document.createElement('input');
	btn.type = 'button'; 
	if (name) btn.value = name; 
	if (onclick) btn.onclick = onclick;
	if (id) btn.id = id;
	if (tooltip) btn.title = tooltip; 
	if (accesskey) { 
		btn.accessKey = accesskey; 
		btn.title += ' [' + tooltipAccessKeyPrefix + btn.accessKey + ']';
	}	
	wpDiff.parentNode.insertBefore(btn, wpDiff);
	return btn;
}

function popupTranslationTool() {
    var editTextBox=document.getElementById('wpTextbox1');
    var englishArticle="";
    //try to get en ARTICLENAME from interwiki code in editbox
    if(editTextBox!=null){
       var englishPattern=/\[\[en:(.*)\]\]/;
       var results=englishPattern.exec(editTextBox.value);
       if(results && results.length>=1)
         englishArticle=results[1];
    }
    var popup = window.open( "", "popup", "height=240,width=250,location=no,status=no" );
 
    popup.document.write('<html><head><title>כלי תרגום</title>');
    popup.document.write('<style type="text/css" media="screen,projection">/*<![CDATA[*/ @import "/skins-1.5/monobook/main.css"; @import "/skins-1.5/monobook/rtl.css"; /*]]>*/</style>');
    popup.document.write('</head><body>');
    popup.document.write('<p>אנא מלאו את הפרמטרים הבאים : </p>');
    popup.document.write('<form name="paramForm">');
    popup.document.write('שם הערך בשפת המקור : <input type="text" name="inputName" value="'+englishArticle+'" style=\"width:140px;\"><p>');
    popup.document.write('קוד שפת מקור : <input type="text" name="inputLang" maxlength=43" value="en" style=\"width:50px;\"><p>');
    popup.document.write('מספר פסקה (אופציונלי) : <input type="text" name="inputSection" maxlength="2" value="" style=\"width:50px;\"><p>');
    popup.document.write('קוד ויקי: <input type="checkbox" name="inputWikiCode" checked="1"><p>');
    popup.document.write('</form>');
    popup.document.write('<p><a href="javascript:window.opener.addTranslationIframe( document.paramForm.inputName.value, document.paramForm.inputLang.value, document.paramForm.inputSection.value, document.paramForm.inputWikiCode.checked); self.close();"> הוספת חלונית מקור</a></p>');
    popup.document.write('<p><a href="javascript:self.close()"> סגירה</a></p>');
    popup.document.write('</body></html>');
    popup.document.close();
}

function addTranslationIframe( orgName, orgLang, orgSection, orgWikiCode){
var editTextBox=document.getElementById('wpTextbox1');
editTextBox.style.height="300px";
var editWarn=document.getElementById('editing-warn');
var otherLangEdit=document.createElement("iframe");
var orgURL="http://"+orgLang+".wikipedia.org/w/index.php?title="+orgName;
if(orgSection!="") orgURL+="&section="+orgSection;
if(orgWikiCode) orgURL+="&action=raw&ctype=text/javascript";
else orgURL+="&action=render";
otherLangEdit.setAttribute("src",orgURL);

otherLangEdit.setAttribute("height","300px");
otherLangEdit.setAttribute("width","100%");
editWarn.parentNode.insertBefore(otherLangEdit,editWarn);
}