PageRenderTime 48ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/common/js/lazycms.js

http://lazycms.googlecode.com/
JavaScript | 1025 lines | 864 code | 11 blank | 150 comment | 70 complexity | 6c4dc35306c2c5a9a02579216186eeef MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1
  1. /**
  2. * +---------------------------------------------------------------------------+
  3. * | LL LLLL LL L LLLL LLLL |
  4. * | LL LL L LLL LL LL L LL LL |
  5. * | LL LLLL LLLLL LL LL LL LLLL LLL LL LL LL LL |
  6. * | LL LL LL LL LL LL L LLL LL LLLLL LL LL LL |
  7. * | LL LLLLL LL LLLL LL L L LL LLLLL LL LL LL |
  8. * | LL LL LL LL LLLL LL L LL LL LLLL LL |
  9. * | LL LL LL LL LL LL L L LL L LL LLLL LL |
  10. * | LLLLLL LLLLL LLLLL LL LLLL L LL LLLL LL LLLLLL |
  11. * | LL |
  12. * | LL |
  13. * +---------------------------------------------------------------------------+
  14. * | Copyright (C) 2007-2010 LazyCMS.com All rights reserved. |
  15. * +---------------------------------------------------------------------------+
  16. * | LazyCMS is free software. See LICENSE for copyright notices and details. |
  17. * +---------------------------------------------------------------------------+
  18. *
  19. * LazyCMS
  20. *
  21. * @author Lukin <my@lukin.cn>
  22. * @version $Id: lazycms.js 757 2011-03-09 15:35:12Z mylukin $
  23. */
  24. var LazyCMS = window.LazyCMS = window.CMS = {
  25. // javascript libaray version
  26. version: '1.0',
  27. // ?????
  28. L10n: {},
  29. // URI??
  30. URI: {},
  31. // ?????
  32. ADMIN: '/admin/',
  33. // ?????
  34. ROOT: '/',
  35. // Loading...
  36. Loading: $('<div class="loading">Loading...</div>').css({width:'90px',position:'fixed',top:'5px',right:'5px'}),
  37. // ????
  38. COUNT_VAR: {
  39. Loading:false,
  40. Masked:false,
  41. Float:{
  42. Scroll:false,
  43. Resize:false
  44. }
  45. },
  46. /**
  47. * ajax success
  48. *
  49. * @param xhr
  50. * @param s
  51. */
  52. success: function(xhr, s, loading){
  53. // ??success
  54. s.orisuccess = s.success;
  55. // ???success
  56. s.success = function(data, status, xhr) {
  57. if (xhr && xhr.getResponseHeader('X-Powered-By') && s.url.toLowerCase().indexOf('.php') != -1) {
  58. if (xhr.getResponseHeader('X-Powered-By').indexOf("\x4c\x61\x7a\x79\x43\x4d\x53") == -1)
  59. return s.error(xhr, status);
  60. }
  61. var data = LazyCMS.ajaxSuccess.apply(this,arguments);
  62. if (null!==data && s.orisuccess) {
  63. s.orisuccess.call(this, data, status, xhr);
  64. }
  65. }
  66. if (typeof loading == 'undefined') {
  67. LazyCMS.Loading.css({'z-index':$('*').maxIndex() + 1}).appendTo('body');
  68. }
  69. },
  70. /**
  71. * ?????
  72. *
  73. * @param msgid ??
  74. */
  75. translate: function(msgid){
  76. return LazyCMS.L10n[msgid] || msgid;
  77. },
  78. /**
  79. * ??alert
  80. *
  81. * @param message ?????html??
  82. * @param callback ???????????
  83. * @param code ?????Success?Error?Other
  84. */
  85. alert: function(message,callback,code) {
  86. var position,IE6_hacker;
  87. if (callback && !$.isFunction(callback)) {
  88. code = callback;
  89. }
  90. if (code) {
  91. switch (code) {
  92. case 'Success':
  93. position = 'background-position:0px 0px;';
  94. break;
  95. case 'Error':
  96. position = 'background-position:0px -40px;';
  97. break;
  98. default:
  99. position = 'background-position:0px -80px;';
  100. break;
  101. }
  102. message = '<div class="icon" style="' + position + '"></div><div class="content"><h6>' + message + '</h6></div>';
  103. }
  104. // ????IE6?? min-width max-width
  105. if ($.browser.msie && $.browser.version == '6.0') {
  106. IE6_hacker = function(){
  107. var cont_width = $('.content',this).width(),
  108. cont_min_width = parseInt($('.content',this).css('min-width')),
  109. cont_max_width = parseInt($('.content',this).css('max-width'));
  110. $('.content',this).width(Math.min(Math.max(cont_width,cont_min_width),cont_max_width));
  111. };
  112. }
  113. LazyCMS.dialog({
  114. name:'alert', title:_('Alert'), close:false, styles:{ 'top':-100, 'max-width':'600px', 'min-width':'400px' },
  115. body:message,
  116. buttons:[{
  117. focus:true,
  118. text:_('Submit'),
  119. handler:function(opts){
  120. LazyCMS.removeDialog('alert');
  121. if ($.isFunction(callback)) callback();
  122. return false;
  123. }
  124. }]
  125. },IE6_hacker);
  126. },
  127. /**
  128. * ?????
  129. *
  130. * @param message ????
  131. * @param callback ????
  132. * @example LazyCMS.confirm('message',function(r){
  133. * if (r) {
  134. * coding...
  135. * }
  136. * });
  137. */
  138. confirm: function(message,callback){
  139. LazyCMS.dialog({
  140. name:'confirm', title:_('Confirm'),styles:{ 'top':-100, width:'400px' },
  141. body:'<div class="icon" style="background-position:0px -80px;"></div><div class="content"><h6>' + message + '</h6></div>',
  142. buttons:[{
  143. focus:true,
  144. text:_('Submit'),
  145. handler:function(){
  146. LazyCMS.removeDialog('confirm');
  147. return callback.call(this,true);
  148. }
  149. },{
  150. text:_('Cancel'),
  151. handler:function(){
  152. LazyCMS.removeDialog('confirm');
  153. return callback.call(this,false);
  154. }
  155. }]
  156. });
  157. return false;
  158. },
  159. /**
  160. * URL??
  161. *
  162. * @param url
  163. * @param time
  164. * @param message
  165. */
  166. redirect: function(url,time,message) {
  167. if (typeof url != 'undefined' && url != '') {
  168. url = url.replace('&amp;', '&');
  169. var win = top || window;
  170. win.location.replace(url);
  171. }
  172. },
  173. // ???????
  174. isMask: function(){
  175. return $('div#lazy_mask').is('div');
  176. },
  177. /**
  178. * ?????
  179. *
  180. * @param options
  181. * {
  182. * width:?????100%,
  183. * height:?????100%,
  184. * opacity:?????? 0.7,
  185. * background:????????#fff
  186. * }
  187. */
  188. masked: function(options) {
  189. var isMask = LazyCMS.isMask();
  190. var maskDiv = isMask ? $('div#lazy_mask') : $('<div id="lazy_mask"></div>');
  191. var maxIndex = $('div#lazy_mask,div.dialog').maxIndex();
  192. // ????
  193. if (!isMask) {
  194. // ????
  195. var styles = $.extend({
  196. width:'100%',
  197. height:'100%',
  198. left:0,
  199. top:0,
  200. opacity:0.7,
  201. background:'#fff',
  202. position:'fixed',
  203. 'z-index': (maxIndex + 1)
  204. }, options||{});
  205. $.extend(styles,{'-ms-filter':'alpha(opacity=' + (100 * styles.opacity) + ')', 'filter':'alpha(opacity=' + (100 * styles.opacity) + ')', '-moz-opacity':styles.opacity});
  206. maskDiv.css(styles);
  207. }
  208. // ?????
  209. else if (isMask && options) {
  210. if (options.opacity) {
  211. $.extend(options,{'-ms-filter':'alpha(opacity=' + (100 * options.opacity) + ')', 'filter':'alpha(opacity=' + (100 * options.opacity) + ')', '-moz-opacity':options.opacity});
  212. }
  213. maskDiv.css(options);
  214. }
  215. if (!isMask) {
  216. // ?????
  217. $('body').append(maskDiv);
  218. // ??????
  219. if ($.browser.msie && $.browser.version == '6.0') {
  220. var reposition = function(){
  221. maskDiv.css({ 'position':'absolute','top':$(window).scrollTop() + 'px'});
  222. }
  223. if (!LazyCMS.COUNT_VAR.Masked) {
  224. $(window).scroll(reposition).resize(reposition);
  225. LazyCMS.COUNT_VAR.Masked = true;
  226. }
  227. // ??IE6????option
  228. reposition(); $('div#lazy_mask').bgiframe();
  229. }
  230. }
  231. return maskDiv;
  232. },
  233. // ?????
  234. removeMask: function() {
  235. if ($('div.dialog').size()==0) {
  236. LazyCMS.masked().remove();
  237. } else {
  238. LazyCMS.masked({'z-index':$('div.dialog').maxIndex() - 1});
  239. }
  240. },
  241. /**
  242. * ????ajax????
  243. *
  244. * @param data ajax response
  245. * @param status
  246. * @param xhr
  247. */
  248. ajaxSuccess: function(r, status, xhr) {
  249. var data,code = xhr.getResponseHeader('X-LazyCMS-Code');
  250. try {
  251. data = $.isPlainObject(r) ? r : $.parseJSON(r);
  252. } catch (e) {
  253. data = r;
  254. }
  255. switch (code) {
  256. // ??
  257. case 'Success': case 'Error': case 'Alert':
  258. LazyCMS.alert(data,function(){
  259. // ????
  260. try { eval(xhr.getResponseHeader('X-LazyCMS-Eval')) } catch (e) {}
  261. },code);
  262. break;
  263. // ??
  264. case 'Confirm':
  265. LazyCMS.confirm(data, function(r){
  266. // ????
  267. if (r) {
  268. try { eval(xhr.getResponseHeader('X-LazyCMS-Submit')) } catch (e) {}
  269. } else {
  270. try { eval(xhr.getResponseHeader('X-LazyCMS-Cancel')) } catch (e) {}
  271. }
  272. });
  273. break;
  274. // ??
  275. case 'Redirect':
  276. LazyCMS.redirect(data.Location, data.Time, data.Message);
  277. break;
  278. // ??????
  279. case 'Validate':
  280. $(document).error(data);
  281. break;
  282. // ????
  283. case 'Return': default:
  284. data = r;
  285. break;
  286. }
  287. if (code && $.inArray(code, ['Success','Return'])==-1) data = null;
  288. return data;
  289. },
  290. /**
  291. * ??????
  292. *
  293. * @param options
  294. * @param callback
  295. */
  296. dialog: function(options,callback) {
  297. return $('body').dialog(options,callback);
  298. },
  299. /**
  300. * ?????
  301. *
  302. * @param name options.name
  303. */
  304. removeDialog: function(name){
  305. var dialog = $.data(document,name);
  306. dialog = dialog ? dialog : $('.lazy_dialog_' + name);
  307. dialog.remove(); LazyCMS.removeMask();
  308. },
  309. /**
  310. * ??????
  311. *
  312. * @example: <select edit="true" default="value"></select>
  313. */
  314. eselect: function() {
  315. $('select[edit=true]').each(function(){
  316. try {
  317. var that = $(this); if (that.is('select')===false) return ;
  318. var name = that.attr('name');
  319. var val = (that.attr('default')!='' && (typeof that.attr('default'))!='undefined') ? that.attr('default') : that.val();
  320. var input = $('<input class="text" type="text" name="' + name + '" value="' + val + '" />');
  321. var width = +that.outerWidth()-20;
  322. if ($.browser.msie && $.browser.version == '6.0') {
  323. input.width(width);
  324. input.height(that.height());
  325. } else {
  326. input.width(width);
  327. input.height(that.outerHeight());
  328. }
  329. input.css({'margin-right':'2px'});
  330. that.wrapAll('<span class="eselect" style="display:inline-block; width:' + (+that.outerWidth()+width+8) + 'px;"></span>');
  331. that.parent().prepend(input);
  332. var select = $('<select name="eselect_' + name + '" edit="yes">' + that.html() + '</select>')
  333. .change(function(){
  334. $(this).prev().val(this.value);
  335. })
  336. .val(val);
  337. if (that.attr('id')!=='') select.attr('id',that.attr('id'));
  338. var attrs = that.getAttrs();
  339. $.each(attrs,function(k,v){
  340. if ($.inArray(k,['id','name','edit'])==-1 && v){
  341. select.attr(k,v);
  342. }
  343. });
  344. that.replaceWith(select);
  345. } catch (e) {}
  346. });
  347. },
  348. // ??????
  349. postAction: function(url,action,listid) {
  350. var listids = [];
  351. if ($.isArray(listid)) {
  352. listids = listid;
  353. } else {
  354. listids.push(listid);
  355. }
  356. var params = {'listids':listids};
  357. if ($.isPlainObject(action)) {
  358. params = $.extend(params,action);
  359. } else {
  360. params = $.extend(params,{action:action});
  361. }
  362. return $.post(LazyCMS.ADMIN + url,params,null,'json');
  363. },
  364. /**
  365. * ??cookie
  366. *
  367. * @param name
  368. * @param key
  369. * @param val
  370. * @param options
  371. */
  372. setCookie: function(name,key,val,options) {
  373. options = options || {};
  374. var cookie = $.cookie(name),
  375. opts = $.extend({ expires: 365, path: LazyCMS.ROOT }, options),
  376. cookies = cookie===null ? {} : LazyCMS.parse_str(cookie);
  377. // ??
  378. if (arguments.length == 2) {
  379. if (cookies[key]) return cookies[key];
  380. else return null;
  381. }
  382. // ??
  383. else {
  384. cookies[key] = val;
  385. return $.cookie(name, $.param(cookies), opts);
  386. }
  387. },
  388. /**
  389. * ??cookie
  390. *
  391. * @param name
  392. * @param key
  393. */
  394. getCookie: function(name,key) {
  395. return LazyCMS.setCookie(name,key);
  396. },
  397. /**
  398. * ???PHP parse_str
  399. *
  400. * @param str
  401. */
  402. parse_str: function(str) {
  403. var pairs = str.split('&'),params = {}, urldecode = function(s){
  404. return decodeURIComponent(s.replace(/\+/g, '%20'));
  405. };
  406. $.each(pairs,function(i,pair){
  407. if ((pair = pair.split('='))[0]) {
  408. var key = urldecode(pair.shift());
  409. var value = pair.length > 1 ? pair.join('=') : pair[0];
  410. if (value != undefined) value = urldecode(value);
  411. if (key in params) {
  412. if (!$.isArray(params[key])) {
  413. params[key] = [params[key]];
  414. }
  415. params[key].push(value);
  416. } else {
  417. params[key] = value;
  418. }
  419. }
  420. });
  421. return params;
  422. }
  423. };
  424. LazyCMS.URI.Host = (('https:' == self.location.protocol) ? 'https://'+self.location.hostname : 'http://'+self.location.hostname);
  425. LazyCMS.URI.Path = self.location.href.replace(/\?(.*)/,'').replace(LazyCMS.URI.Host,'');
  426. LazyCMS.URI.File = LazyCMS.URI.Path.split('/').pop();
  427. LazyCMS.URI.Path = LazyCMS.URI.Path.substr(0,LazyCMS.URI.Path.lastIndexOf('/')+1);
  428. LazyCMS.URI.Url = LazyCMS.URI.Host + LazyCMS.URI.Path + LazyCMS.URI.File;
  429. window._ = LazyCMS.translate;
  430. /**
  431. * jQuery ??
  432. *
  433. * @author: Lukin<my@lukin.cn>
  434. * @date: 2010/1/21 17:11
  435. */
  436. jQuery && (function ($) {
  437. // ?????zIndex
  438. $.fn.maxIndex = function(){
  439. var max = 0;
  440. this.each(function(){
  441. max = Math.max(max,this.style.zIndex);
  442. });
  443. return max;
  444. };
  445. /**
  446. * ???????????
  447. */
  448. $.fn.getAttrs = function() {
  449. var r = {};
  450. if (!this.length) return r;
  451. if ($.browser.msie) {
  452. var p = /([^'"= ]+)=('[^']*'|"[^"]*"|[^'" ]+)/g,
  453. s = this.attr('outerHTML'),
  454. t = /<[^>]*>/.exec(s)[0];
  455. while (m = p.exec(t)) {
  456. r[m[1]] = m[2].replace(/^['"]|['"]$/g, '');
  457. }
  458. } else {
  459. $.each(this.get(0).attributes,function(i){
  460. r[this.name] = this.value;
  461. });
  462. }
  463. return r;
  464. };
  465. /**
  466. * ??????
  467. *
  468. * @param options ??
  469. * {
  470. * name:??,
  471. * title:??,
  472. * body:??,
  473. * styles:css ??,
  474. * masked:?????????true,
  475. * close:???????????true,
  476. * way:?????????????c,lt,rt,lb,rb,
  477. * remove:???????????,
  478. * buttons:??
  479. * }
  480. * @param callback ????(dialog jquery??,??? options)
  481. */
  482. $.fn.dialog = function(options,callback) {
  483. // this
  484. var _this = $(this);
  485. // ????
  486. var opts = $.extend({
  487. title:'',
  488. body:'',
  489. styles:{},
  490. name:null,
  491. masked:true,
  492. close:true,
  493. way:'c',
  494. className:'dialog',
  495. remove:function(){ LazyCMS.removeDialog(opts.name); },
  496. buttons:[]
  497. }, options||{});
  498. // ????
  499. var btnLength = opts.buttons.length;
  500. // ??????
  501. opts.name = opts.name?'lazy_dialog_' + opts.name:'lazy_dialog';
  502. // ???????
  503. var dialog = $('<div class="' + opts.name + ' ' + opts.className + ' window" style="display:none;"><h1>Loading...</h1><div class="wrapper">Loading...</div></div>').css({position:'fixed'});
  504. var target = $('div.' + opts.name,_this);
  505. if (target.is('div')) {
  506. dialog = target;
  507. } else {
  508. _this.append(dialog);
  509. }
  510. // ??????
  511. dialog.removeDialog = opts.remove;
  512. // ?????
  513. if (opts.masked) {
  514. LazyCMS.masked({'z-index':$('*').maxIndex() + 1});
  515. }
  516. // ??????
  517. if (opts.close) {
  518. if ($('.close',dialog).is('a')) {
  519. $('.close',dialog).click(function(){
  520. dialog.removeDialog();
  521. });
  522. } else {
  523. $('<a href="javascript:;" class="close">Close</a>').click(dialog.removeDialog).insertAfter($('h1',dialog));
  524. }
  525. } else {
  526. $('.close',dialog).remove();
  527. }
  528. // ????CSS
  529. var styles = $.extend({overflow:'','z-index':$('*').maxIndex() + 1,height:'auto'},opts.styles); dialog.css(styles);
  530. // ????
  531. $('h1',dialog).text(opts.title);
  532. // ????
  533. if ($('div.wrapper','<div>' + opts.body + '</div>').is('div')) {
  534. $('div.wrapper',dialog).replaceWith(opts.body);
  535. } else {
  536. $('.wrapper',dialog).html(opts.body + '<div class="clear"></div>');
  537. // ?????????
  538. $('.buttons',dialog).remove();
  539. }
  540. // ????
  541. $('[rel=close]',dialog).click(function(){
  542. dialog.removeDialog();
  543. });
  544. // ????IE6?? min-width max-width
  545. if ($.browser.msie && $.browser.version == '6.0') {
  546. var width = dialog.width(),
  547. min_width = parseFloat(dialog.css('min-width')),
  548. max_width = parseFloat(dialog.css('max-width'));
  549. if (!isNaN(min_width)) {
  550. width = Math.max(width,min_width);
  551. }
  552. if (!isNaN(max_width)) {
  553. width = Math.min(width,max_width);
  554. }
  555. dialog.width(width);
  556. }
  557. var overflow = dialog.css('overflow');
  558. if (opts.way) dialog.way({way:opts.way,top:styles.top});
  559. dialog.css({overflow:''}).show();
  560. if (overflow=='auto') {
  561. var wrapper = $('div.wrapper',dialog),
  562. paddtop = parseFloat(wrapper.css('padding-top')),
  563. paddbottom = parseFloat(wrapper.css('padding-bottom')),
  564. h1_height = $('h1',dialog).outerHeight();
  565. wrapper.css({overflow:'auto',width:wrapper.width(),height:dialog.height()-(paddtop+paddbottom)-h1_height});
  566. }
  567. // ????
  568. if (btnLength > 0) {
  569. $('.wrapper',dialog).after('<div class="buttons"></div>');
  570. for (var i=0;i<btnLength;i++) {
  571. var button = $('<button type="button">' + opts.buttons[i].text + '</button>');
  572. // ??????
  573. (function(i){
  574. button.click(function(){
  575. if ($.isFunction(opts.buttons[i].handler)) opts.buttons[i].handler.call(dialog,opts);
  576. return false;
  577. });
  578. })(i);
  579. $('.buttons',dialog).append(button);
  580. // ??????
  581. opts.buttons[i].type && button.attr('type',opts.buttons[i].type) || null;
  582. // ??????
  583. opts.buttons[i].focus && button.focus() || null;
  584. }
  585. }
  586. // ????
  587. $.data(document,opts.name,dialog);
  588. // ??????
  589. if ($.isFunction(callback)) callback.call(dialog,opts);
  590. return dialog;
  591. }
  592. /**
  593. * ????
  594. *
  595. * @param data
  596. * [
  597. * {
  598. * id:???name,
  599. * text:????
  600. * },
  601. * {
  602. * id:???name,
  603. * text:????
  604. * },
  605. * ]
  606. */
  607. $.fn.error = function(data) {
  608. var wrap = this, s = '<ul>', elm, xheLayout;
  609. $.each(data,function(i){
  610. elm = $('#'+this.id, wrap);
  611. if (elm.length > 0) {
  612. xheLayout = elm.next().next().find('.xheLayout');
  613. if (elm.is('textarea') && xheLayout.is('table')) {
  614. xheLayout.addClass(elm.get(0).tagName.toLowerCase() + '_error');
  615. } else {
  616. elm.addClass(elm.get(0).tagName.toLowerCase() + '_error');
  617. }
  618. }
  619. s+= '<li>' + this.text + '</li>';
  620. });
  621. s+= '</ul>';
  622. LazyCMS.alert(s);
  623. };
  624. // ?????
  625. $.fn.semiauto = function() {
  626. var name = LazyCMS.URI.File.substr(0,LazyCMS.URI.File.lastIndexOf('.')),
  627. opts = { path: LazyCMS.URI.Path },last;
  628. // ?????
  629. $('select[cookie=true]',this).each(function(i){
  630. var t = $(this); t.attr('guid',i);
  631. var c = LazyCMS.getCookie(name + '_select', 's' + i);
  632. if (c !== null) {
  633. $('option:selected',this).attr('selected',false);
  634. $('option[value="' + c + '"]',this).attr('selected',true);
  635. }
  636. }).change(function(){
  637. LazyCMS.setCookie(name + '_select', 's' + $(this).attr('guid'), this.value, opts);
  638. });
  639. // ????
  640. $('input:checkbox[cookie=true]',this).each(function(i){
  641. var t = $(this); t.attr('guid',i);
  642. var c = LazyCMS.getCookie(name + '_checkbox', 'c' + i);
  643. if (c !== null) {
  644. this.checked = c == 'true';
  645. }
  646. }).click(function(){
  647. LazyCMS.setCookie(name + '_checkbox', 'c' + $(this).attr('guid'), this.checked, opts);
  648. });
  649. // ??????
  650. $('fieldset[cookie=true]',this).each(function(i){
  651. var t = $(this); t.attr('guid',i);
  652. var c = LazyCMS.getCookie(name + '_fieldset', 'f' + i);
  653. if (c !== null) {
  654. t.toggleClass('closed', c == 'true');
  655. }
  656. }).find('a.toggle,h3').click(function(){
  657. LazyCMS.setCookie(name + '_fieldset', 'f' + $(this).parents('fieldset').attr('guid'), !$(this).parents('fieldset').hasClass('closed'), opts);
  658. });
  659. return this;
  660. };
  661. /**
  662. * ajax ????
  663. *
  664. * @param callback
  665. */
  666. $.fn.ajaxSubmit = function(callback,dataType){
  667. if (callback && $.type(callback) == 'string')
  668. dataType = callback;
  669. dataType = dataType || 'html';
  670. return this.each(function(){
  671. var _this = $(this);
  672. _this.submit(function(){
  673. // ????
  674. $('.input_error,.textarea_error,.ul_error',_this).removeClass('input_error').removeClass('textarea_error').removeClass('ul_error');
  675. var button = $('button[type=submit]',this).attr('disabled',true);
  676. // ?? action ??
  677. var url = _this.attr('action'); if (url==''||typeof url=='undefined') { url = self.location.href; }
  678. // ajax submit
  679. $.ajax({
  680. cache: false, url: url, dataType: dataType,
  681. type: _this.attr('method') && _this.attr('method').toUpperCase() || 'POST',
  682. data: _this.serializeArray(),
  683. success: function(data, status, xhr){
  684. if ($.isFunction(callback)) callback.call(_this,data, status, xhr);
  685. },
  686. complete: function(){
  687. button.attr('disabled',false); LazyCMS.Loading.remove();
  688. }
  689. });
  690. return false;
  691. });
  692. });
  693. };
  694. // ????????
  695. $.fn.actions = function(callback) {
  696. // ?? action ??
  697. var form = $(this);
  698. // ??????
  699. $('input[name=select]',form).click(function(){
  700. $('input[name^=list]:checkbox,input[name=select]:checkbox',form).attr('checked',this.checked);
  701. });
  702. // ??????
  703. $('tbody tr',form).hover(function(){
  704. $('td',this).css({'background-color':'#FFFFCC'});
  705. $('.row-actions',this).css({'visibility': 'visible'});
  706. },function(){
  707. $('td',this).css({'background-color':'#FFFFFF'});
  708. $('.row-actions',this).css({'visibility': 'hidden'});
  709. });
  710. var header = form.attr('header'), method = form.attr('method'),
  711. url = header && $.trim(header.substr(header.indexOf(' '))) || form.attr('action');
  712. method = header && $.trim(header.substring(0,header.indexOf(' '))) || method;
  713. if (url=='' || typeof url=='undefined') url = self.location.href;
  714. $('.table-nav',form).each(function(i){
  715. var _this = $(this);
  716. $('button[type=button]:not([onclick])',_this).click(function(){
  717. var button = $(this), listids = [] ,action = $('select[name=actions]',_this).val(),
  718. // ????
  719. submit = function(url,data) {
  720. button.attr('disabled',true);
  721. $.ajax({
  722. dataType: 'json', url: url, data: data,
  723. type: method.toUpperCase() || 'GET',
  724. success: function(data){
  725. if ($.isFunction(callback)) callback.call(_this,data);
  726. },
  727. complete: function(){
  728. button.attr('disabled',false); LazyCMS.Loading.remove();
  729. }
  730. });
  731. }
  732. if (action=='') {
  733. return LazyCMS.alert(_('Did not select any action!'),'Error');
  734. }
  735. $('input:checkbox[name^=listids]:checked',form).each(function(){
  736. listids.push(this.value);
  737. });
  738. switch (action) {
  739. case 'delete':
  740. LazyCMS.confirm(_('Confirm Delete?'),function(r){
  741. if (r) {
  742. submit(url,{
  743. 'action':action,
  744. 'listids':listids
  745. });
  746. }
  747. });
  748. break;
  749. default:
  750. submit(url,{
  751. 'action':action,
  752. 'listids':listids
  753. });
  754. break;
  755. }
  756. });
  757. });
  758. };
  759. /**
  760. * ?????????
  761. *
  762. * @param opts
  763. * c|Center:??
  764. * lt|LeftTop:???
  765. * rt|RightTop:???
  766. * lb|LeftBottom:???
  767. * rb|RightBottom:???
  768. */
  769. $.fn.way = function(opts) {
  770. var _this = this,way = 'c',css = function(){};
  771. if (typeof opts == 'object') {
  772. way = opts.way;
  773. } else if (typeof opts == 'string') {
  774. way = opts; opts = {};
  775. }
  776. css = function(way) {
  777. var r = {};
  778. switch (way) {
  779. case 'c': case 'Center':
  780. r = {
  781. left:($(window).width() - _this.outerWidth())/2 + (isNaN(+opts.left) ? 0 : opts.left),
  782. top:($(window).height() - _this.outerHeight())/2 + (isNaN(+opts.top) ? 0 : opts.top)
  783. };
  784. break;
  785. case 'lt': case 'LeftTop':
  786. r = { left:(isNaN(+opts.left) ? 0 : opts.left), top:(isNaN(+opts.top) ? 0 : opts.top) };
  787. break;
  788. case 'rt': case 'RightTop':
  789. r = { right:(isNaN(+opts.right) ? 0 : opts.right), top:(isNaN(+opts.top) ? 0 : opts.top) };
  790. break;
  791. case 'lb': case 'LeftBottom':
  792. r = { left:(isNaN(+opts.left) ? 0 : opts.left), bottom:(isNaN(+opts.bottom) ? 0 : opts.bottom) };
  793. break;
  794. case 'rb': case 'RightBottom':
  795. r = { right:(isNaN(+opts.right) ? 0 : opts.right), bottom:(isNaN(+opts.bottom) ? 0 : opts.bottom) };
  796. break;
  797. case 'cb': case 'CenterBottom':
  798. r = {
  799. left:($(window).width() - _this.outerWidth())/2 + (isNaN(+opts.left) ? 0 : opts.left),
  800. bottom:(isNaN(+opts.bottom) ? 0 : opts.bottom)
  801. };
  802. break;
  803. }
  804. if ($.browser.msie && $.browser.version == '6.0') {
  805. var top = r.top;
  806. if (isNaN(parseFloat(top))) {
  807. top = $(window).height() - _this.outerHeight();
  808. }
  809. r = $.extend(r,{ position:'absolute',top: $(window).scrollTop() + top });
  810. } else {
  811. r = $.extend(r,{ position:'fixed' });
  812. }
  813. this.css(r);
  814. }
  815. var position = function() { css.call(_this,way) }; position();
  816. // ??IE6
  817. if ($.browser.msie && $.browser.version == '6.0') {
  818. if (!LazyCMS.COUNT_VAR.Float.Scroll) {
  819. $(window).scroll(position);
  820. LazyCMS.COUNT_VAR.Float.Scroll = true;
  821. }
  822. }
  823. // ????????
  824. $(window).resize(position);
  825. return this;
  826. };
  827. /**
  828. * Create a cookie with the given name and value and other optional parameters.
  829. *
  830. * @example $.cookie('the_cookie', 'the_value');
  831. * @desc Set the value of a cookie.
  832. * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
  833. * @desc Create a cookie with all available options.
  834. * @example $.cookie('the_cookie', 'the_value');
  835. * @desc Create a session cookie.
  836. * @example $.cookie('the_cookie', null);
  837. * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
  838. * used when the cookie was set.
  839. *
  840. * @param String name The name of the cookie.
  841. * @param String value The value of the cookie.
  842. * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
  843. * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
  844. * If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
  845. * If set to null or omitted, the cookie will be a session cookie and will not be retained
  846. * when the the browser exits.
  847. * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
  848. * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
  849. * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
  850. * require a secure protocol (like HTTPS).
  851. * @type undefined
  852. *
  853. * @name $.cookie
  854. * @cat Plugins/Cookie
  855. * @author Klaus Hartl/klaus.hartl@stilbuero.de
  856. */
  857. /**
  858. * Get the value of a cookie with the given name.
  859. *
  860. * @example $.cookie('the_cookie');
  861. * @desc Get the value of a cookie.
  862. *
  863. * @param String name The name of the cookie.
  864. * @return The value of the cookie.
  865. * @type String
  866. *
  867. * @name $.cookie
  868. * @cat Plugins/Cookie
  869. * @author Klaus Hartl/klaus.hartl@stilbuero.de
  870. */
  871. $.cookie = function(name, value, options) {
  872. if (typeof value != 'undefined') { // name and value given, set cookie
  873. options = options || {};
  874. if (value === null) {
  875. value = '';
  876. options.expires = -1;
  877. }
  878. var expires = '';
  879. if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
  880. var date;
  881. if (typeof options.expires == 'number') {
  882. date = new Date();
  883. date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
  884. } else {
  885. date = options.expires;
  886. }
  887. expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
  888. }
  889. // CAUTION: Needed to parenthesize options.path and options.domain
  890. // in the following expressions, otherwise they evaluate to undefined
  891. // in the packed version for some reason...
  892. var path = options.path ? '; path=' + (options.path) : '';
  893. var domain = options.domain ? '; domain=' + (options.domain) : '';
  894. var secure = options.secure ? '; secure' : '';
  895. document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
  896. } else { // only name given, get cookie
  897. var cookieValue = null;
  898. if (document.cookie && document.cookie != '') {
  899. var cookies = document.cookie.split(';');
  900. for (var i = 0; i < cookies.length; i++) {
  901. var cookie = jQuery.trim(cookies[i]);
  902. // Does this cookie string begin with the name we want?
  903. if (cookie.substring(0, name.length + 1) == (name + '=')) {
  904. cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
  905. break;
  906. }
  907. }
  908. }
  909. return cookieValue;
  910. }
  911. };
  912. /**
  913. * The bgiframe is chainable and applies the iframe hack to get
  914. * around zIndex issues in IE6. It will only apply itself in IE6
  915. * and adds a class to the iframe called 'bgiframe'. The iframe
  916. * is appeneded as the first child of the matched element(s)
  917. * with a tabIndex and zIndex of -1.
  918. *
  919. * By default the plugin will take borders, sized with pixel units,
  920. * into account. If a different unit is used for the border's width,
  921. * then you will need to use the top and left settings as explained below.
  922. *
  923. * NOTICE: This plugin has been reported to cause perfromance problems
  924. * when used on elements that change properties (like width, height and
  925. * opacity) a lot in IE6. Most of these problems have been caused by
  926. * the expressions used to calculate the elements width, height and
  927. * borders. Some have reported it is due to the opacity filter. All
  928. * these settings can be changed if needed as explained below.
  929. *
  930. * @example $('div').bgiframe();
  931. * @before <div><p>Paragraph</p></div>
  932. * @result <div><iframe class="bgiframe".../><p>Paragraph</p></div>
  933. *
  934. * @param Map settings Optional settings to configure the iframe.
  935. * @option String|Number top The iframe must be offset to the top
  936. * by the width of the top border. This should be a negative
  937. * number representing the border-top-width. If a number is
  938. * is used here, pixels will be assumed. Otherwise, be sure
  939. * to specify a unit. An expression could also be used.
  940. * By default the value is "auto" which will use an expression
  941. * to get the border-top-width if it is in pixels.
  942. * @option String|Number left The iframe must be offset to the left
  943. * by the width of the left border. This should be a negative
  944. * number representing the border-left-width. If a number is
  945. * is used here, pixels will be assumed. Otherwise, be sure
  946. * to specify a unit. An expression could also be used.
  947. * By default the value is "auto" which will use an expression
  948. * to get the border-left-width if it is in pixels.
  949. * @option String|Number width This is the width of the iframe. If
  950. * a number is used here, pixels will be assume. Otherwise, be sure
  951. * to specify a unit. An experssion could also be used.
  952. * By default the value is "auto" which will use an experssion
  953. * to get the offsetWidth.
  954. * @option String|Number height This is the height of the iframe. If
  955. * a number is used here, pixels will be assume. Otherwise, be sure
  956. * to specify a unit. An experssion could also be used.
  957. * By default the value is "auto" which will use an experssion
  958. * to get the offsetHeight.
  959. * @option Boolean opacity This is a boolean representing whether or not
  960. * to use opacity. If set to true, the opacity of 0 is applied. If
  961. * set to false, the opacity filter is not applied. Default: true.
  962. * @option String src This setting is provided so that one could change
  963. * the src of the iframe to whatever they need.
  964. * Default: "javascript:false;"
  965. *
  966. * @name bgiframe
  967. * @type jQuery
  968. * @cat Plugins/bgiframe
  969. * @author Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
  970. */
  971. $.fn.bgIframe = $.fn.bgiframe = function(s) {
  972. // This is only for IE6
  973. if ( $.browser.msie && /6.0/.test(navigator.userAgent) ) {
  974. s = $.extend({
  975. top : 'auto', // auto == .currentStyle.borderTopWidth
  976. left : 'auto', // auto == .currentStyle.borderLeftWidth
  977. width : 'auto', // auto == offsetWidth
  978. height : 'auto', // auto == offsetHeight
  979. opacity : true,
  980. src : 'javascript:false;'
  981. }, s || {});
  982. var prop = function(n){ return n&&n.constructor==Number?n+'px':n; },
  983. html = '<iframe class="bgiframe" frameborder="0" tabindex="-1" src="'+s.src+'" '+
  984. 'style="display:block;position:absolute;z-index:-1;'+
  985. (s.opacity !== false?'filter:Alpha(Opacity=\'0\');':'')+
  986. 'top:'+(s.top=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\'px\')':prop(s.top))+';'+
  987. 'left:'+(s.left=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\'px\')':prop(s.left))+';'+
  988. 'width:'+(s.width=='auto'?'expression(this.parentNode.offsetWidth+\'px\')':prop(s.width))+';'+
  989. 'height:'+(s.height=='auto'?'expression(this.parentNode.offsetHeight+\'px\')':prop(s.height))+';'+
  990. '"/>';
  991. return this.each(function() {
  992. if ( $('> iframe.bgiframe', this).length == 0 )
  993. this.insertBefore( document.createElement(html), this.firstChild );
  994. });
  995. }
  996. return this;
  997. };
  998. })(jQuery);