Created
June 13, 2013 06:49
-
-
Save gooocho/5771692 to your computer and use it in GitHub Desktop.
https://github.com/feb0223/1pixelTestSample201306_01
jQuery 1.7らしく
This file contains 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
(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