1/* 2 * WPO Confirm Plugin 3 * Open dialog popup (YES/NO) 4 */ 5 6(function( $, undefined ) { 7 var options; 8 9 var default_options = { 10 'message' : '', 11 'yes_label' : 'Yes', 12 'no_label' : 'No' 13 }; 14 15 var methods = { 16 init : function( settings ) { 17 //merge default & current options 18 options = $.extend( {}, default_options, settings ); 19 20 $( this ).each( function() { 21 22 $( this ).data( 'options', options ); 23 24 methods.build.apply( $( this ), [options] ); 25 26 //init links clicks for show confirm 27 $( this ).click( function(e) { 28 var options = $( this ).data( 'options' ); 29 $( '#um_confirm_message' ).html( options.message ); 30 $( '#um_confirm_button_yes' ).html( options.yes_label ); 31 $( '#um_confirm_button_no' ).html( options.no_label ); 32 33 methods.show.apply( this ); 34 35 e.stopPropagation(); 36 }); 37 38 }); 39 40 }, 41 build : function( settings ) { 42 43 if( !methods.is_builded.apply( this ) ) { 44 45 var obj = $( '<div id="um_confirm_block"></div>').appendTo( 'body' ).html( '<div class="um_confirm">' + 46 '<div id="um_confirm_title">Confirmation</div>' + 47 '<div id="um_confirm_message"></div>' + 48 '<div id="um_confirm_buttons">' + 49 '<div id="um_confirm_button_yes" class="um_confirm_button">Yes</div>' + 50 '<div id="um_confirm_button_no" class="um_confirm_button">No</div>' + 51 '</div>' + 52 '</div>' + 53 '<div id="um_confirm_block_back"></div>' ); 54 55 $( document ).on( 'click', '#um_confirm_button_yes', function() { 56 var obj = $( '#um_confirm_block').data( 'obj' ); 57 methods.yes.apply( obj ); 58 }); 59 60 $( document ).on( 'click', '#um_confirm_button_no', function() { 61 var obj = $( '#um_confirm_block').data( 'obj' ); 62 methods.no.apply( obj ); 63 }); 64 65 $( document ).on( 'click', '#um_confirm_block_back', function() { 66 var obj = $( '#um_confirm_block').data( 'obj' ); 67 methods.close.apply( obj ); 68 }); 69 70 71 } 72 }, 73 is_builded : function() { 74 //return confirm already exists 75 return $('#um_confirm_block').length; 76 }, 77 show : function() { 78 $( '#um_confirm_block').data( 'obj', this ).show(); 79 var width = $('.um_confirm').width(); 80 var height = $('.um_confirm').height(); 81 $('.um_confirm').css('margin', '-' + height/2 + 'px 0 0 -' + width/2 + 'px' ); 82 }, 83 close : function() { 84 var opt = $( this ).data( 'options' ); 85 86 $( '#um_confirm_message' ).html( '' ); 87 $( '#um_confirm_block' ).hide(); 88 89 if( typeof opt.onClose === "function" ) { 90 opt.onClose.apply( this ); 91 } 92 }, 93 yes : function() { 94 var opt = $( this ).data( 'options' ); 95 96 var data = {}; 97 if( $( '#um_confirm_block').find('form').length ) { 98 var temp = $( '#um_confirm_block').find('form').serializeArray(); 99 for( key in temp ) { 100 data[ temp[ key ]['name'] ] = temp[ key ]['value']; 101 } 102 } 103 104 methods.close.apply( this ); 105 106 if( typeof opt.onYes === "function" ) { 107 opt.onYes.apply( this, [ data ] ); 108 } 109 }, 110 no : function() { 111 var opt = $( this ).data( 'options' ); 112 113 var data = {}; 114 if( $( '#um_confirm_block').find('form').length ) { 115 var temp = $( '#um_confirm_block').find('form').serializeArray(); 116 for( key in temp ) { 117 data[ temp[ key ]['name'] ] = temp[ key ]['value']; 118 } 119 } 120 121 methods.close.apply( this ); 122 123 if( typeof opt.onNo === "function" ) { 124 opt.onNo.apply( this, [ data ] ); 125 } 126 } 127 }; 128 129 $.fn.um_confirm = function( method ) { 130 if( methods[method] ) { 131 return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ) ); 132 } else if ( typeof method === 'object' || ! method ) { 133 return methods.init.apply( this, arguments ); 134 } else { 135 $.error( 'Method ' + method + ' does not exist for jQuery.um_confirm plugin' ); 136 } 137 }; 138 139 $.um_confirm = function( settings ) { 140 options = $.extend( {}, default_options, settings ); 141 $( settings.object ).data( 'options', options ); 142 143 144 methods.build.apply( $( settings.object ), [options] ); 145 if ( options.title ) { 146 $( '#um_confirm_title' ).html( options.title ); 147 } 148 $( '#um_confirm_message' ).html( options.message ); 149 $( '#um_confirm_button_yes' ).html( options.yes_label ); 150 $( '#um_confirm_button_no' ).html( options.no_label ); 151 methods.show.apply( settings.object ); 152 } 153 154})( jQuery );
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.