Skip to content

Instantly share code, notes, and snippets.

@gooocho
Created June 13, 2013 06:49
Show Gist options
  • Save gooocho/5771692 to your computer and use it in GitHub Desktop.
Save gooocho/5771692 to your computer and use it in GitHub Desktop.
(function(w) {
var model = {
getDetail: function(callback) {
$.getJSON('./detail.json')
.done(function(data) {
callback(data);
});
}
};
var View = (function() {
/**
* @constructor
*/
function View() {
this.main = $('#main');
this.btnShowModal = $('#btn_show_modal');
}
View.prototype.createModalWindow = function(detail) {
var rawModalWindowNode = document.createElement('div');
rawModalWindowNode.innerHTML = [
'<div class="modal-header">',
'<h3 class="title">' + detail.title + '</h3>',
'</div>',
'<div class="modal-body">',
'<p class="description">' + detail.description + '</p>',
'</div>',
'<div class="modal-footer">',
'<button class="btn btn_close">Close</button>',
'</div>'
].join('');
var modalWindowNode = $(rawModalWindowNode);
modalWindowNode.find('.btn_close').data('modalNode', modalWindowNode);
return modalWindowNode;
};
return View;
})();
$(document).ready(function() {
var view = new View();
view.btnShowModal.on(
'click',
function(e) {
model.getDetail(function(detail) {
var modalWindow = view.createModalWindow(detail);
view.main.append(modalWindow);
});
}
);
view.main.on(
'click',
'.btn_close',
function(e) {
$(this).data('modalNode').remove();
}
);
});
})(window);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment