(function($){ $.fn.twistWindow = function(prop){ // default parameters var options = $.extend({ closeIcon: '1', content: 'Description', draggable: '0', entityRequestID: '12345', id: 'Default', modal: '0', position: 'fixed', resizeable: '0', title:"Title", top: '5', width:'90', },prop); // call the functions to actually create the veil and window and style the window if (options.modal=='1') {twistCreateVeil();} twistCreateWindow(); twistStyleWindow(); $('body').css({}); $('.twistWindow').fadeIn(); if (options.draggable=='1') {$('#twistWindow'+options.id).draggable();} if (options.resizeable=='1') {$('#twistWindow'+options.id).resizable();} function twistStyleWindow(){ var windowMainWidth = $(window).width(); var windowTwistWidth = windowMainWidth * options.width; windowTwistWidth = Math.floor(windowTwistWidth/100); var windowMargin = windowMainWidth - windowTwistWidth; var windowLeft = Math.floor(windowMargin/2); windowLeft = windowLeft.toString(); $('.twistWindow'+options.id).css({ 'background': '#ddd', 'border':'2px solid #ff4f6e', 'border-radius':'15px', 'window-shadow': '0px 2px 7px #292929', '-moz-window-shadow': '0px 2px 7px #292929', '-webkit-window-shadow': '0px 2px 7px #292929', 'display':'block', 'height':options.height+'px', 'left':windowLeft+'px', 'min-height': options.height + 'px', 'position':'absolute', 'padding':'5px 20px 20px 20px', 'width':options.width+'%', 'z-index':'2000', }); $('.twistWindowIcon').css({ 'height':'20px', 'width':'20px', 'margin-left':'15px', 'z-index':'2100', }); $('.twistWindowVeil').css({ 'background-color':'rgba(0,0,0,0.3)', 'left':'0', 'width':'100%', 'z-index':'1000' }); $('.twistInnerWindow'+options.id).css({ 'background-color':'#fff', 'border-radius':'5px', '-moz-border-radius':'5px', '-webkit-border-radius':'5px', 'display':'block', 'height': (options.height - 130) + 'px', 'overflow':'auto', 'position':'relative', 'top':'10px', 'width':'100%', }); } /* create the veil */ function twistCreateVeil() { if (document.getElementById('twistWebEditorForm')) { // do what you need here windowHeight = $(window).height(); var offset = $('#twistWebEditorForm').offset(); bannerHeight = offset.top; veilHeight = windowHeight - bannerHeight; var veil = $('
').appendTo('body').css({ position: 'absolute', top: offset.top + 55, left: offset.left, height: veilHeight, width: $('#twistWebEditorForm').outerWidth() }); } else { var windowVeil = $('
'); $(windowVeil).appendTo('body'); } } /* create the window */ function twistCreateWindow(){ //$('body').css('overflow', 'hidden'); console.log('window id ' + options.id); var windowUpdateIcon = ''; draggableIcon = (options.draggable==1) ? 'pin.svg' : 'fullscreen.svg'; var twistWindow = '
' + '
' + '
' + options.title + '
' + '
' + windowUpdateIcon + '' + '' + '
' + '
' + '
' + '
' + options.content + '

' + '
' + 'Powered by the Twist! Cloud
'; if (options.modal=='1') { $(twistWindow).appendTo('#twistWindowVeil' + options.id); console.log('modal window created'); $('#twistWindow' +options.id).css({ "top": $(window).scrollTop()+'px', }); } else { $(twistWindow).appendTo('body'); console.log('non-modal window created'); $('#twistWindow' +options.id).css({ "top": $(window).scrollTop()+'px', }); } if (options.closeIcon=='0') { $('#twistWindowCloseIcon' + options.id).hide(); } $(document).on('click','#twistWindowUpdateIcon' + options.id,function(event) { console.log('window update item clicked'); twistLoadEntityRequest($(this).attr('data-entityRequest')); $('#twistWindowUpdateIcon' + options.id).die('click'); }); // handle click of window close icon $(document).on('click','#twistWindowCloseIcon' + options.id,function(event) { //$('.twistWindowIconClose').click(function(){ // if an exit url is specified if (!$('#twistWindowExitURL').val()=='') { if ($('#twistWindowExitURL').val()=='reload') { window.location.reload(true); } else { window.location.href=$('#twistWindowExitURL').val(); } } console.log('before remove'); console.log($('#twistWindow'+options.id)); var twistWindow = null; $('#twistWindow'+options.id).remove(); console.log('after remove'); console.log($('#twistWindow'+options.id)); $('#twistWindowVeil'+options.id).remove(); $('body').css({ 'overflow':'visible', }); $('#twistWindowCloseIcon' + options.id).die('click'); $('body').css('overflow', 'visible'); }); // handle click of drag / pin icon $(document).on('click','#twistWindowDraggableIcon' + options.id,function(event) { var isDisabled = $('#twistWindow'+options.id).draggable('option', 'disabled'); if (isDisabled===true) { $('#twistWindow'+options.id).draggable('enable'); $('#twistWindowDraggableIcon'+options.id).attr('src','https://www.twistwebsite.com/thirdParty/themify-icons/SVG/pin.svg'); } else { $('#twistWindow'+options.id).draggable('disable'); $('#twistWindowDraggableIcon'+options.id).attr('src','https://www.twistwebsite.com/thirdParty/themify-icons/SVG/fullscreen.svg'); } $('#twistWindowDraggableIcon' + options.id).die('click'); }); } return this; }; })(jQuery);