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