From c87e538fdc337639bc4d54bb087dbf2b4f20297f Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Fri, 11 May 2012 14:41:20 -0700 Subject: 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. --- js/mediators/io-mediator.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'js/mediators') 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, { // fileNew: { enumerable: false, - value: function (file, template, callback) { + value: function (file, url, callback, template) { //Loading template from template URL var xhr = new XMLHttpRequest(), result; - xhr.open("GET", template, false); + xhr.open("GET", url, false); xhr.send(); if (xhr.readyState === 4) { //Making call to create file, checking for return code - switch (this.fio.newFile({ uri: file, contents: xhr.response })) { + switch (this.fio.newFile({ uri: file, contents: parseTemplate(xhr.response, template) })) { case 201: result = { status: 201, success: true, uri: file }; break; @@ -74,6 +74,20 @@ exports.IoMediator = Montage.create(Component, { result = { status: 500, success: false, uri: file }; break; } + //TODO: Improve template data injection + function parseTemplate (content, template) { + // + if (template.name.toLowerCase() === 'banner') { + //Getting dimensions of banner + var dimensions = template.id.split('x'); + dimensions = {width: String(dimensions[0])+'px', height: String(dimensions[1])+'px'}; + // + content = content.replace(/Dimensions@@@/gi, "Dimensions@@@"+template.id); + content = content.replace(/ninja-banner {}/gi, "ninja-banner {width: "+dimensions.width+"; height: "+dimensions.height+"}"); + } + // + return content; + } } else { result = { status: 500, success: false, uri: file }; } -- cgit v1.2.3