coffeescript

Fabricjs: fill svg with image pattern

China☆狼群 提交于 2020-01-24 12:24:09
问题 I’d like to load my SVG file, and fill it with pattern, created from my image file. Here is my current approach: canvas = new fabric.Canvas('mainCanvas') # image = new fabric.Image(img[0]) # console.log image fabric.loadSVGFromURL '/assets/my.svg', (objects) -> fabric.util.loadImage "url/to/my/image", (image) -> console.log image svg = fabric.util.groupSVGElements(objects) svg = svg.scale(0.04).set(fill: "black", opacity: 0.5 ) svg.fill = new fabric.Pattern source: image repeat: "no-repeat"

Dynamic file mapping with relative destination

强颜欢笑 提交于 2020-01-24 00:44:10
问题 This is a generic question about dynamic file mapping with Grunt.js , but for the example purpose, I'll be trying to build coffee files in a project with a dynamic structure : Here, I can have multiple (dynamic) target folders with a different depth. Finding coffee files remain easy, it will match **/coffee/*.coffee anytime. What I'm trying to achieve, is making the dest property relative to the matched coffee file : find **/coffee/*.coffee compile to ../js/*.js Instead of making it relative

Ember fixtures not working

懵懂的女人 提交于 2020-01-23 18:38:09
问题 This is my code (using ember-cli): app.coffee `import Ember from 'ember'` `import Resolver from 'ember/resolver'` `import loadInitializers from 'ember/load-initializers'` Ember.MODEL_FACTORY_INJECTIONS = true App = Ember.Application.extend modulePrefix: 'dashboard' # TODO: loaded via config Resolver: Resolver loadInitializers App, 'dashboard' `export default App` adapters/application.coffee `import DS from 'ember-data'` ApplicationAdapter = DS.FixtureAdapter.extend() `export default

Why multipart is not generating close events

a 夏天 提交于 2020-01-23 17:49:07
问题 Hi I won't to handle upload stream by myself without touching a disk drive. So, the natural selection for me was multiparty module. I took the general example and according the instruction from page https://npmjs.org/package/multiparty I changed form.parse to non callback request. In that case the disk won't be touched. My code looks like this: multiparty = require("multiparty") http = require("http") util = require("util") # show a file upload form http.createServer((req, res) -> if req.url

_.pluck of Backbone collection not working

戏子无情 提交于 2020-01-23 17:46:44
问题 I have this model - class pt.SearchResultModel extends Backbone.Model defaults: id:"", image:"", colour:"" I am trying this - _.pluck(resultsCollection,'id') But it keeps returning undefined - not sure what's going on. What syntax error am I making? 回答1: The Underscore array methods are embedded (so to speak) into Backbone collections. You can call them directly on them: resultsCollection.pluck 'id' In most of the cases you could also use the Underscore methods over the collection's models

Dynamically assign properties to a JS object

非 Y 不嫁゛ 提交于 2020-01-23 11:03:11
问题 I needed to dynamically add properties to an js Object, which I achieved via eval(): $ -> #Methods window.add_address = (attributes, id=new Date().getTime())-> $container = $('ul#addresses_list') $unit = $('<li>') $.each attributes, (key,value)-> $input = $('<input type="hidden">') $input.attr 'name', "contact[addresses_attributes][#{id}][#{key}]" $input.val value $unit.append $input $container.append $unit #Events #Add address button $('a#add_address').on 'click', (ev)-> attributes = new

How to make method private and inherit it in Coffeescript?

柔情痞子 提交于 2020-01-19 17:18:21
问题 How to make method "btnClick" private? class FirstClass constructor: -> $('.btn').click @btnClick btnClick: => alert('Hi from the first class!') class SecondClass extends FirstClass btnClick: => super() alert('Hi from the second class!') @obj = new SecondClass http://jsfiddle.net/R646x/17/ 回答1: There's no private in JavaScript so there's no private in CoffeeScript, sort of. You can make things private at the class level like this: class C private_function = -> console.log('pancakes') That

How does Trello access the user's clipboard?

倾然丶 夕夏残阳落幕 提交于 2020-01-18 04:32:28
问题 When you hover over a card in Trello and press Ctrl + C , the URL of this card is copied to the clipboard. How do they do this? As far as I can tell, there is no Flash movie involved. I've got Flashblock installed, and the Firefox network tab shows no Flash movie loaded. (That's the usual method, for example, by ZeroClipboard.) How do they achieve this magic? (Right at this moment I think I had an epiphany: You cannot select text on the page, so I assume they have an invisible element, where

How to include one CoffeeScript file in another in order to share specs amongst jasmine

a 夏天 提交于 2020-01-17 05:24:16
问题 I'm unable to get CoffeeScript in Jasmine to include another file. I'd like to share common functions amongst Jasmine specs which are written in CoffeeScript. I'm sure I'm getting the syntax wrong, I've tried require and include , I've tried putting the file in the same folder just to be sure, I've tried # = syntax too. I'm looking for something similar to include in php, i.e. go here -> compile this -> come back so the compile this step can easily be shared. NB, I am not talking about

Dashing problems using Rickshaw with one widget

杀马特。学长 韩版系。学妹 提交于 2020-01-17 04:52:07
问题 I'm currently trying to add data types to the x-axis of my graphs in Dashing using the Rickshaw widget. Essentially I want to create data call in the dashboard file that relates to an if statement in the Coffeescript widget Code from coffeescript (Rickshaw.coffee) # Define elements for Rickshaw time time = new Rickshaw.Fixtures.Time months = time.unit('month') weeks = time.unit('week') if @get("weekly-view") x_axis = new Rickshaw.Graph.Axis.Time(graph: graph, timeUnit: weeks) y_axis = new