<script type="text/javascript" src="/libraries/ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="/libraries/ckeditor/adapters/jquery.js"></script>
<script class="footer" type="text/javascript">
  $( function() {
    CKEDITOR.on( 'instanceCreated', function( event ) {
      var editor = event.editor,
      element = editor.element;
      editor.on( 'configLoaded', function () {
        editor.config.extraPlugins = 'showblocks,indent,justify,font,tableresize,find,texttransform,colorbutton,youtube,cmslinkarticle,cmslinkpage,colordialog,googlemaps,ckawesome,'
                + 'jsplus_bootstrap_include,'
                + 'jsplus_bootstrap_block_conf,jsplus_bootstrap_col_move_left,jsplus_bootstrap_col_move_right,jsplus_bootstrap_delete_col,jsplus_bootstrap_delete_row,'
                + 'jsplus_bootstrap_row_move_down,jsplus_bootstrap_row_move_up,jsplus_bootstrap_show_blocks,'
                + 'jsplus_bootstrap_templates,jsplus_bootstrap_table_new,jsplus_bootstrap_button,jsplus_bootstrap_icons,jsplus_bootstrap_badge,jsplus_bootstrap_label,'
                + 'jsplus_bootstrap_breadcrumbs,jsplus_bootstrap_alert,'
                + 'jsplus_bootstrap_table_conf,jsplus_bootstrap_table_row_conf,jsplus_bootstrap_table_col_conf,jsplus_bootstrap_table_cell_conf,jsplus_bootstrap_table_row_move_up,'
                + 'jsplus_bootstrap_table_row_move_down,jsplus_bootstrap_table_col_move_left,jsplus_bootstrap_table_col_move_right,jsplus_bootstrap_table_add_row_up,jsplus_bootstrap_table_add_row_down,'
                + 'jsplus_bootstrap_table_add_col_left,jsplus_bootstrap_table_add_col_right,jsplus_bootstrap_table_add_cell_left,jsplus_bootstrap_table_add_cell_right,jsplus_bootstrap_table_delete_col,'
                + 'jsplus_bootstrap_table_delete_row,jsplus_bootstrap_table_delete_cell,jsplus_bootstrap_table_merge_cells,jsplus_bootstrap_table_merge_cell_right,jsplus_bootstrap_table_merge_cell_down,'
                + 'jsplus_bootstrap_table_split_cell_hor,jsplus_bootstrap_table_split_cell_vert,bootstrapCollapse,bootstrapTab,ckawesome,copyformatting,codemirror,html5video,widget,widgetselection,clipboard,lineutils';
        editor.config.autoParagraph = false;
        editor.config.toolbar = [
                ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord'],
                ['Undo', 'Redo', '-', 'Find', 'Replace', '-', 'SelectAll', 'RemoveFormat'],
                ['Bold', 'Italic', 'Underline', 'Strike', '-', 'Subscript', 'Superscript','CopyFormatting'],
                ['NumberedList', 'BulletedList', 'Indent', 'Outdent', 'CreateDiv'],
                ['TextColor', 'BGColor'],
                ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'],
                ['Link', 'Unlink', 'cmslinkarticle', 'cmslinkpage'],
                ['ckawesome', 'Image', 'Flash', 'Table', 'HorizontalRule', 'SpecialChar', 'Youtube'],
                ['Styles', 'Format', 'Font', 'FontSize', 'ShowBlocks', 'Source', 'Maximize'],
                [
                    'jsplus_bootstrap_show_blocks', 'jsplus_bootstrap_templates', 'jsplus_bootstrap_block_conf', 'jsplus_bootstrap_col_move_left', 'jsplus_bootstrap_col_move_right', 'jsplus_bootstrap_delete_col',
                    'jsplus_bootstrap_delete_row', 'jsplus_bootstrap_row_move_down', 'jsplus_bootstrap_row_move_up'
                ],
                ['BootstrapCollapse', 'BootstrapTab'],
                [
                    'jsplus_bootstrap_alert', 'jsplus_bootstrap_icons', 'jsplus_bootstrap_button', 'jsplus_bootstrap_badge', 'jsplus_bootstrap_label'
                ],
                [
                    'jsplus_bootstrap_table_new', 'jsplus_bootstrap_table_conf', 'jsplus_bootstrap_table_row_conf', 'jsplus_bootstrap_table_col_conf', 'jsplus_bootstrap_table_cell_conf', 'jsplus_bootstrap_table_row_move_up',
                    'jsplus_bootstrap_table_row_move_down', 'jsplus_bootstrap_table_col_move_left', 'jsplus_bootstrap_table_col_move_right', 'jsplus_bootstrap_table_add_row_up', 'jsplus_bootstrap_table_add_row_down',
                    'jsplus_bootstrap_table_add_col_left', 'jsplus_bootstrap_table_add_col_right', 'jsplus_bootstrap_table_add_cell_left', 'jsplus_bootstrap_table_add_cell_right', 'jsplus_bootstrap_table_delete_col',
                    'jsplus_bootstrap_table_delete_row', 'jsplus_bootstrap_table_delete_cell', 'jsplus_bootstrap_table_merge_cells', 'jsplus_bootstrap_table_merge_cell_right', 'jsplus_bootstrap_table_merge_cell_down',
                    'jsplus_bootstrap_table_split_cell_hor', 'jsplus_bootstrap_table_split_cell_vert'
                ],
                ['jsplus_bootstrap_advanced_blocks']
            ];
        editor.config.jsplus_bootstrap_show_blocks_enabled_by_default = false;
        editor.on( 'blur', function( evt ) {

          console.log(editor.getData());
          console.log(editor.name);

          $.ajax(
          {
            type: 'POST',
            cache: false,
            url: '/ajax.php',
            data:
            {
              a: 'inline-edit-save',
              element_id: editor.name,
              element_value: editor.getData(),
              layout_id: <?= \S::get_session( 'layout_id' );?>,
              lang_id: '<? global $lang_id; echo $lang_id;?>',
              alltemplates: $( '#' + editor.name ).attr( 'alltemplates' )
            },
            beforeSend: function()
            {

            },
            success: function( response )
            {
              //data = jQuery.parseJSON( response );
            }
          });

        });
      });
    });
  });
</script>
