Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 8595 | Rev 10441 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |

<?php 
$acl            = $this->viewModel()->getRoot()->getVariable('acl');
$currentUser    = $this->currentUserHelper();

$roleName = $currentUser->getUserTypeId();


$routeAdd       = $this->url('microlearning/content/topics/add');
$routeDatatable = $this->url('microlearning/content/topics');

$allowAdd               = $acl->isAllowed($roleName, 'microlearning/content/topics/add') ? 1 : 0;
$allowEdit              = $acl->isAllowed($roleName, 'microlearning/content/topics/edit') ? 1 : 0;
$allowDelete            = $acl->isAllowed($roleName, 'microlearning/content/topics/delete') ? 1 : 0;


$this->headLink()->appendStylesheet($this->basePath('plugins/nprogress/nprogress.css'));
$this->inlineScript()->appendFile($this->basePath('plugins/nprogress/nprogress.js'));

$this->inlineScript()->appendFile($this->basePath('plugins/ckeditor/ckeditor.js'));


$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap-fileinput/css/fileinput.min.css'));
$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap-fileinput/themes/explorer-fas/theme.css'));

$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-fileinput/js/plugins/piexif.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-fileinput/js/plugins/sortable.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-fileinput/js/fileinput.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-fileinput/js/locales/es.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-fileinput/themes/fas/theme.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-fileinput/themes/explorer-fas/theme.js'));


$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/jquery.validate.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/additional-methods.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/localization/messages_es.js'));

$this->headLink()->appendStylesheet($this->basePath('plugins/datatables-bs4/css/dataTables.bootstrap4.min.css'));
$this->headLink()->appendStylesheet($this->basePath('plugins/datatables-responsive/css/responsive.bootstrap4.min.css'));
$this->headLink()->appendStylesheet($this->basePath('plugins/nelberth-editor/style.css'));
$this->inlineScript()->appendFile($this->basePath('plugins/datatables/jquery.dataTables.min.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-bs4/js/dataTables.bootstrap4.min.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-responsive/js/dataTables.responsive.min.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-responsive/js/responsive.bootstrap4.min.js'));


$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap4-toggle/css/bootstrap4-toggle.min.css'));
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap4-toggle/js/bootstrap4-toggle.min.js'));

$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-confirmation/dist/bootstrap-confirmation.js'));
$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap-checkbox/awesome-bootstrap-checkbox.css'));


$this->inlineScript()->appendFile($this->basePath('plugins/jquery-input-number/input-number-format.jquery.js'));


$status_active = \LeadersLinked\Model\Degree::STATUS_ACTIVE;




$this->inlineScript()->captureStart();
echo <<<JS
    jQuery( document ).ready(function( $ ) {

        $.validator.setDefaults({
            debug: true,
            highlight: function(element) {
                $(element).addClass('is-invalid');
            },
            unhighlight: function(element) {
                $(element).removeClass('is-invalid');
            },
            errorElement: 'span',
            errorClass: 'error invalid-feedback',
            errorPlacement: function(error, element) {
                if(element.parent('.btn-file').length) {
                    error.insertAfter(element.parent().parent());
                } else if(element.parent('.toggle').length) {
                    error.insertAfter(element.parent().parent());
                } else {
                    error.insertAfter(element.parent());
                }
            }
        });
    
    
        $.fn.showFormErrorValidator = function(fieldname, errors) {
            var field = $(fieldname);
            if(field) {
                $(field).addClass('is-invalid');
    

                var error = $('<span id="' + fieldname +'-error" class="error invalid-feedback">' + errors + '</div>');
              /*  if(element.parent('.btn-file').length) {
                    error.insertAfter(element.parent().parent());
                } else if(element.parent('.toggle').length) {
                    error.insertAfter(element.parent().parent());
                } else {
                    error.insertAfter(element.parent());
                }*/
            }
        };




        var allowEdit   = $allowEdit;
        var allowDelete = $allowDelete;
        
        var gridTable = $('#gridTable').dataTable( {
            'processing': true,
            'serverSide': true,
            'searching': true,
            'order': [[ 0, 'asc' ]],
            'ordering':  true,
            'ordenable' : true,
            'responsive': true,
            'select' : false,
                'paging': true,
            'pagingType': 'simple_numbers',
                'ajax': {
                        'url' : '$routeDatatable',
                        'type' : 'get',
                'beforeSend': function (request) {
                  NProgress.start();
                },
                'dataFilter': function(response) {
                    var response = jQuery.parseJSON( response );
                    
                    var json                = {};
                    json.recordsTotal       = 0;
                    json.recordsFiltered    = 0;
                    json.data               = [];
                    
                    
                    if(response.success) {
                        json.recordsTotal       = response.data.total;
                        json.recordsFiltered    = response.data.total;
                        json.data               = response.data.items;
                    } else {
                        $.fn.showError(response.data)
                    }
                    
                    return JSON.stringify( json );
                }
                },
            'language' : {
                'sProcessing':     'LABEL_DATATABLE_SPROCESSING',
                'sLengthMenu':     'LABEL_DATATABLE_SLENGTHMENU',
                'sZeroRecords':    'LABEL_DATATABLE_SZERORECORDS',
                'sEmptyTable':     'LABEL_DATATABLE_SEMPTYTABLE',
                'sInfo':           'LABEL_DATATABLE_SINFO',
                'sInfoEmpty':      'LABEL_DATATABLE_SINFOEMPTY',
                'sInfoFiltered':   'LABEL_DATATABLE_SINFOFILTERED',
                'sInfoPostFix':    '',
                'sSearch':         'LABEL_DATATABLE_SSEARCH',
                'sUrl':            '',
                'sInfoThousands':  ',',
                'sLoadingRecords': 'LABEL_DATATABLE_SLOADINGRECORDS',
                'oPaginate': {
                    'sFirst':    'LABEL_DATATABLE_SFIRST',
                    'sLast':     'LABEL_DATATABLE_SLAST',
                    'sNext':     'LABEL_DATATABLE_SNEXT',
                    'sPrevious': 'LABEL_DATATABLE_SPREVIOUS'
                },
                'oAria': {
                    'sSortAscending':  ': LABEL_DATATABLE_SSORTASCENDING',
                    'sSortDescending': ':LABEL_DATATABLE_SSORTDESCENDING'
                },
            },
            'drawCallback': function( settings ) {
                NProgress.done();
                $('button.btn-delete').confirmation({
                    rootSelector: 'button.btn-delete',
                    title : 'LABEL_ARE_YOU_SURE',
                    singleton : true,
                    btnOkLabel: 'LABEL_YES',
                    btnCancelLabel: 'LABEL_NO',
                    onConfirm: function(value) {
                        action = $(this).data('href');
                        NProgress.start();
                        $.ajax({
                            'dataType'  : 'json',
                            'accept'    : 'application/json',
                            'method'    : 'post',
                            'url'       :  action,
                        }).done(function(response) {
                            if(response['success']) {
                                $.fn.showSuccess(response['data']);
                                gridTable.api().ajax.reload(null, false);
                            } else {
                                $.fn.showError(response['data']);
                            }
                        }).fail(function( jqXHR, textStatus, errorThrown) {
                            $.fn.showError(textStatus);
                        }).always(function() {
                            NProgress.done();
                        });
                    },
                });
            },
            'aoColumns': [
                { 'mDataProp': 'name' },
                { 'mDataProp': 'status' },
                { 'mDataProp': 'image' },
                { 'mDataProp': 'actions' },
            ],
            'columnDefs': [
                {
                    'targets': 0,
                    'className' : 'text-vertical-middle',
                },
                {
                    'targets': -2,
                    'orderable': false,
                    'render' : function ( data, type, row ) {
                        s = '&nbsp;';

                        if( data )  {
                            s = s + '&nbsp;<img class="btn-view-image-app" data-href="' + data + '" data-toggle="tooltip" src="'+data+'" title="LABEL_VIEW" style="width: 40px; object-fit: cover; height: 40px;" /> '
                        }  else {
                            s = s + '&nbsp;LABEL_IMAGE: <br>';    
                        } 


                        return s;
                    }
                },


                {
                    'targets': -1,
                    'orderable': false,
                    'render' : function ( data, type, row ) {
                        s = '';
                        
                        if(allowEdit && data['link_edit']  ) {
                            s = s + '<button class="btn btn-info btn-sm btn-edit" data-href="' + data['link_edit']+ '" data-toggle="tooltip" title="LABEL_EDIT"><i class="fa fa-pencil"></i> LABEL_EDIT </button>&nbsp;';
                        }
                        if(allowDelete && data['link_delete']  ) {
                            s = s + '<button class="btn btn-danger btn-sm btn-delete" data-href="' + data['link_delete']+ '" data-toggle="tooltip" title="LABEL_DELETE"><i class="fa fa-trash"></i> LABEL_DELETE </button>&nbsp;';
                        }
                        return s;
                    }
                }
              ],
        });


    var validatorAdd = $('#form-topic-add').validate({
        debug: true,
        onclick: false,
        onkeyup: false,
        ignore: [],
        rules: {
            'name': {
                required: true,
                maxlength: 128,
            },
            'description': {
                updateCkeditor:function() {
                        CKEDITOR.instances.description_add.updateElement();
                },
                required: true
            },
           'file': {
                required: true,
            },
            'order' : {
                required: true,
                digits: true,
                min: 1,
                max: 250
            },
            'status' : {
                required: true,
            },
        },
        submitHandler: function(form)
        {
            var formdata = false;
            if (window.FormData){
                formdata = new FormData(form); //form[0]);
            }
                

                        $('.info_noticia').prop('disabled', true);
                        NProgress.start();
            $.ajax({
                'dataType'  : 'json',
                'accept'    : 'application/json',
                'method'    : 'post',
                'url'       :  $('#form-topic-add').attr('action'),
                'data'      :  formdata,
                'processData': false,
                'contentType': false,
            }).done(function(response) {
                                console.log(response)
                                if(response['success']) {
                    $.fn.showSuccess(response['data']);
                    $('body, html').animate({scrollTop: '0px'}, 300);
                                        $('#content1').css('display','block');
                        $('#addImage').css('display','none');
                    gridTable.api().ajax.reload(null, false);
                } else {
                    validatorAdd.resetForm();
                    if(jQuery.type(response['data']) == 'string') {
                        $.fn.showError(response['data']);
                    } else  {
                        $.each(response['data'], function( fieldname, errors ) {
                            $.fn.showFormErrorValidator('#form-topic-add #' + fieldname, errors);
                        });
                    }
                }
            }).fail(function( jqXHR, textStatus, errorThrown) {
                                
                                console.log(jqXHR)
                $.fn.showError(textStatus);
            }).always(function() {
                                $('.info_noticia').prop('disabled', false);
                NProgress.done();
            });
            return false;
        },
        invalidHandler: function(form, validator) {
            
        }
    });

    var validatorEdit  = $('#form-topic-edit').validate({
        debug: true,
        onclick: false,
        onkeyup: false,
        ignore: [],
        rules: {
            'name': {
                required: true,
                maxlength: 128,
            },
            'description': {
                updateCkeditor:function() {
                        CKEDITOR.instances.description_edit.updateElement();
                },
                required: true
            },
           'file': {
                required: true,
            },
            'order' : {
                required: true,
                digits: true,
                min: 1,
                max: 250
            },
            'status' : {
                required: true,
            },

        },
        submitHandler: function(form)
        {
            var formdata = false;
            if (window.FormData){
                formdata = new FormData(form); //form[0]);
            }

            $('.info_noticia').prop('disabled', true);
                        NProgress.start();
            $.ajax({
                'dataType'  : 'json',
                'accept'    : 'application/json',
                'method'    : 'post',
                'url'       :  $('#form-topic-edit').attr('action'),
                'data'      :  formdata,
                'processData': false,
                'contentType': false,
            }).done(function(response) {
                if(response['success']) {
                    $.fn.showSuccess(response['data']);
                       
                    $('body, html').animate({scrollTop: '0px'}, 300);
                                        $('#content1').css('display','block');
                        $('#topicEdit').css('display','none');
                    gridTable.api().ajax.reload(null, false);
                } else {
                    validatorAdd.resetForm();
                    if(jQuery.type(response['data']) == 'string') {
                        $.fn.showError(response['data']);
                    } else  {
                        $.each(response['data'], function( fieldname, errors ) {
                            $.fn.showFormErrorValidator('#form-topic-edit #' + fieldname, errors);
                        });
                    }
                }
            }).fail(function( jqXHR, textStatus, errorThrown) {
                $.fn.showError(textStatus);
            }).always(function() {
                                
                                $('.info_noticia').prop('disabled', false);
                NProgress.done();
            });
            return false;
        },
        invalidHandler: function(form, validator) {
            
        }
    });


    
        $('body').on('click', '.btn-view-image-app', function(e) {
            e.preventDefault();
    
            $('#image-app').attr('src', $(this).data('href'));
            $('#modalImageApp').modal('show');
            return false;
        });             

        $('#form-topic-add #order').inputNumberFormat({decimal: 0});
 


        $('body').on('click', 'button.btn-add', function(e) {
            e.preventDefault();
    
            $('#form-topic-add #name').val('');
            $('#form-topic-add #order').val('1');
            $('#form-topic-add #name').val('');
    
            $('#form-topic-add #status').val('');

    
            CKEDITOR.instances.description_add.setData('');
            validatorAdd.resetForm();
            $('#content1').css('display','none');
            $('#addImage').css('display','block');
                        iniciarEditor()
            
            return false;
        });
                $('body').on('click', '#ir_atras', function(e) {
            e.preventDefault();
    
    
                        $('body, html').animate({scrollTop: '0px'}, 300);
            $('#content1').css('display','block');
            $('#addImage').css('display','none');
                        $('#topicEdit').css('display','none');

            
            return false;
        });

    
        $('#form-topic-edit #order').inputNumberFormat({decimal: 0});
    
       /* $('#form-topic-edit #file').fileinput({
            theme: 'fas',
            language: 'es',
            showUpload: false,
            dropZoneEnabled: false,
            maxFileCount: 1,
            allowedFileExtensions: ['jpeg', 'jpg', 'png'],
            msgPlaceholder: 'LABEL_RECOMMENDED_SIZE $image_size',
        });*/

                
        $('body').on('click', 'button.btn-edit', function(e) {
            e.preventDefault();
    
            var url = $(this).data('href');
                        NProgress.start();
            $.ajax({
                'dataType'  : 'json',
                'accept'    : 'application/json',
                'method'    : 'get',
                'url'       :  url,
            }).done(function(response) {
                if(response['success']) {
                                        console.log(response['data'])
                    $('#form-topic-edit')[0].reset();
    
                    $('#form-topic-edit').attr('action',url);
                    $('#form-topic-edit #name').val(response['data']['name']);
                    $('#form-topic-edit #order').val(response['data']['order']);

                                         $('#form-topic-edit #status').val(response['data']['status']);

                    CKEDITOR.instances.description_edit.setData(response['data']['description']);
                    validatorEdit.resetForm();
                                        $('#content1').css('display','none');
                        $('#topicEdit').css('display','block');
                                        iniciarEditor(false,response['data']['image']);
                } else {
                    validatorEdit.resetForm();
                    if(jQuery.type(response['data']) == 'string') {
                        $.fn.showError(response['data']);
                    } else  {
                        $.each(response['data'], function( fieldname, errors ) {
                            $.fn.showFormErrorValidator('#form-topic-edit #' + fieldname, errors);
                        });
                    }
                }
            }).fail(function( jqXHR, textStatus, errorThrown) {
                $.fn.showError(textStatus);
            }).always(function() {
                NProgress.done();
            });
        });

        $('body').on('click', 'button.btn-cancel', function(e) {
            e.preventDefault();
            $('#modalTopicAdd').modal('hide');
            $('#topicEdit').modal('hide');
        });
    
        $('body').on('click', 'button.btn-refresh', function(e) {
            e.preventDefault();
            gridTable.api().ajax.reload(null, false);
        });
        
        CKEDITOR.replace('description_add', {
                        toolbar: [
                    { name: 'editing', items: ['Scayt'] },
                    { name: 'links', items: ['Link', 'Unlink'] },
                    { name: 'paragraph', items: ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', 'Blockquote'] },
                    { name: 'basicstyles', items: ['Bold', 'Italic', 'Strike', 'RemoveFormat'] },
                    '/',
                    { name: 'insert', items: ['Image', 'Table', 'HorizontalRule', 'SpecialChar'] },
                    { name: 'styles', items: ['Styles', 'Format'] },
                    { name: 'tools', items: ['Maximize'] }
                ],
                removePlugins: 'elementspath,Anchor',
                heigth: 100
                });
        CKEDITOR.replace('description_edit', {
                        toolbar: [
                    { name: 'editing', items: ['Scayt'] },
                    { name: 'links', items: ['Link', 'Unlink'] },
                    { name: 'paragraph', items: ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', 'Blockquote'] },
                    { name: 'basicstyles', items: ['Bold', 'Italic', 'Strike', 'RemoveFormat'] },
                    '/',
                    { name: 'insert', items: ['Image', 'Table', 'HorizontalRule', 'SpecialChar'] },
                    { name: 'styles', items: ['Styles', 'Format'] },
                    { name: 'tools', items: ['Maximize'] }
                ],
                removePlugins: 'elementspath,Anchor',
                heigth: 100
                });



                /*Script del editor (Aqui comienza el cielo y la tierra) */
                var imagenServidorNoticia;
                var scroll_altura,viente;
                var nombre_user = $(".perfil_u_nombre").text();
                var primer_nombre = nombre_user.split(" ")[0];
                var nuevoHtmlImagen='<div class="articulo_noticia animated fadeIn"><div class="pasos"><div class="titulo_pasos animated fadeInDown delay-04 fast">LABEL_STEP_1</div><div class="paso_opcion"><div class="responsing_cut"><div class="icon_cut"><span class="fa fa-scissors"></span></div><div class="contenido_cut"><div class="animated fadeInRight delay-04 fast"><div><div class="titulo_cut"><div>LABEL_CUT</div><div class="fa fa-times" id="cerrar_cut_modal"></div></div><div class="opcion_editor recortar10"><div>LABEL_CUT</div><div id="blockCelda"><span class="fa fa-lock"></span></div></div></div></div></div></div><div class="responsing_text"><div class="icon_text"><span class="fa fa-text-width"></span></div><div class="contenido_text"><div class="animated fadeInRight delay-04 fast"><div class="texto"><div class="titulo_text"><div>LABEL_ADD_TEXT</div><div class="fa fa-times" id="cerrar_text_modal"></div></div><input id="texto_input" type="text" name="texto" placeholder="LABEL_ADD_TEXT_HERE"><div class="fonts"><div class="font" id="negritas" data-tooltip="Negritas"><i class="fa fa-bold" aria-hidden="true"></i></div><div class="font" id="italic" data-tooltip="Letra Cursiva"><i class="fa fa-italic" aria-hidden="true"></i></div><input type="color" class="" data-tooltip="Color de la letra" name="" id="color" value="#ffffff"> <input type="number" class="" data-tooltip="Tamaño de la letra" name="" id="font-size" max="500" min="1" step="1" value="48"></div><div class="fonts"><div class="font fa" data-tooltip="Sombra de la letra" id="shadow">A</div><div class="font" id="rectangulo" data-tooltip="Fondo de la letra"><div class="rectangulo">C</div></div><input type="color" name="" id="colorrect" value="#000000" class="" data-tooltip="Color del fondo"> <input type="number" name="" id="opacidad" max="100" min="1" step="1" value="100" class="" data-tooltip="Transparensia del fondo"></div><div class="fonts_style"><div class="fs at" id="arial">LABEL_FONT_ARIAL</div><div class="fs" id="calibri">LABEL_FONT_CALIBRI</div><div class="fs" id="forte">LABEL_FONT_FORTE</div><div class="fs" id="impact">LABEL_FONT_IMPACT</div><div class="fs" id="jokerman">LABEL_FONT_JOKERMAN</div><div class="fs" id="mb">LABEL_FONT_MV_BOLI</div><div class="fs" id="tnr">LABEL_FONT_TIMES_NEW_ROMAN</div><div class="fs" id="verdana">LABEL_FONT_VERDANA</div><div class="fs" id="vivaldi">LABEL_FONT_VIVALDI</div></div></div></div></div></div><div class="responsing_filtros"><div class="icon_filter"><span class="fa fa-eyedropper"></span></div><div class="contenido_filter"><div class="titulo_filtro"><div>LABEL_FILTERS</div><div class="fa fa-times" id="cerrar_filter_modal"></div></div><div class="opciones_imagen"><div class="opcion_editor oa" id="normal">LABEL_FILTER_NORMAL</div><div class="opcion_editor" id="noche">LABEL_FILTER_NIGHT</div><div class="opcion_editor" id="sa">LABEL_FILTER_SAINT_ANA</div><div class="opcion_editor" id="crema">LABEL_FILTER_CREAM</div><div class="opcion_editor" id="magia">LABEL_FILTER_MAGIC</div><div class="opcion_editor" id="relieve">LABEL_FILTER_RELIEF</div><div class="opcion_editor" id="luz">LABEL_FILTER_LIGHT</div><div class="opcion_editor" id="saturacion">LABEL_FILTER_SATURATION</div><div class="opcion_editor" id="retoque">LABEL_FILTER_RETOUCH</div><div class="opcion_editor" id="orange">LABEL_FILTER_ORANGE</div><div class="opcion_editor" id="setenta">LABEL_FILTER_WIND</div><div class="opcion_editor" id="desierto">LABEL_FILTER_DESERT</div><div class="opcion_editor" id="bosque">LABEL_FILTER_FOREST</div><div class="opcion_editor" id="villa">LABEL_FILTER_TOWN</div><div class="opcion_editor" id="rosa">LABEL_FILTER_PINK</div><div class="opcion_editor" id="historia">LABEL_FILTER_HISTORY</div><div class="opcion_editor" id="gris">LABEL_FILTER_GRAY</div><div class="opcion_editor" id="lhs">LABEL_FILTER_OLD_PICTURE</div><div class="opcion_editor" id="encantador">LABEL_FILTER_CHARMING</div><div class="opcion_editor" id="emocion">LABEL_FILTER_EMOTION</div><div class="opcion_editor" id="beige">LABEL_FILTER_BEIGE</div><div class="opcion_editor" id="fine">LABEL_FILTER_FINE</div><div class="opcion_editor" id="lord">LABEL_FILTER_LORD</div><div class="opcion_editor" id="70">LABEL_FILTER_70S</div><div class="opcion_editor" id="arbol">LABEL_FILTER_TREE</div><div class="opcion_editor" id="verano">LABEL_FILTER_SUMMER</div><div class="opcion_editor" id="cf">LABEL_FILTER_COLD_WEATHER</div><div class="opcion_editor" id="angeles">LABEL_FILTER_ANGELS</div><div class="opcion_editor" id="caliente">LABEL_FILTER_HOT</div><div class="opcion_editor" id="otono">LABEL_FILTER_FALL</div><div class="opcion_editor" id="marzo">LABEL_FILTER_MARCH</div><div class="opcion_editor" id="pera">LABEL_FILTER_PEAR</div><div class="opcion_editor" id="comun">LABEL_FILTER_COMMON</div><div class="opcion_editor" id="oro">LABEL_FILTER_GOLD</div><div class="opcion_editor" id="gotico">LABEL_FILTER_GOTHIC</div><div class="opcion_editor" id="forestal">LABEL_FILTER_FORESTRY</div><div class="opcion_editor" id="luna">LABEL_FILTER_MOON</div><div class="opcion_editor" id="fiesta">LABEL_FILTER_PARTY</div></div></div></div><div class="volver"><span class="icon-undo"></span>LABEL_START_OVER</div><div class="paso_1 paso animated bounceInDown delay-04 fast">1</div><div class="paso_2 a1 animated bounceInDown delay-06 fast">2</div><div class="paso_2 b1 animated bounceInDown delay-08 fast">3</div></div></div><div class="editor_imagenes"><div class="fondo_oscuro"></div><div class="editor_imagenes2"><div class="filtros animated fadeInLeft delay-04 fast"><div class="titulo_filtro"><span class="icon-eyedropper fa fa-eyedropper"></span>LABEL_FILTERS</div><div class="opciones_imagen"><div class="opcion_editor oa" id="normal">LABEL_FILTER_NORMAL</div><div class="opcion_editor" id="noche">LABEL_FILTER_NIGHT</div><div class="opcion_editor" id="sa">LABEL_FILTER_SAINT_ANA</div><div class="opcion_editor" id="crema">LABEL_FILTER_CREAM</div><div class="opcion_editor" id="magia">LABEL_FILTER_MAGIC</div><div class="opcion_editor" id="relieve">LABEL_FILTER_RELIEF</div><div class="opcion_editor" id="luz">LABEL_FILTER_LIGHT</div><div class="opcion_editor" id="saturacion">LABEL_FILTER_SATURATION</div><div class="opcion_editor" id="retoque">LABEL_FILTER_RETOUCH</div><div class="opcion_editor" id="orange">LABEL_FILTER_ORANGE</div><div class="opcion_editor" id="setenta">LABEL_FILTER_WIND</div><div class="opcion_editor" id="desierto">LABEL_FILTER_DESERT</div><div class="opcion_editor" id="bosque">LABEL_FILTER_FOREST</div><div class="opcion_editor" id="villa">LABEL_FILTER_TOWN</div><div class="opcion_editor" id="rosa">LABEL_FILTER_PINK</div><div class="opcion_editor" id="historia">LABEL_FILTER_HISTORY</div><div class="opcion_editor" id="gris">LABEL_FILTER_GRAY</div><div class="opcion_editor" id="lhs">LABEL_FILTER_OLD_PICTURE</div><div class="opcion_editor" id="encantador">LABEL_FILTER_CHARMING</div><div class="opcion_editor" id="emocion">LABEL_FILTER_EMOTION</div><div class="opcion_editor" id="beige">LABEL_FILTER_BEIGE</div><div class="opcion_editor" id="fine">LABEL_FILTER_FINE</div><div class="opcion_editor" id="lord">LABEL_FILTER_LORD</div><div class="opcion_editor" id="70">LABEL_FILTER_70S</div><div class="opcion_editor" id="arbol">LABEL_FILTER_TREE</div><div class="opcion_editor" id="verano">LABEL_FILTER_SUMMER</div><div class="opcion_editor" id="cf">LABEL_FILTER_COLD_WEATHER</div><div class="opcion_editor" id="angeles">LABEL_FILTER_ANGELS</div><div class="opcion_editor" id="caliente">LABEL_FILTER_HOT</div><div class="opcion_editor" id="otono">LABEL_FILTER_FALL</div><div class="opcion_editor" id="marzo">LABEL_FILTER_MARCH</div><div class="opcion_editor" id="pera">LABEL_FILTER_PEAR</div><div class="opcion_editor" id="comun">LABEL_FILTER_COMMON</div><div class="opcion_editor" id="oro">LABEL_FILTER_GOLD</div><div class="opcion_editor" id="gotico">LABEL_FILTER_GOTHIC</div><div class="opcion_editor" id="forestal">LABEL_FILTER_FORESTRY</div><div class="opcion_editor" id="luna">LABEL_FILTER_MOON</div><div class="opcion_editor" id="fiesta">LABEL_FILTER_PARTY</div></div></div><div class="canvas_imagen"><div class="canvas recortar"><div class="canvas_subir" id="imagen_noticia">LABEL_DRAG_IMAGE_HERE</div></div></div><div class="modificar animated fadeInRight delay-04 fast"><div><div class="titulo_recortar"><span class="icon-ungroup fa fa-scissors"></span>LABEL_CUT</div><div class="opcion_editor recortar10"><div>LABEL_CUT</div><div id="blockCelda"><span class="fa fa-lock"></span></div></div></div><div class="texto"><div class="titulo_texto"><span class="icon-plus fa fa-text-width"></span>LABEL_ADD_TEXT</div><input id="texto_input" type="text" name="texto" placeholder="LABEL_ADD_TEXT_HERE"><div class="fonts"><div class="font" id="negritas" data-tooltip="Negritas"><i class="fa fa-bold" aria-hidden="true"></i></div><div class="font" id="italic" data-tooltip="Letra Cursiva"><i class="fa fa-italic" aria-hidden="true"></i></div><input type="color" class="" data-tooltip="Color de la letra" name="" id="color" value="#ffffff"> <input type="number" class="" data-tooltip="Tamaño de la letra" name="" id="font-size" max="500" min="1" step="1" value="48"></div><div class="fonts"><div class="font fa" data-tooltip="Sombra de la letra" id="shadow">A</div><div class="font" id="rectangulo" data-tooltip="Fondo de la letra"><div class="rectangulo">C</div></div><input type="color" name="" id="colorrect" value="#000000" class="" data-tooltip="Color del fondo"> <input type="number" name="" id="opacidad" max="100" min="1" step="1" value="100" class="" data-tooltip="Transparensia del fondo"></div><div class="fonts_style"><div class="fs at" id="arial">LABEL_FONT_ARIAL</div><div class="fs" id="calibri">LABEL_FONT_CALIBRI</div><div class="fs" id="forte">LABEL_FONT_FORTE</div><div class="fs" id="impact">LABEL_FONT_IMPACT</div><div class="fs" id="jokerman">LABEL_FONT_JOKERMAN</div><div class="fs" id="mb">LABEL_FONT_MV_BOLI</div><div class="fs" id="tnr">LABEL_FONT_TIMES_NEW_ROMAN</div><div class="fs" id="verdana">LABEL_FONT_VERDANA</div><div class="fs" id="vivaldi">LABEL_FONT_VIVALDI</div></div></div></div></div><div class="botones_dimenciones"><div class="scale"><div class="dimenciones"><div id="ancho">1240px</div><div>x</div><div id="alto">720px</div></div><div class="porciento"><div id="menos_scale"><span class="icon-minus fa fa-minus"></span></div><div class="ps"><ul class="cantidades_scale"><li data-scale="2" class="as">200%</li><li data-scale="1" class="as">100%</li><li data-scale="0.75" class="as">75%</li><li data-scale="0.5" class="as">50%</li><li data-scale="0.25" class="as">25%</li></ul><div id="porciento_scale">50%</div></div><div id="mas_scale"><span class="icon-plus fa fa-plus"></span></div></div></div><div class="botones"><button class="boton_normal" id="ir_atras">LABEL_GO_BACK</button><button class="boton_normal" id="boton_recortar">LABEL_DATATABLE_SNEXT</button></div></div></div></div><dav class="fixed_noticia"></dav><dav class="cuadro_noticias animated bounceInUp delay-04" id="cuadro_noticias"><dav class="relative"><div class="titulo_topico">LABEL_TITLE_TOPIC</div><canvas class="imagen_noticias" id="imagen_noticias" width="320" height="480"></canvas></dav><div class="progreso d-flex align-items-center justify-content-between"><progress value="0" max="100"></progress><span class="ml-2">0.0%</span></div></dav>'       
                
                $(document).on("click", ".info_noticia", function(e){
                        imagenServidorNoticia = elemento.toDataURL("image/jpeg", 1.0);
                        console.log(imagenServidorNoticia.split(','))
                        $('.file').val(imagenServidorNoticia.split(',')[1]);
                        console.log($('.file').val())
                        $(".c1").addClass("paso");

                
                })
                var edit;
                function iniciarEditor(add=true, image=''){
                 cortar=false;
                recorte_listo=false;
                texto="";
                seis=true;
                color="#ffffff";
                texto_listo=false,siete=false;
                uno=true;
                size=48;
                blockCelda=true;
                cinco=true;
                xf=320,yf =480;
                negritas=false, bold="";
                shadow = true, nueve=true;
                italic=false, ita="";
                rectangulo=false, diez=false;
        fontfamily="Arial";
        r=0,g=0,b=0,a=1;
                 edit=add;
                console.log(edit)
                window.clearInterval(editorNoticia);    
                setTimeout(function(){
                        scroll_altura=$(".articulo_noticia").offset().top-110;
                        anchoFondoOscuro = $(".articulo_noticia").width();
                        altoFondoOscuro = $(".editor_imagenes").height();
                        $(".fondo_oscuro").css("width",""+anchoFondoOscuro+"px");
                        $(".fondo_oscuro").css("height",""+altoFondoOscuro+"px");
                
                },navegacion(nuevoHtmlImagen,edit,image));

                }

                $(document).on("click", ".volver", function(){
                var nombre_user = $(".perfil_u_nombre").text();
                var primer_nombre = nombre_user.split(" ")[0];
                 cortar=false;
                cinco=true;
                recorte_listo=false;
                texto="";
                seis=true;
                color="#ffffff";
                texto_listo=false,siete=false;
                uno=true;
                blockCelda=true;
                size=48;
                
        
                xf=320,yf =480;
                negritas=false, bold="";
                shadow = true, nueve=true;
                italic=false, ita="";
                rectangulo=false, diez=false;
        fontfamily="Arial";
        r=0,g=0,b=0,a=1;
                 var imagenServidorNoticia;
                 console.log(edit)
                window.clearInterval(editorNoticia);
                setTimeout(function(){
                        scroll_altura=$(".articulo_noticia").offset().top-110;
                        anchoFondoOscuro = $(".articulo_noticia").width();
                        altoFondoOscuro = $(".editor_imagenes").height();
                        $(".fondo_oscuro").css("width",""+anchoFondoOscuro+"px");
                        $(".fondo_oscuro").css("height",""+altoFondoOscuro+"px");
                
                },navegacion(nuevoHtmlImagen,edit,'',false));
                
                })

                function navegacion(nuevoHtmlImagen,add,image,reload=true){
                        if(add){
                                edit=true;
                                $('#contenido2').html('')
                                $('#contenido').html(nuevoHtmlImagen)
                                
                        }else{
                                if(reload){
                                        $('#contenido').html('')
                                        const getBase64FromUrl = async (url) => {
                                                const data = await fetch(url);
                                                const blob = await data.blob();
                                                return new Promise((resolve) => {
                                                        const reader = new FileReader();
                                                        reader.readAsDataURL(blob); 
                                                        reader.onloadend = function() {
                                                        const base64data = reader.result;   
                                                        resolve(base64data);
                                                        }
                                                });
                                        }

                                        getBase64FromUrl(image).then(function(e){       
                                                $('#form-topic-edit #name').trigger('change');
                                                $(".volver").css("display","block")
                                                $(".a1").addClass("paso");
                                                $(".titulo_pasos").html("LABEL_STEP_2");
                                                setTimeout(function(){
                                                        recorte_listo=true;
                                                        $(".fondo_oscuro").css("display","none");
                                                        $("#boton_recortar").removeClass("recortar").text("LABEL_SEND").addClass("info_noticia").attr('type','submit');
                                                        $(".recortar10").removeClass("recortar");
                                                        $(".canvas").removeClass("recortar");
                                                        $(".b1").addClass("paso");
                                                        $(".titulo_pasos").html("LABEL_STEP_3");
                                                        if(texto!=""){
                                                                seis=true;
                                                                siete=true;
                                                        }
                                                        cinco=true;
                                                        dos=true;
                                                        cuatro=true;
                                                        actualizar();
                                        
                                                },editorNoticia(e));
                                                
                                                
                                        })
                
                                        setTimeout(function(){                          
                                                $(".canvas_subir").html('<span class="icon-plus fa fa-spinner"></span> Cargando...')
                                                $('#form-topic-edit #name').trigger('change');
                                        },$('#contenido2').html(nuevoHtmlImagen));
                                }else{
                                        
                                        edit=true;
                                        $('#contenido').html('')
                                        setTimeout(function(){                          
                                                $('#form-topic-edit #name').trigger('change');
                                        },$('#contenido2').html(nuevoHtmlImagen));
                                }
                        }
                }

                $(window).on("scroll", function(){
                        console.log(scroll_altura)
                if($(window).scrollTop()>scroll_altura){
                        $("#cuadro_noticias").addClass("fixed");
                }else{
                        $("#cuadro_noticias").removeClass("fixed");
                }
        })

        $(document).on("dragover", "#imagen_noticia", function(e){
                e.preventDefault();
                e.stopPropagation();
                $(this).css({"background":"rgba(0,0,0,.2)"})
        })
        $(document).on("drop", "#imagen_noticia", function(e){
                e.preventDefault();
                e.stopPropagation();
                $(this).css("background", "none");
                var archivo = e.originalEvent.dataTransfer.files;
                var img=archivo[0];
                if(img.type =="image/jpeg"||img.type =="image/png"){
                        $(".modificar").removeClass("animated");
                        var render = new FileReader();
                        render.readAsDataURL(img);
                        render.onload = function(e){
                                imagen2=new Image();
                                imagen2.src=e.target.result;
                                
                                $(imagen2).ready(function(e){
                                        if(imagen2.width<200||imagen2.height<200){
                                                $.fn.showError('LABEL_MINIMUM_IMAGE_SIZE');
                                        }else{
                                                $(".volver").css("display","block")
                                                $(".a1").addClass("paso");
                                                $(".titulo_pasos").html("LABEL_STEP_2");
                                                editorNoticia(imagen2.src)
                                        }                       
                                })
                        }
                }else{
                        $.fn.showError('LABEL_SUPPORTED_FORMATS');
                }
        })
                
        $(document).on("dragover", "body", function(e){
                e.preventDefault();
                e.stopPropagation();
        })
        $(document).on("drop", "body", function(e){
                e.preventDefault();
                e.stopPropagation();
        })      

        var canvas='<div class="editorNoticia"><canvas id="editorNoticia">LABEL_NOT_SUPPORTED</canvas></div>';
        $(document).on("mouseover", ".editorNoticia", function(){
                $("body").css({"overflow": "hidden"});
                $(".cuadro_noticias, .fixed_noticia,.tituloEditor,.grid-padre").css("margin-right", "17px")
                $(".barra,.footer").css("padding-right","17px")
                

        })
        $(document).on("mouseover", "#editorNoticia", function(){
                if(recorte_listo){
                        ocho=true;      
                }
        })
        $(document).on("mouseout", "#editorNoticia", function(){
                if(recorte_listo){
                        ocho=false;
                        actualizar2()
                }
        })
        $(document).on("mouseout", ".editorNoticia",function(){
                $("body").css({"overflow": "auto"})
                $(".cuadro_noticias, .fixed_noticia,.tituloEditor,.grid-padre").css("margin-right", "0px")
                $(".barra,.footer").css("padding-right","0px")
                
        })
        $(document).on('mousewheel', ".editorNoticia",function(e){
                var ruedita = e.originalEvent.wheelDelta 
                if(ruedita>0){
                        scale = scale+(scale/10); 
                        $("#porciento_scale").html((scale*100).toFixed(2)+"%")
                }else{
                        scale = scale-(scale/10); 
                        $("#porciento_scale").html((scale*100).toFixed(2)+"%")
                }
                $("#editorNoticia").css({"transform": "scale("+scale+")"});
        })
        $(document).on("click", ".as", function(e){
                e.preventDefault();
                 scale = $(this).data("scale");
                 $("#porciento_scale").html((scale*100).toFixed(2)+"%")
                 $("#editorNoticia").css({"transform": "scale("+scale+")"});
                
        })
        $(document).on("click", ".ps", function(e){
                e.preventDefault();
                $(".cantidades_scale").slideToggle(200).css("display", "block");
        })
        $(document).on("click", "#cerrar_filter_modal, .icon_filter", function(e){
                e.preventDefault();
                if(recorte_listo){
                $(".contenido_filter").slideToggle(200).css("display", "block");
                }
        })
        $(document).on("click", "#cerrar_text_modal, .icon_text", function(e){
                e.preventDefault();
                if(recorte_listo){
                        $(".contenido_text").slideToggle(200).css("display", "block");
                }
        })
        
        $(document).on("click", "#cerrar_cut_modal, .icon_cut", function(e){
                e.preventDefault();
                if(cortar){
                        $(".contenido_cut").slideToggle(200).css("display", "block");
                }
                
        })
        $(document).on("click", "#menos_scale", function(e){
                e.preventDefault();
                scale = scale-(scale/10);
                 $("#porciento_scale").html((scale*100).toFixed(2)+"%")
                 $("#editorNoticia").css({"transform": "scale("+scale+")"});
        })

        $(document).on("click", "#mas_scale", function(e){
                e.preventDefault();
                scale = scale+(scale/10);
                 $("#porciento_scale").html((scale*100).toFixed(2)+"%")
                 $("#editorNoticia").css({"transform": "scale("+scale+")"});
        })
        $(document).on("click", "#noche", function(){
                $(".oa").removeClass("oa")
                filter( .5,1.3,1.31,1.33,1.38);
                $(this).addClass("oa")
        })
        $(document).on("click", "#sa", function(){
                $(".oa").removeClass("oa")
                filter( .7,1.1,1.64,1.66,1.50);
                $(this).addClass("oa")
        })
        $(document).on("click", "#crema", function(){
                $(".oa").removeClass("oa")
                filter( .75,1,1.66,1.60,1.51);
                $(this).addClass("oa")
        })
        $(document).on("click", "#setenta", function(){
                $(".oa").removeClass("oa")
                filter( .8,.75,1.60,1.66,1.58);
                $(this).addClass("oa")
        })
        $(document).on("click", "#orange", function(){
                $(".oa").removeClass("oa")
                filter( .8,1,1.6,1.45,1.49);
                $(this).addClass("oa")
        })
        $(document).on("click", "#relieve", function(){
                $(".oa").removeClass("oa")
                filter( .7,1.2,1.60,1.66,1.58);
                $(this).addClass("oa")
        })
        $(document).on("click", "#bosque", function(){
                $(".oa").removeClass("oa")
                filter( .85,.75,1.47,1.66,1.54);
                $(this).addClass("oa")
        })
        $(document).on("click", "#desierto", function(){
                $(".oa").removeClass("oa")
                filter( .8,.9,1.66,1.43,1.28);
                $(this).addClass("oa")
        })
        $(document).on("click", "#villa", function(){
                $(".oa").removeClass("oa")
                filter( .8,.8,1.71,1.64,1.58);
                $(this).addClass("oa")
        })
        $(document).on("click", "#magia", function(){
                $(".oa").removeClass("oa")
                filter( .7,1.2,1.49,1.49,1.6);
                $(this).addClass("oa")
        })
        $(document).on("click", "#luz", function(){
                $(".oa").removeClass("oa")
                filter( .9,.9,1.45,1.54,1.54);
                $(this).addClass("oa")
        })
        $(document).on("click", "#retoque", function(){
                $(".oa").removeClass("oa")
                filter( .9,1.3,1,1,1);
                $(this).addClass("oa")
        })
        $(document).on("click", "#saturacion", function(){
                $(".oa").removeClass("oa")
                filter( 1,1.5,1,1,1);
                $(this).addClass("oa")
        })
        $(document).on("click", "#rosa", function(){
                $(".oa").removeClass("oa")
                filter( .8,1.2,1.24,.99,1);
                $(this).addClass("oa")
        })
        $(document).on("click", "#historia", function(){
                $(".oa").removeClass("oa")
                filter( .9,1.1,1.33,1.19,.91);
                $(this).addClass("oa")
        })
        $(document).on("click", "#encantador", function(){
                $(".oa").removeClass("oa")
                filter( .9,1.2,26,-12,0,2);
                $(this).addClass("oa")
        })
        $(document).on("click", "#emocion", function(){
                $(".oa").removeClass("oa")
                filter( 1.1,1.4,40,12,-6,2);
                $(this).addClass("oa")
        })
        $(document).on("click", "#beige", function(){
                $(".oa").removeClass("oa")
                filter( .9,1.32,56,47,17,2);
                $(this).addClass("oa")
        })
        $(document).on("click", "#fine", function(){
                $(".oa").removeClass("oa")
                filter( .87,1.19,55,37,23,2);
                $(this).addClass("oa")
        })
        $(document).on("click", "#lord", function(){
                $(".oa").removeClass("oa")
                filter( 1.2,.9,67,13,-23,2);
                $(this).addClass("oa")
        })
        $(document).on("click", "#70", function(){
                $(".oa").removeClass("oa")
                filter( 1.2,1.2,35,7,18,2);
                $(this).addClass("oa")
        })
        $(document).on("click", "#arbol", function(){
                $(".oa").removeClass("oa")
                filter(.92,1.23,-11,11,11,2);
                $(this).addClass("oa")
        })
        $(document).on("click", "#verano", function(){
                $(".oa").removeClass("oa")
                filter( 1,1.4,-3,-1,-12,2);
                $(this).addClass("oa")
        })
        $(document).on("click", "#cf", function(){
                $(".oa").removeClass("oa")
                filter( .85,1.26,-15,2,-1,2);
                $(this).addClass("oa")
        })
        $(document).on("click", "#angeles", function(){
                $(".oa").removeClass("oa")
                filter( 1,1.4,5,12,1,2);
                $(this).addClass("oa")
        })
        $(document).on("click", "#caliente", function(){
                $(".oa").removeClass("oa")
                filter( .9,1.2,43,-17,-55,2);
                $(this).addClass("oa")
        })
        $(document).on("click", "#otono", function(){
                $(".oa").removeClass("oa")
                filter( 1,1.29,29,26,17,2);
                $(this).addClass("oa")
        })
        $(document).on("click", "#marzo", function(){
                $(".oa").removeClass("oa")
                filter( .85,1.3,43,25,-11,2);
                $(this).addClass("oa")
        })
        $(document).on("click", "#pera", function(){
                $(".oa").removeClass("oa")
                filter( .8,1.25,31,41,12,2);
                $(this).addClass("oa")
        })
        $(document).on("click", "#comun", function(){
                $(".oa").removeClass("oa")
                filter( 1,1.36,4,5,1,2);
                $(this).addClass("oa")
        })
        $(document).on("click", "#oro", function(){
                $(".oa").removeClass("oa")
                filter( .9,1.3,37,-25,1,2);
                $(this).addClass("oa")
        })
        $(document).on("click", "#gotico", function(){
                $(".oa").removeClass("oa")
                filter( 1.1,1.3,-47,-42,-30,2);
                $(this).addClass("oa")
        })
        $(document).on("click", "#forestal", function(){
                $(".oa").removeClass("oa")
                filter( 1,1.4,-5,42,11,2);
                $(this).addClass("oa")
        })
        $(document).on("click", "#luna", function(){
                $(".oa").removeClass("oa")
                filter( .9,1.2,-5,-7,4,2);
                $(this).addClass("oa")
        })
        $(document).on("click", "#fiesta", function(){
                $(".oa").removeClass("oa")
                filter( 1.1,1.3,-1,-1,26,2);
                $(this).addClass("oa")
        })
        $(document).on("click", "#gris", function(){
                $(".oa").removeClass("oa")
                filtergris(1,1)
                $(this).addClass("oa")
        })
        $(document).on("click", "#lhs", function(){
                $(".oa").removeClass("oa")
                filtergris(.8,1.5);
                $(this).addClass("oa")
        })
        $(document).on("click", "#normal", function(){
                $(".oa").removeClass("oa")
                $(this).addClass("oa")
                filter();
        })
        var texto_listo=false,siete=false;
        var texto;
        $(document).on("keyup", "#texto_input", function(e){
                e.preventDefault();
                texto = $(this).val();
                if(texto_actualizar){
                        siete=true;     
                }
                if(texto!=""){
                        texto_actualizar=true;
                        actualizar2();
                }else{
                        actualizar2();
                }

        })
        var color="#ffffff";
        $(document).on("change", "#color", function(){
        color=$(this).val();
        seis=true;
        actualizar2();
    })
    var size=48;
    $(document).on("keyup change", "#font-size", function(){
        size=$(this).val();
        size = parseInt(size);
        seis=true;
        siete=true;
        actualizar2();
    })
    var negritas=false, bold="";
    $(document).on("click", "#negritas", function(e){
        e.preventDefault();
        if(!negritas){
                bold="bold";
                $(this).addClass("fa");
                seis=true;
                siete=true;
                actualizar2();
                negritas=true;
        }else{
                bold="";
                $(this).removeClass("fa");
                seis=true;
                siete=true;
                actualizar2();
                negritas=false;
        }
    })
    var italic=false, ita="";
     $(document).on("click", "#italic", function(e){
        e.preventDefault();
        if(!italic){
                ita="italic";
                $(this).addClass("fa");
                seis=true;
                siete=true;
                actualizar2();
                italic=true;
        }else{
                ita="";
                $(this).removeClass("fa");
                seis=true;
                siete=true;
                actualizar2();
                italic=false;
        }
    })
     var fontfamily="Arial";
     $(document).on("click", ".fs", function(e){
        e.preventDefault();
        $(".at").removeClass("at");
        $(this).addClass("at");
        fontfamily= $(this).text();
        seis=true;
        siete=true;
        actualizar2();
        
    })
     var shadow = true, nueve=true;
     $(document).on("click","#shadow", function(e){
        e.preventDefault();
        if(shadow){
                $(this).removeClass("fa");
                seis=true;
                nueve=false;
                actualizar2();
                shadow=false;
        }else{
                $(this).addClass("fa");
                seis=true;
                nueve=true;
                actualizar2();
                shadow=true;
        }

     })
     var rectangulo=false, diez=false, colorrect="#000000";
     $(document).on("click", "#rectangulo", function(e){
        e.preventDefault();
        if(!rectangulo){
                $(this).addClass("fa");
                diez=true;
                actualizar2();
                rectangulo=true;
        }else{
                $(this).removeClass("fa");
                diez=false;
                actualizar2();
                rectangulo=false;
        }

     })
     var r=0,g=0,b=0;
    $(document).on("change", "#colorrect", function(){
        colorrect=$(this).val();
        r=parseInt(colorrect.slice(1,3),16);
        g=parseInt(colorrect.slice(3,5),16);
        b=parseInt(colorrect.slice(5,7),16);
        seis=true;
        actualizar2();
    })
    var a=1;
        
    $(document).on("keyup change", "#opacidad", function(){
        a=$(this).val();
        a=a/100;
        seis=true;
        actualizar2();
    })
        var imaNoti = new Image();
        function filter(brillo=1, contraste=1, rojo=1, verde=1, azul=1, valor=1){
                cuatro=false;
                restaurar(brillo, contraste);
                datos=imagenOriginal.data;
                if(valor==2){
                        for (var i =  0; i <datos.length; i+=4) {
                                datos[i]=datos[i]+rojo;
                                datos[i+1]=datos[i+1]+verde;
                                datos[i+2]=datos[i+2]+azul;
                        }
                }else{
                        for (var i =  0; i <datos.length; i+=4) {
                                datos[i]=datos[i]*rojo;
                                datos[i+1]=datos[i+1]*verde;
                                datos[i+2]=datos[i+2]*azul
                        }       
                }
                editor.putImageData(imagenOriginal,0,0)
                var imagenNoticia = elemento.toDataURL("image/jpeg", 1.0);
            imaNoti.src = imagenNoticia;
                actualizar2();
        }
        function filtergris(brillo=1, contraste=1){
                cuatro=false;
                restaurar(brillo, contraste);
                datos=imagenOriginal.data;
                var auxiliar;
                for (var i =  0; i <datos.length; i+=4) {
                        auxiliar = 0.34 * datos[i] + 0.5 *datos[i+1] + 0.16 * datos[i+2]; 
                        datos[i]=auxiliar;
                        datos[i+1]=auxiliar;
                        datos[i+2]=auxiliar;
                }       
                
                editor.putImageData(imagenOriginal,0,0)
                var imagenNoticia = elemento.toDataURL("image/jpeg", 1.0);
            imaNoti.src = imagenNoticia;
                actualizar2();
        }
        function restaurar(brillo = 1, contraste=1){
                editor.filter = "none"
                editor.filter = 'contrast('+contraste+') brightness('+brillo+') saturate(1) sepia(0)';
                editor.fillStyle="rgba(255,255,255,1)"
                editor.fillRect(0,0,ancho,alto);
                editor.fillStyle=""+color+"";
                var pxf=0,pyf=0;
                        if(xf>=(yf/recorte)){
                                pxf=xf/ancho;
                                pyf=yf/pxf;
                                py=(alto/2)-(pyf/2);
                                editor.drawImage(imagen,x,y,xf,yf,0,py,ancho,pyf);
                        }else{
                                pyf=yf/alto;
                                pxf=xf/pyf;
                                px=(ancho/2)-(pxf/2);
                                editor.drawImage(imagen,x,y,xf,yf,px,0,pxf,alto);
                        }
                imagenOriginal = editor.getImageData(0,0,ancho,alto)
        }
        var ocho=false;
        function actualizar2(){
                if(recorte_listo){
                if(cuatro){
                        imagenOriginal = editor.getImageData(0,0,ancho,alto)
                        var imagenNoticia = elemento.toDataURL("image/jpeg", 1.0);
                imaNoti.src = imagenNoticia;
                cuatro=false;
                }
                editor.filter = "none"
                $(imaNoti).ready(function(e){   
                        noticia.drawImage(imaNoti,0,0,320,480);
                        editor.drawImage(imaNoti,0,0,ancho,alto)
                        if(texto_actualizar){
                                if(texto!=""){
                                        if(seis){
                                                ancho_imaNoti = imaNoti.width;
                                                
                                                scale_noticia = -(((ancho_imaNoti-320)/ancho_imaNoti)-1);
                                                editor.fillStyle=""+color+"";
                                                editor.strokeStyle="rgb(255,255,255)";
                                                if(nueve){
                                                        editor.shadowColor="rgba(0,0,0,.5)";
                                                        editor.shadowOffsetX=6;
                                                        editor.shadowOffsetY=6;
                                                        editor.shadowBlur=6;
                                                        noticia.shadowColor="rgba(0,0,0,.5)";
                                                        noticia.shadowOffsetX=6*scale_noticia;
                                                        noticia.shadowOffsetY=6*scale_noticia;
                                                        noticia.shadowBlur=6*scale_noticia;
                                                }else{
                                                        editor.shadowColor="rgba(0,0,0,0)";
                                                        noticia.shadowColor="rgba(0,0,0,0)";
                                                }
                                                editor.font=""+ita+" "+bold+" "+size+"px "+fontfamily+"";
                                                editor.textAlign="start";
                                                editor.textBaseline="top";
                
                                                var sizeNoticia = size*scale_noticia;
                                                noticia.fillStyle=""+color+"";
                                                noticia.font=""+ita+" "+bold+" "+sizeNoticia+"px "+fontfamily+"";
                                                noticia.textAlign="start";
                                                noticia.textBaseline="top";
                                                seis=false;
                                        }
                                        if(siete){
                                                dimencionesTexto = editor.measureText(texto);
                                                txf=dimencionesTexto.width+20;
                                                tyf= (20+size); 
                                                siete=false;
                                        }
                                        if(cinco){
                                                dimencionesTexto = editor.measureText(texto);
                                                if(xf>=(yf/recorte)){
                                                        tx=(xf/2)-(dimencionesTexto.width/2);
                                                        ty=(xf*recorte/2)-(size/2);
                                                }else{
                                                        tx=(yf/recorte/2)-(dimencionesTexto.width/2);
                                                        ty=(yf/2)-(size/2);
                                                }
                                                
                                                txf=dimencionesTexto.width+20;
                                                tyf= size+20;   
                                                cinco=false;
                                        }
                                        if(diez){
                                                editor.fillStyle="rgba("+r+","+g+","+b+","+a+")";
                                                noticia.fillStyle="rgba("+r+","+g+","+b+","+a+")";
                                                editor.fillRect(tx-10,ty-10,txf,tyf);
                                                noticia.fillRect(((tx-10)*scale_noticia),((ty-10)*scale_noticia),txf*scale_noticia,tyf*scale_noticia);
                                                editor.fillStyle=""+color+"";
                                                noticia.fillStyle=""+color+"";

                                        }
                                        editor.fillText(texto,tx,ty);
                                        noticia.fillText(texto,(tx*scale_noticia),ty*scale_noticia);
                                        if(ocho){
                                                editor.strokeRect(tx-10,ty-10,txf,tyf)
                                                editor.arc(tx+txf,ty+tyf,10,0,Math.PI*2,false);
                                                editor.fill();
                                                editor.beginPath();
                                        }
                                        texto_listo=true;
                                }
                        }
                })
                
        }
        }
        function actualizar(){
                        $(imagen).ready(function(e){
                                if(uno){
                                        ancho=imagen.width, alto = imagen.height;
                                        elemento.width = ancho;
                                        elemento.height = alto;

                                        $(".scale").css("display","flex");
                                        if(ancho<=alto){
                                         scale = -(((alto-450)/alto)-1);
                                        
                                        
                                        }else{                                  
                                         scale = -(((ancho-500)/ancho)-1);
                                
                                        }
                                        if(edit){
                                                if((ancho*recorte)<=alto){
                                                        xf=ancho*.70;
                                                        yf=xf*recorte;
                                                }else{
                                                        yf=alto*.70;
                                                        xf=yf/recorte;
                                                }
                                        }
                                        
                                        cuadro_dimencion=Math.round(12/scale);
                                        
                                        if(xf<50||yf<50){
                                                xf=50;
                                                yf=xf*recorte;
                                        }
                                        console.log(xf+' '+yf)
                                        mitadX=ancho/2;
                                        mitadY=alto/2;
                                        x=mitadX-xf/2;
                                        y=mitadY-yf/2;
                                
                                        $("#porciento_scale").html((scale*100).toFixed(2)+"%")
                                        $("#ancho").html(ancho+"px");
                                        $("#alto").html(alto+"px");
                                        uno=false;
                                }
                                if(dos){
                                        
                                        if(xf>=(yf/recorte)){
                                                alto=xf*recorte;
                                                ancho=xf;
                                        }else{
                                                ancho=yf/recorte;
                                                alto=yf;

                                        }
                                        elemento.width = ancho;
                                        elemento.height = alto;
                                        if(xf<=yf){
                                         scale = -(((yf-450)/yf)-1);
                                         
                                        }else{                                  
                                         scale = -(((xf-500)/xf)-1);
                                        }
                                        
                                        $("#porciento_scale").html((scale*100).toFixed(2)+"%")
                                        $("#ancho").html(Math.round(xf)+"px");
                                        $("#alto").html(Math.round(yf)+"px");
                                        dos=false;
                                }

                                        var pxf=0,pyf=0;
                                        noticia.fillStyle="rgba(255,255,255,1)"
                                        noticia.fillRect(0,0,320,480);
                                if(xf>=(yf/recorte)){
                                        pxf=xf/320;
                                        pyf=yf/pxf;
                                        py=(480/2)-(pyf/2);
                                        noticia.drawImage(imagen,x,y,xf,yf,0,py,320,pyf);
                                }else{
                                        pyf=yf/480;
                                        pxf=xf/pyf;
                                        px=(320/2)-(pxf/2);
                                        noticia.drawImage(imagen,x,y,xf,yf,px,0,pxf,480);
                                }
                                
                                $("#editorNoticia").css({"transform": "scale("+scale+")"});
                                if(!recorte_listo){
                                        editor.drawImage(imagen,0,0,ancho,alto);
                                        editor.fillStyle="rgba(0,0,0,.2)"
                                        editor.fillRect(0,0,ancho,alto);
                                        editor.fillStyle="rgba(255,255,255,.2)"
                                        editor.fillRect(x,y,xf,yf);
                                        editor.fillStyle="rgba(255,255,255,0.8)"
                                        editor.fillRect(x,y,cuadro_dimencion,cuadro_dimencion);
                                        editor.fillRect((x+xf)-cuadro_dimencion,y,cuadro_dimencion,cuadro_dimencion);
                                        editor.fillRect(x,y+yf-cuadro_dimencion,cuadro_dimencion,cuadro_dimencion);
                                        editor.fillRect(x+xf-cuadro_dimencion,yf+y-cuadro_dimencion,cuadro_dimencion,cuadro_dimencion);
                                        esta=true;
                                }else{
                                        var pxf=0,pyf=0;
                                        
                                        editor.fillStyle="rgba(255,255,255,1)"
                                        editor.fillRect(0,0,ancho,alto);
                                        if(xf>=(yf/recorte)){
                                                pxf=xf/ancho;
                                                pyf=yf/pxf;
                                                py=(alto/2)-(pyf/2);
                                                editor.drawImage(imagen,x,y,xf,yf,0,py,ancho,pyf);
                                        }else{
                                                pyf=yf/alto;
                                                pxf=xf/pyf;
                                                px=(ancho/2)-(pxf/2);
                                                editor.drawImage(imagen,x,y,xf,yf,px,0,pxf,alto);
                                }
                                        
                                }
                        })
                }
        var imagenOriginal;
        var x,y,xf=320,yf =480, elemento,editor,centro, total,scale,dimencionesTexto,ancho_imaNoti,
        recorte_listo=false,alto,ancho,tx,ty,txf,tyf,cuatro=true,texto_actualizar=false,cinco=true,seis=true,cuatro;
        var  mitadY,mitadX, uno=true,dos=false, recorte=480/320, imagen_noticias, scale_noticia, tres=true,rotar=false, cortar=false;;
        var translateX, cuadro_dimencion;
                
        $(document).on("click", ".recortar10", function(e){
                
                e.preventDefault();
                recorte_listo=false;
                uno=true;
                $(".fondo_oscuro").css("display","block");
                $("#boton_recortar").addClass("recortar").text("Recortar").removeClass("info_noticia");
                $("#boton_recortar3").addClass("recortar").text("Recortar").removeClass("info_noticia3");
                $(".contenido_text").css("display", "none");
                $(".contenido_filter").css("display", "none");
                $(".recortar10").addClass("recortar");
                $(".canvas").addClass("recortar")
                $(".oa").removeClass("oa");
                $("#normal").addClass("oa");
                $(".b1").removeClass("paso");
                $(".titulo_pasos").html("LABEL_STEP_2");
                window.clearInterval(actualizar2);
                actualizar();

        })

        
        blockCelda=true;
        $(document).on("click", "#blockCelda", function(e){
                e.preventDefault();
                if(blockCelda){
                        $(this).html('<span class="fa fa-unlock"></span>')
                        
                        blockCelda=false;
                }else{
                        $(this).html('<span class="fa fa-lock"></span>')
                        blockCelda=true;
                }
                t4=true;
                
        })
        var imagen 
        function editorNoticia(img){
                 cortar=true;
                imagen= new Image();
                $(".canvas").html(canvas);
                elemento = document.getElementById("editorNoticia");
                editor = elemento.getContext("2d");
                elemento2 = document.getElementById("imagen_noticias");
                noticia = elemento2.getContext("2d");

                $(document).on("click", ".boton_marino.recortar",function(e){
                        e.preventDefault();
                        recorte_listo=true;
                        $(".fondo_oscuro").css("display","none");
                        $("#boton_recortar").removeClass("recortar").text("LABEL_SEND").addClass("info_noticia").attr('type','submit');
                        $(".recortar10").removeClass("recortar");
                        $(".canvas").removeClass("recortar");
                        $(".b1").addClass("paso");
                        $(".titulo_pasos").html("LABEL_STEP_3");
                        if(texto!=""){
                                seis=true;
                                siete=true;
                        }
                        cinco=true;
                        dos=true;
                        cuatro=true;
                        actualizar();
                })

                var cli = false, t1= false, t2=false,t3=false,t4=false,tcli=false;
                var mouse =[];

        
                function raton(elemento, e){
                        return {
                                x:((e.pageX - elemento.offsetLeft - ((ancho/2)-((ancho*scale)/2)))/scale),
                                y:((e.pageY - elemento.offsetTop - ((alto/2)-((alto*scale)/2)))/scale)
                        }
                }

                imagen.src=img;
                $(".recortar10").addClass("recortar");
                $("#boton_recortar").removeClass("boton_normal").addClass("recortar boton_marino").text("LABEL_CUT")
                actualizar();

                $(elemento).mousemove(function(e){
                        mouse = raton(this, e);
                        //console.log("raton x: "+mouse.x+ " raton Y: " +mouse.y+ " tx: "+tx+" ty: "+ty+" txf:"+(txf+tx)+" tyf:"+(tyf+ty) )
                        if(!recorte_listo){
                                if(x<mouse.x &&(xf+x)>mouse.x && y<mouse.y && (y+yf)>mouse.y){
                                        if((xf+x-cuadro_dimencion)<mouse.x &&(xf+x)>mouse.x && (y+yf-cuadro_dimencion)<mouse.y && (y+yf)>mouse.y){
                                                $(elemento).css("cursor","nw-resize");
                                        }else if((xf+x-cuadro_dimencion)<mouse.x &&(xf+x)>mouse.x && y<mouse.y && (y+cuadro_dimencion)>mouse.y){
                                                $(elemento).css("cursor","ne-resize");
                                        }else if(x<mouse.x &&(cuadro_dimencion+x)>mouse.x && y<mouse.y && (y+cuadro_dimencion)>mouse.y){
                                                $(elemento).css("cursor","se-resize");
                                        }else if(x<mouse.x &&(cuadro_dimencion+x)>mouse.x && (y+yf-cuadro_dimencion)<mouse.y &&(y+yf)>mouse.y){
                                                $(elemento).css("cursor","sw-resize");
                                        }else{
                                                $(elemento).css("cursor","move");
                                        }
                                }else{
                                        $(elemento).css("cursor","default");
                                }
                        }else if(texto_listo){
                                if(tx-10<mouse.x && tx-10+txf>mouse.x && ty-10<mouse.y && ty-10+tyf>mouse.y){
                                        $(elemento).css("cursor","move");
                                }else if((txf+tx-10)<mouse.x &&(txf+tx-10+20)>mouse.x && (ty-10+tyf)<mouse.y && (ty-10+tyf+20)>mouse.y){
                                        $(elemento).css("cursor","pointer");
                                }else{
                                        $(elemento).css("cursor","default");
                                }
                        }
                        else{
                                $(elemento).css("cursor","default");
                        }
                })
                $(elemento).mousedown(function(e){
                        mouse = raton(this, e);
                        if(!recorte_listo){
                                if(x<mouse.x &&(xf+x)>mouse.x && y<mouse.y && (y+yf)>mouse.y){
                                        
                                        if((xf+x-cuadro_dimencion)<mouse.x &&(xf+x)>mouse.x && (y+yf-cuadro_dimencion)<mouse.y && (y+yf)>mouse.y){
                                                t4 = true;
                                        }else if((xf+x-cuadro_dimencion)<mouse.x &&(xf+x)>mouse.x && y<mouse.y && (y+cuadro_dimencion)>mouse.y){
                                                t3 = true;
                                        }else if(x<mouse.x &&(cuadro_dimencion+x)>mouse.x && y<mouse.y && (y+cuadro_dimencion)>mouse.y){
                                                t1 = true;
                                        }else if(x<mouse.x &&(cuadro_dimencion+x)>mouse.x && (y+yf-cuadro_dimencion)<mouse.y &&(y+yf)>mouse.y){
                                                t2 = true;
                                        }else{
                                                cli = true;
                                        }
                                }
                                
                        }else if(texto_listo){
                                if(tx-10<mouse.x && tx-10+txf>mouse.x && ty-10<mouse.y && ty-10+tyf>mouse.y){
                                        tcli=true;
                                }else if((txf+tx-10)<mouse.x &&(txf+tx-10+20)>mouse.x && (ty-10+tyf)<mouse.y && (ty-10+tyf+20)>mouse.y){
                                        rotar=true;
                                }
                        }                       
                        
                 })

                 $(elemento).mousemove(function(e){
                        mouse = raton(this, e);
                        if(!recorte_listo){
                                if(cli){
                                        if((mouse.y-(yf/2))>=0&&(mouse.y+(yf/2))<=alto){
                                                y = (mouse.y-(yf/2));
                                        }else{
                                                if((mouse.y-(yf/2))<0){
                                                        y=0;
                                                }
                                                if((mouse.y+(yf/2))>alto){
                                                        y=alto-yf;
                                                }
                                        }
                                        if((mouse.x-(xf/2))>=0&&(mouse.x+(xf/2))<=ancho){
                                                x = (mouse.x-(xf/2));
                                        }else{
                                                if((mouse.x-(xf/2))<0){
                                                        x=0;
                                                }
                                                if((mouse.x+(xf/2))>ancho){
                                                        x=(ancho)-xf;
                                                }
                                        }                               
                                }
                                if(blockCelda){
                                if(t4){
                                        if(mouse.y<(alto-10)&&(x+xf)<=(ancho)){
                                                if(Math.round(xf)>=50){
                                                        if(((mouse.y-y)/recorte)>50){
                                                                yf=mouse.y-y;   
                                                                xf=(yf/recorte);
                                                        }
                                                }
                                        }else{
                                                if(mouse.y>=(alto-10)){
                                                        yf=alto-y;
                                                        xf=(yf/recorte);
                                                        t4=false;       
                                                }
                                                if(x+xf>(ancho)){
                                                        xf=(ancho)-x;
                                                        yf=(xf*recorte);
                                                        t4=false;       
                                                }
                                        }
                                }
                                if(t3){
                                        if(mouse.y>0&&(x+xf)<=(ancho)){
                                                if(Math.round(xf)>=50){
                                                        if(((yf+(y-mouse.y))/recorte)>50){
                                                                yf=yf+(y-mouse.y);
                                                                xf=(yf/recorte);
                                                                y=mouse.y;      
                                                        }
                                                }

                                        }else{
                                                if(mouse.y<=0) {
                                                        yf=yf+(y-mouse.y);
                                                        xf=(yf/recorte);
                                                        y=0;
                                                        t3=false;       
                                                }
                                                if(x+xf>(ancho)){
                                                        xf=(ancho)-x;
                                                        yf=xf*recorte;
                                                        t3=false;       
                                                }
                                        }
                                }
                                if(t2){
                                        if(mouse.y<(alto-10)&&x>=0){
                                                if(Math.round(xf)>=50){ 
                                                        if(((mouse.y-y)/recorte)>50){
                                                                x=(x+(yf-(mouse.y-y))/recorte);
                                                                yf=mouse.y-y;
                                                                xf=(yf/recorte);
                                                        }
                                                }
                                                
                                        }else{
                                                if(mouse.y>=(alto-10)) {
                                                        yf=alto-y;
                                                        xf=(yf/recorte);
                                                        t2=false;
                                                }
                                                if(0>x){
                                                        x=0;
                                                        xf=mouse.y-y;
                                                        yf=(xf*recorte);
                                                        t2=false;
                                                }
                                        }
                                }
                                if(t1){
                                        if(mouse.y>0&&x>=0){
                                                if(Math.round(xf)>=50){ 
                                                        if(((yf+(y-mouse.y))/recorte)>50){
                                                                yf=yf+(y-mouse.y);
                                                                xf=(yf/recorte);
                                                                x=(x-(y-mouse.y)/recorte);
                                                                y=mouse.y;
                                                        }
                                                }
                                        }else{
                                                if(mouse.y<=0) {
                                                        yf=yf+(y-mouse.y);
                                                        xf=(yf/recorte);
                                                        y=0;
                                                        t1=false;       
                                                }
                                                if(0>x){
                                                        x=0;
                                                        xf=yf+(y-mouse.y);
                                                        yf=(xf*recorte);
                                                        t1=false;       
                                                }
                                        }
                                }
                                }else{
                                 if(t4){
                                        if(mouse.y<(alto-10-(2/scale))&&mouse.x<=(ancho-(2/scale))){
                                                
                                                        if((mouse.y-y)>50){
                                                                yf=mouse.y-y;   
                                                        }
                                                        if((mouse.x-x)>50){
                                                                xf=mouse.x-x;
                                                        }
                                                
                                        }else{
                                                if(mouse.y>=(alto-10-(2/scale))){
                                                        yf=alto-y;
                                                }
                                                if(mouse.x>(ancho-(2/scale))){
                                                        xf=(ancho)-x;
                                                }
                                                 t4=false;      
                                        }
                                }
                                if(t3){
                                        if(mouse.y>(2/scale)&&mouse.x<=(ancho-(2/scale))){
                                                
                                                        if((yf-(mouse.y-y))>50){
                                                                yf=yf-(mouse.y-y);
                                                                y=mouse.y;      
                                                        }
                                                        if((mouse.x-x)>50){
                                                                xf=mouse.x-x;
                                                        }
                                                

                                        }else{
                                                if(mouse.x>(ancho-(2/scale))){
                                                        xf=ancho-x;
                                                }
                                                if(mouse.y<=(2/scale)){
                                                        yf=yf-(mouse.y-y);
                                                        y=0;
                                                }
                                                t3=false;               
                                        }
                                }
                                /* Izquierda abajo */
                                if(t2){
                                        if(mouse.y<(alto-10-(2/scale))&&mouse.x>=(2/scale)){
                                                         if((mouse.y-y)>50){
                                                                yf=mouse.y-y;
                                                        }
                                                        if((xf-(mouse.x-x))>50){
                                                                xf=xf-(mouse.x-x);
                                                                x=mouse.x
                                                        }
                        
                                        }else{
                                                if(mouse.y>=(alto-10-(2/scale))) {
                                                        yf=alto-y;
                                                }

                                                if(mouse.x<(2/scale)){
                                                        xf=xf-(mouse.x-x);
                                                        x=0;
                                                }
                                                 t2=false;
                                        }
                                }
                                /* izquierda arriba */
                                if(t1){
                                        if(mouse.y>(2/scale)&&mouse.x>=(2/scale)){
                                                        
                                                        if((yf-(mouse.y-y))>50){
                                                                yf=yf-(mouse.y-y);
                                                                y=mouse.y;      
                                                        }
                                                        if((xf-(mouse.x-x))>50){
                                                                xf=xf-(mouse.x-x);
                                                                x=mouse.x
                                                        }
                                                
                                        }else{
                                                if(mouse.y<=(2/scale)){
                                                        yf=yf-(mouse.y-y);
                                                        y=0;
                                                }
                                                 if(mouse.x<(2/scale)){
                                                        xf=xf-(mouse.x-x);
                                                        x=0;
                                                        
                                                }
                                                 t1=false;
                                        }
                                }
                        }
                                
                        actualizar();
                        }else if(texto_listo){
                                if(tcli){
                                        tx=mouse.x-(txf/2)
                                        ty=mouse.y-(tyf/2)
                                }else if(rotar){

                                }

                                actualizar2();
                        }
                 })
                 $(elemento).mouseup(function(e){
                        if(!recorte_listo){
                                cli=false;
                                t1=false;
                                t2=false;
                                t3=false;
                                t4=false;
                        }else if (texto_listo) {
                                tcli=false;
                        }
                 })


        }
        /* Titulo */
        
var titulo_noticia, censor_titulo = true, numero_titulo=0;
        $(document).on("keyup change", "#name", function(e){
        console.log(numero_titulo)
        titulo_noticia = $(this).val();
        titulo_elemento= $(".titulo_topico");
        if(titulo_noticia!=""){
                if(censor_titulo){
                        titulo_elemento.html(titulo_noticia);
                        if(titulo_elemento.height()>38){
                                var titulo_noticia2 = "";
                                for(var i =0; i <titulo_noticia.length;i++){
                                        titulo_noticia2 = titulo_noticia2 + titulo_noticia.split("")[i];
                                        titulo_elemento.html(titulo_noticia2);
                                        if(titulo_elemento.height()>38){
                                                titulo_noticia2 = titulo_noticia2.slice(0,-5) + "...";
                                                titulo_elemento.html(titulo_noticia2);
                                                numero_titulo = titulo_noticia2.length;
                                                censor_titulo=false;
                                                break;
                                        }

                                }
                        }else{
                                numero_titulo=0;
                        }
                }else{
                        if(numero_titulo+1>=titulo_noticia.length){
                                titulo_elemento.html(titulo_noticia);
                                censor_titulo=true;
                        }
                }
        }else{
                titulo_elemento.html("LABEL_TITLE_TOPIC");
                censor_titulo = true;
        }
})
    });
JS;
$this->inlineScript()->captureEnd();
?>
  

                                
<!-- Content Header (Page header) -->
<section class="content-header">
        <div class="container-fluid">
        <div class="row mb-2">
                <div class="col-sm-12">
                <h1>LABEL_TOPICS</h1>
                        </div>
                </div>
        </div><!-- /.container-fluid -->
</section>

<section class="content" id='content1'>
        <div class="container-fluid">
        <div class="row">
                <div class="col-12">
                                <div class="card">                    
                                        <div class="card-body">
                                <table id="gridTable" class="table   table-hover">
                                <thead>
                                                        <tr>
                                        <th>LABEL_NAME</th>
                                        <th>LABEL_STATUS</th>
                                        <th>LABEL_DETAILS</th>  
                                        <th>LABEL_ACTIONS</th>
                                </tr>
                                </thead>
                                <tbody>
                                </tbody>
                        </table>
                        </div>
                        <div class="card-footer clearfix">
                                <div style="float:right;">
                                                        <button type="button" class="btn btn-info btn-refresh"><i class="fa fa-refresh"></i> LABEL_REFRESH  </button>
                                                        <?php if($allowAdd) : ?>
                                                        <button type="button" class="btn btn-primary btn-add"><i class="fa fa-plus"></i> LABEL_ADD </button>
                                                        <?php endif; ?>
                                                </div>
                        </div>
                        </div>
                </div>     
        </div>          
        </div>
</section> 
<section id="addImage" style='display:none' class="">
<div class="d-flex justify-content-center tituloEditor">
        <h4>LABEL_ADD_TOPIC</h4>

    </div>
        <div class="grid-padre" >
                                <?php 
                         $form = $this->formAdd;
                        $form->setAttributes([
                        'method'  => 'post',
                            'action'  => $routeAdd,
                        'name'    => 'form-topic-add',
                        'id'      => 'form-topic-add',
                    ]);
    
                    $form->prepare();
                    echo $this->form()->openTag($form);
                    ?>                                  
                        <div class="form-group grid-1-2">
                                <?php 
                        $element = $form->get('name');
                        
                        $element->setAttributes(['class' => 'form-control']);
                        $element->setOptions(['label' => 'LABEL_NAME']);
                        echo $this->formLabel($element);
                        echo $this->formText($element);
                    ?>
                                </div>
                        
                <div class="form-group grid-1-2">
                        <?php 
                    $element = $form->get('description');
                    $element->setAttributes(['id' => 'description_add', 'class' => 'form-control', 'rows' => '2','class' => 'form-control']);
                    $element->setOptions(['label' => 'LABEL_DESCRIPTION']);
                    echo $this->formLabel($element);
                    echo $this->formTextArea($element);
                    ?>
                                </div>
                                <div class="form-group grid-1-2">
                                <?php 
                        $element = $form->get('order');
                        $element->setAttributes(['class' => 'form-control']);
                        $element->setOptions(['label' => 'LABEL_ORDER']);
                        echo $this->formLabel($element);
                        echo $this->formText($element);
                    ?>
                                </div>
                                
                        <?php 
                    $element = $form->get('file');
                                        $element->setAttributes([ 'class' => 'file']);
                    echo $this->formHidden($element); ?>

                        <div class="form-group grid-1-2">
                                <?php 
                        $element = $form->get('status');
                        $element->setAttributes(['class' => 'form-control']);
                        $element->setOptions(['label' => 'LABEL_STATUS']);
                        echo $this->formLabel($element);
                        echo $this->formSelect($element);
                    ?>
                                </div>

                                <div class="contenido form-group" id="contenido">


                                </div>          

                                        
                        <?php echo $this->form()->closeTag($form); ?>
                </div>

   
</section>

<section id="topicEdit" style='display:none' class="">
<div class="d-flex justify-content-center tituloEditor">
        <h4>LABEL_EDIT_TOPIC</h4>

    </div>
        <div class="grid-padre" >
                                        <?php 
                          $form = $this->formEdit;
                        $form->setAttributes([
                        'method'    => 'post',
                        'name'      => 'form-topic-edit',
                        'id'        => 'form-topic-edit'
                    ]);
    
                    $form->prepare();
                    echo $this->form()->openTag($form);
                    ?>                                  
                        <div class="form-group grid-1-2">
                                <?php 
                        $element = $form->get('name');
                        
                        $element->setAttributes(['class' => 'form-control']);
                        $element->setOptions(['label' => 'LABEL_NAME']);
                        echo $this->formLabel($element);
                        echo $this->formText($element);
                    ?>
                                </div>
                                <div class="form-group grid-1-2">
                        <?php 
                    $element = $form->get('description');
                    $element->setAttributes(['id' => 'description_edit', 'rows' => '2', 'class' => 'form-control',   'class' => 'form-control']);
                    $element->setOptions(['label' => 'LABEL_DESCRIPTION']);
                    echo $this->formLabel($element);
                    echo $this->formTextArea($element);
                    ?>
                                </div>
                                <div class="form-group grid-1-2">
                                <?php 
                        $element = $form->get('order');
                        $element->setAttributes(['class' => 'form-control']);
                        $element->setOptions(['label' => 'LABEL_ORDER']);
                        echo $this->formLabel($element);
                        echo $this->formText($element);
                    ?>
                                </div>
                                
                        <?php 
                    $element = $form->get('file');
                                        $element->setAttributes([ 'class' => 'file']);
                    echo $this->formHidden($element); 
                                        ?>

                        <div class="form-group grid-1-2">
                                <?php 
                        $element = $form->get('status');
                        $element->setAttributes(['class' => 'form-control']);
                        $element->setOptions(['label' => 'LABEL_STATUS']);
                        echo $this->formLabel($element);
                        echo $this->formSelect($element);
                    ?>
                                </div>

                                <div class="contenido form-group" id="contenido2">
                                </div>          
                                        
                        <?php echo $this->form()->closeTag($form); ?>
                </div>

   
</section>


                        
<!-- The Modal -->
<div class="modal" id="modalImageApp">
        <div class="modal-dialog ">
        <div class="modal-content">

            <!-- Modal Header -->
                <div class="modal-header">
                        <h4 class="modal-title">LABEL_IMAGE</h4>
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                </div>

            <!-- Modal body --> 
            <div class="modal-body text-center">
                                <img src="" class="img img-responsive" style="width: 300px; height: auto" id="image-app" />
                </div>
                
            <!-- Modal footer -->
                <div class="modal-footer">
                        <button type="button" class="btn btn-danger" data-dismiss="modal">Cerrar</button>
                </div>
         </div>         
        </div>
</div>