Skip to content

Commit

Permalink
Allow custom title for download link
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre Kampert committed Aug 19, 2014
1 parent 1a8cb57 commit 449e4e7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 17 deletions.
44 changes: 28 additions & 16 deletions examples/upload.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,27 @@ <h1>JSON Editor Upload Example</h1>

// Specify upload handler
JSONEditor.defaults.options.upload = function(type, file, cbs) {
var tick = 0;
if (type === 'root.upload_fail') cbs.failure('Upload failed');
else {
var tick = 0;

var tickFunction = function() {
var tickFunction = function() {
tick += 1;
console.log('progress: ' + tick);

if (tick < 100) {
cbs.updateProgress(tick);
window.setTimeout(tickFunction, 50)
cbs.updateProgress(tick);
window.setTimeout(tickFunction, 50)
} else if (tick == 100) {
cbs.updateProgress();
window.setTimeout(tickFunction, 500)
cbs.updateProgress();
window.setTimeout(tickFunction, 500)
} else {
cbs.success('http://www.example.com/images/' + file.name);
cbs.success('http://www.example.com/images/' + file.name);
}
};
};

window.setTimeout(tickFunction)
window.setTimeout(tickFunction)
}
};

// Initialize the editor with a JSON schema
Expand All @@ -43,28 +46,36 @@ <h1>JSON Editor Upload Example</h1>
type: "object",
title: "Image",
properties: {
upload1: {
upload_default: {
type: "string",
format: "uri",
options: {
upload: true
}
},
upload2: {
upload_custom_link: {
type: "string",
format: "uri",
options: {
upload: true
upload: true,
link_title: "download"
}
},
readonly: {
upload_readonly: {
readonly: true,
type: "string",
format: "uri",
options: {
upload: true
}
},
upload_fail: {
type: "string",
format: "uri",
options: {
upload: true
}
},
name: {
type: "string"
}
Expand All @@ -73,9 +84,10 @@ <h1>JSON Editor Upload Example</h1>
});

editor.setValue({
upload1: "",
upload2: "",
readonly: "http://www.example.com/images/image.jpg",
upload_default: "",
upload_custom_link: "",
upload_readonly: "http://www.example.com/images/image.jpg",
upload_fail: "",
name: ""
});

Expand Down
5 changes: 4 additions & 1 deletion src/editors/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ JSONEditor.defaults.editors.upload = JSONEditor.AbstractEditor.extend({

var anchor = document.createElement('a');
anchor.setAttribute('href', this.value);
anchor.innerHTML = this.value;

var title = this.schema.options.link_title;
if (!title) title = this.value;
anchor.innerHTML = title;
downloadLink.appendChild(anchor);

this.downloadLink = downloadLink;
Expand Down

0 comments on commit 449e4e7

Please sign in to comment.