src/cm/templates/site/macros/text_editor.html
author gibus
Wed, 25 Apr 2012 09:25:39 +0200
changeset 414 ef8b166a0993
parent 257 7b7ba5e47268
child 549 eb0d56ec0d90
permissions -rw-r--r--
Adds image button in rich text editor for HTML.

{% load i18n %}
<script type="text/javascript" src="{{ CM_MEDIA_PREFIX }}js/lib/markitup/1.1.5/markitup/jquery.markitup.js"></script>
<script type="text/javascript" src="{{ CM_MEDIA_PREFIX }}js/markitup/sets.js"></script>

<script type="text/javascript" src="{{ CM_MEDIA_PREFIX }}js/ckeditor/ckeditor.js"></script>

<link rel="stylesheet" type="text/css" href="{{ CM_MEDIA_PREFIX }}js/lib/markitup/1.1.5/markitup/skins/markitup/style.css" />
<link rel="stylesheet" type="text/css" href="{{ CM_MEDIA_PREFIX }}css/markitup/style.css" />
<link rel="stylesheet" type="text/css" href="{{ CM_MEDIA_PREFIX }}css/markitup/editor.css" />


<script type="text/javascript" >

/* yes 2 different variables */
    myHTMLSettings.previewTemplatePath = "{% url text-wysiwyg-preview "html" %}";
    myMarkdownSettings.previewParserPath = "{% url text-wysiwyg-preview "markdown" %}";
    
    onMarkitupActions = function() {needToConfirm = true ;} ;
    
    myHTMLSettings.afterInsert = onMarkitupActions ;
    myMarkdownSettings.afterInsert = onMarkitupActions ;
    
    $(document).ready(function() {
	    adaptMarkitup = function() {
	        $('#id_content').markItUpRemove();
	        var o=CKEDITOR.instances['id_content'];
	        if (o) o.destroy()
	        var newSet = $('#id_format').val();
	        switch(newSet) {
	            case 'markdown':
	                $('#id_content').markItUp(myMarkdownSettings);
	                break;
	            case 'html':
	                //$('#id_content').markItUp(myHTMLSettings);
					CKEDITOR.replace( 'id_content',
					    {
							language : '{{ LANGUAGE_CODE }}',
							toolbar : 'CMToolbar',
							toolbar_CMToolbar : [['Source','-','Templates'], //'Save','NewPage','Preview','-',
												 ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print'], //,'SpellChecker','Scayt'
												 ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
												 //['Form','Checkbox','Radio','TextField','Textarea','Select','Button','ImageButton','HiddenField'],
												 '/',
												 ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
												 ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote','CreateDiv'],
												 ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
												 ['ImageButton', '-', 'Link','Unlink','Anchor'],
												 ['Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],'/', //'Image','Flash',
												 ['Styles','Format','Font','FontSize'],
												 ['TextColor','BGColor'],
												 ['Maximize','ShowBlocks','-','About']]							
					    });	                
	                break;
	        }
	        return false;
	    }
    
    adaptMarkitup();
    
    $('#id_format').change(function() {adaptMarkitup();}) ;
   });
   
    needToConfirm = false ;
    function confirmExit() {
        if (needToConfirm)
            return "{% blocktrans %}You have attempted to leave this page. Unsaved changes will be lost. Are you sure you want to exit this page?{% endblocktrans %}";
    } ;

    $(document).ready(function() {
        $("input[type='text']").add("textarea").change(function() {needToConfirm = true ;}) ;
        window.onbeforeunload = confirmExit;
	}) ;
</script>