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