DoneJS StealJS jQuery ++ FuncUnit DocumentJS
3.0.0
2.3.27

 

  • Github
  • Twitter
  • Chat
  • Forum
  • Guides
  • Core
  • Ecosystem
  • Infrastructure
    • can-construct
    • can-control
    • can-event
    • can-event/async/async
    • can-event/batch/batch
    • can-observation
    • can-simple-map
    • can-util
    • can-view-callbacks
      • types
        • attrData
        • tagData
      • methods
        • attr
        • tag
    • can-view-live
    • can-view-model
    • can-view-nodelist
    • can-view-parser
    • can-view-scope
    • can-view-target
  • Legacy
  • Bitovi
    • Bitovi.com
    • Blog
    • Consulting
    • Training
    • Open Source
  • Chat
  • Forum
  • Star
  • Follow @canjs
  • CanJS
  • /
  • Infrastructure
  • /
  • can-view-callbacks
  • / On this page
    • can-view-callbacks

      module

      Registered callbacks for behaviors

      • npm package badge
      • Star
      • source

      Object

      Allows registering callback functions that will be called when tags and attributes are rendered in can-view-target.

      Registering tags

      callbacks.tag allows you to register a tag that custom behavior will be attached to.

      This will style elements using the blue-el tag with a blue background.

      var callbacks = require("can-view-callbacks");
      
      callbacks.tag("blue-el", function(el){
          el.style.background = "blue";
      });
      
      <blue-el><p>Some content with a blue background, gross!</p></blue-el>
      

      Registering attributes

      Similarly you can register a callback for an attribute. Here we are using a regular expression to match an attribute that starts with foo-:

      callbacks.attr(/foo-[\w\.]+/, function(el, attrData){
          // Get the part after foo-
          var attrValue = attrData.attributeName.substr(4);
      
          // Set it's content
          el.textContent = attrValue;
      });
      

      So that:

      <div foo-bar></div>
      

      Renders as:

      <div foo-bar>bar</div>
      

      CanJS is part of DoneJS. Created and maintained by the core DoneJS team and Bitovi. Currently 3.0.0.