PageRenderTime 91ms CodeModel.GetById 40ms app.highlight 17ms RepoModel.GetById 23ms app.codeStats 8ms

/Documentation/Help/scripts/script_prototype.js

#
JavaScript | 189 lines | 144 code | 45 blank | 0 comment | 68 complexity | 551591183acdadd896b9c72b1c42a301 MD5 | raw file
  1window.onload = LoadPage;
  2
  3var sd;
  4var lfc;
  5var store;
  6var tf;
  7var mf;
  8var lc;
  9var lang = 'CSharp';
 10
 11function ListController() {
 12    this.tabCollections = new Array();
 13    this.listCollections = new Array();
 14    this.tabCollectionIds = new Array();
 15    this.listCollectionIds = new Array();
 16}
 17
 18ListController.prototype.registerTabbedArea = function(tabCollection, listCollection, tabCollectionId, listCollectionId, filter) {
 19    this.tabCollections.push(tabCollection);
 20    this.listCollections.push(listCollection);
 21    this.tabCollectionIds.push(tabCollectionId);
 22    this.listCollectionIds.push(listCollectionId);
 23}
 24
 25function LoadPage() {
 26    store = new CookieDataStore('docs');
 27    registerEventHandler(window, 'load', 
 28        function() { var ss = new SplitScreen('control','main'); selectLanguage(store.get('lang')); });
 29    sd = getStyleDictionary(); 
 30    lfc = new LanguageFilterController();
 31    lc = new ListController();
 32    tf = new TypeFilter();
 33    mf = new MemberFilter();
 34    
 35    setUpLanguage();
 36    
 37    setUpSyntax();
 38   
 39	setUpSnippets();
 40	
 41	setUpType();
 42	
 43	setUpAllMembers();
 44}
 45
 46function setUpLanguage() {
 47    var langFilter = document.getElementById('languageFilter');
 48    if (langFilter == null) return;
 49  
 50    var options = langFilter.getElementsByTagName('option');   
 51    if (options == null) return;
 52    
 53    var value = options[0].getAttribute('value');
 54    var names = value.split(' ');
 55    lang = names[0];
 56}
 57
 58function setUpSnippets() {
 59    var divs = document.getElementsByTagName("DIV");
 60   
 61    for (var i = 0; i < divs.length; i++) {
 62        var temp = i;
 63        var name =  divs[i].getAttribute("name");
 64        if (name == null || name != "snippetGroup") continue;
 65        processSection(divs[i], 'x-lang', lang, true, true, lfc);
 66        i= temp + 1;
 67    }
 68}
 69
 70function setUpSyntax() {
 71    var syntax = document.getElementById('syntaxSection');
 72    if (syntax == null) return;
 73    
 74    processSection(syntax, 'x-lang', lang, true, true, lfc);
 75    
 76    var usyntax = document.getElementById('usyntaxSection');
 77    if (usyntax == null) return;
 78    
 79    processSection(usyntax, 'x-lang', lang, true, true, lfc);
 80}
 81
 82function setUpType() {
 83    var typeSection = document.getElementById('typeSection');
 84    if (typeSection == null) return;
 85    
 86    processSection(typeSection, 'value', 'all', true, false, lc);
 87}
 88
 89function setUpAllMembers() {
 90    var allMembersSection = document.getElementById('allMembersSection');
 91    if (allMembersSection == null) return;
 92    
 93    processSection(allMembersSection, 'value', 'all', true, false, lc);
 94}
 95
 96function processSection(section, attribute, value, toggleClassValue, toggleStyleValue, registerObject) {
 97    var nodes = section.childNodes;
 98        
 99    var tabs;
100    var blocks;
101    var tabId;
102    var blockId;
103       
104    if(nodes.length != 2) return;
105    
106    if(nodes[0].tagName == 'TABLE') {
107        var rows = nodes[0].getElementsByTagName('tr');
108           
109        if (rows.length == 0) return;
110        
111        tabId = rows[0].getAttribute('id');
112           
113        if (tabId == null) return;
114           
115        tabs = new ElementCollection(tabId);
116    }
117  
118    if(nodes[1].tagName == 'DIV') {
119        blockId = nodes[1].getAttribute('id');
120        if (blockId == null) return;
121            
122        blocks = new ElementCollection(blockId);
123    }
124    else if (nodes[1].tagName == 'TABLE') {
125        blockId = nodes[1].getAttribute('id');
126        if (blockId == null) return;
127            
128        blocks = new ElementCollection(blockId);
129    }
130       
131    if (registerObject != null) registerObject.registerTabbedArea(tabs, blocks, tabId, blockId);
132    if (toggleClassValue) tabs.toggleClass(attribute,value,'activeTab','tab');
133	if (toggleStyleValue) blocks.toggleStyle(attribute,value,'display','block','none');
134}
135
136function toggleClass(id, attributeName, attributeValue, trueClass, falseClass) {
137    for(var i = 0; i < lfc.tabCollections.length; i++) {
138        var tabs = lfc.tabCollections[i];
139              
140        if (lfc.tabCollectionIds[i] == id) { 
141            tabs.toggleClass(attributeName, attributeValue, trueClass, falseClass);
142        }
143    }  
144      
145    for(var j = 0; j < lc.tabCollections.length; j++) {
146        var listTabs = lc.tabCollections[j];
147        
148        if (lc.tabCollectionIds[j] == id) {
149            listTabs.toggleClass(attributeName, attributeValue, trueClass, falseClass);
150        }
151    }
152}
153
154function toggleStyle(id, attributeName, attributeValue, styleName, trueStyleValue, falseStyleValue) {
155    for (var i = 0; i < lfc.blockCollections.length; i++) {
156       
157        var blocks = lfc.blockCollections[i];
158              
159        if (lfc.blockCollectionIds[i] == id) {
160            blocks.toggleStyle(attributeName, attributeValue, styleName, trueStyleValue, falseStyleValue);
161        }
162    }
163}
164
165function processList(id, methodName, typeName) {
166    for (var i = 0; i < lc.listCollections.length; i++) {
167        var list = lc.listCollections[i];
168        if (lc.listCollectionIds[i] == id) {
169            if (typeName == 'type') list.process(getInstanceDelegate(tf,methodName));
170            else if (typeName == 'member') list.process(getInstanceDelegate(mf, methodName));
171        }
172    }
173}
174
175function processSubgroup(subgroup, typeName) {
176    if (typeName == 'type' && tf != null) tf.subgroup = subgroup;
177    else if (typeName == 'member' && mf != null) mf.subgroup = subgroup;
178}
179
180function toggleCheckState(visibility, value) {
181    if (mf == null) return;
182    mf[visibility] = value;
183}
184
185function switchLanguage(names, value) {
186    if (lfc != null) lfc.switchLanguage(names[0]); 
187    store.set('lang',value); 
188    store.save();
189}