Last active
December 22, 2015 06:58
-
-
Save ivikash/6434330 to your computer and use it in GitHub Desktop.
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
<script type="text/javascript" src="RDFaProcessor.1.2.0.js"></script> | |
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script> | |
<script type="text/javascript" src="../playground/js_beautify.js"></script> | |
<script type="text/javascript"> | |
$('#saveSchema') | |
.off('click') | |
.on('click', function() { | |
"use strict"; | |
var baseURI = 'http://schema.org/'; | |
var schema = {}; | |
var schemaWithContext = {}; | |
schemaWithContext["@context"] = {}; | |
var intermediateSchema = {}; | |
var count = 0; | |
var divClass = document.getElementsByType('rdf:Property'); | |
for (var i=0; i<divClass.length; i++) { | |
if(divClass[i] !== undefined) { | |
intermediateSchema[divClass[i].data.getValues('rdfs:label')[0]] = | |
divClass[i].data.getValues("http://schema.org/rangeIncludes"); | |
} | |
} | |
$.each(intermediateSchema, function(objectKey, objectValue){ | |
for (var i = objectValue.length - 1; i >= 0; i--) { | |
if (objectValue[i].search(/\/Text$/) > 0) { | |
if(schema.objectKey === undefined) { | |
schema[objectKey] = baseURI+objectKey; | |
} | |
} | |
else if (objectValue[i].search(/\/Number$/) > 0) { | |
if(schema.objectKey === undefined) { | |
schema[objectKey] = baseURI+objectKey; | |
} | |
} | |
else if (objectValue[i].search(/\/Date$/) > 0) { | |
if(schema.objectKey === undefined) { | |
schema[objectKey] = { | |
"@id" : baseURI+objectKey, | |
"@type" : "xsd:date" | |
} | |
} | |
} | |
else if (objectValue[i].search(/\/DateTime$/) > 0) { | |
if(schema.objectKey === undefined) { | |
schema[objectKey] = { | |
"@id" : baseURI+objectKey, | |
"@type" : "xsd:date" | |
} | |
} | |
} | |
else | |
{ | |
if(schema.objectKey === undefined) { | |
schema[objectKey] = { | |
"@id" : baseURI+objectKey, | |
"@type" : "@id" | |
} | |
} | |
} | |
}; | |
}); | |
schemaWithContext["@context"] = schema; | |
var schemaJSON = JSON.stringify(schemaWithContext); | |
$(this).attr('href','data:Application/octet-stream,'+encodeURIComponent(js_beautify(schemaJSON,{'indent_size': 2}))); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment