[ Index ] |
PHP Cross Reference of vtigercrm-6.1.0 |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** This file is part of KCFinder project 4 * 5 * @desc Miscellaneous methods 6 * @package KCFinder 7 * @version 2.21 8 * @author Pavel Tzonkov <[email protected]> 9 * @copyright 2010 KCFinder Project 10 * @license http://www.opensource.org/licenses/gpl-2.0.php GPLv2 11 * @license http://www.opensource.org/licenses/lgpl-2.1.php LGPLv2 12 * @link http://kcfinder.sunhater.com 13 */?> 14 15 browser.showDialog = function(e) { 16 this.shadow(); 17 if (e) { 18 var left = e.pageX - parseInt($('#dialog').outerWidth() / 2); 19 var top = e.pageY - parseInt($('#dialog').outerHeight() / 2); 20 if (left < 15) left = 15; 21 if (top < 15) top = 15; 22 if (($('#dialog').outerWidth() + left) > $(window).width() - 30) 23 left = $(window).width() - $('#dialog').outerWidth() - 15; 24 if (($('#dialog').outerHeight() + top) > $(window).height() - 30) 25 top = $(window).height() - $('#dialog').outerHeight() - 15; 26 $('#dialog').css('left', left + "px"); 27 $('#dialog').css('top', top + "px"); 28 } else { 29 $('#dialog').css('left', parseInt(($(window).width() - $('#dialog').outerWidth()) / 2) + 'px'); 30 $('#dialog').css('top', parseInt(($(window).height() - $('#dialog').outerHeight()) / 2) + 'px'); 31 $('#dialog').css('display', 'block'); 32 } 33 34 }; 35 36 browser.hideDialog = function() { 37 this.unshadow(); 38 if ($('#clipboard').hasClass('selected')) 39 $('#clipboard').removeClass('selected'); 40 $('#dialog').css('display', 'none'); 41 $('div.folder > a > span.folder').removeClass('context'); 42 $('#dialog').html(''); 43 }; 44 45 browser.shadow = function() { 46 $('#shadow').css('display', 'block'); 47 }; 48 49 browser.unshadow = function() { 50 $('#shadow').css('display', 'none'); 51 }; 52 53 browser.showMenu = function(e) { 54 var left = e.pageX; 55 var top = e.pageY; 56 if (($('#dialog').outerWidth() + left) > $(window).width()) 57 left = $(window).width() - $('#dialog').outerWidth(); 58 if (($('#dialog').outerHeight() + top) > $(window).height()) 59 top = $(window).height() - $('#dialog').outerHeight(); 60 $('#dialog').css('left', left + "px"); 61 $('#dialog').css('top', top + "px"); 62 $('#dialog').css('display', 'none'); 63 $('#dialog').fadeIn(); 64 }; 65 66 browser.fileNameDialog = function(e, post, inputName, inputValue, url, labels, callBack) { 67 var html = '<form method="post" action="javascript:;">' + 68 '<div class="box"><b>' + this.label(labels.title) + '</b><br />' + 69 '<input name="' + inputName + '" value="' + _.htmlValue(inputValue) + '" type="text" /><br />' + 70 '<div style="text-align:right">' + 71 '<input type="submit" value="' + _.htmlValue(this.label("OK")) + '" />' + 72 '<input type="button" value="' + _.htmlValue(this.label("Cancel")) + '" onclick="browser.hideDialog(); return false" />' + 73 '</div></div></form>'; 74 $('#dialog').html(html); 75 $('#dialog').unbind(); 76 $('#dialog').click(function() { 77 return false; 78 }); 79 $('#dialog form').submit(function() { 80 var name = this.elements[0]; 81 name.value = $.trim(name.value); 82 if (name.value == '') { 83 alert(browser.label(labels.errEmpty)); 84 name.focus(); 85 return; 86 } else if (/[\/\\]/g.test(name.value)) { 87 alert(browser.label(labels.errSlash)) 88 name.focus(); 89 return; 90 } else if (name.value.substr(0, 1) == ".") { 91 alert(browser.label(labels.errDot)) 92 name.focus(); 93 return; 94 } 95 eval('post.' + inputName + ' = name.value;'); 96 $.ajax({ 97 type: 'POST', 98 url: url, 99 data: post, 100 async: false, 101 success: function(xml) { 102 if (browser.errors(xml)) return; 103 if (callBack) callBack(xml); 104 browser.hideDialog(); 105 }, 106 error: function(request, error) { 107 alert(browser.label("Unknown error.")); 108 } 109 }); 110 return false; 111 }); 112 browser.showDialog(e); 113 $('#dialog').css('display', 'block'); 114 $('#dialog input[type="submit"]').click(function() { 115 return $('#dialog form').submit(); 116 }); 117 $('#dialog input[type="text"]').get(0).focus(); 118 $('#dialog input[type="text"]').get(0).select(); 119 $('#dialog input[type="text"]').keypress(function(e) { 120 if (e.keyCode == 27) browser.hideDialog(); 121 }); 122 }; 123 124 browser.orderFiles = function(callBack, selected) { 125 var order = _.kuki.get('order'); 126 var desc = (_.kuki.get('orderDesc') == 'on'); 127 128 browser.files = browser.files.sort(function(a, b) { 129 var a1, b1, arr; 130 if (!order) order = 'name'; 131 132 if (order == 'date') { 133 a1 = a.mtime; 134 b1 = b.mtime; 135 } else if (order == 'type') { 136 a1 = _.getFileExtension(a.name); 137 b1 = _.getFileExtension(b.name); 138 } else 139 eval('a1 = a.' + order + '.toLowerCase(); b1 = b.' + order + '.toLowerCase();'); 140 141 if ((order == 'size') || (order == 'date')) { 142 a1 = parseInt(a1 ? a1 : ''); 143 b1 = parseInt(b1 ? b1 : ''); 144 if (a1 < b1) return desc ? 1 : -1; 145 if (a1 > b1) return desc ? -1 : 1; 146 } 147 148 if (a1 == b1) { 149 a1 = a.name.toLowerCase(); 150 b1 = b.name.toLowerCase(); 151 arr = [a1, b1]; 152 arr = arr.sort(); 153 return (arr[0] == a1) ? -1 : 1; 154 } 155 156 arr = [a1, b1]; 157 arr = arr.sort(); 158 if (arr[0] == a1) return desc ? 1 : -1; 159 return desc ? -1 : 1; 160 }); 161 162 browser.showFiles(callBack, selected); 163 browser.initFiles(); 164 }; 165 166 browser.humanSize = function(size) { 167 if (size < 1024) { 168 size = size.toString() + ' B'; 169 } else if (size < 1048576) { 170 size /= 1024; 171 size = parseInt(size).toString() + ' KB'; 172 } else if (size < 1073741824) { 173 size /= 1048576; 174 size = parseInt(size).toString() + ' MB'; 175 } else if (size < 1099511627776) { 176 size /= 1073741824; 177 size = parseInt(size).toString() + ' GB'; 178 } else { 179 size /= 1099511627776; 180 size = parseInt(size).toString() + ' TB'; 181 } 182 return size; 183 }; 184 185 browser.baseGetData = function(act) { 186 var data = 'browse.php?type=' + encodeURIComponent(this.type) + '&lng=' + this.lang; 187 if (act) 188 data += "&act=" + act 189 return data; 190 }; 191 192 browser.label = function(index, data) { 193 var label = this.labels[index] ? this.labels[index] : index; 194 if (data) 195 $.each(data, function(key, val) { 196 label = label.replace('{' + key + '}', val); 197 }); 198 return label; 199 }; 200 201 browser.errors = function(xml) { 202 if (!xml.getElementsByTagName('error').length) 203 return false; 204 var alertMsg = ''; 205 $.each(xml.getElementsByTagName('error'), function(i, error) { 206 alertMsg += browser.xmlData(error.childNodes) + "\n"; 207 }); 208 alertMsg = alertMsg.substr(0, alertMsg.length - 1); 209 alert(alertMsg); 210 return true; 211 }; 212 213 browser.post = function(url, data) { 214 var html = '<form id="postForm" method="POST" action="' + url + '">'; 215 $.each(data, function(key, val) { 216 if ($.isArray(val)) 217 $.each(val, function(i, aval) { 218 html += '<input type="hidden" name="' + _.htmlValue(key) + '[]" value="' + _.htmlValue(aval) + '" />'; 219 }); 220 else 221 html += '<input type="hidden" name="' + _.htmlValue(key) + '" value="' + _.htmlValue(val) + '" />'; 222 }); 223 html += '</form>'; 224 $('#dialog').html(html); 225 $('#dialog').css('display', 'block'); 226 $('#postForm').get(0).submit(); 227 }; 228 229 browser.fadeFiles = function() { 230 $('#files > div').css('opacity', '0.4'); 231 $('#files > div').css('filter', 'alpha(opacity:40)'); 232 }; 233 234 browser.xmlData = function(nodes) { 235 var data = ''; 236 $.each(nodes, function(i) { 237 data += nodes[i].nodeValue; 238 }); 239 return data; 240 };
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:08:37 2014 | Cross-referenced by PHPXref 0.7.1 |