Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(mvc.View): set style via options #2705

Merged
merged 1 commit into from
Jul 11, 2024

Conversation

kumilingus
Copy link
Contributor

Description

Allow style attribute to be set via options.

All other properties can be set either as a class property or as a constructor option.

// Already supported
(new mvc.View.extend({ style: { color: 'red' }})).el.style.color === 'red';
// Supported after this PR
(new mvc.View({ style: { color: 'red' }})).el.style.color === 'red'

Documentation

The documentation missing not only the style property but also events and constructor().
https://docs.jointjs.com/api/mvc/View/#properties

style

A hash of CSS properties that will be set as inline style on the view's el (color: red;, etc.), or a function that returns such a hash.

constructor()

There are several special options that, if passed, will be attached directly to the view: model, collection, el, id, className, tagName, attributes, style and events. If the view defines an initialize function, it will be called when the view is first created. If you'd like to create a view that references an element already in the DOM, pass in the element as an option: new View({el: existingElement})

var doc = documents.first();

new DocumentRow({
  model: doc,
  id: "document-row-" + doc.id
});

events

The events hash (or method) can be used to specify a set of DOM events that will be bound to methods on your View through delegateEvents.

JointJS will automatically attach the event listeners at instantiation time, right before invoking initialize.

var ENTER_KEY = 13;
var InputView = Backbone.View.extend({

  tagName: 'input',

  events: {
    "keydown" : "keyAction",
  },

  render: function() { ... },

  keyAction: function(e) {
    if (e.which === ENTER_KEY) {
      this.collection.add({text: this.$el.val()});
    }
  }
});

@jamesgeorgewilliams jamesgeorgewilliams merged commit db07082 into clientIO:master Jul 11, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants