integration/js/common.js
author cavaliet
Wed, 05 Jun 2013 11:56:20 +0200
changeset 78 5dddae65a99a
parent 74 22aca5b735a2
child 174 a1656f70f1c9
permissions -rw-r--r--
iframe modal used for content preview
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
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     7
//open modal
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     8
    $(document).on('click', 'a.open-modal', function(e){
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     9
        e.preventDefault();
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    10
        var modalRemote = $(this).attr('href'),
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    11
            typeMedia = $(this).attr('data-type-media'),
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    12
            modalTitleInfo = $(this).attr('data-title'),
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    13
            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
    14
            hideAddNew = $(this).hasAttr('data-hide-add-new') ? true : false,
78
5dddae65a99a iframe modal used for content preview
cavaliet
parents: 74
diff changeset
    15
            isIframe = $(this).hasAttr('data-iframe') ? true : false,
9
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    16
            titleFront;
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    17
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    18
        switch(typeMedia){
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    19
            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
    20
            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
    21
        }
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    22
        $('#modal-template .modal-header h3').html(titleFront);
78
5dddae65a99a iframe modal used for content preview
cavaliet
parents: 74
diff changeset
    23
        
5dddae65a99a iframe modal used for content preview
cavaliet
parents: 74
diff changeset
    24
        if(isIframe){
9
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    25
            if(hideBibliotheque)
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    26
                $("#modal-template").find(".bibliotheque-link").hide();
66
dd2fbf4c998f hide add new on modal
Anthony Ly <anthonyly.com@gmail.com>
parents: 55
diff changeset
    27
            if(hideAddNew)
dd2fbf4c998f hide add new on modal
Anthony Ly <anthonyly.com@gmail.com>
parents: 55
diff changeset
    28
                $("#modal-template").find(".add-new").hide();
9
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    29
78
5dddae65a99a iframe modal used for content preview
cavaliet
parents: 74
diff changeset
    30
            $("#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
    31
            $("#modal-template").modal("show");
5dddae65a99a iframe modal used for content preview
cavaliet
parents: 74
diff changeset
    32
        }
5dddae65a99a iframe modal used for content preview
cavaliet
parents: 74
diff changeset
    33
        else{
5dddae65a99a iframe modal used for content preview
cavaliet
parents: 74
diff changeset
    34
            $("#modal-template .modal-body").load(modalRemote, function() { 
5dddae65a99a iframe modal used for content preview
cavaliet
parents: 74
diff changeset
    35
                $("#modal-template").modal("show"); 
5dddae65a99a iframe modal used for content preview
cavaliet
parents: 74
diff changeset
    36
                if(hideBibliotheque)
5dddae65a99a iframe modal used for content preview
cavaliet
parents: 74
diff changeset
    37
                    $("#modal-template").find(".bibliotheque-link").hide();
5dddae65a99a iframe modal used for content preview
cavaliet
parents: 74
diff changeset
    38
                if(hideAddNew)
5dddae65a99a iframe modal used for content preview
cavaliet
parents: 74
diff changeset
    39
                    $("#modal-template").find(".add-new").hide();
5dddae65a99a iframe modal used for content preview
cavaliet
parents: 74
diff changeset
    40
            });
5dddae65a99a iframe modal used for content preview
cavaliet
parents: 74
diff changeset
    41
        }
9
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    42
    });
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    43
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    44
    $('.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
    45
        
2542e988f80c no-prevent class on bibliotheque
Anthony Ly <anthonyly.com@gmail.com>
parents: 66
diff changeset
    46
        if($(this).hasClass('no-prevent')){
2542e988f80c no-prevent class on bibliotheque
Anthony Ly <anthonyly.com@gmail.com>
parents: 66
diff changeset
    47
            return true;
2542e988f80c no-prevent class on bibliotheque
Anthony Ly <anthonyly.com@gmail.com>
parents: 66
diff changeset
    48
        }else{
2542e988f80c no-prevent class on bibliotheque
Anthony Ly <anthonyly.com@gmail.com>
parents: 66
diff changeset
    49
            e.preventDefault();
2542e988f80c no-prevent class on bibliotheque
Anthony Ly <anthonyly.com@gmail.com>
parents: 66
diff changeset
    50
        }
9
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    51
        if($(this).hasClass('btn-cancel')){
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    52
            $(this).parents('.popup').modal('hide');
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    53
        }
74
22aca5b735a2 edit and preview buttons on project div home page
Anthony Ly <anthonyly.com@gmail.com>
parents: 70
diff changeset
    54
9
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    55
    });
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    56
78
5dddae65a99a iframe modal used for content preview
cavaliet
parents: 74
diff changeset
    57
// empty modal when closed
5dddae65a99a iframe modal used for content preview
cavaliet
parents: 74
diff changeset
    58
      $("#modal-template .modal-header .close").click(function(e){
5dddae65a99a iframe modal used for content preview
cavaliet
parents: 74
diff changeset
    59
          $("#modal-template .modal-body").html('');
5dddae65a99a iframe modal used for content preview
cavaliet
parents: 74
diff changeset
    60
      });
5dddae65a99a iframe modal used for content preview
cavaliet
parents: 74
diff changeset
    61
9
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    62
//confirmation suppression
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    63
    $(document).on('click','.btn-delete', function(e){
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    64
        e.preventDefault();
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    65
        var titleMedia = $(this).attr('data-title'),
42
95e64fb6730f modal delete url
Anthony Ly <anthonyly.com@gmail.com>
parents: 21
diff changeset
    66
            urlDelete = $(this).attr('href');
95e64fb6730f modal delete url
Anthony Ly <anthonyly.com@gmail.com>
parents: 21
diff changeset
    67
        $("#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
    68
        $("#modal-confirm .modal-body").find('.titleMedia').text(titleMedia);
9
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    69
        $("#modal-confirm").modal('show');
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    70
    });
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    71
21
abd04f346dbe delete row on enter key press in modal
Anthony Ly <anthonyly.com@gmail.com>
parents: 9
diff changeset
    72
    $("#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
    73
        $("#modal-confirm #btn-delete-modal").focus();
9
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    74
    });
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    75
    
e3d551eda5a6 ajout de common.js
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    76
});