[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

how to call ajax code from an external js file

Posted on 2014-07-14
2
Medium Priority
?
1,184 Views
Last Modified: 2014-07-14
I use this code to create jquery dialog and CKEditor instance

 <input class="boton_fancybox" onclick="createEditor(this);" id="boton_texto" type="button" style="text-decoration:none;" value="Editar el contenido de este campo">

<textarea rows="5" class="campo" cols="90" id="texto" name="texto" style="display:none;"></textarea>

<script type="text/javascript" src="../../contenidos/ckeditor5/ckeditor.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.0/jquery-ui.min.js"></script>
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.0/themes/smoothness/jquery-ui.css" />    
            
<script type="text/javascript">
var editor, html = '';
var config = {};

function createEditor(campo)
{
 var temp = campo.id.split("_");

       if ( editor )
                return;

        $("#div_"+temp[1]).bind('dialogopen', function() //JQ
        {
                editor = CKEDITOR.replace( temp[1],
					{
						height:"600", width:"780",
						toolbar: [
	{ name: 'document', groups: [ 'mode', 'document', 'doctools' ], items: [ 'Source' ] },
	{ name: 'clipboard', groups: [ 'clipboard', 'undo' ], items: [ 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo' ] },
	'/',
	{ name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ], items: [ 'Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat' ] },
	{ name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align', 'bidi' ], items: [ 'NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote' ] },
	{ name: 'links', items: [ 'Link', 'Unlink', 'Anchor' ] },
	{ name: 'insert', items: [ 'HorizontalRule', 'SpecialChar', 'Iframe' ] },
	{ name: 'tools', items: [ 'Maximize' ] },
	 { name: 'colors', items: ['TextColor', 'BGColor'] }


	],
		enterMode : CKEDITOR.ENTER_BR,
						shiftEnterMode: CKEDITOR.ENTER_P
					});
        }).bind('dialogclose', function()
        {
                removeEditor();//CK
                $(this).dialog('destroy');
        })
        .dialog({autoOpen: false,
                maxHeight:0.95 * $(window).height(),//1
                width: 800,
                modal: false,
                position: 'top',
                resizable: false,
                autoResize: true }).dialog('open');
}

function removeEditor()
{
        if ( !editor )
                return;

        editor.destroy();
        editor = null;
}
</script>

Open in new window


I tried to use createeditor() and removeeditor() in an external js file to use them in other file but they doesnt works.

I there way to use my code in an external js file????
0
Comment
Question by:altariamx2003
2 Comments
 
LVL 30

Accepted Solution

by:
Alexandre Simões earned 2000 total points
ID: 40194469
Of course there is, just make sure you reference your js file AFTER the ckeditor.js reference.

Also make sure the DOM is ready...
The easiest way is to declare your script last thing before the end of the </body>

This way you're sure all dependencies are loaded and the DOM is ready.
Also like this you don't need to use jquery DOM ready function.
0
 

Author Comment

by:altariamx2003
ID: 40195046
So easy!!!!!!!

Mr. Simoes you are a genius!!!!!!!!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses
Course of the Month19 days, 13 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question