Is this possible to set the language in tinymce editor in javascript? - tinymce

I have using tinymce text edit for my asp.net applications.Now i have added language pack.now i want to set the language pack for the text editor programatically.And also hide the language pack bar from the visible state.
for example : i want to programatically set the language of the text editior is hindi.Pleasr guide me to get out of this...
whenever user clicks translation Button in my web form , i have initialized this string variable.then i want to set the tinymce editor language programatically.
string lang="Hindi";
ptp.js
function LoadTypePad()
{
// Initialize pad
tinyMCE.init({
// General options
mode : "textareas",
theme : "advanced",
skin : "o2k7",
skin_variant : "silver",
plugins : "safari,style,table,advhr,advimage,advlink,inlinepopups,insertdatetime,preview,media,searchreplace,print,paste,fullscreen,indicime,aksharspellchecker",
// Theme options
theme_advanced_buttons1 : "newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,formatselect,fontsizeselect,fontselect,aksharspellchecker,indicime, indicimehelp",
theme_advanced_buttons2 : "selectall,cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,media,advhr,|,print",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_resizing : true,
spellchecker_rpc_url:"http://service.vishalon.net/spellchecker.aspx",
// Example content CSS (should be your site CSS)
content_css : "css/content.css",
// Drop lists for link/image/media/template dialogs
template_external_list_url : "lists/template_list.js",
external_link_list_url : "lists/link_list.js",
external_image_list_url : "lists/image_list.js",
media_external_list_url : "lists/media_list.js",
width : "100%",
init_instance_callback : "afterInit"
});
}
function showPleaseWait()
{
var mainMessage = document.getElementById("message").innerHTML;
document.getElementById("message").innerHTML = pleaseWait;
pleaseWait = mainMessage;
}
// This function finds absolute position of the element in screen and returns array.
function findPos(obj) {
var curleft = curtop = 0;
if (obj.offsetParent) {
do {
curleft += obj.offsetLeft;
curtop += obj.offsetTop;
} while (obj = obj.offsetParent);
return [curleft,curtop];
}
}
// id= outer most id for show/hide. baseid = reference id for pointer
function showPopup(id, baseid)
{
toggle_menu(id);
var base = document.getElementById(baseid);
var l = findPos(base);
var obj = document.getElementById(id + 'content');
var im = document.getElementById(id + 'img');
var left = im.src.indexOf('left.gif') > 0;
obj.style.top = (l[1] - obj.offsetHeight - 20) + "px";
obj.style.left = (l[0] + (base.offsetWidth/2) - (left?obj.offsetWidth:0)) + "px";
l = findPos(obj);
im.style.top = (l[1] + obj.offsetHeight - 1) + "px";
im.style.left = (l[0] + (left?obj.offsetWidth - 26:0)) + "px";
}
function closePopup()
{
// hide popup
var elem = document.getElementById("step1");
elem.style.display = "none";
elem = document.getElementById("step2");
elem.style.display = "none";
elem = document.getElementById("step3");
elem.style.display = "none";
}
// Once tinymce is fully loaded
function afterInit()
{
// Find search string from referral
var term = document.referrer;
var re = /bengali|gujarati|gujrati|hindi|marathi|devnagari|devanagari|punjabi|gurmukhi|kannada|malayalam|tamil|telugu|thelugu|thamil/gi ;
var m = re.exec(term);
var result ='';
if (m != null && m.length > 0)
result = "<strong>" + m[0] + "</strong>";
else
result = "your favourite Indic Script";
// Create popup
CreatePopup("step1", "Step 1", "Click here to erase existing contents", "right");
CreatePopup("step2", "Step 2", "Select " + result + " from this dropdown list and start typing.", "left");
CreatePopup("step3", "Step 3", "Click here to get a help for typing once you selected script in Step 2", "right");
// Restore the message from please wait to spell checker
document.getElementById("message").innerHTML = "Now Akshar Spell Checker for Gujarati is available!!! Click on <img src=\"tiny_mce/plugins/aksharspellchecker/img/aksharspellchecker.gif\"> to check Gujarati spelling";
// Initialize for google search
pph = new PramukhPhoneticHandler();
pph.convertToIndicIME("q");
pph.onScriptChange("q", indicChange);
// Open up popups
showPopup("step1","elm1_newdocument");
showPopup("step2","elm1_indicime");
showPopup("step3","elm1_indicimehelp");
// Close popup after xx seconds.
setTimeout("closePopup();",15000);
}
function toggle_menu(id)
{
var elem = document.getElementById(id);
elem.style.display = elem.style.display=="none"? "":"none";
}
function CheckNewVersion()
{
var JSONRequest = tinymce.util.JSONRequest;
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
} catch (e) {
// do nothing
}
JSONRequest.sendRPC({
url : "http://service.vishalon.net/pramukhtypepadmessage.aspx?v=2.5.00",
method : "",
params : "",
type: "GET",
success : function(r){
var message = r.substring(r.indexOf(",")+1);
if (message != "")
document.getElementById("message").innerHTML = "<img src='img/info.jpg' >" + message + "<br><br>";
},
error : function(e, x) {
// do nothing
}
});
}
function indicChange(id, lang)
{
var s = document.getElementById('language');
s.value = lang;
if (lang == null || lang == "")
lang = 'english';
pph.setScript(id, lang);
}
function CreatePopup(id, title,content, dir)
{
var holder = document.getElementById("plholder");
holder.innerHTML += "<div id='" +id + "' style='display:none;'>"+
"<div class='popupbody' id='" +id + "content'>" +
"<div style='float:right;'><img src='img/close.gif' style='cursor:pointer;cursor:hand;' onclick='toggle_menu(\"" + id + "\");'/></div>"+
"<div><strong>" + title + "</strong></div>"+
"<div style='clear:both'></div>"+
"<div>" + content + "</div>"+
"</div>"+
"<img src='img/" + dir + ".gif' id='" + id + "img' style='position:absolute;'/>"+
"</div>";
}
var pph, pleaseWait = "Please wait while Pramukh Type Pad is loading... <img src='img/progress.gif' /> (Loading problem??? Get Simple Pramukh Type Pad )";

You have to download your language pack and unzip it.
Then you have to put every single js file in the corresponding folder of your tinymce folder.
You have to specify the language as well.
If you're using TinyMCE - jQuery Plugin you have to do something like this:
// Initializes all textareas with the tinymce class
$(document).ready(function() {
$('textarea.tinymce').tinymce({
script_url : '../js/tinymce/jscripts/tiny_mce/tiny_mce.js',
theme : "advanced",
language: "hi",
...
});
});
If you want to remove tinyMCE (and I guess you have to do it if you want to reset the language) from your text-area you can use this code:
tinyMCE.execCommand('mceRemoveControl', false, 'mycontrol_id');
as specified here.
and you can recreate it using the same code.
You can wrap everything in a function and pass the language parameter:
function setup(language) {
tinyMCE.init({
mode : "textareas",
theme : "advanced",
language: language,
plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_resizing : true
});
}
If you want to remove buttons from the toolbar you have to work on these lines:
theme_advanced_buttons1
theme_advanced_buttons2
...
removing those you don't need.
There's a list of all buttons and plugins here.
If you want to add your own buttons you can find a sample here.
UPDATE:
Since you've used your own plugin, I guess you have defined it in the plugin section:
tinyMCE.init({
mode : "textareas",
theme : "advanced",
language: 'hi',
plugins : "myPlugin, pagebreak ... ",
theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
theme_advanced_buttons2 : "myPlugin",
...
});
If you don't want to show it, just remove it from the theme_advanced_buttons2.

Related

Can't get the autocomplete search form to work

I'm implementing a search form that displays suggestions as you start typing but can't get it to work..the problem is that when you start typing it doesn't shows any suggestion. Can you help me to get the code right? Many thanks!
This is the code:
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script>
<div><input id="autocomplete" type="text"></div>
<script>
$("input#autocomplete").autocomplete({
source: [
{ id : "Google", value : "Google"},
{ id : "Yahoo", value : "Yahoo"},
],
minLength: 1,
open: function(event, ui) {
$("ul.ui-autocomplete").unbind("click");
var data = $(this).data("autocomplete");
console.log(data);
for(var i=0; i<=data.options.source.length-1;i++)
{
var s = data.options.source[i];
$("li.ui-menu-item a:contains(" + s.value + ")").attr("href", "/" + s.id);
}
}
});
/*
$("input#autocomplete").bind("autocompleteselect", function(event, ui) {
//alert(ui.item.id + ' - ' + ui.item.value);
//document.location.href = ui.item.id + '/' + ui.item.value;
//event.preventDefault;
} );
*/
</script>
Here Is the code:
<div id="search">
<input list="results" id="project" onkeydown="if (event.keyCode == 13) { checkInput(this.value); return false; }" />
</div>
The avaible results...
<datalist id="results">
<option>Demo</option>
<option>Example</option>
<option>pizza</option>
</datalist>
Finally the javascript
function checkInput(searchQuery)
{
if(searchQuery=="Home")
{
window.location = "Home.html";
}
else if(searchQuery == "Contact")
{
window.location = "Contact.html";
}
else if(searchQuery == "Sitemap")
{
window.location = "Sitemap.html";
}
else
{
window.location = "noresult.html";
}
}
So that way when ever someone goes to search they have a limited amount of options in the pre-populated list and which ever one they select leads them to your target page! I can't take all the credit, but I hope that helps!

adding external plugin in CKEditor 3.6

I am trying to add an external plugin in ckeditor but it looks that I am not registering correctly my plugin and it isn' showing.
1.- I tried adding it directly to the CKEditor config file and it didn't work.
CKEDITOR.editorConfig = function(config) {
config.toolbar = [
['Bold'],['Italic'],['myplugin']
]
};
2.- Tried adding it to the html file when initiating CKEditor and also didn't work.
var editor = CKEDITOR.replace( 'editor1',
{
removePlugins : 'forms,table,tabletools',
extraPlugins : 'msugetprop,msuforms,msutable,msutabletools,msumobile',
toolbar :
[
['Cut','Copy','PasteText','Preview'],
['Undo','Redo','-','SelectAll'],
['MsuForm','MsuGetProp','MsuCheckbox', 'MsuRadio', 'MsuTextField', 'MsuTextarea', 'MsuSelect', 'MsuButton', 'MsuTable', 'MsuHiddenField'],
'/',
['Styles','-','NumberedList','BulletedList','-','CreateDiv'],
['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
['Link','Unlink','Anchor'],
['Source','-','About'],
['myplugin'],
]
});
3.- My plugin is under /ckeditor/plugins/myplugin with filename plugin.js
(function() {
var o = { exec: function(p) {
url = baseUrl + "/GetSomeData";
$.post(url, function(response) {
alert(response)
});
}
};
CKEDITOR.plugins.add('myplugin', {
init: function(editor) {
editor.addCommand('myplugin', o);
editor.ui.addButton('myplugin', {
label: 'myplugin',
icon: this.path + 'myplugin.png',
command: 'myplugin'
});
}
});
})();
What am I missing ?
Solved.
forgot to add 'myplugin" under extraPlugins.

Getting Image path instead of Image - PhoneGap Listview

I am working on an PhoneGap application in which I am saving user's name , number and Email , after that I am displaying that data to another page in list - view. That has been done very successfully. But now when I want to store Image of user in my local Storage, I am getting the path of image instead of Image.
I am saving my data in this way :
<SCRIPT Language="JavaScript" charset="utf-8" type="text/javascript">
var userName, userNumber, userEmail, userImage ;
function showAndClearField(frm)
{
userName = frm.name.value;
userNumber = frm.number.value;
userEmail = frm.email.value;
if (frm.name.value == "" )
{
alert("Please enter your name!")
}
else if(frm.number.value == "")
{
alert("Please enter your number!")
}
else if(frm.email.value == "")
{
alert("Please enter your Email !")
}
else
{
alert("Name : " + userName + '\n' + " Number: " + userNumber + '\n' + " Email: " + userEmail )
frm.name.value = ""
frm.number.value = ""
frm.email.value = ""
var db = window.openDatabase("TestingDemo", "1.0", "PhoneGapTesting Demo", 200000);
db.transaction(populateDB, errorCB, successCB);
}
function populateDB(tx)
{
tx.executeSql('INSERT INTO DEMO (id, data, userName, userNumber, userEmail, userImage) VALUES (1, "Third row", "'+ userName +'" , "'+ userNumber +'" , "'+ userEmail +'", "'+ userImage +'")');
}
While displaying data I am using following code :
var nameOfUser , numberOfUser , emailOfUser, imageOfUser;
for (var i=0; i<len; i++)
{
nameOfUser = results.rows.item(i).userName;
numberOfUser = results.rows.item(i).userNumber;
emailOfUser = results.rows.item(i).userEmail;
imageOfUser = results.rows.item(i).userImage;
numArr.push({ name : nameOfUser , number : numberOfUser , email : emailOfUser, image : imageOfUser });
}
function createCheckboxes(){
$("#createBtn").remove();
$("#content").append('<fieldset id="cbFieldSet" data-role="controlgroup" style = "padding : 20px" >');
var length = numArr.length;
for(var i=0;i<length;i++)
{
$("#cbFieldSet").append('<input type="checkbox" name= "cb-'+i+'" id="cb-' + i +'" number = "'+numArr[i].name+'"/> <label for= "cb-'+i+'">' + "Name : " + numArr[i].name + ' <br>' + "Email : " + numArr[i].email +' <br>' + " Number " + numArr[i].number +' <br>' + numArr[i].image + ' <br><br> </label>' );
alert("List Created !");
}
alert("Out of For loop !");
$("#content").trigger("create");
alert("Content Created !");
$("#showBtn").css("visibility","visible");
}
function showSelectedNames(){
var count = $("#cbFieldSet input:checked").length;
var str = '';
for(i=0;i<count;i++){
str += ' '+$("#cbFieldSet input:checked")[i].value;
}
alert("You selected----"+str);
}
</script>
How the view I am getting is :
i do not know about this particular program,
but i do know that you are passing the image location as an argument, (text).
the other arguments are also text, and you have no done anything differently with the image argument to have the UI display an image. maybe you are missing image tags, or an "getImage(location)" type function.
edit:
<img src="PATH" />
you need to put PATH as image location and this is what will display it.

Fancybox title / caption

I'm very new to website design and can't write js scripts as yet. My CSS is fairly basic. I'm using FB 1.3.4 and it all works fine but I want to change the format of the image title / caption.
I currently have this format:
"Image 1 of 10 This is the caption for this image. [Photo: a Smith]"
What I want is this:
"This is the caption for this image. [Photo: A Smith]
Image 1 of 10"
Note that the Image 1 of 10 is on a new line. I would also like extra spaces between the end of the image caption and the [Photo: A Smith] although I can't work out how to show it here
My script is:
<script type="text/javascript">
$(document).ready(function() {
$(".fancybox").fancybox({
'transitionIn' : 'none',
'transitionOut' : 'none',
'overlayColor' : '#000000',
'overlayOpacity' : '0.90',
'titlePosition' : 'over',
'titleFormat' : function(title, currentArray, currentIndex, currentOpts) {
return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' of ' + currentArray.length + (title.length ? ' ' + title : '') + '</span>';
}
});
});
</script>
My CSS for fancybox-title-over is:
.fancybox-title-over {
position: absolute;
bottom: 0;
left: 0;
color: #FFF;
text-align: left;
}
I know that I need to alter titlePosition to 'inside' but can't get beyond that! Can anyone help me with this? Many thanks.
For your titleFormat, replace this line:
'titleFormat' : function(title, currentArray, currentIndex, currentOpts) {
return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' of ' + currentArray.length + (title.length ? ' ' + title : '') + '</span>';
}
with this:
'titleFormat' : function(title, currentArray, currentIndex, currentOpts) {
return '<span>'+title+'<br />Image ' + (currentIndex + 1) + ' of ' + currentArray.length + (title.length ? ' ' : '') + '</span>';
}
For the extra spaces you want, you may use the character code (one for each extra space you need) inside your title attribute like
title="This is the caption for this image. [Photo: a Smith]"
Also, change the titlePosition to inside like
'titlePosition' : 'inside'
and last: I wouldn't advice you set the title with position: absolute. You may change the text-align to the left with an inline CSS declaration (after you loaded the fancybox CSS file) though with:
.fancybox-title-inside {
text-align: left;
}

Plupload conflict with moxiemanager (tinymce)

I have a problem with the work of plupload namely:
I have tinyMCE embedded on one page with the MoxieMannager plugin and I have Plupload on the same page (for uploading files).
So Plupload works, but if you activate Moxiemanager (on page), then everything stops working right away? How to bypass this restriction?
code sample:
<script type="text/javascript" src="./plupload/plupload.full.min.js"></script>
<script src="tinymce/tinymce.min.js"></script>
<script>tinymce.init({
selector:'<?php print $MCE3; ?>',
toolbar: "<?php print $MCE2; ?>",
language: 'ru',
plugins: '<?php print $MCE; ?>',
relative_urls : true,
document_base_url : "<?php print $url; ?>"
});</script>
<a data-action='uploadFile' class="ipsButton ipsButton_small ipsButton_primary ipsPos_left" id="pickfiles" href="javascript:;">Выбрать файл...1</a>
<a data-action='uploadFile' class="ipsButton ipsButton_small ipsButton_primary ipsPos_left" id="uploadfiles" href="javascript:;">Загрузить на сервер</a>
<ul id="filelist"></ul>
<pre id="console"></pre>
<script type="text/javascript">
// Custom example logic
var uploader3 = new plupload.Uploader({
runtimes : 'html5,flash,silverlight,html4',
browse_button : 'pickfiles', // you can pass in id...
container: document.getElementById('container'),
url : "./plupload/examples/q1.php?pgid=<?php print $pgid; ?>",
filters : {
pgid: <?php print $pgid; ?>,
max_file_size : '10mb',
mime_types: [
{title : "Image files", extensions : "jpg,gif,png"},
{title : "Zip files", extensions : "zip"}
]
},
// Flash settings
flash_swf_url : '/plupload/Moxie.swf',
// Silverlight settings
silverlight_xap_url : '/plupload/Moxie.xap',
init: {
PostInit: function() {
document.getElementById('filelist').innerHTML = '';
document.getElementById('uploadfiles').onclick = function() {
uploader3.start();
return false;
};
},
FilesAdded: function(up, files) {
plupload.each(files, function(file) {
document.getElementById('filelist').innerHTML += '<div id="' + file.id + '">' + file.name + ' (' + plupload.formatSize(file.size) + ') <b></b></div>';
});
},
UploadProgress: function(up, file) {
document.getElementById(file.id).getElementsByTagName('b')[0].innerHTML = '<span>' + file.percent + "%</span>";
},
Error: function(up, err) {
document.getElementById('console').innerHTML += "\nError #" + err.code + ": " + err.message;
}
}
});
uploader3.init();
</script>
Please help solve the problem