diff options
author | Jose Antonio Marquez | 2012-05-11 14:41:20 -0700 |
---|---|---|
committer | Jose Antonio Marquez | 2012-05-11 14:41:20 -0700 |
commit | c87e538fdc337639bc4d54bb087dbf2b4f20297f (patch) | |
tree | bbbcf496841932261b21f977061fd41c01c0e0a6 /js/mediators | |
parent | f10bec0c594c6404eec51dc1a005f7f17570ba52 (diff) | |
download | ninja-c87e538fdc337639bc4d54bb087dbf2b4f20297f.tar.gz |
Adding support for new templates
This is supported for NEW and OPEN, SAVE is not supported yet by I/O. Saving works, but it will not be a banner template.
Diffstat (limited to 'js/mediators')
-rw-r--r-- | js/mediators/io-mediator.js | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js index dae0f359..0bff1f3b 100644 --- a/js/mediators/io-mediator.js +++ b/js/mediators/io-mediator.js | |||
@@ -53,14 +53,14 @@ exports.IoMediator = Montage.create(Component, { | |||
53 | // | 53 | // |
54 | fileNew: { | 54 | fileNew: { |
55 | enumerable: false, | 55 | enumerable: false, |
56 | value: function (file, template, callback) { | 56 | value: function (file, url, callback, template) { |
57 | //Loading template from template URL | 57 | //Loading template from template URL |
58 | var xhr = new XMLHttpRequest(), result; | 58 | var xhr = new XMLHttpRequest(), result; |
59 | xhr.open("GET", template, false); | 59 | xhr.open("GET", url, false); |
60 | xhr.send(); | 60 | xhr.send(); |
61 | if (xhr.readyState === 4) { | 61 | if (xhr.readyState === 4) { |
62 | //Making call to create file, checking for return code | 62 | //Making call to create file, checking for return code |
63 | switch (this.fio.newFile({ uri: file, contents: xhr.response })) { | 63 | switch (this.fio.newFile({ uri: file, contents: parseTemplate(xhr.response, template) })) { |
64 | case 201: | 64 | case 201: |
65 | result = { status: 201, success: true, uri: file }; | 65 | result = { status: 201, success: true, uri: file }; |
66 | break; | 66 | break; |
@@ -74,6 +74,20 @@ exports.IoMediator = Montage.create(Component, { | |||
74 | result = { status: 500, success: false, uri: file }; | 74 | result = { status: 500, success: false, uri: file }; |
75 | break; | 75 | break; |
76 | } | 76 | } |
77 | //TODO: Improve template data injection | ||
78 | function parseTemplate (content, template) { | ||
79 | // | ||
80 | if (template.name.toLowerCase() === 'banner') { | ||
81 | //Getting dimensions of banner | ||
82 | var dimensions = template.id.split('x'); | ||
83 | dimensions = {width: String(dimensions[0])+'px', height: String(dimensions[1])+'px'}; | ||
84 | // | ||
85 | content = content.replace(/Dimensions@@@/gi, "Dimensions@@@"+template.id); | ||
86 | content = content.replace(/ninja-banner {}/gi, "ninja-banner {width: "+dimensions.width+"; height: "+dimensions.height+"}"); | ||
87 | } | ||
88 | // | ||
89 | return content; | ||
90 | } | ||
77 | } else { | 91 | } else { |
78 | result = { status: 500, success: false, uri: file }; | 92 | result = { status: 500, success: false, uri: file }; |
79 | } | 93 | } |