Skip to content

Commit 74f21e6

Browse files
committed
Update package
1 parent af5f747 commit 74f21e6

File tree

10 files changed

+76
-54
lines changed

10 files changed

+76
-54
lines changed

get-started.zip

720 Bytes
Binary file not shown.

node-package/core/jsonary-core.js

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2022,6 +2022,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
20222022

20232023
this.baseUrl = request.url;
20242024
this.fragment = fragment;
2025+
this.document = request.document;
20252026
if (fragment == null) {
20262027
fragment = "";
20272028
}
@@ -4463,13 +4464,18 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
44634464
}
44644465
var hrefBase = this.hrefBase;
44654466
var submissionSchemas = this.submissionSchemas.getFull();
4466-
if (callback && submissionSchemas.length == 0 && this.method == "PUT") {
4467+
if (callback && !origData && submissionSchemas.length == 0 && this.method == "PUT") {
4468+
var readOnlySchema = Jsonary.createSchema({readOnly: true});
4469+
var resultData = Jsonary.create('...').addSchema(readOnlySchema, 'tmp');
44674470
Jsonary.getData(this.href, function (data) {
4471+
resultData.removeSchema('tmp');
4472+
resultData.set(data.get());
4473+
resultData.addSchema(data.schemas().fixed());
44684474
if (typeof callback === 'function') {
4469-
callback(origData || data.editableCopy());
4475+
callback(resultData);
44704476
}
44714477
});
4472-
return this;
4478+
return resultData;
44734479
}
44744480
var baseUri = (publicApi.isData(origData) && origData.resolveUrl('')) || hrefBase;
44754481
return submissionSchemas.createData(origData, baseUri, callback);
@@ -7297,14 +7303,20 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
72977303
return str.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;").replace("'", "&#39;");
72987304
}
72997305

7306+
var fixScrollActive = false;
73007307
function fixScroll(execFunction) {
7308+
if (fixScrollActive) return execFunction();
7309+
fixScrollActive = true;
73017310
var doc = document.documentElement, body = document.body;
73027311
var left = (doc && doc.scrollLeft || body && body.scrollLeft || 0);
73037312
var top = (doc && doc.scrollTop || body && body.scrollTop || 0);
73047313
execFunction();
7305-
if (left || top) {
7306-
window.scrollTo(left, top);
7307-
}
7314+
setTimeout(function () {
7315+
if (left || top) {
7316+
window.scrollTo(left, top);
7317+
}
7318+
fixScrollActive = false;
7319+
}, 10);
73087320
}
73097321

73107322
var prefixPrefix = "Jsonary";
@@ -9190,13 +9202,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
91909202
return false;
91919203
}
91929204
context.uiState.submitLink = arg1;
9193-
if (link.method == "PUT" && link.submissionSchemas.length == 0) {
9194-
// TODO: editable copy of actual target?
9195-
context.uiState.editing = context.data.editableCopy();
9196-
context.uiState.submissionData = context.data.editableCopy();
9197-
} else {
9198-
context.uiState.submissionData = link.createSubmissionData(undefined, true);
9199-
}
9205+
context.uiState.submissionData = link.createSubmissionData(undefined, true);
92009206
if (link.method == "PUT") {
92019207
context.uiState.editInPlace = true;
92029208
}

node-package/core/jsonary-core.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node-package/core/jsonary-core.min.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node-package/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jsonary",
3-
"version": "0.0.13",
3+
"version": "0.0.14",
44
"author": "Geraint Luff",
55
"description": "Jsonary - use JSON Schema in your client",
66
"dependencies": {

node-package/plugins/jsonary.render.table.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -789,17 +789,13 @@
789789
if (link.submissionSchemas.length) {
790790
context.uiState.linkRel = linkRel;
791791
context.uiState.linkIndex = linkIndex;
792-
var linkData = Jsonary.create();
793-
linkData.addSchema(link.submissionSchemas);
792+
var linkData = link.createSubmissionData(undefined, true);
794793
context.uiState.linkData = linkData;
795794
if (subPath) {
796795
context.uiState.linkPath = subPath;
797796
} else {
798797
delete context.uiState.linkPath;
799798
}
800-
link.submissionSchemas.createValue(function (value) {
801-
linkData.setValue(value);
802-
});
803799
delete context.uiState.expand;
804800
} else if (link.rel == "edit") {
805801
context.uiState.linkRel = linkRel;
@@ -822,12 +818,16 @@
822818
delete context.uiState.linkData;
823819
delete context.uiState.expand;
824820
} else {
821+
link.follow();
822+
return;
823+
/*
825824
var targetExpand = (link.rel == "self") ? true : link.href;
826825
if (context.uiState.expand == targetExpand) {
827826
delete context.uiState.expand;
828827
} else {
829828
context.uiState.expand = targetExpand;
830829
}
830+
*/
831831
}
832832
return true;
833833
} else if (actionName == "link-confirm") {

node-package/plugins/jsonary.route.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
(function (Jsonary) {
22
function Route(templateStr, handlerFunction) {
33
this.template = Jsonary.UriTemplate(templateStr);
4+
this.templateString = templateStr;
45
this.run = handlerFunction;
56
}
67
Route.prototype = {
78
test: function (url) {
89
var params = this.template.fromUri(url);
9-
if (this.template.fillFromObject(params) === url) {
10+
if (params && this.template.fillFromObject(params) === url) {
1011
return params;
1112
}
13+
},
14+
url: function (params) {
15+
return this.template.fillFromObject(params);
1216
}
1317
};
1418

1519
function getCurrent() {
16-
return Jsonary.location.base.replace(/^[^:]*:\/\/[^/]*/, '').replace(/\?.*$/, '');
20+
return Jsonary.location.base.replace(/^[^:]*:\/\/[^/]*/, '').replace(/[?#].*$/, '');
1721
}
1822

1923
var routes = [];
@@ -48,6 +52,7 @@
4852
var route = new Route(template, handler);
4953
routes.push(route);
5054
runRoutesLater();
55+
return route;
5156
};
5257
api.shortUrl = function (url) {
5358
var shortUrl = url.replace(/#$/, "");

node-package/super-bundle/jsonary-super-bundle.js

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2022,6 +2022,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
20222022

20232023
this.baseUrl = request.url;
20242024
this.fragment = fragment;
2025+
this.document = request.document;
20252026
if (fragment == null) {
20262027
fragment = "";
20272028
}
@@ -4463,13 +4464,18 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
44634464
}
44644465
var hrefBase = this.hrefBase;
44654466
var submissionSchemas = this.submissionSchemas.getFull();
4466-
if (callback && submissionSchemas.length == 0 && this.method == "PUT") {
4467+
if (callback && !origData && submissionSchemas.length == 0 && this.method == "PUT") {
4468+
var readOnlySchema = Jsonary.createSchema({readOnly: true});
4469+
var resultData = Jsonary.create('...').addSchema(readOnlySchema, 'tmp');
44674470
Jsonary.getData(this.href, function (data) {
4471+
resultData.removeSchema('tmp');
4472+
resultData.set(data.get());
4473+
resultData.addSchema(data.schemas().fixed());
44684474
if (typeof callback === 'function') {
4469-
callback(origData || data.editableCopy());
4475+
callback(resultData);
44704476
}
44714477
});
4472-
return this;
4478+
return resultData;
44734479
}
44744480
var baseUri = (publicApi.isData(origData) && origData.resolveUrl('')) || hrefBase;
44754481
return submissionSchemas.createData(origData, baseUri, callback);
@@ -7297,14 +7303,20 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
72977303
return str.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;").replace("'", "&#39;");
72987304
}
72997305

7306+
var fixScrollActive = false;
73007307
function fixScroll(execFunction) {
7308+
if (fixScrollActive) return execFunction();
7309+
fixScrollActive = true;
73017310
var doc = document.documentElement, body = document.body;
73027311
var left = (doc && doc.scrollLeft || body && body.scrollLeft || 0);
73037312
var top = (doc && doc.scrollTop || body && body.scrollTop || 0);
73047313
execFunction();
7305-
if (left || top) {
7306-
window.scrollTo(left, top);
7307-
}
7314+
setTimeout(function () {
7315+
if (left || top) {
7316+
window.scrollTo(left, top);
7317+
}
7318+
fixScrollActive = false;
7319+
}, 10);
73087320
}
73097321

73107322
var prefixPrefix = "Jsonary";
@@ -9190,13 +9202,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
91909202
return false;
91919203
}
91929204
context.uiState.submitLink = arg1;
9193-
if (link.method == "PUT" && link.submissionSchemas.length == 0) {
9194-
// TODO: editable copy of actual target?
9195-
context.uiState.editing = context.data.editableCopy();
9196-
context.uiState.submissionData = context.data.editableCopy();
9197-
} else {
9198-
context.uiState.submissionData = link.createSubmissionData(undefined, true);
9199-
}
9205+
context.uiState.submissionData = link.createSubmissionData(undefined, true);
92009206
if (link.method == "PUT") {
92019207
context.uiState.editInPlace = true;
92029208
}
@@ -10367,19 +10373,23 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
1036710373
(function (Jsonary) {
1036810374
function Route(templateStr, handlerFunction) {
1036910375
this.template = Jsonary.UriTemplate(templateStr);
10376+
this.templateString = templateStr;
1037010377
this.run = handlerFunction;
1037110378
}
1037210379
Route.prototype = {
1037310380
test: function (url) {
1037410381
var params = this.template.fromUri(url);
10375-
if (this.template.fillFromObject(params) === url) {
10382+
if (params && this.template.fillFromObject(params) === url) {
1037610383
return params;
1037710384
}
10385+
},
10386+
url: function (params) {
10387+
return this.template.fillFromObject(params);
1037810388
}
1037910389
};
1038010390

1038110391
function getCurrent() {
10382-
return Jsonary.location.base.replace(/^[^:]*:\/\/[^/]*/, '').replace(/\?.*$/, '');
10392+
return Jsonary.location.base.replace(/^[^:]*:\/\/[^/]*/, '').replace(/[?#].*$/, '');
1038310393
}
1038410394

1038510395
var routes = [];
@@ -10414,6 +10424,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
1041410424
var route = new Route(template, handler);
1041510425
routes.push(route);
1041610426
runRoutesLater();
10427+
return route;
1041710428
};
1041810429
api.shortUrl = function (url) {
1041910430
var shortUrl = url.replace(/#$/, "");
@@ -11692,17 +11703,13 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
1169211703
if (link.submissionSchemas.length) {
1169311704
context.uiState.linkRel = linkRel;
1169411705
context.uiState.linkIndex = linkIndex;
11695-
var linkData = Jsonary.create();
11696-
linkData.addSchema(link.submissionSchemas);
11706+
var linkData = link.createSubmissionData(undefined, true);
1169711707
context.uiState.linkData = linkData;
1169811708
if (subPath) {
1169911709
context.uiState.linkPath = subPath;
1170011710
} else {
1170111711
delete context.uiState.linkPath;
1170211712
}
11703-
link.submissionSchemas.createValue(function (value) {
11704-
linkData.setValue(value);
11705-
});
1170611713
delete context.uiState.expand;
1170711714
} else if (link.rel == "edit") {
1170811715
context.uiState.linkRel = linkRel;
@@ -11725,12 +11732,16 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
1172511732
delete context.uiState.linkData;
1172611733
delete context.uiState.expand;
1172711734
} else {
11735+
link.follow();
11736+
return;
11737+
/*
1172811738
var targetExpand = (link.rel == "self") ? true : link.href;
1172911739
if (context.uiState.expand == targetExpand) {
1173011740
delete context.uiState.expand;
1173111741
} else {
1173211742
context.uiState.expand = targetExpand;
1173311743
}
11744+
*/
1173411745
}
1173511746
return true;
1173611747
} else if (actionName == "link-confirm") {

node-package/super-bundle/jsonary-super-bundle.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node-package/super-bundle/jsonary-super-bundle.min.js

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)