Code Monkey home page Code Monkey logo

Comments (6)

mlshvdv avatar mlshvdv commented on August 18, 2024

@anthonyjb I've added gif to show case.

from contenttools.

anthonyjb avatar anthonyjb commented on August 18, 2024

Yes (well sort of) - there is already a behaviour defined for the the mouse up/down events against an image so you'd be changing that behaviour in essence. There are a couple of ways to do that:

You can either monkey patch the classes directly:

# Override the specific behaviour
ContentEdit.Image._onMouseDown = (ev) ->
    ...Perform my custom behaviour...

# Change the DOM event bindings
ContentEdit.Image._addDOMEventListeners = () ->

    @_domElement.addEventListener 'click', (ev) =>
        ...Perform my custom behaviour...

Alternatively you could inherit from the Image class and create a new class to override the behaviours:

class MyImage extends ContentEdit.Image

    ...override the _onMouseDown or _addDOMEventListeners methods here...

# Register your new class as the default class to use for images
ContentEdit.TagNames.get().register(MyImage, 'img')

Finally you could potentially add custom events via the root node like so:

# Capture node being mounted in the DOM event
ContentEdit.Root().bind 'mount', (node) ->

    # Check the node is an image
    if node.constructor.name != 'Image'
        return

    node.domElement().addEventListener 'click', (ev) ->
        ...Perform my custom behaviour...

from contenttools.

mlshvdv avatar mlshvdv commented on August 18, 2024

@anthonyjb Thanks! Will try.

from contenttools.

anthonyjb avatar anthonyjb commented on August 18, 2024

@MalyshevDmitry Let me know how you get on - this is bound to be something others want to do so if there's no an easy way potentially this is something I need to improve on.

from contenttools.

bfintal avatar bfintal commented on August 18, 2024

Interested in this as well.

from contenttools.

Pandahisham avatar Pandahisham commented on August 18, 2024

following

from contenttools.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.