1/** 2 * Created by Sara on 19-Oct-17. 3 * 4 * iframes don't work with jquery 3.1.1 5 * now with some changes iframes work! 6 * 7 */ 8/* ======================================================================== 9 * SaRibe: eModal.js v1.2.65 10 * http://saribe.github.io/eModal 11 * ======================================================================== 12 * Copyright Samuel Ribeiro. 13 * Licensed under MIT. 14 * ======================================================================== */ 15 16/** 17 * Easy Modal for bootstrap, is a simple way to create modal dialogs using javascript. 18 * @params allowed elements: 19 * buttons {array}: An array of objects to configure buttons to modal footer; only able if message == string 20 * css {object}: CSS object try apply into message body; only able if message == string 21 * loading {boolean}: Set loading progress as message. 22 * message {string|object}: The body message string or the HTML element. e.g.: $(selector); 23 * size {string}: sm || lg || xl -> define the modal size. 24 * subtitle {string}: The header subtitle string. This appear in a smaller text. 25 * title {string}: The header title string. 26 * useBin {boolean}: Set message as recyclable. 27 * classname {string}: Set a class container applied to modal-dialog. 28 * </summary> 29 * <param name="params" >Modal options parameters of string body message.</param> 30 * <param name="title" >The string header title or a flag to set default parameters.</param> 31 * <returns type="Promise">{ then, element }.</returns> 32 */ 33 34; 35(function (define) { 36 define(['jquery'], function ($, root) { 37 var $modal; 38 var BIN = 'recycle-bin'; 39 var DIV = '<div>'; 40 var EMPTY = ''; 41 var EVENT_CLICK = 'click'; 42 var EVENT_HIDE = 'hide'; 43 var EVENT_SHOW = 'shown.bs.modal'; 44 var EVENT_SUBMIT = 'submit'; 45 var FOOTER_ID = 'eFooter'; 46 var HIDE = EVENT_HIDE + '.bs.modal'; 47 var INPUT = 'input'; 48 var KEY_DANGER = 'danger'; 49 var LABEL = { 50 OK: 'Cancel', 51 True: 'False', 52 Yes: 'No' 53 }; 54 var lastParams = {}; 55 var MODAL_BODY = 'modal-body'; 56 var MODAL_DIALOG = '.modal-dialog'; 57 var options = {}; 58 var REC_MODAL_CONTENT = 'modal-rec'; 59 var SIZE = { 60 sm: 'sm', 61 lg: 'lg', 62 xl: 'xl' 63 }; 64 var TMP_MODAL_CONTENT = 'modal-tmp'; 65 66 var defaultSettings = { 67 allowContentRecycle: true, 68 confirmLabel: Object.keys(LABEL)[0], 69 labels: LABEL, 70 loadingHtml: '<h5>Loading...</h5><div class=progress><div class="progress-bar progress-bar-striped active" style="width: 100%"></div></div>', 71 size: EMPTY, 72 classname : EMPTY, 73 title: 'Attention' 74 }; 75 76 root.addLabel = addLabel; 77 root.ajax = ajax; 78 root.alert = alert; 79 root.close = close; 80 root.confirm = confirm; 81 root.emptyBin = emptyBin; 82 root.iframe = iframe; 83 root.prompt = prompt; 84 root.setId = setId; 85 root.setEModalOptions = setEModalOptions; 86 root.setModalOptions = setModalOptions; 87 root.size = SIZE; 88 root.version = '1.2.65'; 89 90 return root; 91 92 //#region /////////////////////////* Private Logic *///////////////////////// 93 /** 94 * Find modal body and append message to it. 95 * @param {String | DOM} message 96 */ 97 function _build(message) { 98 $modal 99 .modal(options) 100 .find('.modal-content') 101 .append(message); 102 } 103 104 /** 105 * Will find what Promises approach the developer is using. 106 * Will use Promises A+ if Q.js is present, otherwise will use Promises A from jQuery. 107 * @returns {Promise} 108 */ 109 function _createDeferred() { 110 var defer; 111 112 // try native promise 113 //if (Promise) defer = Promise.defer(); 114 115 var q; 116 117 try { 118 q = require('Q'); 119 } // Load option Q by require if exist 120 catch (e) { 121 q = window.Q; 122 } 123 124 if (q) { // try Q 125 defer = q.defer(); 126 } else { // Use jQuery :( 127 defer = $.Deferred(); 128 defer.promise = defer.promise(); 129 } 130 131 defer.promise.element = _getModalInstance(true).find(MODAL_DIALOG); 132 return defer; 133 } 134 135 /** 136 * Will create modal DOM footer with all buttons. 137 * @param {Array} buttons - all custom buttons, if none, will generate defaults 138 * @returns {$DOM} footer DOM element 139 */ 140 function _getFooter(buttons) { 141 if (buttons === false) { 142 return EMPTY; 143 } 144 145 var messageFotter = $(DIV).addClass('modal-footer').prop('id', FOOTER_ID); 146 if (buttons) { 147 for (var i = 0, k = buttons.length; i < k; i++) { 148 var btnOp = buttons[i]; 149 var btn = $('<button>').addClass('btn btn-' + (btnOp.style || 'primary')); 150 151 for (var index in btnOp) { 152 if (btnOp.hasOwnProperty(index)) { 153 switch (index) { 154 case 'close': 155 //add close event 156 if (btnOp[index]) { 157 btn.attr('data-dismiss', 'modal') 158 .addClass('x'); 159 } 160 break; 161 case EVENT_CLICK: 162 //click event 163 var fn = btnOp.click.bind(_getModalInstance(true).find('.modal
163-content')); 164 btn.click(fn); 165 break; 166 case 'text': 167 btn.html(btnOp[index]); 168 break; 169 default: 170 //all other possible HTML attributes to button element 171 btn.attr(index, btnOp[index]); 172 } 173 } 174 } 175 176 messageFotter.append(btn); 177 } 178 } else { 179 //if no buttons defined by user, add a standard close button. 180 messageFotter.append('<button class="x btn btn-primary" data-dismiss=modal type=button>Close</button>'); 181 } 182 return messageFotter; 183 } 184 185 /** 186 * Extract message from arguments. 187 * @param {Object | String} data - this can be the message string or the full detailed object 188 * @returns {$DOM} 189 */ 190 function _getMessage(data) { 191 var $message; 192 var content = data.loading ? 193 defaultSettings.loadingHtml : 194 (data.message || data); 195 196 if (content.on || content.onclick) { 197 $message = data.clone === true ? 198 $(content).clone() : 199 $(content); 200 201 $message.addClass(data.useBin && !data.loading ? REC_MODAL_CONTENT : TMP_MODAL_CONTENT); 202 } else { 203 $message = $(DIV) 204 .attr('style', 'position:relative;word-wrap:break-word;') 205 .addClass(MODAL_BODY) 206 .html(content); 207 } 208 209 return data.css && (data.css !== $message.css && $message.css(data.css)), $message; 210 } 211 212 /** 213 * Return a new modal object if is the first request or the already created model. 214 * @param {boolean} skipEventChageIfExists 215 * @returns {jQuery Object} 216 */ 217 function _getModalInstance(skipEventChageIfExists) { 218 if (!$modal) { 219 //add recycle bin container to document 220 if (!$('#' + BIN).length) { 221 $('body').append($(DIV).prop('id', BIN).hide()); 222 } 223 224 $modal = createModalElement(); 225 } 226 227 if (skipEventChageIfExists && $modal) { 228 return $modal; 229 } 230 231 return $modal 232 .on(EVENT_SHOW, function () { 233 $(this).find(INPUT).first().focus(); 234 }); 235 236 function createModalElement() { 237 return $('<div class="modal fade" tabindex="-1"><style>.modal-xl{width:96%;}.modal-body{max-height: calc(100vh - 145px);overflow-y: auto;}</style>' + 238 '<div class=modal-dialog>' + 239 '<div class=modal-content>' + 240 ' <div class=modal-header><button type=button class="x close" data-dismiss=modal><span aria-hidden=true>×</span><span class=sr-only>Close</span></button><h4 class=modal-title></h4></div>' + 241 '</div>' + 242 '</div>' + 243 '</div>') 244 .on('hidden.bs.modal', _recycleModal) 245 .on(EVENT_CLICK, 'button.x', function (ev) { 246 var btn = $(ev.currentTarget); 247 248 if (btn.prop('type') !== EVENT_SUBMIT) 249 return $modal.modal(EVENT_HIDE); 250 251 try { 252 if (btn.closest('form')[0].checkValidity()) 253 return close(); 254 } catch (e) { 255 return close(); 256 } 257 258 return $modal; 259 }); 260 } 261 } 262 263 /** 264 * Move content to recycle bin if is a DOM object defined by user, 265 * delete it if is a simple string message. 266 * All modal messages can be deleted if default setting "allowContentRecycle" = false. 267 */ 268 function _recycleModal() { 269 if (!$modal) return; 270 271 var $content = $modal.find('.' + REC_MODAL_CONTENT).removeClass(REC_MODAL_CONTENT) 272 .appendTo('#' + BIN); 273 274 $modal 275 .off(HIDE) 276 .off(EVENT_SHOW) 277 .find('.modal-content > div:not(:first-child)') 278 .remove(); 279 280 if (!defaultSettings.allowContentRecycle || lastParams.clone) { 281 $content.remove(); 282 } 283 } 284 285 /** 286 * Handle default values and toggle between {Object | String}.
287 * Create or get Modal element 288 * @param {Object | String} data - this can be the message string or the full detailed object 289 * @param {String} title - the string that will be shown in modal header 290 * @returns {Promise} Promise with modal $DOM element 291 */ 292 function _setup(params, title) { 293 if (!params) throw new Error('Invalid parameters!'); 294 295 _recycleModal(); 296 lastParams = params; 297 298 // Lazy loading 299 var $ref = _getModalInstance(); 300 301 //#region change size 302 $ref.find(MODAL_DIALOG) 303 .removeClass('modal-sm modal-lg modal-xl') 304 .addClass(params.size ? 'modal-' + params.size : defaultSettings.size); 305 //#endregion 306 307 //#region change classname 308 if(params.classname){ 309 $ref.find(".modal-content") 310 .attr("class","modal-content " + params.classname); 311 //#endregion 312 } 313 314 315 //#region change title 316 $ref.find('.modal-title') 317 .html((params.title || title || defaultSettings.title) + ' ') 318 .append($('<small>').html(params.subtitle || EMPTY)); 319 //#endregion 320 321 $ref.on(HIDE, params.onHide); 322 } 323 //#endregion 324 325 //#region /////////////////////////* Public Methods *///////////////////////// 326 327 function addLabel(yes, no) { 328 LABEL[yes] = no; 329 } 330 331 /** 332 * Gets data from URL to eModal body 333 * @param {Object | String} data - this can be the message string or the full detailed object 334 * @param {String} title - the string that will be shown in modal header 335 * @returns {Promise} Promise with modal $DOM element 336 */ 337 function ajax(data, title) { 338 var dfd = _createDeferred(); 339 340 var params = { 341 async: true, 342 deferred: dfd, 343 loading: true, 344 title: data.title || title || defaultSettings.title, 345 classname: data.classname || defaultSettings.classname, 346 url: data.url || data, 347 dataType: data.dataType || 'text' 348 }; 349 350 if (data.url) { 351 $.extend(params, data); 352 } 353 354 $.ajax(params) 355 .done(ok) 356 .fail(error); 357 358 return alert(params, title); 359 360 function ok(html) { 361 $modal 362 .find('.' + MODAL_BODY) 363 .html(data.success ? data.success(html) : html); 364 365 return dfd.resolve($modal); 366 } 367 368 function error(responseText, textStatus) { 369 var msg = data.error ? 370 data.error(responseText, textStatus, params) : 371 '<div class="alert alert-danger">' + 372 '<strong>XHR Fail: </strong>URL [ ' + params.url + '] load fail.' + 373 '</div>'; 374 375 $modal 376 .find('.' + MODAL_BODY) 377 .html(msg); 378 return dfd.reject(responseText); 379 } 380 } 381 382 /** 383 * Non blocking alert whit bootstrap. 384 * @param {Object | String} data - this can be the message string or the full detailed object. 385 * @param {String} title - the string that will be shown in modal header. 386 * @returns {Promise} Promise with modal $DOM element 387 */ 388 function alert(data, title) { 389 _setup(data, title); 390 391 var dfd = data.deferred || _createDeferred(); 392 var $message = $(DIV).append(_getMessage(data), _getFooter(data.buttons)); 393 394 _build($message); 395 396 if (!data.async) { 397 $modal.on(EVENT_SHOW, dfd.resolve); 398 } 399 400 return dfd.promise; 401 } 402 403 /** 404 * Non blocking confirm dialog with bootstrap. 405 * @param {Object | String} data - this can be the message string or the full detailed object. 406 * @param {String} title - the string that will be shown in modal header. 407 * @returns {Promise} Promise with modal $DOM element 408 */ 409 function confirm(data, title) { 410 var dfd = _createDeferred(); 411 412 return alert({ 413 async: true, 414 buttons: [{ 415 close: true, 416 click: click, 417 text: LABEL[data.label] ? LABEL[data.label] : LABEL[defaultSettings.confirmLabel], 418 style: data.style && data.style[0] || KEY_DANGER 419 }, { 420 close: true, 421 click: click, 422 text: LABEL[data.label] ? data.label : defaultSettings.confirmLabel, 423 style: data.style && data.style[1] 424 }], 425 deferred: dfd, 426 message: data.message || data, 427 onHide: click, 428 size: data.size, 429 title: data.title || title, 430 classname: data.classname || defaultSettings.classname 431 }); 432 433 function click(ev) { 434 close(); 435 436 var key = $(ev.currentTarget).html(); 437 return LABEL[key] ? dfd.resolve() : dfd.reject(); 438 } 439 } 440 441 /** 442 * Will load a URL in iFrame inside the modal body. 443 * @param {Object | String} data - this can be the URL string or the full detailed object. 444 * @param {String} title - the string that will be shown in modal header. 445 * @returns {Promise} Promise with modal $DOM element 446 */ 447 function iframe(params, title) { 448 var dfd = _createDeferred(); 449 var html = ('<div class=modal-body style="position: absolute;width: 100%;background-color: rgba(255,255,255,0.8);height: 100%;">%1%</div>' + 450 '<iframe class="embed-responsive-item" frameborder=0 src="%0%" style="width:100%;height:75vh;display:block;"/>') 451 .replace('%0%', params.message || params.url || params) 452 .replace('%1%', defaultSettings.loadingHtml); 453 454 var message = $(html).on( "load", iframeReady ); 455 456 return alert({ 457 async: true, 458 buttons: params.buttons || false, 459 deferred: dfd, 460 message: message, 461 size: params.size || SIZE.xl, 462 classname: params.classname || EMPTY, 463 title: params.title || title 464 });
465 ////////// 466 467 function iframeReady() { 468 $(this) 469 .parent() 470 .find('div.' + TMP_MODAL_CONTENT) 471 .fadeOut(function () { 472 $(this).remove(); 473 }); 474 475 return dfd.resolve(); 476 } 477 } 478 479 /** 480 * Remove all Dom elements in recycle bin. 481 * @returns {Array} All removed elements 482 */ 483 function emptyBin() { 484 return $('#' + BIN + ' > *').remove(); 485 } 486 487 /** 488 * Provides one value form. 489 * @param {Object | String} data - this can be the value string label or the full detailed object. 490 * @param {String} title - the string that will be shown in modal header. 491 * @returns {Promise} Promise with modal $DOM element 492 */ 493 function prompt(data, title) { 494 var dfd = _createDeferred(); 495 var params = { 496 deferred: dfd 497 }; 498 499 if (typeof data === 'object') { 500 $.extend(params, data); 501 } else { 502 params.message = data; 503 params.title = title; 504 } 505 506 params.async = true; 507 508 if (params.buttons) { 509 var btn; 510 for (var i = 0, k = params.buttons.length; i < k; i++) { 511 btn = params.buttons[i]; 512 btn.style = (btn.style || 'default') + ' pull-left'; 513 btn.type = btn.type || 'button'; 514 } 515 } 516 517 var buttons = _getFooter([{ 518 close: true, 519 type: 'reset', 520 text: LABEL.OK, 521 style: KEY_DANGER 522 }, { 523 close: false, 524 type: EVENT_SUBMIT, 525 text: defaultSettings.confirmLabel 526 }].concat(params.buttons || [])); 527 528 params.buttons = false; 529 params.onHide = submit; 530 531 params.message = $('<form role=form style="margin-bottom:0;">' + 532 '<div class=modal-body>' + 533 '<label for=prompt-input class=control-label>' + (params.message || EMPTY) + '</label>' + 534 '<input type=text class=form-control required autocomplete="on" value="' + (params.value || EMPTY) + (params.pattern ? '" pattern="' + params.pattern : EMPTY) + '">' + 535 '</div></form>') 536 .append(buttons) 537 .on(EVENT_SUBMIT, submit); 538 539 return alert(params); 540 541 function submit(ev) { 542 var value = $modal.find(INPUT).val(); 543 close(); 544 545 //TODO: 546 ev.type !== EVENT_SUBMIT ? 547 dfd.reject(value) : 548 dfd.resolve(value); 549 550 return false; 551 } 552 } 553 554 function setId(id) { 555 _getModalInstance(true) 556 .find(MODAL_DIALOG) 557 .prop('id', id); 558 } 559 560 /** 561 * Set or change eModal options. 562 * @param {Object} overrideOptions 563 * @returns {Object} merged eModal options 564 */ 565 function setEModalOptions(overrideOptions) { 566 return $.extend(defaultSettings, overrideOptions); 567 } 568 569 /** 570 * Set or change bootstrap modal options. 571 * @param {Object} overrideOptions 572 * @returns {Object} merged eModal options 573 */ 574 function setModalOptions(overrideOptions) { 575 $modal && $modal.remove(); 576 577 return $.extend(options, overrideOptions); 578 } 579 580 /** 581 * Close the current open eModal 582 * @returns {$DOM} eModal DOM element 583 */ 584 function close() { 585 if ($modal) { 586 $modal.off(HIDE).modal(EVENT_HIDE); 587 } 588 return $modal; 589 } 590 //#endregion 591 }); 592}(typeof define == 'function' && define.amd ? 593 define : 594 function (args, mName) { 595 this.eModal = typeof module != 'undefined' && module.exports ? 596 mName(require(args[0]), module.exports) : 597 mName(window.$, {}); 598 })); 599 600/* customizing loader modal */ 601eModal.setEModalOptions({ 602 loadingHtml: '<div class="vc_loading" style="display:block"><div class="vc_circle_loading"></div></div>' 603});
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.