Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / app / fusion / external / ebz / js / attHeaderSnippet.js
1 /* Popup Box function */
2 (function(){
3
4   $.fn.popbox = function(options){
5     settings = $.extend({
6       selector          : this.selector,
7       open              : '.openpopbox',
8       box               : '.box1',
9       arrow             : '.arrow',
10       arrow_border      : '.arrow-border',
11       close             : '.close'
12     }, options);
13
14     var methods = {
15       open: function(event){
16         event.preventDefault();
17         var pop = $(this);
18         var box = $(this).parent().find(settings['box']);
19         box.find(settings['arrow']).css({'left': box.width()/2 - 10 + 46});
20         box.find(settings['arrow_border']).css({'left': box.width()/2 - 10 - 63});
21         if(box.css('display') == 'block'){
22           /* methods.close();
23           setTimeout(function(){ $(".btn-panel-vertical,#actionsDropDown").css('z-index','999'); },200);
24         // $(".btn-panel-vertical,#actionsDropDown").css('z-index','999');
25             if($(window).scrollTop() > 20){
26                  setTimeout(function(){ $(".btn-panel-vertical,#actionsDropDown").css('z-index','-999'); },200);
27                   // $(".btn-panel-vertical,#actionsDropDown").css('z-index','-999');
28             };*/
29                          $('.box1').fadeIn('slow');
30         } else {
31            $('.chatBox').fadeOut('fast');
32           $(".btn-panel-vertical,#actionsDropDown").css('z-index','-999');
33                 if(box.attr('target') == 'auth'){
34                         box.find(settings['arrow']).css({'left': box.width()/2 + 36});
35                         box.css({'display': 'block', 'top': 0, 'left': ((pop.parent().parent().width()/2) -box.width()/2 ) - 90});
36                 }
37                 else{
38                         box.find(settings['arrow']).css({'left': box.width()/2 - 42});
39                         box.css({'display': 'block', 'top': 0, 'left': ((pop.parent().parent().width()/2) -box.width()/2-15 )});
40                         box.find("#header_login_id").focus();
41                         box.find('#header_password').val('');
42                         }
43         }
44       },
45
46       close: function(){
47         $(settings['box']).fadeOut("fast");
48       }
49     };
50     
51     $(document).bind('keyup', function(event){
52       if(event.keyCode == 27){
53         setTimeout(function(){ $(".btn-panel-vertical,#actionsDropDown").css('z-index','999'); },200);
54         // $(".btn-panel-vertical,#actionsDropDown").css('z-index','999');
55         if($(window).scrollTop() > 20){
56            // setTimeout(function(){ $(".btn-panel-vertical,#actionsDropDown").css('z-index','-999'); },200);
57           $(".btn-panel-vertical,#actionsDropDown").css('z-index','-999');
58         };
59         methods.close();
60       }
61     });
62  // Close chat-box and popup on clicking out of chat-box
63     $(document).bind('click', function(event){
64       if(!($(event.target).closest('.chatBox').length || $(event.target).hasClass('chatIcon') || $(event.target).closest(settings['selector']).length)){
65         methods.close();
66          if ($("#actionsDropDown").css('z-index')=='-999'){
67            setTimeout(function(){ $(".btn-panel-vertical,#actionsDropDown").css('z-index','999'); },200);
68         }
69         if($(window).scrollTop() > 20){
70            setTimeout(function(){ $(".btn-panel-vertical,#actionsDropDown").css('z-index','-999'); },200);
71            // $(".btn-panel-vertical,#actionsDropDown").css('z-index','-999');
72         };
73        
74           $('.chatBox').fadeOut('fast');
75         
76       }
77     });
78
79     return this.each(function(){
80
81       $(this).css({'width': $(settings['box']).width()}); // Width needs to be set otherwise popbox will not move when window resized.
82       $(settings['open'], this).bind('click', methods.open);
83       $(".btn-panel-vertical,#actionsDropDown").css('z-index','-999');
84       $(settings['open'], this).parent().find(settings['close']).bind('click', function(event){
85         // $(".btn-panel-vertical,#actionsDropDown").css('z-index','999');
86         setTimeout(function(){ $(".btn-panel-vertical,#actionsDropDown").css('z-index','999'); },200);
87         methods.close();
88       });
89     });
90   }
91
92 }).call(this);
93
94
95 $('.popbox').popbox();
96
97 $(function(){
98         var displayName = "";
99         if($("#reg-fn-ln-id").length > 0){
100                 var fnln = $("#reg-fn-ln-id").val().length; 
101                 if(fnln > 0){
102                         var fnVar = $("#reg-fname-id").val();
103                         var lnVar = $("#reg-lname-id").val();
104                         var numChars = 13;
105                         var nameLen = fnVar.length + lnVar.length + 1; // 1 for space between the first name and the last name
106                         if(fnVar != " " && lnVar != " "){
107                                 if(nameLen <= numChars){
108                                         displayName = fnVar+" "+lnVar;
109                                 }else if(nameLen <= (numChars * 2)){
110                                                 displayName = fnVar+"<br/>"+lnVar;
111                                         }else
112                                                 {
113                                                         if(fnVar.length < numChars && lnVar.length > numChars){ //Smaller first name and longer last name                                                       
114                                                                 displayName = fnVar+"<br/>"+lnVar.substring(0,numChars-1)+"...";
115                                                         }
116                                                         
117                                                         if(fnVar.length >= numChars ){ //Longer first name
118                                                                 // 2 = 1 for elipses, 1 for space between the first name and last name
119                                                                 longLName = numChars - ((fnVar.substring(numChars,fnVar.length)).length + 2); 
120                                                                 displayName = fnVar.substring(0,numChars)+"<br/>"+fnVar.substring(numChars,fnVar.length)+" "+lnVar.substring(0,longLName)+"...";
121                                                         }
122                                                 }               
123                         }
124                         else{
125                                 displayName = fnVar+" "+lnVar;
126                         }
127                 }       
128                 
129                 $("#reg-userName").html(displayName);
130         }
131 });
132
133 /* ClickToChat ANONYMOUS FUNCTION DEFINITION       *
134  * =============================================== *
135  * On clicking the chat icon displays the chat box */
136 (function(){
137
138   var chatbox = $('.chatBox'); 
139
140   // var actionsDropDown = $('#actionsDropDown');
141   var methods = {
142     open: function(){chatbox.css('display','block');},
143     close: function(){chatbox.fadeOut('fast');}
144   };
145   $('.chatIcon').click(function(){
146     if (chatbox.css('display') == 'block'){
147       methods.close();
148       setTimeout(function(){ $(".btn-panel-vertical,#actionsDropDown").css('z-index','999'); },200);
149        // $(".btn-panel-vertical,#actionsDropDown").css('z-index','999');
150       if($(window).scrollTop() > 20){
151            setTimeout(function(){ $(".btn-panel-vertical,#actionsDropDown").css('z-index','-999'); },200);
152             // $(".btn-panel-vertical,#actionsDropDown").css('z-index','-999');
153       };
154     } else {
155        $(".btn-panel-vertical,#actionsDropDown").css('z-index','-999');
156       methods.open();
157       $(settings['box']).fadeOut("fast");
158     }
159   });
160
161   // Close chat-box on clicking cross icon
162   $('.circle_close_chat').click(function(){
163     // $(".btn-panel-vertical,#actionsDropDown").css('z-index','999');
164     setTimeout(function(){ $(".btn-panel-vertical,#actionsDropDown").css('z-index','999'); },200);
165     methods.close();
166     if($(window).scrollTop() > 20){
167        setTimeout(function(){ $(".btn-panel-vertical,#actionsDropDown").css('z-index','-999'); },200);
168        // $(".btn-panel-vertical,#actionsDropDown").css('z-index','-999');
169     };
170   });
171
172   // Close chat-box on Escape key press
173   $(document).bind('keyup', function(event){
174     if(event.keyCode == 27){ 
175       setTimeout(function(){ $(".btn-panel-vertical,#actionsDropDown").css('z-index','999'); },200);
176       methods.close();
177       if($(window).scrollTop() > 20){
178            setTimeout(function(){ $(".btn-panel-vertical,#actionsDropDown").css('z-index','-999'); },200);
179            //$(".btn-panel-vertical,#actionsDropDown").css('z-index','-999');
180       };
181     }
182   });
183
184   // Close chat-box on clicking out of chat-box
185   // $(document).bind('click', function(event){
186
187   //   console.log(event.target,"2");
188   //   if(!($(event.target).closest('.chatBox').length || $(event.target).hasClass('chatIcon'))) {
189   //     event.preventDefault();
190   //   // console.log($(event.target).closest(settings['selector']).length);
191   //   console.log($(event.target).closest('.   ').length);
192   //   console.log($(event.target).hasClass('chatIcon'));
193
194
195   //     // $(".btn-panel-vertical,#actionsDropDown").css('z-index','999');
196   //     methods.close();
197   //     if ($("#actionsDropDown").css('z-index')=='-999') {
198   //       $(".btn-panel-vertical,#actionsDropDown").css('z-index','999');
199   //     };
200   //     // if (flag!="clicked") {
201   //     //   if ($('.box').css('display') == 'block' || $('.chatBox').css('display') == 'block' ){
202   //     //     $(".btn-panel-vertical,#actionsDropDown").css('z-index','-999');
203   //     //   } else {
204   //     //     $(".btn-panel-vertical,#actionsDropDown").css('z-index','999');
205   //     //   }
206   //     // }
207   //    }
208   // });
209
210 })();