codemirror
4 years ago
jquery-tiptip
5 years ago
select2
5 years ago
how-to.js
8 years ago
how-to.min.js
6 years ago
jquery.colorbox.js
8 years ago
jquery.colorbox.min.js
6 years ago
metabox.js
4 years ago
metabox.min.js
4 years ago
multisite-updater.js
2 years ago
multisite-updater.min.js
6 years ago
welcome-modal.js
3 years ago
welcome-modal.min.js
3 years ago
wp-pages.js
3 years ago
wp-pages.min.js
3 years ago
yit-cpt-unlimited.js
6 years ago
yit-cpt-unlimited.min.js
6 years ago
yit-plugin-panel.js
1 year ago
yit-plugin-panel.min.js
1 year ago
yit-wp-pointer.js
5 years ago
yit-wp-pointer.min.js
5 years ago
yith-bh-onboarding.js
3 years ago
yith-bh-onboarding.min.js
3 years ago
yith-colorpicker.min.js
5 years ago
yith-dashboard.js
7 years ago
yith-dashboard.min.js
6 years ago
yith-date-format.js
5 years ago
yith-date-format.min.js
5 years ago
yith-enhanced-select-wc-2.6.js
5 years ago
yith-enhanced-select-wc-2.6.min.js
5 years ago
yith-enhanced-select.js
2 years ago
yith-enhanced-select.min.js
2 years ago
yith-fields.js
2 years ago
yith-fields.min.js
2 years ago
yith-promo.js
7 years ago
yith-promo.min.js
6 years ago
yith-system-info.js
2 years ago
yith-system-info.min.js
2 years ago
yith-ui.js
1 year ago
yith-ui.min.js
1 year ago
yith-update-plugins.js
7 years ago
yith-update-plugins.min.js
6 years ago
yith-ui.js
328 lines
| 1 | /* globals yith_plugin_fw_ui */ |
| 2 | |
| 3 | // Make sure the yith object exists. |
| 4 | window.yith = window.yith || {}; |
| 5 | |
| 6 | ( function ( $, yith ) { |
| 7 | yith.ui = yith.ui || {}; |
| 8 | |
| 9 | var cssClasses = function ( classes ) { |
| 10 | if ( typeof classes === 'string' ) { |
| 11 | return classes; |
| 12 | } else { |
| 13 | var filteredClasses = []; |
| 14 | |
| 15 | for ( var value of classes ) { |
| 16 | if ( value && filteredClasses.indexOf( value ) < 0 ) { |
| 17 | filteredClasses.push( cssClasses( value ) ); |
| 18 | } |
| 19 | } |
| 20 | return filteredClasses.join( ' ' ); |
| 21 | } |
| 22 | }; |
| 23 | |
| 24 | /** |
| 25 | * Confirm window. |
| 26 | */ |
| 27 | yith.ui.confirm = function ( options ) { |
| 28 | var defaults = { |
| 29 | title : false, |
| 30 | message : false, |
| 31 | onCreate : false, |
| 32 | onConfirm : false, |
| 33 | onCancel : false, |
| 34 | onClose : false, |
| 35 | classes : { |
| 36 | wrap : '', |
| 37 | content: '', |
| 38 | title : '', |
| 39 | message: '', |
| 40 | footer : '', |
| 41 | cancel : '', |
| 42 | confirm: '' |
| 43 | }, |
| 44 | confirmButtonType : 'confirm', |
| 45 | cancelButton : yith_plugin_fw_ui.i18n.cancel, |
| 46 | confirmButton : yith_plugin_fw_ui.i18n.confirm, |
| 47 | width : 350, |
| 48 | closeAfterConfirm : true, |
| 49 | allowWpMenu : false, |
| 50 | allowWpMenuInMobile : false, |
| 51 | showClose : true, |
| 52 | confirmButtonLoadingAfterConfirm: false, |
| 53 | closeWhenClickingOnOverlay : false |
| 54 | }, |
| 55 | self = {}; |
| 56 | |
| 57 | options = typeof options !== 'undefined' ? options : {}; |
| 58 | options = $.extend( {}, defaults, options ); |
| 59 | options.classes = $.extend( {}, defaults.classes, options.classes ); |
| 60 | |
| 61 | var classes = { |
| 62 | wrap : cssClasses( [ 'yith-plugin-fw__confirm__wrap', options.classes.wrap ] ), |
| 63 | content: cssClasses( [ 'yith-plugin-fw__confirm__content', options.classes.content ] ), |
| 64 | title : cssClasses( [ 'yith-plugin-fw__confirm__title', options.classes.title ] ), |
| 65 | message: cssClasses( [ 'yith-plugin-fw__confirm__message', options.classes.message ] ), |
| 66 | footer : cssClasses( [ 'yith-plugin-fw__confirm__footer', options.classes.footer ] ), |
| 67 | cancel : cssClasses( [ 'yith-plugin-fw__confirm__button', 'yith-plugin-fw__confirm__button--cancel', options.classes.cancel ] ), |
| 68 | confirm: cssClasses( [ 'yith-plugin-fw__confirm__button', 'yith-plugin-fw__confirm__button--' + options.confirmButtonType, options.classes.confirm ] ) |
| 69 | }, |
| 70 | dom = { |
| 71 | message: false, |
| 72 | footer : false, |
| 73 | cancel : false, |
| 74 | confirm: false |
| 75 | }, |
| 76 | modal = false, |
| 77 | initialize = function () { |
| 78 | create(); |
| 79 | initEvents(); |
| 80 | }, |
| 81 | handleClose = function () { |
| 82 | modal && modal.close(); |
| 83 | modal = false; |
| 84 | }, |
| 85 | create = function () { |
| 86 | dom.message = $( '<div class="' + classes.message + '">' ); |
| 87 | dom.footer = $( '<div class="' + classes.footer + '">' ); |
| 88 | dom.cancel = $( '<span class="' + classes.cancel + '">' + options.cancelButton + '</span>' ); |
| 89 | dom.confirm = $( '<span class="' + classes.confirm + '">' + options.confirmButton + '</span>' ); |
| 90 | |
| 91 | if ( options.message ) { |
| 92 | dom.message.html( options.message ); |
| 93 | } |
| 94 | |
| 95 | dom.footer.append( dom.cancel ); |
| 96 | dom.footer.append( dom.confirm ); |
| 97 | |
| 98 | modal = yith.ui.modal( |
| 99 | { |
| 100 | classes : { |
| 101 | wrap : classes.wrap, |
| 102 | title : classes.title, |
| 103 | content: classes.content |
| 104 | }, |
| 105 | title : options.title, |
| 106 | content : [ dom.message, dom.footer ], |
| 107 | width : options.width, |
| 108 | allowWpMenu : options.allowWpMenu, |
| 109 | allowWpMenuInMobile : options.allowWpMenuInMobile, |
| 110 | showClose : options.showClose, |
| 111 | onCreate : options.onCreate, |
| 112 | onClose : options.onClose, |
| 113 | closeWhenClickingOnOverlay: options.closeWhenClickingOnOverlay |
| 114 | } |
| 115 | ); |
| 116 | }, |
| 117 | handleCancel = function () { |
| 118 | if ( typeof options.onCancel === 'function' ) { |
| 119 | options.onCancel(); |
| 120 | } |
| 121 | |
| 122 | handleClose(); |
| 123 | }, |
| 124 | handleConfirm = function () { |
| 125 | if ( dom.confirm.hasClass( 'yith-plugin-fw__confirm__button--is-loading' ) ) { |
| 126 | return; |
| 127 | } |
| 128 | |
| 129 | if ( typeof options.onConfirm === 'function' ) { |
| 130 | options.onConfirm(); |
| 131 | } |
| 132 | |
| 133 | if ( options.confirmButtonLoadingAfterConfirm ) { |
| 134 | dom.confirm.addClass( 'yith-plugin-fw__confirm__button--is-loading' ); |
| 135 | } |
| 136 | |
| 137 | if ( options.closeAfterConfirm ) { |
| 138 | handleClose(); |
| 139 | } |
| 140 | }, |
| 141 | initEvents = function () { |
| 142 | dom.cancel.on( 'click', handleCancel ); |
| 143 | dom.confirm.on( 'click', handleConfirm ); |
| 144 | }; |
| 145 | |
| 146 | initialize(); |
| 147 | |
| 148 | self.elements = $.extend( {}, dom ); |
| 149 | self.modal = $.extend( {}, modal ); |
| 150 | self.close = handleClose; |
| 151 | self.cancel = handleCancel; |
| 152 | }; |
| 153 | |
| 154 | |
| 155 | /** |
| 156 | * Modal window. |
| 157 | */ |
| 158 | yith.ui.modal = function ( options ) { |
| 159 | var defaults = { |
| 160 | allowWpMenu : true, |
| 161 | allowWpMenuInMobile : false, |
| 162 | title : false, |
| 163 | content : false, |
| 164 | footer : false, |
| 165 | showClose : true, |
| 166 | closeSelector : false, |
| 167 | classes : { |
| 168 | wrap : '', |
| 169 | main : '', |
| 170 | close : '', |
| 171 | title : '', |
| 172 | content: '', |
| 173 | footer : '' |
| 174 | }, |
| 175 | width : 500, |
| 176 | allowClosingWithEsc : true, |
| 177 | closeWhenClickingOnOverlay: false, |
| 178 | scrollContent : true, |
| 179 | onCreate : false, |
| 180 | onClose : false |
| 181 | }, |
| 182 | self = {}; |
| 183 | |
| 184 | options = typeof options !== 'undefined' ? options : {}; |
| 185 | options = $.extend( {}, defaults, options ); |
| 186 | options.classes = $.extend( {}, defaults.classes, options.classes ); |
| 187 | |
| 188 | var container = $( '#wpwrap' ), |
| 189 | classes = { |
| 190 | wrap : [ 'yith-plugin-ui', 'yith-plugin-fw__modal__wrap', options.classes.wrap ], |
| 191 | main : [ 'yith-plugin-fw__modal__main', options.classes.main ], |
| 192 | close : [ 'yith-plugin-fw__modal__close', 'yith-icon', 'yith-icon-close', options.classes.close ], |
| 193 | title : [ 'yith-plugin-fw__modal__title', options.classes.title ], |
| 194 | content: [ 'yith-plugin-fw__modal__content', options.classes.content ], |
| 195 | footer : [ 'yith-plugin-fw__modal__footer', options.classes.footer ] |
| 196 | }, |
| 197 | dom = { |
| 198 | wrap : false, |
| 199 | main : false, |
| 200 | close : false, |
| 201 | title : false, |
| 202 | content: false, |
| 203 | footer : false |
| 204 | }, |
| 205 | initialize = function () { |
| 206 | close(); |
| 207 | |
| 208 | create(); |
| 209 | initEvents(); |
| 210 | }, |
| 211 | close = function () { |
| 212 | $( '.yith-plugin-fw__modal__wrap' ).remove(); |
| 213 | container.removeClass( 'yith-plugin-fw__modal--opened' ); |
| 214 | container.removeClass( 'yith-plugin-fw__modal--allow-wp-menu' ); |
| 215 | container.removeClass( 'yith-plugin-fw__modal--allow-wp-menu-in-mobile' ); |
| 216 | removeEvents(); |
| 217 | }, |
| 218 | handleClose = function () { |
| 219 | close(); |
| 220 | |
| 221 | if ( typeof options.onClose === 'function' ) { |
| 222 | options.onClose(); |
| 223 | } |
| 224 | }, |
| 225 | create = function () { |
| 226 | dom.wrap = $( '<div class="' + cssClasses( classes.wrap ) + '">' ); |
| 227 | dom.main = $( '<div class="' + cssClasses( classes.main ) + '">' ); |
| 228 | dom.close = $( '<span class="' + cssClasses( classes.close ) + '">' ); |
| 229 | dom.title = $( '<div class="' + cssClasses( classes.title ) + '">' ); |
| 230 | dom.content = $( '<div class="' + cssClasses( classes.content ) + '">' ); |
| 231 | dom.footer = $( '<div class="' + cssClasses( classes.footer ) + '">' ); |
| 232 | |
| 233 | dom.main.css( { width: options.width } ); |
| 234 | |
| 235 | if ( options.title ) { |
| 236 | if ( typeof options.title === 'string' ) { |
| 237 | dom.title.html( options.title ); |
| 238 | } else { |
| 239 | dom.title.append( options.title ); |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | if ( options.content ) { |
| 244 | if ( typeof options.content === 'string' ) { |
| 245 | dom.content.html( options.content ); |
| 246 | } else { |
| 247 | dom.content.append( options.content ); |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | if ( options.showClose ) { |
| 252 | dom.main.append( dom.close ); |
| 253 | } |
| 254 | |
| 255 | if ( options.title !== false ) { |
| 256 | dom.main.append( dom.title ); |
| 257 | } else { |
| 258 | container.addClass( 'yith-plugin-fw__modal--no-title' ); |
| 259 | } |
| 260 | |
| 261 | dom.main.append( dom.content ); |
| 262 | |
| 263 | if ( options.footer ) { |
| 264 | if ( typeof options.footer === 'string' ) { |
| 265 | dom.footer.html( options.footer ); |
| 266 | } else { |
| 267 | dom.footer.append( options.footer ); |
| 268 | } |
| 269 | |
| 270 | dom.main.append( dom.footer ); |
| 271 | } |
| 272 | |
| 273 | |
| 274 | dom.wrap.append( dom.main ); |
| 275 | |
| 276 | if ( options.scrollContent ) { |
| 277 | dom.wrap.addClass( 'yith-plugin-fw__modal__wrap--scroll-content' ); |
| 278 | } |
| 279 | |
| 280 | container.append( dom.wrap ); |
| 281 | container.addClass( 'yith-plugin-fw__modal--opened' ); |
| 282 | if ( options.allowWpMenu ) { |
| 283 | container.addClass( 'yith-plugin-fw__modal--allow-wp-menu' ); |
| 284 | } |
| 285 | |
| 286 | if ( options.allowWpMenuInMobile ) { |
| 287 | container.addClass( 'yith-plugin-fw__modal--allow-wp-menu-in-mobile' ); |
| 288 | } |
| 289 | |
| 290 | if ( typeof options.onCreate === 'function' ) { |
| 291 | options.onCreate(); |
| 292 | } |
| 293 | }, |
| 294 | handleClickOnOverlay = function ( event ) { |
| 295 | var target = $( event.target ); |
| 296 | if ( target.is( dom.wrap ) && options.closeWhenClickingOnOverlay ) { |
| 297 | handleClose(); |
| 298 | } |
| 299 | }, |
| 300 | initEvents = function () { |
| 301 | dom.close.on( 'click', handleClose ); |
| 302 | if ( options.closeSelector ) { |
| 303 | container.on( 'click', options.closeSelector, handleClose ); |
| 304 | } |
| 305 | |
| 306 | dom.wrap.on( 'click', handleClickOnOverlay ); |
| 307 | |
| 308 | $( document ).on( 'keydown', handleKeyboard ); |
| 309 | }, |
| 310 | removeEvents = function () { |
| 311 | $( document ).off( 'keydown', handleKeyboard ); |
| 312 | }, |
| 313 | handleKeyboard = function ( event ) { |
| 314 | if ( options.allowClosingWithEsc && event.keyCode === 27 ) { |
| 315 | handleClose(); |
| 316 | } |
| 317 | }; |
| 318 | |
| 319 | initialize(); |
| 320 | |
| 321 | self.elements = $.extend( {}, dom ); |
| 322 | self.close = handleClose; |
| 323 | |
| 324 | return self; |
| 325 | }; |
| 326 | |
| 327 | } )( window.jQuery, window.yith ); |
| 328 |