Last active
March 22, 2021 04:45
-
-
Save kidGodzilla/72d5059acd7de98fae11b3ea31e8177a to your computer and use it in GitHub Desktop.
jQuery Automatic Data Fill
This file contains hidden or 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
/** | |
* Instant Data for your OCDB Project (requires jQuery) | |
* | |
* Just use magic classes or data attributes matching your string data and they'll be automatically filled | |
* | |
* Example: | |
* | |
* <h1 data-for-h1></h1> <!-- This gets populated with data from the key `h1` --> | |
* | |
*/ | |
// Replace this URL with your own | |
let OCDB_URL = 'https://ocdb-db.patgriffith.com/v1/db/9/gW0D5osEwOXrrdM0lH3oMr5dYHf1Bsnp7OxuLlWE'; | |
$(document).ready(function () { | |
$.get(OCDB_URL, function (data) { | |
if (!data || typeof data !== 'object') return; | |
for (let k in data) { | |
let item = data[k]; | |
if (item && item.value && typeof item.value === 'string') { | |
$(`[data-for-${ k }]`).attr('src', item.value); | |
$(`[data-for-${ k }]`).html(item.value); | |
$(`.data-for-${ k }`).html(item.value); | |
} | |
} | |
}).fail(function (e) { | |
console.log(e); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment