/upload/misc/js/main.js

http://torrentpier2.googlecode.com/ · JavaScript · 596 lines · 481 code · 61 blank · 54 comment · 101 complexity · 978828072348647e0ebef4fa3a79d89a MD5 · raw file

  1. /**
  2. * SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
  3. *
  4. * SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
  5. * http://www.opensource.org/licenses/mit-license.php
  6. *
  7. */
  8. if(typeof deconcept=="undefined"){var deconcept=new Object();}if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a){if(!document.getElementById){return;}this.DETECT_KEY=_a?_a:"detectflash";this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);this.params=new Object();this.variables=new Object();this.attributes=new Array();if(_1){this.setAttribute("swf",_1);}if(id){this.setAttribute("id",id);}if(w){this.setAttribute("width",w);}if(h){this.setAttribute("height",h);}if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();if(!window.opera&&document.all&&this.installedVer.major>7){deconcept.SWFObject.doPrepUnload=true;}if(c){this.addParam("bgcolor",c);}var q=_7?_7:"high";this.addParam("quality",q);this.setAttribute("useExpressInstall",false);this.setAttribute("doExpressInstall",false);var _c=(_8)?_8:window.location;this.setAttribute("xiRedirectUrl",_c);this.setAttribute("redirectUrl","");if(_9){this.setAttribute("redirectUrl",_9);}};deconcept.SWFObject.prototype={useExpressInstall:function(_d){this.xiSWFPath=!_d?"expressinstall.swf":_d;this.setAttribute("useExpressInstall",true);},setAttribute:function(_e,_f){this.attributes[_e]=_f;},getAttribute:function(_10){return this.attributes[_10];},addParam:function(_11,_12){this.params[_11]=_12;},getParams:function(){return this.params;},addVariable:function(_13,_14){this.variables[_13]=_14;},getVariable:function(_15){return this.variables[_15];},getVariables:function(){return this.variables;},getVariablePairs:function(){var _16=new Array();var key;var _18=this.getVariables();for(key in _18){_16[_16.length]=key+"="+_18[key];}return _16;},getSWFHTML:function(){var _19="";if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");this.setAttribute("swf",this.xiSWFPath);}_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\"";_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";var _1a=this.getParams();for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}var _1c=this.getVariablePairs().join("&");if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");this.setAttribute("swf",this.xiSWFPath);}_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\">";_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";var _1d=this.getParams();for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}var _1f=this.getVariablePairs().join("&");if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}_19+="</object>";}return _19;},write:function(_20){if(this.getAttribute("useExpressInstall")){var _21=new deconcept.PlayerVersion([6,0,65]);if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){this.setAttribute("doExpressInstall",true);this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));document.title=document.title.slice(0,47)+" - Flash Player Installation";this.addVariable("MMdoctitle",document.title);}}if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){var n=(typeof _20=="string")?document.getElementById(_20):_20;n.innerHTML=this.getSWFHTML();return true;}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}return false;}};deconcept.SWFObjectUtil.getPlayerVer
  9. sion=function(){var _23=new deconcept.PlayerVersion([0,0,0]);if(navigator.plugins&&navigator.mimeTypes.length){var x=navigator.plugins["Shockwave Flash"];if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}}else{if(navigator.userAgent&&navigator.userAgent.indexOf("Windows CE")>=0){var axo=1;var _26=3;while(axo){try{_26++;axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+_26);_23=new deconcept.PlayerVersion([_26,0,0]);}catch(e){axo=null;}}}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}}return _23;};deconcept.PlayerVersion=function(_29){this.major=_29[0]!=null?parseInt(_29[0]):0;this.minor=_29[1]!=null?parseInt(_29[1]):0;this.rev=_29[2]!=null?parseInt(_29[2]):0;};deconcept.PlayerVersion.prototype.versionIsValid=function(fv){if(this.major<fv.major){return false;}if(this.major>fv.major){return true;}if(this.minor<fv.minor){return false;}if(this.minor>fv.minor){return true;}if(this.rev<fv.rev){return false;}return true;};deconcept.util={getRequestParameter:function(_2b){var q=document.location.search||document.location.hash;if(_2b==null){return q;}if(q){var _2d=q.substring(1).split("&");for(var i=0;i<_2d.length;i++){if(_2d[i].substring(0,_2d[i].indexOf("="))==_2b){return _2d[i].substring((_2d[i].indexOf("=")+1));}}}return "";}};deconcept.SWFObjectUtil.cleanupSWFs=function(){var _2f=document.getElementsByTagName("OBJECT");for(var i=_2f.length-1;i>=0;i--){_2f[i].style.display="none";for(var x in _2f[i]){if(typeof _2f[i][x]=="function"){_2f[i][x]=function(){};}}}};if(deconcept.SWFObject.doPrepUnload){if(!deconcept.unloadSet){deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};window.attachEvent("onunload",deconcept.SWFObjectUtil.cleanupSWFs);};window.attachEvent("onbeforeunload",deconcept.SWFObjectUtil.prepUnload);deconcept.unloadSet=true;}}if(!document.getElementById&&document.all){document.getElementById=function(id){return document.all[id];};}var getQueryParamValue=deconcept.util.getRequestParameter;var FlashObject=deconcept.SWFObject;var SWFObject=deconcept.SWFObject;
  10. // prototype $
  11. function $p() {
  12. var elements = new Array();
  13. for (var i = 0; i < arguments.length; i++) {
  14. var element = arguments[i];
  15. if (typeof element == 'string')
  16. element = document.getElementById(element);
  17. if (arguments.length == 1)
  18. return element;
  19. elements.push(element);
  20. }
  21. return elements;
  22. }
  23. // from http://www.dustindiaz.com/rock-solid-addevent/
  24. function addEvent( obj, type, fn ) {
  25. if (obj.addEventListener) {
  26. obj.addEventListener( type, fn, false );
  27. EventCache.add(obj, type, fn);
  28. }
  29. else if (obj.attachEvent) {
  30. obj["e"+type+fn] = fn;
  31. obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
  32. obj.attachEvent( "on"+type, obj[type+fn] );
  33. EventCache.add(obj, type, fn);
  34. }
  35. else {
  36. obj["on"+type] = obj["e"+type+fn];
  37. }
  38. }
  39. var EventCache = function(){
  40. var listEvents = [];
  41. return {
  42. listEvents : listEvents,
  43. add : function(node, sEventName, fHandler){
  44. listEvents.push(arguments);
  45. },
  46. flush : function(){
  47. var i, item;
  48. for(i = listEvents.length - 1; i >= 0; i = i - 1){
  49. item = listEvents[i];
  50. if(item[0].removeEventListener){
  51. item[0].removeEventListener(item[1], item[2], item[3]);
  52. };
  53. if(item[1].substring(0, 2) != "on"){
  54. item[1] = "on" + item[1];
  55. };
  56. if(item[0].detachEvent){
  57. item[0].detachEvent(item[1], item[2]);
  58. };
  59. item[0][item[1]] = null;
  60. };
  61. }
  62. };
  63. }();
  64. if (document.all) { addEvent(window,'unload',EventCache.flush); }
  65. function imgFit (img, maxW)
  66. {
  67. img.title = '??????? ???????????: '+img.width+' x '+img.height;
  68. if (typeof(img.naturalHeight) == 'undefined') {
  69. img.naturalHeight = img.height;
  70. img.naturalWidth = img.width;
  71. }
  72. if (img.width > maxW) {
  73. img.height = Math.round((maxW/img.width)*img.height);
  74. img.width = maxW;
  75. img.title = '??????? ?? ???????????, ????? ?????????? ??? ? ?????? ??????';
  76. img.style.cursor = 'move';
  77. return false;
  78. }
  79. else if (img.width == maxW && img.width < img.naturalWidth) {
  80. img.height = img.naturalHeight;
  81. img.width = img.naturalWidth;
  82. img.title = '??????? ???????????: '+img.naturalWidth+' x '+img.naturalHeight;
  83. return false;
  84. }
  85. else {
  86. return true;
  87. }
  88. }
  89. function toggle_block (id)
  90. {
  91. var el = document.getElementById(id);
  92. el.style.display = (el.style.display == 'none') ? '' : 'none';
  93. }
  94. function toggle_disabled (id, val)
  95. {
  96. document.getElementById(id).disabled = (val) ? 0 : 1;
  97. }
  98. function rand (min, max)
  99. {
  100. return min + Math.floor((max - min + 1) * Math.random());
  101. }
  102. //
  103. // Cookie functions [based on ???]
  104. //
  105. /**
  106. * name Name of the cookie
  107. * value Value of the cookie
  108. * [days] Number of days to remain active (default: end of current session)
  109. * [path] Path where the cookie is valid (default: path of calling document)
  110. * [domain] Domain where the cookie is valid
  111. * (default: domain of calling document)
  112. * [secure] Boolean value indicating if the cookie transmission requires a
  113. * secure transmission
  114. */
  115. function setCookie (name, value, days, path, domain, secure)
  116. {
  117. if (days != 'SESSION') {
  118. var date = new Date();
  119. days = days || 365;
  120. date.setTime(date.getTime() + days*24*60*60*1000);
  121. var expires = date.toGMTString();
  122. } else {
  123. var expires = '';
  124. }
  125. document.cookie =
  126. name +'='+ escape(value)
  127. + ((expires) ? '; expires='+ expires : '')
  128. + ((path) ? '; path='+ path : ((cookiePath) ? '; path='+ cookiePath : ''))
  129. + ((domain) ? '; domain='+ domain : ((cookieDomain) ? '; domain='+ cookieDomain : ''))
  130. + ((secure) ? '; secure' : ((cookieSecure) ? '; secure' : ''));
  131. }
  132. /**
  133. * Returns a string containing value of specified cookie,
  134. * or null if cookie does not exist.
  135. */
  136. function getCookie (name)
  137. {
  138. var c, RE = new RegExp('(^|;)\\s*'+ name +'\\s*=\\s*([^\\s;]+)', 'g');
  139. return (c = RE.exec(document.cookie)) ? c[2] : null;
  140. }
  141. /**
  142. * name name of the cookie
  143. * [path] path of the cookie (must be same as path used to create cookie)
  144. * [domain] domain of the cookie (must be same as domain used to create cookie)
  145. */
  146. function deleteCookie (name, path, domain)
  147. {
  148. setCookie(name, '', -1, path, domain);
  149. }
  150. // Simple Javascript Browser/OS detection (based on "Harald Hope, Tapio Markula, http://techpatterns.com ver 2.0.1")
  151. var ua = navigator.userAgent;
  152. var os_win = ( navigator.appVersion.indexOf( 'Win' ) != -1 );
  153. var os_mac = ( navigator.appVersion.indexOf( 'Mac' ) != -1 );
  154. var os_lin = ( ua.indexOf( 'Linux' ) != -1 );
  155. var is_opera = ( ua.indexOf( 'Opera' ) != -1 );
  156. var is_konq = ( ua.indexOf( 'Konqueror' ) != -1 );
  157. var is_saf = ( ua.indexOf( 'Safari' ) != -1 );
  158. var is_moz = ( ua.indexOf( 'Gecko' ) != -1 && !is_saf && !is_konq);
  159. var is_ie = ( document.all && !is_opera );
  160. var is_ie4 = ( is_ie && !document.getElementById );
  161. // ie5x tests only for functionality
  162. // Opera will register true in this test if set to identify as IE 5
  163. var is_ie5x = ( document.all && document.getElementById );
  164. var os_ie5mac = ( os_mac && is_ie5x );
  165. var os_ie5xwin = ( os_win && is_ie5x );
  166. // Copy text to clipboard. Originally got from decompiled `php_manual_en.chm`.
  167. function ie_copyTextToClipboard (fromNode)
  168. {
  169. var txt = document.body.createTextRange();
  170. txt.moveToElementText(fromNode);
  171. return txt.execCommand("Copy");
  172. }
  173. //
  174. // Menus
  175. //
  176. var Menu = {
  177. hideSpeed : 'fast',
  178. offsetCorrection_X : -4,
  179. offsetCorrection_Y : 2,
  180. iframeFix : false,
  181. activeMenuId : null, // currently opened menu (from previous click)
  182. clickedMenuId : null, // menu to show up
  183. $root : null, // root element for menu with "href = '#clickedMenuId'"
  184. $menu : null, // clicked menu
  185. positioningType : null, // reserved
  186. outsideClickWatch : false, // prevent multiple $(document).click binding
  187. clicked: function($root) {
  188. $root.blur();
  189. this.clickedMenuId = this.getMenuId($root);
  190. this.$menu = $(this.clickedMenuId);
  191. this.$root = $root;
  192. this.toggle();
  193. },
  194. hovered: function($root) {
  195. if (this.activeMenuId && this.activeMenuId !== this.getMenuId($root)) {
  196. this.clicked($root);
  197. }
  198. },
  199. unhovered: function($root) {
  200. },
  201. getMenuId: function($el) {
  202. var href = $el.attr('href');
  203. return href.substr(href.indexOf('#'));
  204. },
  205. setLocation: function() {
  206. var CSS = this.$root.offset();
  207. CSS.top += this.$root.height() + this.offsetCorrection_Y;
  208. var curTop = parseInt(CSS.top);
  209. var tCorner = $(document).scrollTop() + $(window).height() - 20;
  210. var maxVisibleTop = Math.min(curTop, Math.max(0, tCorner - this.$menu.height()));
  211. if (curTop != maxVisibleTop) {
  212. CSS.top = maxVisibleTop;
  213. }
  214. CSS.left += this.offsetCorrection_X;
  215. var curLeft = parseInt(CSS.left);
  216. var rCorner = $(document).scrollLeft() + $(window).width() - 6;
  217. var maxVisibleLeft = Math.min(curLeft, Math.max(0, rCorner - this.$menu.width()));
  218. if (curLeft != maxVisibleLeft) {
  219. CSS.left = maxVisibleLeft;
  220. }
  221. this.$menu.css(CSS);
  222. if (this.iframeFix) {
  223. $('iframe.ie-fix-select-overlap', $menu).css({ width: $menu.width(), height: $menu.height() });
  224. }
  225. },
  226. fixLocation: function() {
  227. var $menu = this.$menu;
  228. var curLeft = parseInt($menu.css('left'));
  229. var rCorner = $(document).scrollLeft() + $(window).width() - 6;
  230. var maxVisibleLeft = Math.min(curLeft, Math.max(0, rCorner - $menu.width()));
  231. if (curLeft != maxVisibleLeft) {
  232. $menu.css('left', maxVisibleLeft);
  233. }
  234. var curTop = parseInt($menu.css('top'));
  235. var tCorner = $(document).scrollTop() + $(window).height() - 20;
  236. var maxVisibleTop = Math.min(curTop, Math.max(0, tCorner - $menu.height()));
  237. if (curTop != maxVisibleTop) {
  238. $menu.css('top', maxVisibleTop);
  239. }
  240. if (this.iframeFix) {
  241. $('iframe.ie-fix-select-overlap', $menu).css({ width: $menu.width(), height: $menu.height() });
  242. }
  243. },
  244. toggle: function() {
  245. if (this.activeMenuId && this.activeMenuId !== this.clickedMenuId) {
  246. $(this.activeMenuId).hide(this.hideSpeed);
  247. }
  248. // toggle clicked menu
  249. if (this.$menu.is(':visible')) {
  250. this.$menu.hide(this.hideSpeed);
  251. this.activeMenuId = null;
  252. } else {
  253. this.showClickedMenu();
  254. if (!this.outsideClickWatch) {
  255. $(document).one('mousedown', function(e){ Menu.hideClickWatcher(e); });
  256. this.outsideClickWatch = true;
  257. }
  258. }
  259. },
  260. showClickedMenu: function() {
  261. this.setLocation();
  262. this.$menu.css({display: 'block'});
  263. // this.fixLocation();
  264. this.activeMenuId = this.clickedMenuId;
  265. },
  266. // hide if clicked outside of menu
  267. hideClickWatcher: function(e) {
  268. this.outsideClickWatch = false;
  269. this.hide(e);
  270. },
  271. hide: function(e) {
  272. if (this.$menu) {
  273. this.$menu.hide(this.hideSpeed);
  274. }
  275. this.activeMenuId = this.clickedMenuId = this.$menu = null;
  276. }
  277. };
  278. $(document).ready(function(){
  279. // Menus
  280. $('body').append($('div.menu-sub'));
  281. $('a.menu-root')
  282. .click(
  283. function(e){ e.preventDefault(); Menu.clicked($(this)); return false; })
  284. .hover(
  285. function(){ Menu.hovered($(this)); return false; },
  286. function(){ Menu.unhovered($(this)); return false; }
  287. )
  288. ;
  289. $('div.menu-sub')
  290. .mousedown(function(e){ e.stopPropagation(); })
  291. .find('a')
  292. .click(function(e){ Menu.hide(e); })
  293. ;
  294. // Input hints
  295. $('input')
  296. .filter('.hint').one('focus', function(){
  297. $(this).val('').removeClass('hint');
  298. })
  299. .end()
  300. .filter('.error').one('focus', function(){
  301. $(this).removeClass('error');
  302. })
  303. ;
  304. });
  305. //
  306. // Ajax
  307. //
  308. function Ajax(handlerURL, requestType, dataType) {
  309. this.url = handlerURL;
  310. this.type = requestType;
  311. this.dataType = dataType;
  312. this.errors = { };
  313. }
  314. Ajax.prototype = {
  315. init : {}, // init functions (run before submit, after triggering ajax event)
  316. callback : {}, // callback functions (response handlers)
  317. state : {}, // current action state
  318. request : {}, // request data
  319. params : {}, // action params, format: ajax.params[ElementID] = { param: "val" ... }
  320. form_token : '',
  321. exec: function(request) {
  322. this.request[request.action] = request;
  323. request['form_token'] = this.form_token;
  324. $.ajax({
  325. url : this.url,
  326. type : this.type,
  327. dataType : this.dataType,
  328. data : request,
  329. success : ajax.success,
  330. error : ajax.error
  331. });
  332. },
  333. success: function(response) {
  334. var action = response.action;
  335. // raw_output normally might contain only error messages (if php.ini.display_errors == 1)
  336. if (response.raw_output) {
  337. $('body').prepend(response.raw_output);
  338. }
  339. if (response.sql_log) {
  340. $('#sqlLog').prepend(response.sql_log +'<hr />');
  341. fixSqlLog();
  342. }
  343. if (response.update_ids) {
  344. for (id in response.update_ids) {
  345. $('#'+id).html( response.update_ids[id] );
  346. }
  347. }
  348. if (response.prompt_password) {
  349. var user_password = prompt('??? ??????? ? ?????? ???????, ??????????, ??????? ???? ??????', '');
  350. if (user_password) {
  351. var req = ajax.request[action];
  352. req.user_password = user_password;
  353. ajax.exec(req);
  354. }
  355. else {
  356. ajax.clearActionState(action);
  357. ajax.showErrorMsg('?????? ???????? ??????');
  358. }
  359. }
  360. else if (response.prompt_confirm) {
  361. if (window.confirm(response.confirm_msg)) {
  362. var req = ajax.request[action];
  363. req.confirmed = 1;
  364. ajax.exec(req);
  365. }
  366. else {
  367. ajax.clearActionState(action);
  368. }
  369. }
  370. else if (response.error_code) {
  371. ajax.showErrorMsg(response.error_msg);
  372. $('.loading-1').removeClass('loading-1').html('error');
  373. }
  374. else {
  375. ajax.callback[action](response);
  376. ajax.clearActionState(action);
  377. }
  378. },
  379. error: function(xml, desc) {
  380. },
  381. clearActionState: function(action){
  382. ajax.state[action] = ajax.request[action] = '';
  383. },
  384. showErrorMsg: function(msg){
  385. alert(msg);
  386. },
  387. callInitFn: function(event) {
  388. event.stopPropagation();
  389. var params = ajax.params[$(this).attr('id')];
  390. var action = params.action;
  391. if (ajax.state[action] == 'readyToSubmit' || ajax.state[action] == 'error') {
  392. return false;
  393. } else {
  394. ajax.state[action] = 'readyToSubmit';
  395. }
  396. ajax.init[action](params);
  397. },
  398. setStatusBoxPosition: function($el) {
  399. var newTop = $(document).scrollTop();
  400. var rCorner = $(document).scrollLeft() + $(window).width() - ($.browser.opera ? 14 : 8);
  401. var newLeft = Math.max(0, rCorner - $el.width());
  402. $el.css({ top: newTop, left: newLeft });
  403. },
  404. makeEditable: function(rootElementId, editableType) {
  405. var $root = $('#'+rootElementId);
  406. var $editable = $('.editable', $root);
  407. var inputsHtml = $('#editable-tpl-'+editableType).html();
  408. $editable.hide().after(inputsHtml);
  409. var $inputs = $('.editable-inputs', $root);
  410. if (editableType == 'input' || editableType == 'textarea') {
  411. $('.editable-value', $inputs).val( $.trim($editable.text()) );
  412. }
  413. $('input.editable-submit', $inputs).click(function(){
  414. var params = ajax.params[rootElementId];
  415. var $val = $('.editable-value', '#'+rootElementId);
  416. params.value = ($val.size() == 1) ? $val.val() : $val.filter(':checked').val();
  417. params.submit = true;
  418. ajax.init[params.action](params);
  419. });
  420. $('input.editable-cancel', $inputs).click(function(){
  421. ajax.restoreEditable(rootElementId);
  422. });
  423. $inputs.show().find('.editable-value').focus();
  424. $root.removeClass('editable-container');
  425. },
  426. restoreEditable: function(rootElementId, newValue) {
  427. var $root = $('#'+rootElementId);
  428. var $editable = $('.editable', $root);
  429. $('.editable-inputs', $root).remove();
  430. if (newValue) {
  431. $editable.text(newValue);
  432. }
  433. $editable.show();
  434. ajax.clearActionState( ajax.params[rootElementId].action );
  435. ajax.params[rootElementId].submit = false;
  436. $root.addClass('editable-container');
  437. }
  438. };
  439. $(document).ready(function(){
  440. // Setup ajax-loading box
  441. $("#ajax-loading").ajaxStart(function(){
  442. $("#ajax-error").hide();
  443. $(this).show();
  444. ajax.setStatusBoxPosition($(this));
  445. });
  446. $("#ajax-loading").ajaxStop(function(){ $(this).hide(); });
  447. // Setup ajax-error box
  448. $("#ajax-error").ajaxError(function(req, xml){
  449. var status = xml.status;
  450. var text = xml.statusText;
  451. if (status == 200) {
  452. status = '';
  453. text = '???????? ?????? ??????';
  454. }
  455. $(this).html(
  456. "?????? ?: <i>"+ ajax.url +"</i><br /><b>"+ status +" "+ text +"</b>"
  457. ).show();
  458. ajax.setStatusBoxPosition($(this));
  459. });
  460. // Bind ajax events
  461. $('var.ajax-params').each(function(){
  462. var params = $.evalJSON( $(this).html() );
  463. params.event = params.event || 'dblclick';
  464. ajax.params[params.id] = params;
  465. $("#"+params.id).bind(params.event, ajax.callInitFn);
  466. if (params.event == 'click' || params.event == 'dblclick') {
  467. $("#"+params.id).addClass('editable-container');
  468. }
  469. });
  470. });
  471. /**
  472. * Autocomplete password
  473. **/
  474. var array_for_rand_pass = ["a", "A", "b", "B", "c", "C", "d", "D", "e", "E", "f", "F", "g", "G", "h", "H", "i", "I", "j", "J", "k", "K", "l", "L", "m", "M", "n", "N", "o", "O", "p", "P", "q", "Q", "r", "R", "s", "S", "t", "T", "u", "U", "v", "V", "w", "W", "x", "X", "y", "Y", "z", "Z", 0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
  475. var array_rand = function (array) {
  476. var array_length = array.length;
  477. var result = Math.random() * array_length;
  478. return Math.floor(result);
  479. };
  480. var autocomplete = function (noCenter) {
  481. var string_result = ""; // Empty string
  482. for (var i = 1; i <= 8; i++) {
  483. string_result += array_for_rand_pass[array_rand(array_for_rand_pass)];
  484. }
  485. var _popup_left = (Math.ceil(window.screen.availWidth / 2) - 150);
  486. var _popup_top = (Math.ceil(window.screen.availHeight / 2) - 50);
  487. if (!noCenter) {
  488. $("div#autocomplete_popup").css({
  489. left:_popup_left + "px",
  490. top:_popup_top + "px"
  491. }).show(1000);
  492. } else {
  493. $("div#autocomplete_popup").show(1000);
  494. }
  495. $("input#pass, input#pass_confirm, div#autocomplete_popup input").each(function () {
  496. $(this).val(string_result);
  497. });
  498. };
  499. $(document).ready(function () {
  500. $("span#autocomplete").click(function() {
  501. autocomplete();
  502. });
  503. // ??????????? ????
  504. var _X, _Y;
  505. var _bMoveble = false;
  506. $("div#autocomplete_popup div.title").mousedown(function (event) {
  507. _bMoveble = true;
  508. _X = event.clientX;
  509. _Y = event.clientY;
  510. });
  511. $("div#autocomplete_popup div.title").mousemove(function (event) {
  512. var jFrame = $("div#autocomplete_popup");
  513. var jFLeft = parseInt(jFrame.css("left"));
  514. var jFTop = parseInt(jFrame.css("top"));
  515. if (_bMoveble) {
  516. if (event.clientX < _X) {
  517. jFrame.css("left", jFLeft - (_X - event.clientX) + "px");
  518. } else {
  519. jFrame.css("left", (jFLeft + (event.clientX - _X)) + "px");
  520. }
  521. if (event.clientY < _Y) {
  522. jFrame.css("top", jFTop - (_Y - event.clientY) + "px");
  523. } else {
  524. jFrame.css("top", (jFTop + (event.clientY - _Y)) + "px");
  525. }
  526. _X = event.clientX;
  527. _Y = event.clientY;
  528. }
  529. });
  530. $("div#autocomplete_popup div.title").mouseup(function () {
  531. _bMoveble = false;
  532. }).mouseout(function () {
  533. _bMoveble = false;
  534. });
  535. });