Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="http://documentcloud.github.com/underscore/underscore-min.js"></script>
<script src="http://documentcloud.github.com/backbone/backbone-min.js"></script>
  <script src="https://raw.github.com/marionettejs/backbone.wreqr/master/lib/backbone.wreqr.js"></script>
  <script src="https://raw.github.com/marionettejs/backbone.eventbinder/master/lib/backbone.eventbinder.js"></script>
  <script src="https://raw.github.com/marionettejs/backbone.marionette/master/lib/backbone.marionette.js"></script>
<meta name="description" content="" />
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  <script type="text/html" id="template-empty"> </script>
<script type="text/html" id="template-image-and-map">
<img usemap="#imagemap" style="width:200px; height:200px" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyRpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNiAoTWFjaW50b3NoKSIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDpCRUQwREIxNjE4OEIxMUUyOTRGQkFEQjFENkJFMUE0NyIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDpCRUQwREIxNzE4OEIxMUUyOTRGQkFEQjFENkJFMUE0NyI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOkJFRDBEQjE0MTg4QjExRTI5NEZCQURCMUQ2QkUxQTQ3IiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOkJFRDBEQjE1MTg4QjExRTI5NEZCQURCMUQ2QkUxQTQ3Ii8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+5vfxFAAAABpJREFUeNpi/P//PwMxgImBSDCqkDoKAQIMANUSAxFqvpFcAAAAAElFTkSuQmCC" />
<map name="imagemap"></map>
</script>
  
<script>
window.addEventListener('load', function() {
  var Button = Backbone.Model.extend({
    defaults: {
      name: 'default',
      mouse_state: 'off',
      shape: 'rect',
      coords: '0,0,20,20'
    }
  });
  var Buttons = Backbone.Collection.extend({
    model: Button,
    createAll: function() {
      var list = [{
        name: 'insert',
        shape: 'poly',
        coords: '10,10,20,0,30,10,40,20,30,30,20,40'
      }, {
        name: 'higher',
        shape: 'poly',
        coords: '110,10,120,0,130,10,140,20,130,30,120,40'
      }, {
        name: 'lower',
        shape: 'poly',
        coords: '110,110,120,100,130,110,140,120,130,130,120,140'
      }],
        buttons = this;
      list.forEach(function(props) {
        buttons.add(props);
      });
    }
  });
  /* SpriteView only _reacts_ to changes in the Model, it never sets anything there */
  var SpriteView = Marionette.ItemView.extend({
    template: '#template-empty',
    // empty, we just want a single tag
    modelEvents: {
      'change:mouse_state': 'changeMouseState'
    },
    initialize: function() {
      // add initial classes to the created element
      $(this.el).addClass('sprite ' + this.model.get('name') + ' ' + this.model.get('mouse_state'));
    },
    changeMouseState: function() {
      $(this.el).removeClass('mouseover mouseout mousedown mouseup').addClass(this.model.get('mouse_state'));
    }
  });
  var SpritesView = Marionette.CompositeView.extend({
    itemView: SpriteView,
    template: '#template-empty'
  });
  // The &quot;areas&quot; in the &quot;map&quot; actual set things on the model,
  // rather than reacting to changes in it
  var AreaView = Marionette.ItemView.extend({
    template: '#template-empty',
    // empty, we just want a single tag
    tagName: 'area',
    events: {
      mouseover: 'mouseevent',
      mouseout: 'mouseevent',
      mousedown: 'mouseevent',
      mouseup: 'mouseevent',
      click: 'clickevent'
    },
    initialize: function() {
      var name = this.model.get('name');
      $(this.el).attr({
        href: '#',
        title: name,
        shape: this.model.get('shape'),
        coords: this.model.get('coords')
      });
    },
    mouseevent: function(event) {
      this.model.set('mouse_state', event.type);
    },
    clickevent: function(event) {
    // Assumes you're using a Marionette App and it's "vent".
      App.vent.trigger('click', this.model.get('name'));
      return false;
    }
  });
  var ImageAndMap = Marionette.CompositeView.extend({
    template: '#template-image-and-map',
    itemView: AreaView,
    itemViewContainer: 'map'
  });
  // make an App
  var App = new Marionette.Application();
  // add some regions for automatic dom insertion
  App.addRegions({
    sprites: '#sprites',
    overlay: '#overlay'
  });
  // create the default collection
  var buttons = new Buttons();
  buttons.createAll();
  // show the views
  App.sprites.show(new SpritesView({collection:buttons}));
  App.overlay.show(new ImageAndMap({collection:buttons}));
  App.vent.on('click', function(name) {
    console.log('You clicked: '+name);
  })
  App.start();
});
    
</script>
<style>
  #sprites {
    background-color: #eee;
  }
  #sprites, #overlay {
    width: 200px;
    height: 200px;
    position: absolute;
    top: 0px;
    left: 0px;
  }
  .sprite {
    background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAACtCAYAAADyDywn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DnJ4R20hRKXAgZewNq6tg2FL9nEDww1TbDBSk16fc+qiZrsoEIXvMCIOqXu5pDrxYzOjDLJywtIpv1Rpuh3khDrBQnd3L7HgCZ/SCz6P/t5JS+7IPaf5vhbr4vD/XNXghoIYEa6t6GVCoBknNm380dKAbNAd3VXHYfcSt3owKlgnAMMSctILa2EyQJwO6E4j1EkGtt/OddJ5E66boxE+MwUg8gK+ZQpR2A010irUSYfuddmvNgFEHKTh8aDY+z26q9YKUckU1hS7WPSc67KrvAUgEgAiByMYNJvYMPltTiki7qLvQUQiRDxAZCEEfj5oQKDt/heiwdqxe/UsIi+BsLWwwQMCk0IRme3sWUR2hHCIEC2NriCKiEu4yNrqaLtG6Sgi4d+lEBYRorneGTwgeOaxDXcWkS5RRFqIbiDMDU6iuc4ZZBFx8qc7i0joXhaolXgA7RbCHFQR4XgpvbitHiLSDJOPh9ezsIsJhd0JAoelIYhqhIfGg13KQ0SaAeZOmHwWRsdubS/szhB480fzLdNuQQhpN8XFHYbJF4OIXGBvZbNsoZSkhHkBxtIFBArO4AHBybLCzU4OQG6zt3K1GAHckRdqBd6zwnM3iCeEkiu77nzQQXQQHUQH0UF0EB1EB1Hv+L8AAwAjp68gIFAl9gAAAABJRU5ErkJggg==);
    width: 30px;
    height: 44px;
    position: absolute;
    background-repeat: no-repeat;
    background-position: -10px -10px;
  }
  .insert {
    top: 0px;
    left: 10px;
  }
  .higher {
    top: 0px;
    left: 110px;
  }
  .lower {
    top: 100px;
    left: 110px;
  }
  .insert.mouseover,
  .higher.mouseover,
  .lower.mouseover {
    background-position: -10px -65px;
  }
  .insert.mousedown,
  .higher.mousedown,
  .lower.mousedown {
    background-position: -10px -120px;
  }
</style>
  <div id="controls">
    <div id="sprites"></div>
    <div id="overlay"></div>
  </div>
  
</body>
</html>
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
pete_otaquipro
0viewers