integration/js/common.js
author ymh <ymh.work@gmail.com>
Tue, 12 May 2015 14:36:11 +0200
changeset 198 b7d90dd57afc
parent 174 a1656f70f1c9
permissions -rw-r--r--
increment version
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     1
$(function(){
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     2
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     3
    $.fn.hasAttr = function(name) {  
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     4
       return this.attr(name) !== undefined;
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     5
    };
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     6
174
a1656f70f1c9 center modal
Anthony Ly <anthonyly.com@gmail.com>
parents: 78
diff changeset
     7
    $('.modal').on('show', function () {
a1656f70f1c9 center modal
Anthony Ly <anthonyly.com@gmail.com>
parents: 78
diff changeset
     8
        var halfWidth = $(this).width() / 2;
a1656f70f1c9 center modal
Anthony Ly <anthonyly.com@gmail.com>
parents: 78
diff changeset
     9
        $(this).css({
a1656f70f1c9 center modal
Anthony Ly <anthonyly.com@gmail.com>
parents: 78
diff changeset
    10
            'margin-left' : - halfWidth +'px'
a1656f70f1c9 center modal
Anthony Ly <anthonyly.com@gmail.com>
parents: 78
diff changeset
    11
        });
a1656f70f1c9 center modal
Anthony Ly <anthonyly.com@gmail.com>
parents: 78
diff changeset
    12
    });
a1656f70f1c9 center modal
Anthony Ly <anthonyly.com@gmail.com>
parents: 78
diff changeset
    13
9
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    14
//open modal
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    15
    $(document).on('click', 'a.open-modal', function(e){
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    16
        e.preventDefault();
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    17
        var modalRemote = $(this).attr('href'),
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    18
            typeMedia = $(this).attr('data-type-media'),
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    19
            modalTitleInfo = $(this).attr('data-title'),
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    20
            hideBibliotheque = $(this).hasAttr('data-hide-bibliotheque') ? true : false,
66
dd2fbf4c998f hide add new on modal
Anthony Ly <anthonyly.com@gmail.com>
parents: 55
diff changeset
    21
            hideAddNew = $(this).hasAttr('data-hide-add-new') ? true : false,
78
5dddae65a99a iframe modal used for content preview
cavaliet
parents: 74
diff changeset
    22
            isIframe = $(this).hasAttr('data-iframe') ? true : false,
9
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    23
            titleFront;
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    24
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    25
        switch(typeMedia){
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    26
            case 'video' : titleFront = '<i class="icon-film"></i> Vidéo - '+modalTitleInfo; break;
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    27
            case 'image' : titleFront = '<i class="icon-picture"></i> Image - '+modalTitleInfo; break;
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    28
        }
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    29
        $('#modal-template .modal-header h3').html(titleFront);
78
5dddae65a99a iframe modal used for content preview
cavaliet
parents: 74
diff changeset
    30
        
5dddae65a99a iframe modal used for content preview
cavaliet
parents: 74
diff changeset
    31
        if(isIframe){
9
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    32
            if(hideBibliotheque)
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    33
                $("#modal-template").find(".bibliotheque-link").hide();
66
dd2fbf4c998f hide add new on modal
Anthony Ly <anthonyly.com@gmail.com>
parents: 55
diff changeset
    34
            if(hideAddNew)
dd2fbf4c998f hide add new on modal
Anthony Ly <anthonyly.com@gmail.com>
parents: 55
diff changeset
    35
                $("#modal-template").find(".add-new").hide();
9
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    36
78
5dddae65a99a iframe modal used for content preview
cavaliet
parents: 74
diff changeset
    37
            $("#modal-template .modal-body").html('<iframe src="' + modalRemote + '" seamless="seamless" width="580" height="440"></iframe>');
5dddae65a99a iframe modal used for content preview
cavaliet
parents: 74
diff changeset
    38
            $("#modal-template").modal("show");
5dddae65a99a iframe modal used for content preview
cavaliet
parents: 74
diff changeset
    39
        }
5dddae65a99a iframe modal used for content preview
cavaliet
parents: 74
diff changeset
    40
        else{
5dddae65a99a iframe modal used for content preview
cavaliet
parents: 74
diff changeset
    41
            $("#modal-template .modal-body").load(modalRemote, function() { 
5dddae65a99a iframe modal used for content preview
cavaliet
parents: 74
diff changeset
    42
                $("#modal-template").modal("show"); 
5dddae65a99a iframe modal used for content preview
cavaliet
parents: 74
diff changeset
    43
                if(hideBibliotheque)
5dddae65a99a iframe modal used for content preview
cavaliet
parents: 74
diff changeset
    44
                    $("#modal-template").find(".bibliotheque-link").hide();
5dddae65a99a iframe modal used for content preview
cavaliet
parents: 74
diff changeset
    45
                if(hideAddNew)
5dddae65a99a iframe modal used for content preview
cavaliet
parents: 74
diff changeset
    46
                    $("#modal-template").find(".add-new").hide();
5dddae65a99a iframe modal used for content preview
cavaliet
parents: 74
diff changeset
    47
            });
5dddae65a99a iframe modal used for content preview
cavaliet
parents: 74
diff changeset
    48
        }
9
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    49
    });
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    50
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    51
    $('.popup').on('click', '.popup-content a', function(e){
70
2542e988f80c no-prevent class on bibliotheque
Anthony Ly <anthonyly.com@gmail.com>
parents: 66
diff changeset
    52
        
2542e988f80c no-prevent class on bibliotheque
Anthony Ly <anthonyly.com@gmail.com>
parents: 66
diff changeset
    53
        if($(this).hasClass('no-prevent')){
2542e988f80c no-prevent class on bibliotheque
Anthony Ly <anthonyly.com@gmail.com>
parents: 66
diff changeset
    54
            return true;
2542e988f80c no-prevent class on bibliotheque
Anthony Ly <anthonyly.com@gmail.com>
parents: 66
diff changeset
    55
        }else{
2542e988f80c no-prevent class on bibliotheque
Anthony Ly <anthonyly.com@gmail.com>
parents: 66
diff changeset
    56
            e.preventDefault();
2542e988f80c no-prevent class on bibliotheque
Anthony Ly <anthonyly.com@gmail.com>
parents: 66
diff changeset
    57
        }
9
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    58
        if($(this).hasClass('btn-cancel')){
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    59
            $(this).parents('.popup').modal('hide');
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    60
        }
74
22aca5b735a2 edit and preview buttons on project div home page
Anthony Ly <anthonyly.com@gmail.com>
parents: 70
diff changeset
    61
9
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    62
    });
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    63
78
5dddae65a99a iframe modal used for content preview
cavaliet
parents: 74
diff changeset
    64
// empty modal when closed
5dddae65a99a iframe modal used for content preview
cavaliet
parents: 74
diff changeset
    65
      $("#modal-template .modal-header .close").click(function(e){
5dddae65a99a iframe modal used for content preview
cavaliet
parents: 74
diff changeset
    66
          $("#modal-template .modal-body").html('');
5dddae65a99a iframe modal used for content preview
cavaliet
parents: 74
diff changeset
    67
      });
5dddae65a99a iframe modal used for content preview
cavaliet
parents: 74
diff changeset
    68
9
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    69
//confirmation suppression
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    70
    $(document).on('click','.btn-delete', function(e){
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    71
        e.preventDefault();
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    72
        var titleMedia = $(this).attr('data-title'),
42
95e64fb6730f modal delete url
Anthony Ly <anthonyly.com@gmail.com>
parents: 21
diff changeset
    73
            urlDelete = $(this).attr('href');
95e64fb6730f modal delete url
Anthony Ly <anthonyly.com@gmail.com>
parents: 21
diff changeset
    74
        $("#modal-confirm #btn-delete-modal").attr('href', urlDelete).focus();
55
cedadc7d039a modal delete in html title update
Anthony Ly <anthonyly.com@gmail.com>
parents: 42
diff changeset
    75
        $("#modal-confirm .modal-body").find('.titleMedia').text(titleMedia);
9
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    76
        $("#modal-confirm").modal('show');
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    77
    });
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    78
21
abd04f346dbe delete row on enter key press in modal
Anthony Ly <anthonyly.com@gmail.com>
parents: 9
diff changeset
    79
    $("#modal-confirm").on('shown', function() {
74
22aca5b735a2 edit and preview buttons on project div home page
Anthony Ly <anthonyly.com@gmail.com>
parents: 70
diff changeset
    80
        $("#modal-confirm #btn-delete-modal").focus();
9
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    81
    });
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    82
    
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    83
});