Created
April 12, 2014 10:14
-
-
Save bloodyowl/10528398 to your computer and use it in GitHub Desktop.
cornea real-world example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = require("bloody-events").create() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cornea = require("cornea") | |
, request = require("bloody-request") | |
, app = require("./app") | |
module.exports = cornea.extend({ | |
element : document.documentElement, | |
events : [ | |
{ | |
type : "click", | |
selector : ".js-Lightbox", | |
listener : "showLightbox" | |
} | |
], | |
showLightbox : function(eventObject, target){ | |
var url = target.getAttribute("data-url") | |
request.create(url) | |
.load() | |
.then(function(xhr){ | |
app.fire("lightbox:show", xhr.responseText) | |
}) | |
} | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cornea = require("cornea") | |
, app = require("./app") | |
module.exports = cornea.extend({ | |
element : ".Lightbox", | |
initialize : function(){ | |
var lightbox = this | |
app.listen("lightbox:show", function(data){ | |
lightbox.update("value", data) | |
lightbox.show() | |
}) | |
}, | |
events : [ | |
{ | |
type : "click", | |
selector : ".js-close", | |
listener : "hide" | |
} | |
], | |
hide : function(){ | |
this.element.classList.remove("Lightbox--visible") | |
}, | |
show : function(){ | |
this.element.classList.add("Lightbox--visible") | |
}, | |
template : function(data){ | |
return [ | |
"<div class='Lightbox-overlay'></div>", | |
"<div class='Lightbox-lightbox'>", | |
"<button class='Lightbox-close js-Close'>×</button>", | |
this.binding("value").toString({ | |
className : "Lightbox-content", | |
escape : false, | |
nodeName : "div" | |
}), | |
"</div>" | |
].join("") | |
}, | |
data : { | |
value : "" | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment