var opDailogCallbackListner = [];
$.fn.opDialog = function(_value, _id, _data){
var tempId = this.selector.replace('#','');
if($(this.selector).length != 1){
$('body').append('<iframe id="'+tempId+'" style="display: none;" data-value=undefined iframe>');
}
if(_value == 'open'){
$(this.selector).css({"background-color": "rgba(0, 0, 0, 0.5)"
, "display":"block"
, "left": "0px"
, "top": "0px"
, "width": "100%"
, "height": "100%"
, "position": "absolute"
});
var url = $(this.selector).attr('data-url');
$(this.selector).attr('src',inavigator.getUrl(url));
}else if(_value == 'close'){
var removeIndex = -1;
for (var index = 0; index < window.parent.opDailogCallbackListner.length; index++) {
if(window.parent.opDailogCallbackListner[index].id == tempId){
removeIndex = index;
var events = window.parent.opDailogCallbackListner[index].event;
for (var key in events) {
if(_id == key){
events[key](_data);
}
}
}
}
if(removeIndex != -1){
window.parent.opDailogCallbackListner.splice(removeIndex,1);
}
var frame = window.parent.document.getElementById(tempId);
frame.parentNode.removeChild(frame);
}else{
$(this.selector).attr('data-url',_value.url);
$(this.selector).attr('data-value', JSON.stringify(_value.data));
opDailogCallbackListner.push({id:tempId , event:_value.buttons});
}
//요 리턴하는법이 체이닝 방식으로 할수있는법
// $('a').func1().func2() 이렇게 호출가능
return this;
}
//사용방법 팝업 생성
$('#iframe0').opDialog({
url : 'popup_test.html',
data : { text : "전달"},
buttons: {
button0 : function(d){console.log(d)},
button1 : function(d){console.log(d)}
}
}).opDialog('open');
//사용방법 팝업 닫기
$('#iframe0').opDialog('close', "button1" , {text :"리턴데이타" });