aboutsummaryrefslogtreecommitdiff
path: root/js/mediators
diff options
context:
space:
mode:
authorValerio Virgillito2012-06-06 00:27:59 -0700
committerValerio Virgillito2012-06-06 00:27:59 -0700
commit91123fef348ec54d89005adbc151e816856a6a18 (patch)
treeac20e473f2ef52ef1f7deb18eab4d38d6a35ec4b /js/mediators
parent0e1a276f19ea70009c5a649e9667861d7c346a7e (diff)
parent18e212dca48066d1ddaca96875a3f40adcc859b6 (diff)
downloadninja-91123fef348ec54d89005adbc151e816856a6a18.tar.gz
Merge branch 'refs/heads/master' into montage-v10-integration
Conflicts: js/components/tools-properties/fill-properties.reel/fill-properties.js Signed-off-by: Valerio Virgillito <valerio@motorola.com>
Diffstat (limited to 'js/mediators')
-rwxr-xr-xjs/mediators/element-mediator.js88
-rw-r--r--js/mediators/io-mediator.js712
2 files changed, 85 insertions, 715 deletions
diff --git a/js/mediators/element-mediator.js b/js/mediators/element-mediator.js
index 1d5e9ade..da8cbb76 100755
--- a/js/mediators/element-mediator.js
+++ b/js/mediators/element-mediator.js
@@ -373,78 +373,76 @@ exports.ElementMediator = Montage.create(Component, {
373 }, 373 },
374 374
375 getStroke: { 375 getStroke: {
376 value: function(el) { 376 value: function(el, strokeProperties) {
377 if(!el.elementModel) { 377 return el.elementModel.controller["getStroke"](el, strokeProperties);
378 NJUtils.makeElementModel(el, "Div", "block");
379 }
380 return el.elementModel.controller["getStroke"](el);
381 } 378 }
382 }, 379 },
383 380
384
385 /** 381 /**
386 Set a property change command for an element or array of elements 382 Set stroke/border properties on an element or array of elements
387 @param els: Array of elements. Can contain 1 or more elements 383 @param els: Array of elements. Can contain 1 or more elements
388 @param value: Value to be set. This is the stroke info 384 @param value: Value to be set. This is the stroke info
389 @param eventType: Change/Changing. Will be passed to the dispatched event 385 @param eventType: Change/Changing. Will be passed to the dispatched event
390 @param source: String for the source object making the call 386 @param source: String for the source object making the call
391 @param currentValue *OPTIONAL*: current value array. If not found the current value is calculated 387 @param currentValue *OPTIONAL*: current value array. If not found the current value is calculated
392 @param stageRedraw: *OPTIONAL*: True. If set to false the stage will not redraw the selection/outline
393 */ 388 */
394 setStroke: { 389 setStroke: {
395 value: function(els, value, eventType, source, currentValue) { 390 value: function(els, value, eventType, source, currentValue) {
396 391
397 if(eventType === "Changing") { 392 if(eventType !== "Changing") {
398 this._setStroke(els, value, isFill, eventType, source);
399 } else {
400 // Calculate currentValue if not found for each element 393 // Calculate currentValue if not found for each element
401 if(!currentValue) { 394 if(!currentValue) {
402 var that = this; 395 var that = this,
396 val = value;
403 currentValue = els.map(function(item) { 397 currentValue = els.map(function(item) {
404 return that.getStroke(item); 398 return that.getStroke(item, val);
405 }); 399 });
406 } 400 }
401 document.application.undoManager.add("Set stroke", this.setStroke, this, els, currentValue, eventType, source, value);
402 }
407 403
408 var command = Montage.create(Command, { 404 for(var i=0, item; item = els[i]; i++) {
409 _els: { value: els }, 405 item.elementModel.controller["setStroke"](item, (value[i] || value), eventType, source);
410 _value: { value: value },
411 _previous: { value: currentValue },
412 _eventType: { value: eventType},
413 _source: { value: "undo-redo"},
414 description: { value: "Set Color"},
415 receiver: { value: this},
416
417 execute: {
418 value: function(senderObject) {
419 if(senderObject) this._source = senderObject;
420 this.receiver._setStroke(this._els, this._value, this._eventType, this._source);
421 this._source = "undo-redo";
422 return "";
423 }
424 },
425
426 unexecute: {
427 value: function() {
428 this.receiver._setStroke(this._els, this._previous, this._eventType, this._source);
429 return "";
430 }
431 }
432 });
433
434 NJevent("sendToUndo", command);
435 command.execute(source);
436 } 406 }
437 407
408 NJevent("element" + eventType, {type : "setStroke", source: source, data: {"els": els, "prop": "stroke", "value": value}, redraw: null});
438 } 409 }
439 }, 410 },
440 411
441 _setStroke: { 412 getFill: {
442 value: function(els, value, eventType, source) { 413 value: function(el, fillProperties) {
414 return el.elementModel.controller["getFill"](el, fillProperties);
415 }
416 },
417
418 /**
419 Set fill/background properties for an element or array of elements
420 @param els: Array of elements. Can contain 1 or more elements
421 @param value: Value to be set. This is the fill info
422 @param eventType: Change/Changing. Will be passed to the dispatched event
423 @param source: String for the source object making the call
424 @param currentValue *OPTIONAL*: current value array. If not found the current value is calculated
425 */
426 setFill: {
427 value: function(els, value, eventType, source, currentValue) {
428
429 if(eventType !== "Changing") {
430 // Calculate currentValue if not found for each element
431 if(!currentValue) {
432 var that = this,
433 val = value;
434 currentValue = els.map(function(item) {
435 return that.getFill(item, val);
436 });
437 }
438 document.application.undoManager.add("Set fill", this.setFill, this, els, currentValue, eventType, source, value);
439 }
440
443 for(var i=0, item; item = els[i]; i++) { 441 for(var i=0, item; item = els[i]; i++) {
444 item.elementModel.controller["setStroke"](item, value); 442 item.elementModel.controller["setFill"](item, (value[i] || value));
445 } 443 }
446 444
447 NJevent("element" + eventType, {type : "setStroke", source: source, data: {"els": els, "prop": "stroke", "value": value}, redraw: null}); 445 NJevent("element" + eventType, {type : "setFill", source: source, data: {"els": els, "prop": "fill", "value": value}, redraw: null});
448 } 446 }
449 }, 447 },
450 448
diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js
index 4dbf32d5..c9e10896 100644
--- a/js/mediators/io-mediator.js
+++ b/js/mediators/io-mediator.js
@@ -10,49 +10,58 @@ var Montage = require("montage/core/core").Montage,
10 Component = require("montage/ui/component").Component, 10 Component = require("montage/ui/component").Component,
11 FileIo = require("js/io/system/fileio").FileIo, 11 FileIo = require("js/io/system/fileio").FileIo,
12 ProjectIo = require("js/io/system/projectio").ProjectIo, 12 ProjectIo = require("js/io/system/projectio").ProjectIo,
13 TemplateCreator = require("node_modules/tools/template/template-creator").TemplateCreator; 13 TemplateMediator = require("js/document/mediators/template").TemplateDocumentMediator;
14//////////////////////////////////////////////////////////////////////// 14////////////////////////////////////////////////////////////////////////
15// 15//
16exports.IoMediator = Montage.create(Component, { 16exports.IoMediator = Montage.create(Component, {
17 //////////////////////////////////////////////////////////////////// 17 ////////////////////////////////////////////////////////////////////
18 // 18 //
19 hasTemplate: { 19 hasTemplate: {
20 enumerable: false,
21 value: false 20 value: false
22 }, 21 },
23 //////////////////////////////////////////////////////////////////// 22 ////////////////////////////////////////////////////////////////////
24 // 23 //
25 deserializedFromTemplate: { 24 deserializedFromTemplate: {
26 enumerable: false,
27 value: function () { 25 value: function () {
28 // 26 //
29 } 27 }
30 }, 28 },
31 //////////////////////////////////////////////////////////////////// 29 ////////////////////////////////////////////////////////////////////
32 // 30 //
31 tmplt: {
32 value: TemplateMediator
33 },
34 ////////////////////////////////////////////////////////////////////
35 //
33 fio: { 36 fio: {
34 enumerable: false,
35 value: FileIo 37 value: FileIo
36 }, 38 },
37 //////////////////////////////////////////////////////////////////// 39 ////////////////////////////////////////////////////////////////////
38 // 40 //
39 pio: { 41 pio: {
40 enumerable: false,
41 value: ProjectIo 42 value: ProjectIo
42 }, 43 },
43 //////////////////////////////////////////////////////////////////// 44 ////////////////////////////////////////////////////////////////////
44 // 45 //
45 getAppTemplatesUrlRegEx: { 46 parseToTemplate: {
46 enumerable: false, 47 value: function(content, template) {
47 value: function () { 48 //
48 var regex = new RegExp(chrome.extension.getURL('js/document/templates/montage-html').replace(/\//gi, '\\\/'), 'gi'); 49 if (template.name.toLowerCase() === 'banner' || template.name.toLowerCase() === 'animation') {
49 return regex; 50 //Getting dimensions of banner
50 } 51 var dimensions = template.id.split('x');
52 dimensions = {width: String(dimensions[0])+'px', height: String(dimensions[1])+'px'};
53 //
54 content = content.replace(/Dimensions@@@/gi, "Dimensions@@@"+template.id);
55 content = content.replace(/ninja-banner {}/gi, "ninja-banner {overflow: visible; width: "+dimensions.width+"; height: "+dimensions.height+"}");
56 content = content.replace(/ninja-content-wrapper {}/gi, "ninja-content-wrapper {overflow: hidden; width: "+dimensions.width+"; height: "+dimensions.height+"}");
57 }
58 //
59 return content;
60 }
51 }, 61 },
52 //////////////////////////////////////////////////////////////////// 62 ////////////////////////////////////////////////////////////////////
53 // 63 //
54 fileNew: { 64 fileNew: {
55 enumerable: false,
56 value: function (file, url, callback, template) {