1function mergeArrays() { 2 var arr = arguments[0] || []; 3 for (var i = 1; i < arguments.length; i++) { 4 arr = arr.concat(arguments[i]); 5 } 6 return arr; 7} 8 9var ALL_RESOURCES = mergeArrays( 10 ABOUT_RESOURCES, 11 DESIGN_RESOURCES, 12 DISTRIBUTE_RESOURCES, 13 GOOGLE_RESOURCES, 14 GUIDE_RESOURCES, 15 SAMPLES_RESOURCES, 16 TOOLS_RESOURCES, 17 TRAINING_RESOURCES, 18 YOUTUBE_RESOURCES, 19 BLOGGER_RESOURCES 20); 21 22for (var i = 0; i < ALL_RESOURCES.length; i++) { 23 ALL_RESOURCES[i].index = i; 24} 25 26function mergeMaps() { 27 var allRes = {}; 28 var offset = 0; 29 30 for (var i = 0; i < arguments.length; i++) { 31 var r = arguments[i]; 32 for (var tag in r.map) { 33 allRes[tag] = allRes[tag] || []; 34 allRes[tag] = allRes[tag].concat(r.map[tag].map(function(i){ return ALL_RESOURCES[i + offset]; })); 35 } 36 offset += r.arr.length; 37 } 38 39 return allRes; 40} 41 42function setFromArray(arr) { 43 arr = arr || []; 44 var set = {}; 45 for (var i = 0; i < arr.length; i++) { 46 set[arr[i]] = true; 47 } 48 return set; 49} 50 51function buildResourceLookupMap(resourceDict) { 52 var map = {}; 53 for (var key in resourceDict) { 54 var dictForKey = {}; 55 var srcArr = resourceDict[key]; 56 for (var i = 0; i < srcArr.length; i++) { 57 dictForKey[srcArr[i].index] = true; 58 } 59 map[key] = dictForKey; 60 } 61 return map; 62} 63 64// Type lookups 65 66var ALL_RESOURCES_BY_TYPE = { 67 'about': ABOUT_RESOURCES, 68 'design': DESIGN_RESOURCES, 69 'distribute': DISTRIBUTE_RESOURCES, 70 'google': GOOGLE_RESOURCES, 71 'guide': GUIDE_RESOURCES, 72 'samples': SAMPLES_RESOURCES, 73 'tools': TOOLS_RESOURCES, 74 'training': TRAINING_RESOURCES, 75 'youtube': YOUTUBE_RESOURCES, 76 'blog': BLOGGER_RESOURCES 77}; 78var IS_RESOURCE_OF_TYPE = buildResourceLookupMap(ALL_RESOURCES_BY_TYPE); 79 80// Tag lookups 81 82var ALL_RESOURCES_BY_TAG = mergeMaps( 83 {map:ABOUT_BY_TAG,arr:ABOUT_RESOURCES}, 84 {map:DESIGN_BY_TAG,arr:DESIGN_RESOURCES}, 85 {map:DISTRIBUTE_BY_TAG,arr:DISTRIBUTE_RESOURCES}, 86 {map:GOOGLE_BY_TAG,arr:GOOGLE_RESOURCES}, 87 {map:GUIDE_BY_TAG,arr:GUIDE_RESOURCES}, 88 {map:SAMPLES_BY_TAG,arr:SAMPLES_RESOURCES}, 89 {map:TOOLS_BY_TAG,arr:TOOLS_RESOURCES}, 90 {map:TRAINING_BY_TAG,arr:TRAINING_RESOURCES}, 91 {map:YOUTUBE_BY_TAG,arr:YOUTUBE_RESOURCES}, 92 {map:BLOGGER_BY_TAG,arr:BLOGGER_RESOURCES} 93); 94var IS_RESOURCE_TAGGED = buildResourceLookupMap(ALL_RESOURCES_BY_TAG); 95 96// URL and language lookups 97 98var ALL_RESOURCES_BY_URL = {}; 99var ALL_RESOURCES_BY_LANG = {}; 100 101for (var i = 0; i < ALL_RESOURCES.length; i++) { 102 var res = ALL_RESOURCES[i]; 103 var lang = res.lang; 104 if (lang) { 105 ALL_RESOURCES_BY_LANG[lang] = ALL_RESOURCES_BY_LANG[lang] || []; 106 ALL_RESOURCES_BY_LANG[lang].push(res); 107 } 108 var url = res.url; 109 if (url) { 110 ALL_RESOURCES_BY_URL[url] = res; 111 } 112} 113var IS_RESOURCE_IN_LANG = buildResourceLookupMap(ALL_RESOURCES_BY_LANG);