3 /** This file is part of KCFinder project
5 * @desc Object initializations
8 * @author Pavel Tzonkov <pavelc@users.sourceforge.net>
9 * @copyright 2010, 2011 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
15 browser.init = function() {
16 if (!this.checkAgent()) return;
18 $('body').click(function() {
21 $('#shadow').click(function() {
24 $('#dialog').unbind();
25 $('#dialog').click(function() {
29 $('#alert').click(function() {
37 this.initDropUpload();
40 browser.checkAgent = function() {
41 if (!$.browser.version ||
42 ($.browser.msie && (parseInt($.browser.version) < 7) && !this.support.chromeFrame) ||
43 ($.browser.opera && (parseInt($.browser.version) < 10)) ||
44 ($.browser.mozilla && (parseFloat($.browser.version.replace(/^(\d+(\.\d+)?)([^\d].*)?$/, "$1")) < 1.8))
46 var html = '<div style="padding:10px">Your browser is not capable to display KCFinder. Please update your browser or install another one: <a href="http://www.mozilla.com/firefox/" target="_blank">Mozilla Firefox</a>, <a href="http://www.apple.com/safari" target="_blank">Apple Safari</a>, <a href="http://www.google.com/chrome" target="_blank">Google Chrome</a>, <a href="http://www.opera.com/browser" target="_blank">Opera</a>.';
48 html += ' You may also install <a href="http://www.google.com/chromeframe" target="_blank">Google Chrome Frame ActiveX plugin</a> to get Internet Explorer 6 working.';
56 browser.initOpeners = function() {
57 if (this.opener.TinyMCE && (typeof(tinyMCEPopup) == 'undefined'))
58 this.opener.TinyMCE = null;
60 if (this.opener.TinyMCE)
61 this.opener.callBack = true;
63 if ((!this.opener.name || (this.opener.name == 'fckeditor')) &&
64 window.opener && window.opener.SetUrl
66 this.opener.FCKeditor = true;
67 this.opener.callBack = true;
70 if (this.opener.CKEditor) {
71 if (window.parent && window.parent.CKEDITOR)
72 this.opener.CKEditor.object = window.parent.CKEDITOR;
73 else if (window.opener && window.opener.CKEDITOR) {
74 this.opener.CKEditor.object = window.opener.CKEDITOR;
75 this.opener.callBack = true;
77 this.opener.CKEditor = null;
80 if (!this.opener.CKEditor && !this.opener.FCKEditor && !this.TinyMCE) {
81 if ((window.opener && window.opener.KCFinder && window.opener.KCFinder.callBack) ||
82 (window.parent && window.parent.KCFinder && window.parent.KCFinder.callBack)
84 this.opener.callBack = window.opener
85 ? window.opener.KCFinder.callBack
86 : window.parent.KCFinder.callBack;
90 window.opener.KCFinder &&
91 window.opener.KCFinder.callBackMultiple
94 window.parent.KCFinder &&
95 window.parent.KCFinder.callBackMultiple
98 this.opener.callBackMultiple = window.opener
99 ? window.opener.KCFinder.callBackMultiple
100 : window.parent.KCFinder.callBackMultiple;
104 browser.initContent = function() {
105 $('div#folders').html(this.label("Loading folders..."));
106 $('div#files').html(this.label("Loading files..."));
110 url: browser.baseGetData('init'),
112 success: function(data) {
113 if (browser.check4errors(data))
115 browser.dirWritable = data.dirWritable;
116 $('#folders').html(browser.buildTree(data.tree));
117 browser.setTreeData(data.tree);
118 browser.initFolders();
119 browser.files = data.files ? data.files : [];
120 browser.orderFiles();
123 $('div#folders').html(browser.label("Unknown error."));
124 $('div#files').html(browser.label("Unknown error."));
129 browser.initResizer = function() {
130 var cursor = ($.browser.opera) ? 'move' : 'col-resize';
131 $('#resizer').css('cursor', cursor);
132 $('#resizer').drag('start', function() {
133 $(this).css({opacity:'0.4', filter:'alpha(opacity:40)'});
134 $('#all').css('cursor', cursor);
136 $('#resizer').drag(function(e) {
137 var left = e.pageX - parseInt(_.nopx($(this).css('width')) / 2);
138 left = (left >= 0) ? left : 0;
139 left = (left + _.nopx($(this).css('width')) < $(window).width())
140 ? left : $(window).width() - _.nopx($(this).css('width'));
141 $(this).css('left', left);
143 var end = function() {
144 $(this).css({opacity:'0', filter:'alpha(opacity:0)'});
145 $('#all').css('cursor', '');
146 var left = _.nopx($(this).css('left')) + _.nopx($(this).css('width'));
147 var right = $(window).width() - left;
148 $('#left').css('width', left + 'px');
149 $('#right').css('width', right + 'px');
150 _('files').style.width = $('#right').innerWidth() - _.outerHSpace('#files') + 'px';
151 _('resizer').style.left = $('#left').outerWidth() - _.outerRightSpace('#folders', 'm') + 'px';
152 _('resizer').style.width = _.outerRightSpace('#folders', 'm') + _.outerLeftSpace('#files', 'm') + 'px';
153 browser.fixFilesHeight();
155 $('#resizer').drag('end', end);
156 $('#resizer').mouseup(end);
159 browser.resize = function() {
160 _('left').style.width = '25%';
161 _('right').style.width = '75%';
162 _('toolbar').style.height = $('#toolbar a').outerHeight() + "px";
163 _('shadow').style.width = $(window).width() + 'px';
164 _('shadow').style.height = _('resizer').style.height = $(window).height() + 'px';
165 _('left').style.height = _('right').style.height =
166 $(window).height() - $('#status').outerHeight() + 'px';
167 _('folders').style.height =
168 $('#left').outerHeight() - _.outerVSpace('#folders') + 'px';
169 browser.fixFilesHeight();
170 var width = $('#left').outerWidth() + $('#right').outerWidth();
171 _('status').style.width = width + 'px';
172 while ($('#status').outerWidth() > width)
173 _('status').style.width = _.nopx(_('status').style.width) - 1 + 'px';
174 while ($('#status').outerWidth() < width)
175 _('status').style.width = _.nopx(_('status').style.width) + 1 + 'px';
176 if ($.browser.msie && ($.browser.version.substr(0, 1) < 8))
177 _('right').style.width = $(window).width() - $('#left').outerWidth() + 'px';
178 _('files').style.width = $('#right').innerWidth() - _.outerHSpace('#files') + 'px';
179 _('resizer').style.left = $('#left').outerWidth() - _.outerRightSpace('#folders', 'm') + 'px';
180 _('resizer').style.width = _.outerRightSpace('#folders', 'm') + _.outerLeftSpace('#files', 'm') + 'px';
183 browser.fixFilesHeight = function() {
184 _('files').style.height =
185 $('#left').outerHeight() - $('#toolbar').outerHeight() - _.outerVSpace('#files') -
186 (($('#settings').css('display') != "none") ? $('#settings').outerHeight() : 0) + 'px';