]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/themes/Sugar5/js/style.js
Release 6.5.0
[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         //set up any action style menus
40         $(document).ready(function(){
41                 $("ul.clickMenu").each(function(index, node){
42                         $(node).sugarActionMenu();
43                 });
44         });
45
46 /**
47  * Handles loading the sitemap popup
48  */
49 YAHOO.util.Event.onAvailable('sitemapLinkSpan',function()
50 {
51     document.getElementById('sitemapLinkSpan').onclick = function()
52     {
53         ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_LOADING_PAGE'));
54     
55         var smMarkup = '';
56         var callback = {
57              success:function(r) {     
58                  ajaxStatus.hideStatus();
59                  document.getElementById('sm_holder').innerHTML = r.responseText;
60                  with ( document.getElementById('sitemap').style ) {
61                      display = "block";
62                      position = "absolute";
63                      right = 0;
64                      top = 80;
65                  }
66                  document.getElementById('sitemapClose').onclick = function()
67                  {
68                      document.getElementById('sitemap').style.display = "none";
69                  }
70              } 
71         } 
72         postData = 'module=Home&action=sitemap&GetSiteMap=now&sugar_body_only=true';    
73         YAHOO.util.Connect.asyncRequest('POST', 'index.php', callback, postData);
74     }
75 });
76
77
78 function IKEADEBUG()
79 {
80     var moduleLinks = document.getElementById('moduleList').getElementsByTagName("a");
81     moduleLinkMouseOver = function() 
82         {
83             var matches      = /grouptab_([0-9]+)/i.exec(this.id);
84             var tabNum       = matches[1];
85             var moduleGroups = document.getElementById('subModuleList').getElementsByTagName("span"); 
86             for (var i = 0; i < moduleGroups.length; i++) { 
87                 if ( i == tabNum ) {
88                     moduleGroups[i].className = 'selected';
89                 }
90                 else {
91                     moduleGroups[i].className = '';
92                 }
93             }
94             
95             var groupList = document.getElementById('moduleList').getElementsByTagName("li");
96                         var currentGroupItem = tabNum;
97             for (var i = 0; i < groupList.length; i++) {
98                 var aElem = groupList[i].getElementsByTagName("a")[0];
99                 if ( aElem == null ) {
100                     // This is the blank <li> tag at the start of some themes, skip it
101                     continue;
102                 }
103                 // notCurrentTabLeft, notCurrentTabRight, notCurrentTab
104                 var classStarter = 'notC';
105                 if ( aElem.id == "grouptab_"+tabNum ) {
106                     // currentTabLeft, currentTabRight, currentTab
107                     classStarter = 'c';
108                                         currentGroupItem = i;
109                 }
110                 var spanTags = groupList[i].getElementsByTagName("span");
111                 for (var ii = 0 ; ii < spanTags.length; ii++ ) {
112                     if ( spanTags[ii].className == null ) { continue; }
113                     var oldClass = spanTags[ii].className.match(/urrentTab.*/);
114                     spanTags[ii].className = classStarter + oldClass;
115                 }
116             }
117             ////////////////////////////////////////////////////////////////////////////////////////
118                         ////update submenu position
119                         //get sub menu dom node
120                         var menuHandle = moduleGroups[tabNum];
121                         
122                         //get group tab dom node
123                         var parentMenu = groupList[currentGroupItem];
124
125                         if(menuHandle && parentMenu){
126                                 updateSubmenuPosition(menuHandle , parentMenu);
127                         }
128                         ////////////////////////////////////////////////////////////////////////////////////////
129         };
130     for (var i = 0; i < moduleLinks.length; i++) {
131         moduleLinks[i].onmouseover = moduleLinkMouseOver;
132     }
133 };
134
135 function updateSubmenuPosition(menuHandle , parentMenu){        
136         var left='';
137         if (left == "") {
138                 p = parentMenu;
139                 var left = 0;
140                 while(p&&p.tagName.toUpperCase()!='BODY'){
141                         left+=p.offsetLeft;
142                         p=p.offsetParent;
143                 }
144         }
145
146         //get browser width
147         var bw = checkBrowserWidth();
148         
149         //If the mouse over on 'MoreMenu' group tab, stop the following function
150         if(!parentMenu){
151                 return;
152         }
153         //Calculate left position of the middle of current group tab .
154         var groupTabLeft = left + (parentMenu.offsetWidth / 2);
155         var subTabHalfLength = 0;
156         var children = menuHandle.getElementsByTagName('li');
157         for(var i = 0; i< children.length; i++){
158                 //offsetWidth = width + padding + border
159                 if(children[i].className == 'subTabMore' || children[i].parentNode.className == 'cssmenu'){
160                         continue;
161                 }
162                 subTabHalfLength += parseInt(children[i].offsetWidth);
163         }
164         
165         if(subTabHalfLength != 0){
166                 subTabHalfLength = subTabHalfLength / 2;
167         }
168         
169         var totalLengthInTheory = subTabHalfLength + groupTabLeft;
170         if(subTabHalfLength>0 && groupTabLeft >0){
171                 if(subTabHalfLength >= groupTabLeft){
172                         left = 1;
173                 }else{
174                         left = groupTabLeft - subTabHalfLength;
175                 }
176         }
177         
178         //If the sub menu length > browser length
179         if(totalLengthInTheory > bw){
180                 var differ = totalLengthInTheory - bw;
181                 left = groupTabLeft - subTabHalfLength - differ - 2;
182         }
183         
184         if (left >=0){
185                 menuHandle.style.marginLeft = left+'px';
186         }
187 }
188
189 YAHOO.util.Event.onDOMReady(function()
190 {
191         if ( document.getElementById('subModuleList') ) {
192             ////////////////////////////////////////////////////////////////////////////////////////
193         ////update current submenu position
194         var parentMenu = false;
195         var moduleListDom = document.getElementById('moduleList');
196         if(moduleListDom !=null){
197             var parentTabLis = moduleListDom.getElementsByTagName("li");
198             var tabNum = 0;
199             for(var ii = 0; ii < parentTabLis.length; ii++){
200                 var spans = parentTabLis[ii].getElementsByTagName("span");
201                 for(var jj =0; jj < spans.length; jj++){
202                     if(spans[jj].className.match(/currentTab.*/)){
203                         tabNum = ii;
204                     }
205                 }
206             }
207             var parentMenu = parentTabLis[tabNum];
208         }
209         var moduleGroups = document.getElementById('subModuleList').getElementsByTagName("span"); 
210         for(var i = 0; i < moduleGroups.length; i++){
211             if(moduleGroups[i].className.match(/selected/)){
212                 tabNum = i;
213             }
214         }
215         var menuHandle = moduleGroups[tabNum];
216         
217         if(menuHandle && parentMenu){
218             updateSubmenuPosition(menuHandle , parentMenu);
219         }
220     }
221         ////////////////////////////////////////////////////////////////////////////////////////
222 });
223
224 /**
225  * For the module list menu
226  */
227 SUGAR.themes = SUGAR.namespace("themes");
228
229 SUGAR.append(SUGAR.themes, {
230     allMenuBars: {},
231     setModuleTabs: function(html) {
232         var el = document.getElementById('ajaxHeader');
233
234         if (el) {
235             try {
236                 //This can fail hard if multiple events fired at the same time
237                 YAHOO.util.Event.purgeElement(el, true);
238                 for (var i in this.allMenuBars) {
239                     if (this.allMenuBars[i].destroy)
240                         this.allMenuBars[i].destroy();
241                 }
242             } catch (e) {
243                 //If the menu fails to load, we can get leave the user stranded, reload the page instead.
244                 window.location.reload();
245             }
246
247             if (el.hasChildNodes()) {
248                 while (el.childNodes.length >= 1) {
249                     el.removeChild(el.firstChild);
250                 }
251             }
252
253             el.innerHTML += html;
254             this.loadModuleList();
255         }
256     },
257     actionMenu: function() {
258         //set up any action style menus
259         $("ul.clickMenu").each(function(index, node){
260             $(node).sugarActionMenu();
261         });
262     },
263     loadModuleList: function() {
264         var nodes = YAHOO.util.Selector.query('#moduleList>div'),
265             currMenuBar;
266         this.allMenuBars = {};
267
268         for (var i = 0 ; i < nodes.length ; i++) {
269             currMenuBar = SUGAR.themes.currMenuBar = new YAHOO.widget.MenuBar(nodes[i].id, {
270                 autosubmenudisplay: true,
271                 visible: false,
272                 hidedelay: 750,
273                 lazyload: true
274             });
275
276             /*
277               Call the "render" method with no arguments since the
278               markup for this MenuBar already exists in the page.
279             */
280             currMenuBar.render();
281             this.allMenuBars[nodes[i].id.substr(nodes[i].id.indexOf('_')+1)] = currMenuBar;
282
283             if (typeof YAHOO.util.Dom.getChildren(nodes[i]) == 'object' && YAHOO.util.Dom.getChildren(nodes[i]).shift().style.display != 'none') {
284                 // This is the currently displayed menu bar
285                 oMenuBar = currMenuBar;
286             }
287         }
288         /**
289          * Handles changing the sub menu items when using grouptabs
290          */
291         YAHOO.util.Event.onAvailable('subModuleList',IKEADEBUG);
292     },
293     //dummy function to make classic theme work with 6.5
294     setCurrentTab: function(){}
295 });
296
297 YAHOO.util.Event.onDOMReady(SUGAR.themes.loadModuleList, SUGAR.themes, true);