4 |
8 |
9 |
10 | Copy
11 | Open in Converter
12 | Validate
13 |
14 |
15 |
16 | Copy
17 | Open in Playground
18 | Open in Converter
19 | Validate
20 |
21 |
22 |
`;
23 | return structure;
24 | }
25 |
26 |
27 | /**
28 | * auxiliary function to get around the issue that indexOf() is not working with jquery.
29 | */
30 |
31 | function myIndexOf(list, val) {
32 | var myindex = -1;
33 | var i = 0;
34 |
35 | var elem = list[0];
36 |
37 | while ( i < list.length ) {
38 | if ( elem == val ) return i;
39 | i = i+1;
40 | elem = list[i];
41 |
42 | }
43 |
44 | return -1;
45 |
46 | }
47 |
48 |
49 | /**
50 | * Fills in the direct input area with some samples
51 | * @param {string} file - file containing the sample
52 | */
53 | function loadFile(editorinstance, file) {
54 | var xmlhttp;
55 | if (window.XMLHttpRequest) {
56 | xmlhttp = new XMLHttpRequest();
57 | } else {
58 | xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
59 | }
60 | xmlhttp.onreadystatechange = function () {
61 | if (xmlhttp.readyState === 4 && xmlhttp.status !== 200) {
62 | alert('Error when opening the file: ' + file + ' - ' + xmlhttp.status + ' ' + xmlhttp.statusText);
63 | } else if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
64 | editorinstance.setValue(xmlhttp.responseText);
65 | }
66 | };
67 | xmlhttp.open("GET", file, true);
68 | xmlhttp.send();
69 | return xmlhttp.responseText;
70 | }
71 |
72 | function loadShape(file, dataGraph, format) {
73 | var xmlhttp;
74 | if (window.XMLHttpRequest) {
75 | xmlhttp = new XMLHttpRequest();
76 | } else {
77 | xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
78 | }
79 | xmlhttp.onreadystatechange = function () {
80 | if (xmlhttp.readyState === 4 && xmlhttp.status !== 200) {
81 | alert('Error when opening the file: ' + file + ' - ' + xmlhttp.status + ' ' + xmlhttp.statusText);
82 | } else if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
83 | newUrl = "https://shacl-playground.zazuko.com/#page=0&shapesGraph=" + encodeURIComponent(xmlhttp.responseText) + "&shapesGraphFormat=text%2Fturtle&dataGraph=" + encodeURIComponent(dataGraph) + "&dataGraphFormat=" + format ;
84 | //console.log(newUrl);
85 | window.open(newUrl, '_blank');
86 | }
87 | };
88 | xmlhttp.open("GET", file, true);
89 | xmlhttp.send();
90 | return xmlhttp.responseText;
91 | }
92 |
93 | function createTurtleEditorFrom(selector) {
94 | return CodeMirror.fromTextArea(selector, {
95 | mode: "turtle",
96 | lineNumbers: true
97 | });
98 | }
99 |
100 | function createJSONLDEditorFrom(selector) {
101 | return CodeMirror.fromTextArea(selector, {
102 | mode: "application/ld+json",
103 | lineNumbers: true
104 | });
105 | }
106 |
107 |
108 | $(document).ready(function () {
109 |
110 |
111 |
112 | var examples = [];
113 | var editors = [];
114 |
115 | var examples_id = ".examples";
116 | var examples_class = ".h3";
117 | var folder = "./html/examples/";
118 | var $examples = $(examples_id);
119 |
120 | // $examples.children(examples_class).each(function(index){
121 | $examples.each(function(index){
122 | exampleid = this.id;
123 | examples.push(exampleid);
124 | var text = example_structure(exampleid);
125 | $(this).after(text);
126 |
127 | var obj = {CM0: createTurtleEditorFrom(document.getElementById(exampleid + "-tab1validationquery")), CM1: createJSONLDEditorFrom(document.getElementById(exampleid + "-tab2validationquery"))};
128 | editors[index] = obj;
129 | //editors[index].push({CM: createTurtleEditorFrom(document.getElementById(exampleid + "-tab1validationquery")}, CM2: createJSONLDEditorFrom(document.getElementById(exampleid + "-tab2validationquery")});
130 | //editors[index].push({CM: createJSONLDEditorFrom(document.getElementById(exampleid + "-tab2validationquery")});
131 | //editors[index][0] = createTurtleEditorFrom(document.getElementById(exampleid + "-tab1validationquery"));
132 | //editors[index][1] = createJSONLDEditorFrom(document.getElementById(exampleid + "-tab2validationquery"));
133 |
134 | $("#" + exampleid + "-tabs").tabs();
135 |
136 | $("#" + exampleid + "-tabs a").on('click', function(e) {
137 | $('.CodeMirror').each(function(i, el){
138 | el.CodeMirror.refresh();
139 | });
140 | });
141 |
142 | path_to_file = folder + exampleid;
143 | loadFile(editors[index].CM0, path_to_file + ".ttl");
144 | loadFile(editors[index].CM1, path_to_file + ".jsonld");
145 |
146 | });
147 |
148 | $("button.copyturtletoclipboard").on({
149 | "click": function() {
150 | var exampleid = $(this).parent().parent().attr("exampleid");
151 | var indexValues = $examples.map(function() { return this.id; }) ;
152 | var index = myIndexOf(indexValues, exampleid);
153 | texttocopy = editors[index].CM0.getValue()
154 | navigator.clipboard.writeText(texttocopy);
155 | $(this).tooltip({ items: "#" + this.id, content: "Copied !"});
156 | $(this).tooltip("open");
157 | },
158 | "mouseout": function() {
159 | $(this).tooltip("disable");
160 | }
161 | });
162 | $("button.copyjsonldtoclipboard").on({
163 | "click": function() {
164 | var exampleid = $(this).parent().parent().attr("exampleid");
165 | var indexValues = $examples.map(function() { return this.id; }) ;
166 | var index = myIndexOf(indexValues, exampleid);
167 | texttocopy = editors[index].CM1.getValue();
168 | navigator.clipboard.writeText(texttocopy);
169 | $(this).tooltip({ items: "#" + this.id, content: "Copied !"});
170 | $(this).tooltip("open");
171 | },
172 | "mouseout": function() {
173 | $(this).tooltip("disable");
174 | }
175 | });
176 | $("button.openinplayground").on('click', function(e) {
177 | var exampleid = $(this).parent().parent().attr("exampleid");
178 | var indexValues = $examples.map(function() { return this.id; }) ;
179 | var index = myIndexOf(indexValues, exampleid);
180 |
181 | newUrl = "https://json-ld.org/playground/#startTab=tab-expand&json-ld=" + encodeURIComponent(editors[index].CM1.getValue());
182 | window.open(newUrl, '_blank');
183 | return false;
184 | });
185 | $("button.openTurtleInConverter").on('click', function(e) {
186 | var exampleid = $(this).parent().parent().attr("exampleid");
187 | var indexValues = $examples.map(function() { return this.id; }) ;
188 | var index = myIndexOf(indexValues, exampleid);
189 |
190 | newUrl = "https://converter.zazuko.com/#value=" + encodeURIComponent(editors[index].CM0.getValue()) + "&format=text%2Fturtle";
191 | window.open(newUrl, '_blank');
192 | return false;
193 | });
194 | $("button.openJsonldInConverter").on('click', function(e) {
195 | var exampleid = $(this).parent().parent().attr("exampleid");
196 | var indexValues = $examples.map(function() { return this.id; }) ;
197 | var index = myIndexOf(indexValues, exampleid);
198 |
199 | newUrl = "https://converter.zazuko.com/#value=" + encodeURIComponent(editors[index].CM1.getValue()) + "&format=application%2Fld%2Bjson";
200 | window.open(newUrl, '_blank');
201 | return false;
202 | });
203 | $("button.openTurtleInSHACLPlayground").on('click', function(e) {
204 | var exampleid = $(this).parent().parent().attr("exampleid");
205 | var indexValues = $examples.map(function() { return this.id; }) ;
206 | var index = myIndexOf(indexValues, exampleid);
207 | var shapes = loadShape(shaclfilepath, editors[index].CM0.getValue(), "text%2Fturtle");
208 | return false;
209 | });
210 | $("button.openJsonldInSHACLPlayground").on('click', function(e) {
211 | var exampleid = $(this).parent().parent().attr("exampleid");
212 | var indexValues = $examples.map(function() { return this.id; }) ;
213 | var index = myIndexOf(indexValues, exampleid);
214 | var shapes = loadShape(shaclfilepath, editors[index].CM1.getValue(), "application%2Fld%2Bjson");
215 | return false;
216 | });
217 | $("div.CodeMirror pre").on('click', function(e) {
218 | var et = $(e.target);
219 | if(et.hasClass('cm-url')) {
220 | newUrl = $(this).text();
221 | window.open(encodeURI(newUrl), '_blank');
222 | return false;
223 | }
224 | });
225 | });
226 |
--------------------------------------------------------------------------------
/releases/0.04/cpev_v0.04.owl:
--------------------------------------------------------------------------------
1 |
2 |