]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/themes/Sugar5/js/style.js
Release 6.4.1
[Github/sugarcrm.git] / jssource / src_files / themes / Sugar5 / js / style.js
1 /*********************************************************************************
2  * SugarCRM Community Edition is a customer relationship management program developed by
3  * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
4  * 
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU Affero General Public License version 3 as published by the
7  * Free Software Foundation with the addition of the following permission added
8  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
9  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
10  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
11  * 
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
15  * details.
16  * 
17  * You should have received a copy of the GNU Affero General Public License along with
18  * this program; if not, see http://www.gnu.org/licenses or write to the Free
19  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20  * 02110-1301 USA.
21  * 
22  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
23  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
24  * 
25  * The interactive user interfaces in modified source and object code versions
26  * of this program must display Appropriate Legal Notices, as required under
27  * Section 5 of the GNU Affero General Public License version 3.
28  * 
29  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
30  * these Appropriate Legal Notices must retain the display of the "Powered by
31  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
32  * technical reasons, the Appropriate Legal Notices must display the words
33  * "Powered by SugarCRM".
34  ********************************************************************************/
35
36  
37
38
39 /**
40  * Handles loading the sitemap popup
41  */
42 YAHOO.util.Event.onAvailable('sitemapLinkSpan',function()
43 {
44     document.getElementById('sitemapLinkSpan').onclick = function()
45     {
46         ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_LOADING_PAGE'));
47     
48         var smMarkup = '';
49         var callback = {
50              success:function(r) {     
51                  ajaxStatus.hideStatus();
52                  document.getElementById('sm_holder').innerHTML = r.responseText;
53                  with ( document.getElementById('sitemap').style ) {
54                      display = "block";
55                      position = "absolute";
56                      right = 0;
57                      top = 80;
58                  }
59                  document.getElementById('sitemapClose').onclick = function()
60                  {
61                      document.getElementById('sitemap').style.display = "none";
62                  }
63              } 
64         } 
65         postData = 'module=Home&action=sitemap&GetSiteMap=now&sugar_body_only=true';    
66         YAHOO.util.Connect.asyncRequest('POST', 'index.php', callback, postData);
67     }
68 });
69
70
71 function IKEADEBUG()
72 {
73     var moduleLinks = document.getElementById('moduleList').getElementsByTagName("a");
74     moduleLinkMouseOver = function() 
75         {
76             var matches      = /grouptab_([0-9]+)/i.exec(this.id);
77             var tabNum       = matches[1];
78             var moduleGroups = document.getElementById('subModuleList').getElementsByTagName("span"); 
79             for (var i = 0; i < moduleGroups.length; i++) { 
80                 if ( i == tabNum ) {
81                     moduleGroups[i].className = 'selected';
82                 }
83                 else {
84                     moduleGroups[i].className = '';
85                 }
86             }
87             
88             var groupList = document.getElementById('moduleList').getElementsByTagName("li");
89                         var currentGroupItem = tabNum;
90             for (var i = 0; i < groupList.length; i++) {
91                 var aElem = groupList[i].getElementsByTagName("a")[0];
92                 if ( aElem == null ) {
93                     // This is the blank <li> tag at the start of some themes, skip it
94                     continue;
95                 }
96                 // notCurrentTabLeft, notCurrentTabRight, notCurrentTab
97                 var classStarter = 'notC';
98                 if ( aElem.id == "grouptab_"+tabNum ) {
99                     // currentTabLeft, currentTabRight, currentTab
100                     classStarter = 'c';
101                                         currentGroupItem = i;
102                 }
103                 var spanTags = groupList[i].getElementsByTagName("span");
104                 for (var ii = 0 ; ii < spanTags.length; ii++ ) {
105                     if ( spanTags[ii].className == null ) { continue; }
106                     var oldClass = spanTags[ii].className.match(/urrentTab.*/);
107                     spanTags[ii].className = classStarter + oldClass;
108                 }
109             }
110             ////////////////////////////////////////////////////////////////////////////////////////
111                         ////update submenu position
112                         //get sub menu dom node
113                         var menuHandle = moduleGroups[tabNum];
114                         
115                         //get group tab dom node
116                         var parentMenu = groupList[currentGroupItem];
117
118                         if(menuHandle && parentMenu){
119                                 updateSubmenuPosition(menuHandle , parentMenu);
120                         }
121                         ////////////////////////////////////////////////////////////////////////////////////////
122         };
123     for (var i = 0; i < moduleLinks.length; i++) {
124         moduleLinks[i].onmouseover = moduleLinkMouseOver;
125     }
126 };
127
128 function updateSubmenuPosition(menuHandle , parentMenu){        
129         var left='';
130         if (left == "") {
131                 p = parentMenu;
132                 var left = 0;
133                 while(p&&p.tagName.toUpperCase()!='BODY'){
134                         left+=p.offsetLeft;
135                         p=p.offsetParent;
136                 }
137         }
138
139         //get browser width
140         var bw = checkBrowserWidth();
141         
142         //If the mouse over on 'MoreMenu' group tab, stop the following function
143         if(!parentMenu){
144                 return;
145         }
146         //Calculate left position of the middle of current group tab .
147         var groupTabLeft = left + (parentMenu.offsetWidth / 2);
148         var subTabHalfLength = 0;
149         var children = menuHandle.getElementsByTagName('li');
150         for(var i = 0; i< children.length; i++){
151                 //offsetWidth = width + padding + border
152                 if(children[i].className == 'subTabMore' || children[i].parentNode.className == 'cssmenu'){
153                         continue;
154                 }
155                 subTabHalfLength += parseInt(children[i].offsetWidth);
156         }
157         
158         if(subTabHalfLength != 0){
159                 subTabHalfLength = subTabHalfLength / 2;
160         }
161         
162         var totalLengthInTheory = subTabHalfLength + groupTabLeft;
163         if(subTabHalfLength>0 && groupTabLeft >0){
164                 if(subTabHalfLength >= groupTabLeft){
165                         left = 1;
166                 }else{
167                         left = groupTabLeft - subTabHalfLength;
168                 }
169         }
170         
171         //If the sub menu length > browser length
172         if(totalLengthInTheory > bw){
173                 var differ = totalLengthInTheory - bw;
174                 left = groupTabLeft - subTabHalfLength - differ - 2;
175         }
176         
177         if (left >=0){
178                 menuHandle.style.marginLeft = left+'px';
179         }
180 }
181
182 YAHOO.util.Event.onDOMReady(function()
183 {
184         if ( document.getElementById('subModuleList') ) {
185             ////////////////////////////////////////////////////////////////////////////////////////
186         ////update current submenu position
187         var parentMenu = false;
188         var moduleListDom = document.getElementById('moduleList');
189         if(moduleListDom !=null){
190             var parentTabLis = moduleListDom.getElementsByTagName("li");
191             var tabNum = 0;
192             for(var ii = 0; ii < parentTabLis.length; ii++){
193                 var spans = parentTabLis[ii].getElementsByTagName("span");
194                 for(var jj =0; jj < spans.length; jj++){
195                     if(spans[jj].className.match(/currentTab.*/)){
196                         tabNum = ii;
197                     }
198                 }
199             }
200             var parentMenu = parentTabLis[tabNum];
201         }
202         var moduleGroups = document.getElementById('subModuleList').getElementsByTagName("span"); 
203         for(var i = 0; i < moduleGroups.length; i++){
204             if(moduleGroups[i].className.match(/selected/)){
205                 tabNum = i;
206             }
207         }
208         var menuHandle = moduleGroups[tabNum];
209         
210         if(menuHandle && parentMenu){
211             updateSubmenuPosition(menuHandle , parentMenu);
212         }
213     }
214         ////////////////////////////////////////////////////////////////////////////////////////
215 });
216
217 /**
218  * For the module list menu
219  */
220 SUGAR.themes = SUGAR.namespace("themes");
221
222 SUGAR.append(SUGAR.themes, {
223     allMenuBars: {},
224     setModuleTabs: function(html) {
225         var el = document.getElementById('ajaxHeader');
226
227         if (el) {
228             try {
229                 //This can fail hard if multiple events fired at the same time
230                 YAHOO.util.Event.purgeElement(el, true);
231                 for (var i in this.allMenuBars) {
232                     if (this.allMenuBars[i].destroy)
233                         this.allMenuBars[i].destroy();
234                 }
235             } catch (e) {
236                 //If the menu fails to load, we can get leave the user stranded, reload the page instead.
237                 window.location.reload();
238             }
239
240             if (el.hasChildNodes()) {
241                 while (el.childNodes.length >= 1) {
242                     el.removeChild(el.firstChild);
243                 }
244             }
245
246             el.innerHTML += html;
247             this.loadModuleList();
248         }
249     },
250     
251     loadModuleList: function() {
252         var nodes = YAHOO.util.Selector.query('#moduleList>div'),
253             currMenuBar;
254         this.allMenuBars = {};
255
256         for (var i = 0 ; i < nodes.length ; i++) {
257             currMenuBar = SUGAR.themes.currMenuBar = new YAHOO.widget.MenuBar(nodes[i].id, {
258                 autosubmenudisplay: true,
259                 visible: false,
260                 hidedelay: 750,
261                 lazyload: true
262             });
263
264             /*
265               Call the "render" method with no arguments since the
266               markup for this MenuBar already exists in the page.
267             */
268             currMenuBar.render();
269             this.allMenuBars[nodes[i].id.substr(nodes[i].id.indexOf('_')+1)] = currMenuBar;
270
271             if (typeof YAHOO.util.Dom.getChildren(nodes[i]) == 'object' && YAHOO.util.Dom.getChildren(nodes[i]).shift().style.display != 'none') {
272                 // This is the currently displayed menu bar
273                 oMenuBar = currMenuBar;
274             }
275         }
276         /**
277          * Handles changing the sub menu items when using grouptabs
278          */
279         YAHOO.util.Event.onAvailable('subModuleList',IKEADEBUG);
280     }
281 });
282
283 YAHOO.util.Event.onDOMReady(SUGAR.themes.loadModuleList, SUGAR.themes, true);