Skip to content

Instantly share code, notes, and snippets.

@nicohvi
Created October 31, 2013 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicohvi/7248457 to your computer and use it in GitHub Desktop.
Save nicohvi/7248457 to your computer and use it in GitHub Desktop.
Modular javascript
var Order = function($el) {
// private variables
el = $el;
// public API
var Order = {
removeTarget: function() {
el.find('#order-target').remove();
removePersonalia();
updateView();
},
removeDirectMail: function() {
el.find('#order-direct-mail').remove();
updateView();
}
}
// private functions
function removePersonalia() {
el.find('.personalia').remove();
}
function updateView() {
if( !hasTarget() ) addTargetButton()
}
function hasTarget() {
return el.find('#order-target').length > 0;
}
function addTargetButton() {
el.find('#target').prepend('<div class="push-3-2 order-button">'+
'<a class="btn" href="http://localhost:3000/malgruppe" id="add-target-to-order">'+
'Legg til målgruppe'+
'</a></div>');
}
return Order;
}
@haeric
Copy link

haeric commented Oct 31, 2013

For ordens skyld: husk var når du erklærer variabler! Altså var el = $el; :) Men du trenger jo ikke den deklarasjonen engang, du kan jo bare bruke $el overvalt?

@nicohvi
Copy link
Author

nicohvi commented Oct 31, 2013

Det er sant!

Laget egentlig bare deklarasjonen av gamle vaner :p

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment