1// Namespace definition 2var toolfactory = toolfactory || {}; 3toolfactory.common = toolfactory.common || {}; 4toolfactory.common.helpers = toolfactory.common.helpers || {}; 5 6// Modal remote class. 7// This class handles all modal application windows. 8toolfactory.common.helpers.modalremote = 9(function () { 10 "use strict"; 11 var ModalRemoteClass = function () { 12 13 // ** Private vars ** // 14 var that = this; 15 16 // ** Functions ** // 17 18 // Show modal iframe. 19 /*var _onIframeLoaded = function ($iframe, $modal) { 20 $iframe.show(); 21 $modal.find('.modal-body .modalRemoteLoading').hide(); 22 $iframe.find('.lazy').lazyload(); 23 $iframe.height($iframe.contents().find('body').height()); 24 };*/ 25 26 // Append iframe to modal body. 27 var _appendIframeToModalBody = function ($modal) { 28 var $body = $modal.find('.modal-body'); 29 if ($body.find('iframe').length === 0) { 30 $('<iframe src="" frameborder="0" height="100%" scrolling="no" width="100%"></iframe>').appendTo($body); 31 } 32 }; 33 34 // Show modal. 35 this.showModal = function (id, frameSrc, title, callback, iframeEnabled) { 36 var $modal = $('.modal' + id); 37 38 $modal.one('shown.bs.modal', function () { 39 if (title !== '' && title !== undefined) { 40 // Prevent avoid repeat. 41 var $title = $modal.find('#titleModal'); 42 if ($title.length > 0) { 43 $title.html(title); 44 } else { 45 $modal.find('.modal-header .titleModal').html(title); 46 } 47 } 48 49 // Append remote loading to modal body. 50 that.appendRemoteLoadingToModalBody($modal); 51 52 if (typeof iframeEnabled !== 'undefined' && iframeEnabled) { 53 _appendIframeToModalBody($modal); 54 var $body = $modal.find('.modal-body'); 55 var $iframe = $body.find('iframe'); 56 $iframe.attr('style','display:none;'); 57 $iframe.attr('src', frameSrc); 58 if (typeof callback !== 'undefined' && typeof callback === "function") { 59 $iframe.load(function () { 60 $iframe.attr('style','display:block;'); 61 $body.find('.modalRemoteLoading').attr('style','display:none;'); 62 $iframe.find('.lazy').lazyload(); 63 $iframe.height($iframe.contents().find('body').height()); 64 }, callback); 65 } else { 66 // $iframe.load(_onIframeLoaded($iframe, $modal)); 67 $iframe.load(function () { 68 $iframe.attr('style','display:block;'); 69 $body.find('.modalRemoteLoading').attr('style','display:none;'); 70 $iframe.find('.lazy').lazyload(); 71 $iframe.height($iframe.contents().find('body').height()); 72 }); 73 74 } 75 } else { 76 $modal.find('.modal-body').load(frameSrc, callback, function () { 77 window.setTimeout(function () { ($modal).find('img.lazy:visible').lazyload(); }, 300); 78 }); 79 80 if (id == "#modalWaitingCruises") { 81 var $ul = $modal.find('.modal-body ul'); 82 83 if ($ul.length > 0) { 84 var html = ""; 85 86 $.each($(".camposBuscadorCruceros").find("select option:selected"), function (index, element) { 87 if ($(element).val() !== "0") { 88 html += "<li class='searchTag'>" + $(element).text() + "</li>"; 89 } 90 }); 91 92 $ul.html(html); 93 } 94 } 95 96 if (typeof callback !== 'undefined' && typeof callback === "function") { 97 callback(); 98 } 99 } 100 }); 101 102 $(id).modal('show'); 103 }; 104 105 // Append remote loading. 106 this.appendRemoteLoadingToModalBody = function ($modal) {
107 if ($modal.find('.modal-body .modalRemoteLoading').length === 0) { 108 var domain = toolfactory.common.configuration.globals.cdnUrl; 109 $('<div class="modalRemoteLoading text-center p-40"><img src="' + domain + '/comun/images/esperas/loadingNew.gif"/></div>').appendTo($modal.find('.modal-body')); 110 } 111 $modal.find('.modal-body .modalRemoteLoading').attr('style','display:block;'); 112 }; 113 114 this.modalDynamicJSONLoad = function (id, frameSrc, title, options, callback) { 115 var that = this; 116 if (id.indexOf('#') === -1) 117 { id = '#' + id; } 118 119 var $modal = $('.modal' + id); 120 121 //Si el modal no existe creamos la estructura y la anyadimos 122 //al body de la pagina 123 if ($modal.length === 0) 124 { createModalHTML.call(that, id, title, options); } 125 else 126 { $modal.find('h6.titulo').html(title); } 127 128 $modal.one('show.bs.modal', function() { 129 $modal.find('.modal-body').html(''); 130 that.appendRemoteLoadingToModalBody($modal); 131 if (title !== '' && title !== undefined) { 132 //Solucion para evitar ID repetidos en paginas con mas de un modalRemote 133 var $title = $modal.find('#titleModal'); 134 if ($title.length > 0) { 135 $title.html(title); 136 } else { 137 $modal.find('.modal-header .titleModal').html(title); 138 } 139 } 140 if (typeof options !== 'undefined' && options !== null && options.responseType == 'jsonp') { 141 loadFromJSONP.call(that, $modal, frameSrc, options, callback); 142 } else { 143 loadFromJSON.call(that, $modal, frameSrc, options, callback); 144 } 145 }); 146 $modal.on('hidden.bs.modal', function () { 147 //Para evitar conflictos de CSS entre web origen y activities 148 toolfactory.common.helpers.dynamicloader.removeCSS(); 149 }); 150 $(id).modal('show'); 151 }; 152 153 /* 154 Load JSON response using CORS (Cross Domain Request Friendly) 155 */ 156 var loadFromJSON = function ($modal, targeturl, options, callback) { 157 toolfactory.common.helpers.crossdomain.sendCORSRequest(targeturl, "GET", null, function (data) { doOnOk.call(this, data, $modal, options, callback); }, function (err) { alert(err.status + ' ' + err.statusText); }); 158 }; 159 160 /* 161 Load JSONP response (Cross Domain Request Friendly) 162 */ 163 var loadFromJSONP = function ($modal, targeturl, options, callback) { 164 $.ajax({
165 url: targeturl, 166 type: 'GET', 167 data: {}, 168 dataType: "jsonp", 169 crossDomain: true, 170 cache: false, 171 success: function (data) { 172 doOnOk.call(this, data, $modal, options, callback); }, 173 error: function (err) { 174 alert(err.status + ' ' + err.statusText); 175 } 176 }); 177 }; 178 179 /* 180 Create Default modal structure 181 Requires i_funcions.js 182 */ 183 var createModalHTML = function (id, title, options) { 184 //Quitamos la # si la hay 185 if (id.indexOf('#') !== -1) 186 { id = id.substring(1, id.length); } 187 var str = ''; 188 str += '<!-- Modal -->'; 189 str += '<div class="modal fade lg" id="' + id + '" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">'; 190 str += ' <div class="modal-dialog">'; 191 str += ' <div class="modal-content">'; 192 str += ' <div class="modal-header">'; 193 str += ' <h6 class="titulo x2">' + title + '</h6>'; 194 str += ' <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>'; 195 str += ' </div>'; 196 str += ' <div class="modal-body">'; 197 str += ' </div>'; 198 str += ' </div>'; 199 str += ' <!-- /.modal-content -->'; 200 str += ' </div>'; 201 str += ' <!-- /.modal-dialog -->'; 202 str += '</div>'; 203 str += '<!-- /.modal -->'; 204 $('body').append(str); 205 if (typeof options !== 'undefined' && options !== null && typeof options.overridesHeaderHTML !== 'undefined' && options.overridesHeaderHTML !== '') { 206 $('#' + id).find('.modal-header').html($('<div></div>').append(options.overridesHeaderHTML).text()); 207 } 208 }; 209 210 var doOnOk = function (data, $modal, options, callback) { 211 if (data.Result === 'Ok') { 212 toolfactory.common.helpers.dynamicloader.loadData(data, $modal, callback); 213 } else { 214 data.Html = '<h2>Error getting Modal Content: ' + data.ErrorMessage + '</h2>'; 215 toolfactory.common.helpers.dynamicloader.loadHTML($modal, data); 216 $modal.modal('toggle'); 217 } 218 $modal.find('.modal-body .modalRemoteLoading').attr('style','display:none;'); 219 }; 220 }; 221 return new ModalRemoteClass(); 222})();
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.