integration/js/edition.js
author Anthony Ly <anthonyly.com@gmail.com>
Thu, 16 May 2013 12:58:48 +0200
changeset 6 547b3ddedf7f
child 9 e3d551eda5a6
permissions -rw-r--r--
organisation des fichiers avancement édition
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     1
(function(){
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     2
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     3
var global = {
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     4
    diaporama : null,
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     5
    idAnnotation : null
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     6
};
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     7
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     8
//modal
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     9
    $('.popup').on('click', '.popup-content a', function(e){
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    10
    	e.preventDefault();
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    11
    	if($(this).hasClass('btn-cancel')){
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    12
    		$(this).parents('.popup').modal('hide');
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    13
    	}
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    14
    	if($(this).hasClass('btn-previsualisation')){
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    15
    		var imgPrev = $('<img src="img/520x520.gif" alt="" />');
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    16
    		$('.previsualisation').empty().append(imgPrev);
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    17
    	}
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    18
    });
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    19
//edition image
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    20
    $('.popup').on('change', '#media-type-select', function(e){
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    21
        var typeImage = $(this).val();
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    22
        $('.input-image-url, .input-image-upload').hide();
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    23
        $('.input-image-'+typeImage).show();
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    24
    });
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    25
//bibliotheque
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    26
    //video
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    27
    $('.popup').on('click', '.bibliotheque-video a', function(e){
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    28
        e.preventDefault();
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    29
        $('.popup').modal('hide');
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    30
        $.get('template.html', function(templates){
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    31
            var videoWrap = $('#'+global.idAnnotation).find('.annotation-video-content'),
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    32
                tplVideo = $(templates).filter('#tpl-video-row').html();
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    33
            videoWrap.empty().append(tplVideo);
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    34
        });
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    35
        
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    36
    });
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    37
    //image
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    38
    $('.popup').on('click', '.bibliotheque-image a', function(e){
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    39
        e.preventDefault();
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    40
        var listDiaporama = $('#'+global.diaporama);
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    41
        addImageToDiaporama(listDiaporama);
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    42
        $('.popup').modal('hide');
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    43
    });
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    44
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    45
    $(document).on('click','.btn-delete', function(e){
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    46
        e.preventDefault();
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    47
        var titleMedia = $(this).attr('data-title'),
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    48
            textModal = $('<p>Êtes-vous sûr de vouloir supprimer <strong>'+titleMedia+'</strong> ?</p>'),
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    49
            eltDelete = $(this).attr('href');
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    50
        $("#modal-confirm #btn-delete-modal").attr('data-id-elt-delete', eltDelete);
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    51
        $("#modal-confirm .modal-body").empty().append(textModal); 
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    52
        $("#modal-confirm").modal('show');
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    53
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    54
        //si c'est une annotation et que la tab est ouverte, on la ferme
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    55
        var type = $(this).attr('data-type');
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    56
        if(type == 'annotation'){
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    57
            var idAnnotation = $(this).attr('data-id');
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    58
            $('a[href=#annotation-'+idAnnotation+']').closest('li').remove();
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    59
            $('.tab-content #annotation'+idAnnotation).remove();
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    60
            $('#tab-list-annotation').tab('show');
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    61
        }
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    62
    });
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    63
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    64
    //confirmation suppression
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    65
    $("#modal-confirm").on('click', '#btn-delete-modal', function(e){
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    66
        e.preventDefault();
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    67
        var idEltDelete = $(this).attr('data-id-elt-delete');
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    68
        $(idEltDelete).remove();
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    69
        $("#modal-confirm").modal('hide');
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    70
    });
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    71
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    72
    
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    73
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    74
//page edition
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    75
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    76
//title-editor
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    77
$('.project-title-editor ._popover').bind('click',function(e){e.preventDefault()});
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    78
    $('.project-title-editor ._popover').popover({
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    79
        html : true,
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    80
        content : function(){
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    81
            var previousValue = $('.project-title').text(),
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    82
                formInput = 
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    83
                    '<form action="#" class="project-title-editor-form">'+
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    84
                        '<input type="text" class="project-title-editor-input" value="'+previousValue+'">'+
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    85
                    '</form>';
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    86
            return formInput;
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    87
        }
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    88
    });
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    89
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    90
    $('body').on('click', function (e) {
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    91
        $('._popover').each(function () {
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    92
            if (!$(this).is(e.target) && $(this).has(e.target).length === 0 && $('.popover').has(e.target).length === 0) {
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    93
                $(this).popover('hide');
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    94
            }
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    95
        });
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    96
    });
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    97
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    98
    $('body').on('submit', '.project-title-editor-form', function(e){
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    99
        e.preventDefault();
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   100
        $('._popover').popover('hide');
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   101
    });
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   102
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   103
    $(document).on('keyup', '.project-title-editor-input', function() {
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   104
        $('.project-title').html($(this).val());
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   105
    });
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   106
//chapter
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   107
    $('.list-chapter-wrap').on('click', '.edit-chapter', function(e){
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   108
        e.preventDefault();
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   109
        var viewChapter = {
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   110
            titre : 'titre du chapitre',
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   111
            tags : 'tag 1, tag 2, tag 3',
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   112
            description : 'lorem ipsum'
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   113
        }
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   114
        
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   115
        $.get('template.html', function(templates){
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   116
            var tpl = $(templates).filter('#tpl-chapter-edit').html();
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   117
            var tpl = Mustache.render(tpl, viewChapter);
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   118
            $('.form-chapter-edit').empty().append(tpl);
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   119
        });
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   120
    });
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   121
    //nouveau chapitre
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   122
    $('.chapter-widget').on('click', '.btn-cut-chapter', function(e){
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   123
        e.preventDefault();
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   124
        var uniqId = 'id' + (new Date()).getTime();
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   125
        $.get('template.html', function(templates){
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   126
            var viewChapterRow = {
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   127
                    id : uniqId
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   128
                };
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   129
            var tpl = $(templates).filter('#tpl-chapter-row').html();
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   130
            var tpl = Mustache.render(tpl, viewChapterRow);
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   131
            $('.list-chapter-rows-wrap').append(tpl);
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   132
        });
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   133
    });
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   134
//tab
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   135
    $('#annotation-tab').on('click', 'a', function(e){
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   136
        e.preventDefault();
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   137
        $(this).tab('show');
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   138
    });
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   139
    $('#annotation-tab a:last-child').tab('show');
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   140
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   141
    //fermer tab
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   142
    $('#annotation-tab').on('click', 'span.close-tab', function(e){
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   143
        e.preventDefault();e.stopPropagation();
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   144
        var idTab = $(this).parents('a').attr('href');
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   145
        $(this).closest('li').remove();
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   146
        $('.tab-content '+idTab).remove();
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   147
        $('#tab-list-annotation').tab('show');
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   148
    });
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   149
    
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   150
    //ouvrir tab
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   151
    $(document).on('click', '.open-tab', function(e){
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   152
        e.preventDefault();
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   153
        var type = $(this).attr('data-type');
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   154
        var data = $(this).attr('data-data'); // à définir
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   155
        openNewTab(type);
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   156
    });
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   157
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   158
    //edit annotation
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   159
    $('#list-annotations').on('click', 'a.btn-edit-annotation', function(e){
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   160
        e.preventDefault();
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   161
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   162
        var idAnnotation = $(this).attr('data-id');
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   163
        //si il est déjà ouvert
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   164
        if($('#annotation-'+idAnnotation).length){
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   165
            $('a[href=#annotation-'+idAnnotation+']').tab('show');
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   166
        }else{
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   167
            var typeAnnotation = $(this).attr('data-type'),
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   168
                data = {id:idAnnotation};
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   169
            openNewTab(typeAnnotation, data);
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   170
        } 
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   171
    });
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   172
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   173
    function openNewTab(type, data){
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   174
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   175
        var uniqId = 'id' + (new Date()).getTime(),
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   176
            idAnnotation = (data !== undefined) ? data.id : uniqId,
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   177
            tabContent = $('<div class="tab-pane" id="annotation-'+idAnnotation+'"></div>'),
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   178
            iconTab;
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   179
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   180
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   181
        $.get('template.html', function(templates){
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   182
            //head commun à tous
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   183
            var view = {
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   184
                    titre : "un titre mustache",
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   185
                    id : uniqId
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   186
                };
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   187
            var tplHead = $(templates).filter('#tpl-head').html();
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   188
            var output = Mustache.render(tplHead, view);
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   189
            $(tabContent).append(output);
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   190
            $(tabContent).find(".slider-duration").slider(configSlider);
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   191
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   192
            //type
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   193
            var viewType = {id : uniqId};
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   194
            var tpl = $(templates).filter('#tpl-'+type).html();
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   195
            tpl = Mustache.render(tpl, viewType);
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   196
            $(tabContent).append(tpl);
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   197
            $('.tab-content').append(tabContent);
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   198
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   199
            //particularité selon type
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   200
            switch(type){
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   201
                case 'video': iconTab = 'film';
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   202
                    break;
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   203
                case 'text': 
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   204
                    iconTab = 'align-left';
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   205
                    $(tabContent).find('.wysiwyg').cleditor(wysiwygConfig);
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   206
                    break;
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   207
                case 'html': iconTab = 'link';
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   208
                    break;
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   209
                case 'diaporama': iconTab = 'picture';
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   210
                    $(tabContent).find('.number-spin').spin(spinParam);
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   211
                    $(tabContent).find('.ui-sortable').sortable({
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   212
                        stop : function(event, ui){
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   213
                            disabledBtnSortable($(this));
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   214
                        }
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   215
                    });
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   216
                    break;
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   217
            }
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   218
            $(".nav-tabs li:last-child").after('<li><a href="#annotation-'+idAnnotation+'"><i class="icon-'+iconTab+'"></i> New <span class="close-tab">&times;</span></a></li>');
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   219
            $('a[href=#annotation-'+idAnnotation+']').tab('show');
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   220
        });
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   221
    }//openNewTab()
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   222
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   223
//diaporama
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   224
function addImageToDiaporama(diaporama){
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   225
        $.get('template.html', function(templates){
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   226
            var tplDiapo = $(templates).filter('#tpl-diaporama-row').html(),
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   227
                uniqId = 'id' + (new Date()).getTime(),
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   228
                viewDiapo = { ridid : uniqId};
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   229
            tplDiapo = Mustache.render(tplDiapo, viewDiapo);
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   230
            diaporama.append(tplDiapo);
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   231
            disabledBtnSortable(diaporama);
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   232
        });
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   233
    };
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   234
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   235
    $(document).on('click', '.ui-sortable .btn-sort', function(e){
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   236
        e.preventDefault();
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   237
        var row = $(this).parents('tr.row-image-diaporama'),
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   238
            listDiaporama = $(this).parents('.list-image-diaporama');
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   239
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   240
        if($(this).hasClass('down'))
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   241
            row.insertAfter(row.next());
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   242
        else if($(this).hasClass('up'))
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   243
            row.insertBefore(row.prev());
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   244
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   245
        disabledBtnSortable(listDiaporama);
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   246
    });
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   247
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   248
    function disabledBtnSortable(listDiaporama){
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   249
        listDiaporama.find('.btn-sort.disabled').removeClass('disabled');
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   250
        listDiaporama.find('tr.row-image-diaporama:first-child').find('.btn-sort.up').addClass('disabled');
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   251
        listDiaporama.find('tr.row-image-diaporama:last-child').find('.btn-sort.down').addClass('disabled');
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   252
    }
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   253
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   254
    $(document).on('click', 'a.open-modal', function(e){
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   255
        e.preventDefault();
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   256
        var modalRemote = $(this).attr('href'),
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   257
            typeMedia = $(this).attr('data-type-media'),
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   258
            modalTitleInfo = $(this).attr('data-title'),
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   259
            diaporama = $(this).attr('data-diaporama'),
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   260
            idAnnotation = $(this).attr('data-id'),
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   261
            titleFront;
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   262
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   263
        if(diaporama !== undefined){
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   264
            global.diaporama = diaporama;
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   265
        }
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   266
        if(idAnnotation !== undefined){
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   267
            global.idAnnotation = idAnnotation;
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   268
        }
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   269
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   270
        switch(typeMedia){
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   271
            case 'video' : titleFront = '<i class="icon-film"></i> Vidéo - '+modalTitleInfo; break;
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   272
            case 'image' : titleFront = '<i class="icon-picture"></i> Image - '+modalTitleInfo; break;
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   273
        }
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   274
        $('#modal-template .modal-header h3').html(titleFront);
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   275
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   276
        $("#modal-template .modal-body").load(modalRemote, function() { 
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   277
            $("#modal-template").modal("show"); 
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   278
        });
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   279
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   280
    });
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   281
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   282
//sauvegarder annotation
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   283
$('.tab-content').on('click', '.btn-save-annotation', function(e){
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   284
    e.preventDefault();
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   285
    var idAnnotation = $(this).attr('data-id');
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   286
});
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   287
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   288
//annotation html
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   289
$('.tab-content').on('click', '.btn-html-apercu', function(e){
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   290
    e.preventDefault();
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   291
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   292
    var apercuWrap = $(this).parents('.edit-annotation-html').find('.html-apercu'),
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   293
        htmlTextarea = $(this).parents('.edit-annotation-html').find('textarea');
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   294
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   295
    apercuWrap.empty().html(htmlTextarea.val());
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   296
});
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   297
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   298
//annotation > diaporama (spin)
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   299
var spinParam = {
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   300
    imageBasePath :'lib/spin/img/',
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   301
    max:60,
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   302
    min:0
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   303
};
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   304
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   305
//config
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   306
//CLEditor annotation > text (wysiwyg)
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   307
//http://premiumsoftware.net/cleditor/docs/GettingStarted.html#optionalParameters
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   308
var wysiwygConfig = {
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   309
    width:        456, 
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   310
    height:       250, 
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   311
    controls:     "bold italic underline strikethrough | font size " +
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   312
                    "style | color highlight removeformat | bullets numbering | outdent ",
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   313
    fonts:        "Arial,Arial Black,Comic Sans MS,Courier New,Narrow,Garamond," +
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   314
                    "Georgia,Impact,Sans Serif,Serif,Tahoma,Trebuchet MS,Verdana",
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   315
    sizes:        "1,2,3,4,5,6,7",
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   316
    styles:       [["Paragraph", "<p>"], ["Header 1", "<h1>"], ["Header 2", "<h2>"],
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   317
                    ["Header 3", "<h3>"],  ["Header 4","<h4>"],  ["Header 5","<h5>"],
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   318
                    ["Header 6","<h6>"]],
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   319
    docType:      '<!DOCTYPE HTML>',
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   320
    bodyStyle:    "margin:0; font-family: 'Helvetica Neue',​Helvetica,​Arial,​sans-serif;"
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   321
};
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   322
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   323
//slider
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   324
var configSlider = {
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   325
    range: true,
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   326
    values: [ 0, 1*60*1000 ],
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   327
    min: 0,
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   328
    max: 10*60*1000,
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   329
    slide: function( event, ui ) {
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   330
        
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   331
        var debutString = millisecondsToString(ui.values[0]);
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   332
        var endString = millisecondsToString(ui.values[1]);
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   333
        var durationString = millisecondsToString(ui.values[1] - ui.values[0]);
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   334
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   335
        var idSlider = $(this).attr('data-id');
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   336
        
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   337
        $( '#'+ idSlider +'-begin' ).html(debutString);
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   338
        $( '#'+ idSlider +'-duration' ).html(durationString);
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   339
        $( '#'+ idSlider +'-end' ).html(endString);
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   340
        
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   341
    }
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   342
};
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   343
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   344
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   345
//test
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   346
if($(".wysiwyg").length){
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   347
    $(".wysiwyg").cleditor(wysiwygConfig);
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   348
}
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   349
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   350
if($(".number-spin").length){
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   351
    $('.number-spin').spin(spinParam);
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   352
}
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   353
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   354
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   355
disabledBtnSortable($('.ui-sortable'))
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   356
$('.ui-sortable').sortable({
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   357
    stop : function(event, ui){
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   358
        disabledBtnSortable($(this));
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   359
    }
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   360
});
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   361
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   362
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   363
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   364
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   365
$('.slider-duration').slider(configSlider);
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   366
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   367
function millisecondsToString(milliseconds) {
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   368
    var oneHour = 3600000;
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   369
    var oneMinute = 60000;
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   370
    var oneSecond = 1000;
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   371
    var seconds = 0;
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   372
    var minutes = 0;
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   373
    var hours = 0;
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   374
    var result;
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   375
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   376
    if (milliseconds >= oneHour) {
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   377
        hours = Math.floor(milliseconds / oneHour);
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   378
    }
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   379
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   380
    milliseconds = hours > 0 ? (milliseconds - hours * oneHour) : milliseconds;
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   381
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   382
    if (milliseconds >= oneMinute) {
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   383
        minutes = Math.floor(milliseconds / oneMinute);
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   384
    }
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   385
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   386
    milliseconds = minutes > 0 ? (milliseconds - minutes * oneMinute) : milliseconds;
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   387
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   388
    if (milliseconds >= oneSecond) {
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   389
        seconds = Math.floor(milliseconds / oneSecond);
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   390
    }
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   391
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   392
    milliseconds = seconds > 0 ? (milliseconds - seconds * oneSecond) : milliseconds;
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   393
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   394
    if (hours > 0) {
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   395
        result = (hours > 9 ? hours : "0" + hours) + "h";
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   396
    } else {
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   397
        result = "";
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   398
    }
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   399
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   400
    if (minutes > 0) {
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   401
        result += (minutes > 9 ? minutes : "0" + minutes) + "m";
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   402
    } else {
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   403
        result += "00m";
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   404
    }
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   405
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   406
    if (seconds > 0) {
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   407
        result += (seconds > 9 ? seconds : "0" + seconds) + "s";
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   408
    } else {
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   409
        result += "00s";
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   410
    }
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   411
/*
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   412
    if (milliseconds > 0) {
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   413
        result += (milliseconds > 9 ? milliseconds : "0" + milliseconds);
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   414
    } else {
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   415
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   416
        result += "00";
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   417
    }
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   418
*/
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   419
    return result;
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   420
}
547b3ddedf7f organisation des fichiers
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   421
})(jQuery);