PageRenderTime 66ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/includes/js/common.js

http://compactcms.googlecode.com/
JavaScript | 408 lines | 279 code | 46 blank | 83 comment | 11 complexity | d61bf7a6780f3cdb6a3334836f598f32 MD5 | raw file
Possible License(s): GPL-3.0, CC0-1.0
  1. /**
  2. * Copyright (C) 2008 - 2010 by Xander Groesbeek (CompactCMS.nl)
  3. *
  4. * Last changed: $LastChangedDate$
  5. * @author $Author$
  6. * @version $Revision$
  7. * @package CompactCMS.nl
  8. * @license GNU General Public License v3
  9. *
  10. * This file is part of CompactCMS.
  11. *
  12. * CompactCMS is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation, either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * CompactCMS is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * A reference to the original author of CompactCMS and its copyright
  23. * should be clearly visible AT ALL TIMES for the user of the back-
  24. * end. You are NOT allowed to remove any references to the original
  25. * author, communicating the product to be your own, without written
  26. * permission of the original copyright owner.
  27. *
  28. * You should have received a copy of the GNU General Public License
  29. * along with CompactCMS. If not, see <http://www.gnu.org/licenses/>.
  30. *
  31. * > Contact me for any inquiries.
  32. * > E: Xander@CompactCMS.nl
  33. * > W: http://community.CompactCMS.nl/forum
  34. **/
  35. window.addEvent('domready', function(){
  36. function editin_init() {
  37. $$('.liveedit').each(function(el) {
  38. el.addEvent('click',function() {
  39. el.set('class','liveedit2');
  40. var before = el.get('html').trim();
  41. el.set('html','');
  42. var input = new Element('textarea', { 'wrap':'soft', 'class':'textarea', 'text':before });
  43. input.addEvent('click', function (e) {
  44. e.stop();
  45. return;
  46. });
  47. input.addEvent('keydown', function(e) { if(e.key == 'enter') { this.fireEvent('blur'); } });
  48. input.inject(el).select();
  49. //add blur event to input
  50. input.addEvent('blur', function() {
  51. //get value, place it in original element
  52. val = input.get('value').trim();
  53. el.set('text',val);
  54. //save respective record
  55. var content = el.get('text');
  56. var request = new Request.HTML({
  57. url:'./includes/process.inc.php?action=liveedit&part='+el.get('rel'),
  58. method:'post',
  59. update: el,
  60. data: 'action=liveedit&id='+el.get('id')+'&content='+content,
  61. onRequest: function() {
  62. el.set("html","<img src='img/saving.gif' alt='Saving' />");
  63. },
  64. onComplete: function() {
  65. el.set("class","sprite-hover liveedit");
  66. }
  67. }).send();
  68. });
  69. });
  70. });
  71. }
  72. // Show list onload
  73. var dyn_list = $('dyn_list').empty().addClass('loading');
  74. var req = new Request.HTML({
  75. method: 'get',
  76. url: './includes/process.inc.php?action=update',
  77. update: dyn_list,
  78. onComplete: function() {
  79. dyn_list.removeClass('loading');
  80. editin_init();
  81. editPlace();
  82. externalLinks();
  83. doEditor();
  84. }
  85. }).send();
  86. /**
  87. *
  88. * Actions based on user clicks
  89. *
  90. */
  91. // Process new page
  92. $('addForm').addEvent('submit', function(add) {
  93. new Event(add).stop();
  94. // Setting waiting style
  95. var notify = $('notify_res').empty();
  96. var status = $('notify').addClass('loading');
  97. closeMenu();
  98. // Wait for response and act
  99. new Request.HTML({
  100. method: 'post',
  101. url: './includes/process.inc.php',
  102. update: notify,
  103. onComplete: function() {
  104. status.removeClass('loading');
  105. refreshContent();
  106. renderList();
  107. }
  108. }).post($('addForm'));
  109. });
  110. // Process delete page
  111. $('delete').addEvent('submit', function(remove) {
  112. var agree = confirm($('ad_msg01').value);
  113. if(agree) {
  114. closeMenu();
  115. new Event(remove).stop();
  116. //var url = this.href;
  117. var notify = $('notify_res').empty();
  118. var status = $('notify').addClass('loading');
  119. // Wait for response and act
  120. new Request.HTML({
  121. method: 'post',
  122. url: './includes/process.inc.php',
  123. update: notify,
  124. onComplete: function() {
  125. status.removeClass('loading');
  126. refreshContent();
  127. renderList();
  128. }
  129. }).post($('delete'));
  130. } else {
  131. new Event(remove).stop();
  132. }
  133. });
  134. // Process menu order preference
  135. $('menuForm').addEvent('submit', function(menu) {
  136. new Event(menu).stop();
  137. // Setting waiting style
  138. var notify = $('notify_res').empty();
  139. var status = $('notify').addClass('loading');
  140. // Wait for response and act
  141. new Request.HTML({
  142. url: './includes/process.inc.php',
  143. method: 'post',
  144. update: notify,
  145. onComplete: function() {
  146. status.removeClass('loading');
  147. refreshContent();
  148. }
  149. }).post($('menuForm'));
  150. });
  151. /**
  152. *
  153. * Functions
  154. *
  155. */
  156. // Render menu depth list
  157. function renderList() {
  158. var menudepth = $('menuFields').addClass('loading');
  159. new Request.HTML({
  160. method: 'get',
  161. url: './includes/process.inc.php?action=renderlist',
  162. update: menudepth,
  163. onComplete: function() {
  164. menudepth.removeClass('loading');
  165. isLink();
  166. }
  167. }).send();
  168. }
  169. // Change linkage preference
  170. function isLink() {
  171. $$('.islink').addEvent('click', function(islink) {
  172. var item_id = this.id;
  173. var cvalue = this.checked;
  174. var status = $('notify').addClass('loading');
  175. var islink = $('td-islink-'+item_id).addClass('printloading');
  176. new Request({
  177. url:'./includes/process.inc.php?action=islink',
  178. method:'post',
  179. autoCancel:true,
  180. data:'cvalue=' + cvalue + '&action=islink&id='+item_id,
  181. onSuccess: function() {
  182. status.removeClass('loading');
  183. islink.removeClass('printloading');
  184. },
  185. onFailure: function() {
  186. $('notify').set('text','Undocumented error!');
  187. }
  188. }).send();
  189. });
  190. }
  191. // Refresh on print/publish update
  192. function refreshContent() {
  193. var dyn_list = $('dyn_list').empty().addClass('loading');
  194. var notify = $('notify_res');
  195. var status = $('notify').addClass('loading');
  196. notify.setStyle('border', 'none');
  197. new Request.HTML({
  198. method: 'get',
  199. url: './includes/process.inc.php?action=update',
  200. update: dyn_list,
  201. onComplete: function() {
  202. editin_init();
  203. editPlace();
  204. externalLinks();
  205. renderList();
  206. doEditor();
  207. dyn_list.removeClass('loading');
  208. status.removeClass('loading');
  209. }
  210. }).send();
  211. }
  212. // Change print or publish value
  213. function editPlace() {
  214. $$('.editinplace').addEvent('click', function(editinplace) {
  215. new Event(editinplace).stop();
  216. closeMenu();
  217. var url = './includes/process.inc.php?action=editinplace&id='+this.id+'&s='+this.rel;
  218. var status = $(this.id).addClass('printloading');
  219. new Request.HTML({
  220. method: 'get',
  221. url: url,
  222. update: status,
  223. onComplete: function() {
  224. status.removeClass('printloading');
  225. refreshContent();
  226. }
  227. }).send();
  228. });
  229. }
  230. // Apply editor window to all $$('.tabs') links
  231. function doEditor() {
  232. MUI.myChain = new Chain();
  233. MUI.myChain.chain(
  234. function(){MUI.Desktop.initialize();},
  235. function(){MUI.Dock.initialize();},
  236. function(){initializeWindows();}
  237. ).callChain();
  238. }
  239. /**
  240. *
  241. * Single calls
  242. *
  243. */
  244. // Fade non-focused divs
  245. $$('.container').each(function(container) {
  246. container.getChildren().each(function(child) {
  247. var siblings = child.getParent().getChildren().erase(child);
  248. child.addEvents({
  249. mouseenter: function() { siblings.tween('opacity',0.6); },
  250. mouseleave: function() { siblings.tween('opacity',1); }
  251. });
  252. });
  253. });
  254. // Collapsible - add page
  255. var myAdd = new Fx.Slide('form_wrapper');
  256. myAdd.toggle();
  257. $('toggle-1').addEvent('click', function(e){
  258. e = new Event(e);
  259. myAdd.toggle();
  260. e.stop();
  261. });
  262. // Collapsible - menu depth
  263. var myMenu = new Fx.Slide('menu_wrapper');
  264. renderList();
  265. myMenu.toggle();
  266. $('toggle-3').addEvent('click', function(e){
  267. e = new Event(e);
  268. myMenu.toggle();
  269. e.stop();
  270. });
  271. // Close only (menuDepth)
  272. function closeMenu() {
  273. var menuClose = new Fx.Slide('menu_wrapper');
  274. menuClose.slideOut();
  275. }
  276. // Tips links
  277. $$('span.ss_help').each(function(element,index) {
  278. var content = element.get('title').split('::');
  279. element.store('tip:title', content[0]);
  280. element.store('tip:text', content[1]);
  281. });
  282. // Create the tooltips
  283. var tipz = new Tips('.ss_help',{
  284. className: 'ss_help',
  285. fixed: true,
  286. hideDelay: 50,
  287. showDelay: 50
  288. });
  289. /**
  290. *
  291. * Editor window preferences
  292. *
  293. */
  294. initializeWindows = function(){
  295. // Examples
  296. MUI.editWindow = function(id,url,title){
  297. new MUI.Window({
  298. id: id+'_ccms',
  299. title: title,
  300. loadMethod: 'iframe',
  301. contentURL: url,
  302. width: 910,
  303. height: 640,
  304. padding: {top: 0, right:0, left:0, bottom:0},
  305. toolbar: false
  306. });
  307. };
  308. if ($$('a.tabs')) {
  309. $$('a.tabs').addEvent('click', function(e){
  310. new Event(e).stop();
  311. MUI.editWindow(this.id,this.href,this.rel);
  312. });
  313. }
  314. MUI.clockWindow = function(){
  315. new MUI.Window({
  316. id: 'clock',
  317. title: 'Clock',
  318. addClass: 'transparent',
  319. contentURL: '../lib/includes/js/plugins/clock.html',
  320. shape: 'gauge',
  321. headerHeight: 30,
  322. width: 160,
  323. height: 160,
  324. x: 10,
  325. y: 10,
  326. padding: { top: 0, right: 0, bottom: 0, left: 0 },
  327. require: {
  328. js: ['../lib/includes/js/plugins/clock.js'],
  329. onload: function(){
  330. if (CoolClock) new CoolClock();
  331. }
  332. }
  333. });
  334. };
  335. if ($$('.clock')){
  336. $$('.clock').addEvent('click', function(e){
  337. new Event(e).stop();
  338. MUI.clockWindow();
  339. });
  340. }
  341. // Deactivate menu header links
  342. $$('a.returnFalse').each(function(el) {
  343. el.addEvent('click', function(e) {
  344. new Event(e).stop();
  345. });
  346. });
  347. // Build windows onLoad
  348. //MUI.myChain.callChain();
  349. };
  350. });
  351. // External links script (rel=external)
  352. function externalLinks() {
  353. if (!document.getElementsByTagName) return;
  354. var anchors = document.getElementsByTagName("a");
  355. for (var i=0; i<anchors.length; i++) {
  356. var anchor = anchors[i];
  357. if (anchor.getAttribute("href") &&
  358. anchor.getAttribute("class") == "external")
  359. anchor.target = "_blank";
  360. }
  361. }
  362. window.onload = externalLinks;