Skip to content

Instantly share code, notes, and snippets.

View lorenzoplanas's full-sized avatar
💭
🏖️

Lorenzo Planas lorenzoplanas

💭
🏖️
View GitHub Profile
@lorenzoplanas
lorenzoplanas / pulsate_path.css
Created October 12, 2014 17:05
Pulsating SVG Path
.pulsate path {
stroke: #2980b9;
-webkit-animation: pulsate 5s ease-out;
-webkit-animation-iteration-count: infinite;
-moz-animation: pulsate 5s ease-out;
-moz-animation-iteration-count: infinite;
-ms-animation: pulsate 5s ease-out;
-ms-animation-iteration-count: infinite;
animation: pulsate 5s ease-out;
animation-iteration-count: infinite;
// Listen for DOM events and trigger applicable methods
this.domListen = function(element) {
// Using jQuery's .on() for DOM events
(element || this.$element).on("click", ".close", null, self.unload);
}
// Tear down this presenter
this.unload = function(e) {
if (e) { e.preventDefault(); };
self.unlisten.call(self);
@lorenzoplanas
lorenzoplanas / item.js
Created March 12, 2014 08:30
Test event binding / unbinding with Jasmine
App.ItemPresenter = (function() {
var ItemPresenter = function($element, options) {
var self = this;
this.$element = $element;
this.bus = options.bus;
this.model = options.model;
this.clasName = "item";
this.listen = function() {
// Search for a selector within $el
function finder(selector) {
return (function() {
return $(selector, this.$el);
})
}
@lorenzoplanas
lorenzoplanas / DomHooks
Last active August 29, 2015 13:57
DOM hooks
// DOM hooks
this.$form = finder("form");
this.$inputEmail = finder("input[name='email']");
this.$inputPassword = finder("input[name='password']");
this.$errorMessages = finder(".error");
// Handle login form submit
this.logIn = function(e) {
e.preventDefault();
this.$errorMessages.remove();
@lorenzoplanas
lorenzoplanas / LoginSpecRefactored
Created March 5, 2014 16:15
Login spec refactored
it("renders an error message if credentials incorrect", function() {
loginPresenter.render();
loginPresenter.bindDomEvents();
expect(loginPresenter.$errorMessages().length).toBe(0);
loginPresenter.$inputEmail().val("wrong");
loginPresenter.$inputPassword().val("wrong");
loginPresenter.$form().trigger("submit");
@lorenzoplanas
lorenzoplanas / domHooksAsFunctions
Created March 5, 2014 16:14
DOM hooks as functions
// DOM Hooks
this.$form = function() {
return $("form", this.$el);
};
this.$inputEmail = function() {
return $("input[name='email']", this.$el);
};
this.$inputPassword = function() {
@lorenzoplanas
lorenzoplanas / LoginSpec
Created March 5, 2014 16:13
Login spec
it("renders an error message if credentials incorrect", function() {
loginPresenter.render();
loginPresenter.listen();
expect($(".error", loginPresenter.$el).length).toBe(0);
$("input[name='email']", loginPresenter.$el).val("wrong");
$("input[name='email']", loginPresenter.$el).val("wrong");
$("form", loginPresenter.$el).trigger("submit");
@lorenzoplanas
lorenzoplanas / loginFunction
Created March 5, 2014 16:12
Login function
// Handle login form submit
this.logIn = function(e) {
e.preventDefault();
$(".error", this.$el).remove();
options.user.login({
email: $("input[name='email']", this.$el).val();
password: $("input[name='password']", this.$el).val();
})
.fail(this.loginError.bind(this))
@lorenzoplanas
lorenzoplanas / login.js
Last active August 29, 2015 13:57
DOM Hooks for cleaner presenter specs (using Riot.js and Jasmine)
App.LoginPresenter = (function() {
var Login = function($el, options) {
this.$el = $el;
this.name = "login";
this.errorMessage = $.render(
App.templates.error, { text: "Wrong credentials" }
);
// Listen to relevant events