-
-
Save sterlingrobot/d91e71dfade09a37d83f76925c816f54 to your computer and use it in GitHub Desktop.
Fetch JSON that defines ids and labels for tags, store in localStorage for performance.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! GENERIC - WORDMAPS */ | |
/** | |
* Initializes WordmapIds, so that the data can be set to a local | |
* lookup hash object, to get the label of a given | |
* wordmapId. Initialization fetches external wordmap data (once) | |
* via ajax if there is no localStorage wordmap data, and stores | |
* returned wordmap data in localStorage for improved performance. | |
* @class Wordmaps.init | |
* @returns {Promise} - a chainable $.Deferred object | |
* @requires jQuery | |
* @example | |
* <caption><b>NOTE:</b> Because the wordmap data may require an ajax call, you must use a Promise callback to know when the data is available. If the wordmap data is found in localStorage the promise will resolve immediately.</caption> | |
* var wordmapData; | |
* | |
* Wordmaps.init().then(function(data) { | |
* wordmapData = data; | |
* ...other callbacks that will use wordmapData... | |
* }) | |
*/ | |
var Wordmaps = (function($, window) { | |
'use strict'; | |
var endpoint = '/wordmaptaxonomy/mapping.json', | |
// if additional taxonomies are needed, add to this array | |
taxonomies = ['webtypeclassification', 'themes'], | |
// set expiration of 2 weeks | |
expires = +new Date(+new Date() + 1000 * 60 * 60 * 24 *14), | |
promise = $.Deferred(), | |
init = false, | |
storageKey = 'wordmapIds', | |
wordmapData = getLocalStorage(storageKey); | |
function fetchWordMapJSON() { | |
// if ajax call already initialized, return a reference | |
if(init) { return promise; } | |
promise = $.when.apply(null, taxonomies.map(function(taxonomy) { | |
return $.getJSON(endpoint, { taxonomy: taxonomy }); | |
})) | |
.then(function() { | |
var wordmaps = Array.prototype.slice.call(arguments) | |
.reduce(function(arr, arg) { | |
return arg[1] === 'success' && arr.concat(arg[0]); | |
}, []); | |
return setLocalStorage(storageKey, wordmaps); | |
}) | |
.fail(function(err) { | |
switch(err.status) { | |
case 200 : | |
console.warn('WordmapId file ' + | |
endpoint + ' found, but with JSON errors'); | |
break; | |
default : | |
console.warn('WordmapId file ' + | |
endpoint + ' error: ' + err.statusText); | |
} | |
}); | |
// set this immediately, to prevent multiple ajax calls | |
init = true; | |
return promise; | |
} | |
function generateLookup(data) { | |
wordmapData = wordmapData || {}; | |
data.forEach(function(wm) { | |
wordmapData[wm.wordmapid] = wm.label; | |
}); | |
return wordmapData; | |
} | |
/* globals JSON */ | |
function getLocalStorage(key) { | |
var storage = JSON.parse(localStorage.getItem(key)), | |
isValid = storage && | |
!!storage.expires && | |
storage.expires > +new Date() && | |
// check if any new taxonomies have been added | |
// since localStorage was set | |
!!storage.taxonomies && | |
storage.taxonomies.length === taxonomies.length; | |
return isValid ? storage : false; | |
} | |
function setLocalStorage(key, data) { | |
wordmapData = generateLookup(data); | |
wordmapData.expires = expires; | |
// check for new multiple taxonomy support | |
wordmapData.taxonomies = taxonomies; | |
localStorage.setItem(key, JSON.stringify(wordmapData)); | |
return wordmapData; | |
} | |
function removeLocalStorage(key) { | |
wordmapData = null; | |
localStorage.setItem(key, false); | |
} | |
return { | |
init: function() { | |
return (wordmapData && promise.resolve(wordmapData)) || fetchWordMapJSON(); | |
} | |
}; | |
})(jQuery, window); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ { | |
"wordmapid" : "WM177447", | |
"label" : "Accelerated Buying Experience" | |
}, { | |
"wordmapid" : "WM177740", | |
"label" : "OTNHeadlines" | |
}, { | |
"wordmapid" : "WM178651", | |
"label" : "Internet of Things - themes" | |
}, { | |
"wordmapid" : "WM178653", | |
"label" : "Security - themes" | |
}, { | |
"wordmapid" : "WM178652", | |
"label" : "Sustainability - themes" | |
}, { | |
"wordmapid" : "WM178843", | |
"label" : "A/B Testing" | |
}, { | |
"wordmapid" : "WM178844", | |
"label" : "Account-Based Marketing" | |
}, { | |
"wordmapid" : "WM178845", | |
"label" : "B2B Marketing" | |
}, { | |
"wordmapid" : "WM178846", | |
"label" : "B2C Marketing" | |
}, { | |
"wordmapid" : "WM178847", | |
"label" : "Campaign Analytics" | |
}, { | |
"wordmapid" : "WM178848", | |
"label" : "CMO" | |
}, { | |
"wordmapid" : "WM178849", | |
"label" : "Content Marketing" | |
}, { | |
"wordmapid" : "WM178850", | |
"label" : "Cross-Channel Marketing" | |
}, { | |
"wordmapid" : "WM178851", | |
"label" : "Data Activation" | |
}, { | |
"wordmapid" : "WM178852", | |
"label" : "Data Management" | |
}, { | |
"wordmapid" : "WM178853", | |
"label" : "Demand Generation" | |
}, { | |
"wordmapid" : "WM178854", | |
"label" : "Digital Marketing" | |
}, { | |
"wordmapid" : "WM178855", | |
"label" : "Display Advertising" | |
}, { | |
"wordmapid" : "WM178856", | |
"label" : "Drip Marketing" | |
}, { | |
"wordmapid" : "WM178857", | |
"label" : "Email Deliverability" | |
}, { | |
"wordmapid" : "WM178858", | |
"label" : "Email Marketing" | |
}, { | |
"wordmapid" : "WM178859", | |
"label" : "Enterprise Marketing" | |
}, { | |
"wordmapid" : "WM178860", | |
"label" : "Lead Generation" | |
}, { | |
"wordmapid" : "WM178861", | |
"label" : "Lead Management" | |
}, { | |
"wordmapid" : "WM178862", | |
"label" : "Lead Nurturing" | |
}, { | |
"wordmapid" : "WM178863", | |
"label" : "Lead Qualification" | |
}, { | |
"wordmapid" : "WM178864", | |
"label" : "Lead Scoring" | |
}, { | |
"wordmapid" : "WM178865", | |
"label" : "Marketing Automation" | |
}, { | |
"wordmapid" : "WM178866", | |
"label" : "Marketing Effectiveness" | |
}, { | |
"wordmapid" : "WM178867", | |
"label" : "Marketing Leadership" | |
}, { | |
"wordmapid" : "WM178868", | |
"label" : "Marketing ROI" | |
}, { | |
"wordmapid" : "WM178869", | |
"label" : "Marketing Strategy" | |
}, { | |
"wordmapid" : "WM178870", | |
"label" : "Mobile Marketing" | |
}, { | |
"wordmapid" : "WM178871", | |
"label" : "Multivariate Testing" | |
}, { | |
"wordmapid" : "WM178872", | |
"label" : "Revenue Performance Management" | |
}, { | |
"wordmapid" : "WM178873", | |
"label" : "Sales and Marketing Alignment" | |
}, { | |
"wordmapid" : "WM178874", | |
"label" : "Sales Effectiveness" | |
}, { | |
"wordmapid" : "WM178875", | |
"label" : "Sales Enablement" | |
}, { | |
"wordmapid" : "WM178876", | |
"label" : "Sales Lead" | |
}, { | |
"wordmapid" : "WM178877", | |
"label" : "Social Marketing" | |
}, { | |
"wordmapid" : "WM178878", | |
"label" : "Testing and Optimization" | |
}, { | |
"wordmapid" : "WM178879", | |
"label" : "Web Marketing" | |
}, { | |
"wordmapid" : "WM178880", | |
"label" : "Website Testing" | |
} ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ { | |
"wordmapid" : "WM147082", | |
"label" : "Press Release" | |
}, { | |
"wordmapid" : "WM147085", | |
"label" : "Product Overview" | |
}, { | |
"wordmapid" : "WM147038", | |
"label" : "Social Media" | |
}, { | |
"wordmapid" : "WM147040", | |
"label" : "Facebook Account" | |
}, { | |
"wordmapid" : "WM147042", | |
"label" : "LinkedInGroup" | |
}, { | |
"wordmapid" : "WM147039", | |
"label" : "YouTube Channel" | |
}, { | |
"wordmapid" : "WM147041", | |
"label" : "Twitter Feed" | |
}, { | |
"wordmapid" : "WM151003", | |
"label" : "Mix" | |
}, { | |
"wordmapid" : "WM147087", | |
"label" : "Product Resources" | |
}, { | |
"wordmapid" : "WM147084", | |
"label" : "Product Features and Benefits" | |
}, { | |
"wordmapid" : "WM147083", | |
"label" : "Product Family Comparisons" | |
}, { | |
"wordmapid" : "WM147046", | |
"label" : "Blog" | |
}, { | |
"wordmapid" : "WM170581", | |
"label" : "Webinar" | |
}, { | |
"wordmapid" : "WM170580", | |
"label" : "Infographic" | |
}, { | |
"wordmapid" : "WM175019", | |
"label" : "Event - In Person" | |
}, { | |
"wordmapid" : "WM175032", | |
"label" : "Best Practice Brief" | |
}, { | |
"wordmapid" : "WM175030", | |
"label" : "Best Practice Guide" | |
}, { | |
"wordmapid" : "WM175025", | |
"label" : "Competitive Page" | |
}, { | |
"wordmapid" : "WM175022", | |
"label" : "E-book" | |
}, { | |
"wordmapid" : "WM175023", | |
"label" : "Feature" | |
}, { | |
"wordmapid" : "WM175031", | |
"label" : "Keynote" | |
}, { | |
"wordmapid" : "WM175024", | |
"label" : "News Article" | |
}, { | |
"wordmapid" : "WM175020", | |
"label" : "Oracle by Example (OBE)" | |
}, { | |
"wordmapid" : "WM175028", | |
"label" : "Pricelist" | |
}, { | |
"wordmapid" : "WM175026", | |
"label" : "Product Capabilities" | |
}, { | |
"wordmapid" : "WM175027", | |
"label" : "Solution Capabilities" | |
}, { | |
"wordmapid" : "WM175029", | |
"label" : "Topic Page" | |
}, { | |
"wordmapid" : "WM175021", | |
"label" : "Tutorial" | |
}, { | |
"wordmapid" : "WM176802", | |
"label" : "Webast - Live" | |
}, { | |
"wordmapid" : "WM147078", | |
"label" : "Newsletter" | |
}, { | |
"wordmapid" : "WM147061", | |
"label" : "Customer Success Story" | |
}, { | |
"wordmapid" : "WM147043", | |
"label" : "Analyst report" | |
}, { | |
"wordmapid" : "WM147044", | |
"label" : "Article" | |
}, { | |
"wordmapid" : "WM147045", | |
"label" : "Benchmark" | |
}, { | |
"wordmapid" : "WM147047", | |
"label" : "Brief" | |
}, { | |
"wordmapid" : "WM147048", | |
"label" : "Brochure" | |
}, { | |
"wordmapid" : "WM147051", | |
"label" : "Corporate Strategy Brochure" | |
}, { | |
"wordmapid" : "WM147049", | |
"label" : "Long Brochure" | |
}, { | |
"wordmapid" : "WM147050", | |
"label" : "Short Brochure" | |
}, { | |
"wordmapid" : "WM147052", | |
"label" : "Case Study" | |
}, { | |
"wordmapid" : "WM147053", | |
"label" : "Customer Book" | |
}, { | |
"wordmapid" : "WM147054", | |
"label" : "Customer Business Benefit Brief" | |
}, { | |
"wordmapid" : "WM147055", | |
"label" : "Customer Business Benefit Study" | |
}, { | |
"wordmapid" : "WM147056", | |
"label" : "Customer Case Study" | |
}, { | |
"wordmapid" : "WM147057", | |
"label" : "Customer Oracle or Profit Magazine Article" | |
}, { | |
"wordmapid" : "WM147058", | |
"label" : "Customer Press Release" | |
}, { | |
"wordmapid" : "WM147059", | |
"label" : "Customer Snapshot" | |
}, { | |
"wordmapid" : "WM147060", | |
"label" : "Customer Spotlight" | |
}, { | |
"wordmapid" : "WM147062", | |
"label" : "Customer SuccessCast" | |
}, { | |
"wordmapid" : "WM147063", | |
"label" : "Customer Video" | |
}, { | |
"wordmapid" : "WM147064", | |
"label" : "Data Sheet" | |
}, { | |
"wordmapid" : "WM147065", | |
"label" : "Demo" | |
}, { | |
"wordmapid" : "WM147067", | |
"label" : "Elevator Pitch" | |
}, { | |
"wordmapid" : "WM147068", | |
"label" : "Executive Brief" | |
}, { | |
"wordmapid" : "WM147069", | |
"label" : "Executive Paper" | |
}, { | |
"wordmapid" : "WM147070", | |
"label" : "FAQ" | |
}, { | |
"wordmapid" : "WM147071", | |
"label" : "Generic Content" | |
}, { | |
"wordmapid" : "WM147072", | |
"label" : "HowTo" | |
}, { | |
"wordmapid" : "WM147073", | |
"label" : "Images" | |
}, { | |
"wordmapid" : "WM147074", | |
"label" : "Magazine" | |
}, { | |
"wordmapid" : "WM147076", | |
"label" : "Java Magazine" | |
}, { | |
"wordmapid" : "WM147075", | |
"label" : "Oracle Magazine" | |
}, { | |
"wordmapid" : "WM147077", | |
"label" : "Profit Magazine" | |
}, { | |
"wordmapid" : "WM147080", | |
"label" : "Podcast" | |
}, { | |
"wordmapid" : "WM147081", | |
"label" : "Presentation" | |
}, { | |
"wordmapid" : "WM147086", | |
"label" : "Product Requirements (for software)" | |
}, { | |
"wordmapid" : "WM147090", | |
"label" : "Product Solution" | |
}, { | |
"wordmapid" : "WM147088", | |
"label" : "Product Specifications (for hardware)" | |
}, { | |
"wordmapid" : "WM147089", | |
"label" : "Product System Requirement" | |
}, { | |
"wordmapid" : "WM147091", | |
"label" : "Reference Manual" | |
}, { | |
"wordmapid" : "WM147092", | |
"label" : "Self-Service Brief" | |
}, { | |
"wordmapid" : "WM151018", | |
"label" : "Delicious" | |
}, { | |
"wordmapid" : "WM151004", | |
"label" : "Google Plus" | |
}, { | |
"wordmapid" : "WM151005", | |
"label" : "Mix Blog" | |
}, { | |
"wordmapid" : "WM151006", | |
"label" : "Pinterest" | |
}, { | |
"wordmapid" : "WM151001", | |
"label" : "Weibo" | |
}, { | |
"wordmapid" : "WM151002", | |
"label" : "Youku" | |
}, { | |
"wordmapid" : "WM147097", | |
"label" : "Solution Brief" | |
}, { | |
"wordmapid" : "WM147093", | |
"label" : "Statement of Direction" | |
}, { | |
"wordmapid" : "WM147096", | |
"label" : "Technical White Paper" | |
}, { | |
"wordmapid" : "WM147094", | |
"label" : "Video" | |
}, { | |
"wordmapid" : "WM147095", | |
"label" : "White Paper" | |
}, { | |
"wordmapid" : "WM176810", | |
"label" : "Trial" | |
}, { | |
"wordmapid" : "WM176862", | |
"label" : "Webast - On Demand" | |
}, { | |
"wordmapid" : "WM177024", | |
"label" : "Customer Viewpoint" | |
}, { | |
"wordmapid" : "WM177231", | |
"label" : "Customer Feature Article" | |
}, { | |
"wordmapid" : "WM177322", | |
"label" : "Thought Leadership Editorial" | |
}, { | |
"wordmapid" : "WM178623", | |
"label" : "Documentation" | |
}, { | |
"wordmapid" : "WM178624", | |
"label" : "Sample Application" | |
}, { | |
"wordmapid" : "WM178625", | |
"label" : "Learning Path" | |
}, { | |
"wordmapid" : "WM178711", | |
"label" : "API Reference" | |
}, { | |
"wordmapid" : "WM178749", | |
"label" : "Discussion" | |
}, { | |
"wordmapid" : "WM178750", | |
"label" : "Poll" | |
}, { | |
"wordmapid" : "WM178751", | |
"label" : "Solution Overview" | |
}, { | |
"wordmapid" : "WM179068", | |
"label" : "Solution Architecture" | |
}, { | |
"wordmapid" : "WM179069", | |
"label" : "Troubleshooting Guide" | |
}, { | |
"wordmapid" : "WM179341", | |
"label" : "Assessment Tool" | |
}, { | |
"wordmapid" : "WM178751", | |
"label" : "Solution Overview" | |
} ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment