Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

ajout FactorSelector

  • Loading branch information...
commit 18f0268cf7a5bfa85f0b9479073c311a64c4d0e3 1 parent 8dea83e
@Mparaiso authored
Showing with 67 additions and 7 deletions.
  1. +2 −0  index.html
  2. +20 −4 js/faviconbuilder.coffee
  3. +45 −3 js/faviconbuilder.js
View
2  index.html
@@ -21,6 +21,8 @@
<div id="menu"> </div>
<h3>Favicon preview</h3>
<div id="canvasPreview"></div>
+ h3{factorSelector}
+ <div id="factorSelector"></div>
</div>
<div class="left inline">
<h3>Favicon</h3>
View
24 js/faviconbuilder.coffee
@@ -126,6 +126,9 @@ class App.Models.ColorSelector
class App.Models.CanvasPreview
constructor:(@targetId,@gridModel,@factor=4)->
+class App.Models.FactorSelector
+ constructor:(@targetId,@selectors=[1,2,3,4])->
+
class App.Models.Menu
constructor:(@items=[],@targetId)->
addItem:(item)->
@@ -168,7 +171,7 @@ class App.Views.Grid
@eventDispatcher.dispatch(new App.Utils.Event("faviconrender"),@)
fillCell:(e)->
@gridModel.grid[parseInt(e.currentTarget.dataset.row)][parseInt(e.currentTarget.dataset.column)].color = @pen.color.color # App.Models.Application::currentColor.color
- @render()
+ @eventDispatcher.dispatch(new App.Utils.Event("updateviews"),@)
setDrawMode:(event)=>
@drawMode = event.datas
setPenColor:(color)=>
@@ -246,6 +249,16 @@ class App.Views.CanvasPreview
@el=@model.targetId.innerHTML
return this
+class App.Views.FactorSelector
+ constructor:(@model)->
+ render:->
+ @el = ""
+ for i in @model.selectors
+ @el+="<input type='radio' name='factor' value=#{i}/> x #{i} <br/>"
+ @model.targetDiv?.innerHTML = @el
+ return this
+x #{i} <br/>"
+
class App.Views.Menu
constructor:(@model)->
@eventDispatcher = new App.Utils.EventDispatcher()
@@ -283,6 +296,7 @@ class Main
$canvasPreview = document.getElementById("canvasPreview")
$colorSelector = document.getElementById("colorSelector")
$menu = document.getElementById("menu")
+ $factorSelector = document.getElementById("factorSelector")
title = "Fav icon builder"
defaultColor = "#000000"
### MODELS ###
@@ -318,7 +332,7 @@ class Main
@gridView.divTargetId.onmouseup = (e)=>
@gridView.eventDispatcher.dispatch(new App.Utils.Event("drawmodechange"),false)
@gridView.eventDispatcher.addListener("faviconrender",@renderCanvasPreview)
-
+ @gridView.eventDispatcher.addListener("updateviews",@updateViews)
renderCanvasPreview:(e)=>
@canvasPreviewView.render()
oncolorchange:(e)=>
@@ -344,7 +358,9 @@ class Main
@gridModel.grid = gridModel.grid
@gridModel.rows = gridModel.rows
@gridModel.columns = gridModel.columns
- @applicationView.render()
-
+ @updateViews()
+ updateViews:=>
+ @applicationView.render()
window?.onload = ->
window?.main = new Main()
+
View
48 js/faviconbuilder.js
@@ -256,6 +256,17 @@ App.Models.CanvasPreview = (function() {
})();
+App.Models.FactorSelector = (function() {
+
+ function FactorSelector(targetId, selectors) {
+ this.targetId = targetId;
+ this.selectors = selectors != null ? selectors : [1, 2, 3, 4];
+ }
+
+ return FactorSelector;
+
+})();
+
App.Models.Menu = (function() {
function Menu(items, targetId) {
@@ -337,7 +348,7 @@ App.Views.Grid = (function() {
Grid.prototype.fillCell = function(e) {
this.gridModel.grid[parseInt(e.currentTarget.dataset.row)][parseInt(e.currentTarget.dataset.column)].color = this.pen.color.color;
- return this.render();
+ return this.eventDispatcher.dispatch(new App.Utils.Event("updateviews"), this);
};
Grid.prototype.setDrawMode = function(event) {
@@ -483,6 +494,30 @@ App.Views.CanvasPreview = (function() {
})();
+App.Views.FactorSelector = (function() {
+
+ function FactorSelector(model) {
+ this.model = model;
+ }
+
+ FactorSelector.prototype.render = function() {
+ var i, _i, _len, _ref, _ref2;
+ this.el = "";
+ _ref = this.model.selectors;
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ i = _ref[_i];
+ this.el += "<input type='radio' name='factor' value=" + i + "/> x " + i + " <br/>";
+ }
+ if ((_ref2 = this.model.targetDiv) != null) _ref2.innerHTML = this.el;
+ return this;
+ };
+
+ return FactorSelector;
+
+})();
+
+x;
+
App.Views.Menu = (function() {
function Menu(model) {
@@ -542,6 +577,7 @@ App.Controllers.Application = (function() {
Main = (function() {
function Main() {
+ this.updateViews = __bind(this.updateViews, this);
this.restoreFromLocal = __bind(this.restoreFromLocal, this);
this.savetolocal = __bind(this.savetolocal, this);
this.emptygrid = __bind(this.emptygrid, this);
@@ -549,12 +585,13 @@ Main = (function() {
this.exportCanvas = __bind(this.exportCanvas, this);
this.oncolorchange = __bind(this.oncolorchange, this);
this.renderCanvasPreview = __bind(this.renderCanvasPreview, this);
- var $canvasPreview, $colorSelector, $menu, $target, defaultColor, title,
+ var $canvasPreview, $colorSelector, $factorSelector, $menu, $target, defaultColor, title,
_this = this;
$target = document.getElementById("target");
$canvasPreview = document.getElementById("canvasPreview");
$colorSelector = document.getElementById("colorSelector");
$menu = document.getElementById("menu");
+ $factorSelector = document.getElementById("factorSelector");
title = "Fav icon builder";
defaultColor = "#000000";
/* MODELS
@@ -595,6 +632,7 @@ Main = (function() {
return _this.gridView.eventDispatcher.dispatch(new App.Utils.Event("drawmodechange"), false);
};
this.gridView.eventDispatcher.addListener("faviconrender", this.renderCanvasPreview);
+ this.gridView.eventDispatcher.addListener("updateviews", this.updateViews);
}
Main.prototype.renderCanvasPreview = function(e) {
@@ -635,10 +673,14 @@ Main = (function() {
this.gridModel.grid = gridModel.grid;
this.gridModel.rows = gridModel.rows;
this.gridModel.columns = gridModel.columns;
- return this.applicationView.render();
+ return this.updateViews();
}
};
+ Main.prototype.updateViews = function() {
+ return this.applicationView.render();
+ };
+
return Main;
})();
Please sign in to comment.
Something went wrong with that request. Please try again.