PageRenderTime 54ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/pivotx_2.2.5-sqlite/pivotx/includes/js/pivotx.js

http://pivotx-sqlite.googlecode.com/
JavaScript | 1083 lines | 589 code | 283 blank | 211 comment | 78 complexity | d38ba48a0296d3db4d6a1fe6a6ab4c7e MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-2.1, BSD-3-Clause
  1. // Don't break on browsers without console.log();
  2. if (typeof(console) === 'undefined') { console = { log: function() {}, assert: function() {} }; }
  3. /**
  4. * Some events that are initialized during page load.
  5. */
  6. jQuery(function($) {
  7. // Initialise the main menu
  8. if($("ul.sf-menu").is('*')) {
  9. $("ul.sf-menu").superfish({
  10. pathClass: 'current'
  11. });
  12. }
  13. // Make 'suggested tags' clickable in 'new entry' screen.
  14. $("a[rel=tag]").click( function(tag){
  15. var keywords = $('#f_keywords').val();
  16. var tagfield = $('#f_tag').val();
  17. var tag = $(this).html();
  18. if (keywords=="") {
  19. $('#f_keywords').val(tag);
  20. } else {
  21. $('#f_keywords').val(keywords + ", " + tag);
  22. }
  23. });
  24. // Add calendar popups to all inputs with class 'date-picker'
  25. if($('input.date-picker').is('*')) {
  26. $('input.date-picker').datepicker({
  27. yearRange:'1970:2099', dateFormat: 'dd-mm-yy', gotoCurrent: true
  28. });
  29. }
  30. // Handler for Dialog links..
  31. $('.dialog').bind('click', function() {
  32. // If we passed an extra class to set the type of dialog, we use it here
  33. // to set the size of the window.
  34. if ($(this).hasClass('editor')) {
  35. var dialogwidth='800';
  36. var dialogheight='540';
  37. } else if ($(this).hasClass('user')) {
  38. var dialogwidth='540';
  39. var dialogheight='620';
  40. } else if ($(this).hasClass('chapter')) {
  41. var dialogwidth='540';
  42. var dialogheight='240';
  43. } else if ($(this).hasClass('comment')) {
  44. var dialogwidth='540';
  45. var dialogheight='560';
  46. } else {
  47. var dialogwidth='460';
  48. var dialogheight='440';
  49. }
  50. if (dialogheight > ($('body').height()-30)) {
  51. dialogheight = $('body').height()-30;
  52. }
  53. openDialog($(this).attr('title'), $(this).attr('href'), dialogwidth, dialogheight);
  54. return false;
  55. });
  56. // Make all textareas with class='resizeable' automagically resizeable
  57. makeResizeable();
  58. // A nasty fix, so that IE recognizes the 'mouseover'
  59. if($.browser.msie) {
  60. $('#nav li').hover(function(){ $(this).addClass("sfhover"); },function(){
  61. $(this).removeClass("sfhover");
  62. });
  63. }
  64. // Highlight the active form element
  65. $(".formclass input, .formclass select, .formclass textarea").focus( function(){
  66. $(this).addClass("activeinput");
  67. });
  68. $(".formclass input, .formclass select, .formclass textarea").blur( function(){
  69. $(this).removeClass("activeinput");
  70. });
  71. // Add an onclick event to all checkboxes that have a 'rowselect' class.
  72. $("input.rowselect").click( function() { rowSelect($(this)) });
  73. // Add masks to some inputs when writing/editing a new post or entry.
  74. if( $('input.date-picker').is('*') || $("#date1").is('*') ) {
  75. $("#publish_date1").inputmask("d-m-y");
  76. $("#publish_date2").inputmask("H-i");
  77. $("#date1").inputmask("d-m-y");
  78. $("#date2").inputmask("H-i");
  79. }
  80. // Add 'no wrap' to .clip-ed text, but only in FF and Opera..
  81. if ($.browser.mozilla || $.browser.opera) { $('.clip').addClass('extraclip'); }
  82. // If there's an input with id='keywords', we add tagging autocomplete to it.
  83. if ($("#keywords").is('*')) {
  84. // Make the #keywords an autocomplete field..
  85. $("#keywords").autocomplete("./ajaxhelper.php?function=getTagSuggest", {
  86. multiple: true,
  87. multipleSeparator: " ",
  88. autoFill: true,
  89. delay: 150,
  90. width: 250,
  91. selectFirst: true,
  92. minChars: 2,
  93. max: 50
  94. });
  95. // Make sure pressing 'enter' in the autocompleter doesn't submit the form.
  96. $("#keywords").bind("keypress", function(event) {
  97. if(event.keyCode == 13) { return false; }
  98. });
  99. // Get a small cloud of the 40 most populair tags.
  100. getAllTags(40);
  101. }
  102. if($('#chapterjumpform')) {
  103. $('#chapterjumpform').bind('submit', function(e){e.preventDefault();});
  104. $('#pagesjumplist').bind('change', function(e, o) {
  105. //console.log($(this).val());
  106. window.location.hash = $(this).val();
  107. });
  108. }
  109. // Attach the handler for resizing the browser window. Call it almost immediately
  110. // as well. (yes, we have to do this with a timeout, and yes, we have to do it multiple times. Stupid Safari!)
  111. $(window).bind('resize', function(){ pivotxResizeWindow(true); });
  112. setTimeout( function(){ pivotxResizeWindow(false); }, 50 );
  113. });
  114. // Textarea resizer variables.
  115. var startpos, diffpos=0, currentresizer = "", currentheight="", resizehandled=false;
  116. // Make all textareas with class='resizeable' automagically resizeable
  117. function makeResizeable() {
  118. // Safari 3 has this built in, so don't do it again.
  119. if ($.browser.safari) { return; }
  120. $('.resizable').each(function(i) {
  121. var width = $(this).width();
  122. if ($.browser.mozilla) { width = width + 8; }
  123. $(this).after("<div class='resizer' style='width:" + width + "px;' title='Drag me..'></div>");
  124. $(this).next().mousedown( function(e) {
  125. startpos = e.pageY;
  126. currentresizer = $(this).prev();
  127. currentheight = $(currentresizer).height();
  128. resizehandled = true;
  129. // Make the document trigger on mouseup, to stop resizing of textarea's. We bind this event only when one
  130. // of the resizers is clicked.
  131. $(document).mouseup(function() {
  132. resizehandled = false;
  133. });
  134. // Resize the textarea if 'resizehandled' is true. We bind this event only when one
  135. // of the resizers is clicked.
  136. $(document).mousemove(function(e) {
  137. if (resizehandled) {
  138. curpos = e.pageY;
  139. diffpos = startpos - curpos;
  140. if (diffpos > -800 && diffpos < 400) {
  141. $(currentresizer).height(currentheight - diffpos + 'px');
  142. }
  143. }
  144. });
  145. });
  146. });
  147. }
  148. function openDialog(title, href, dialogwidth, dialogheight, vars) {
  149. // Make sure we have a fresh #dialog..
  150. $('#dialog').remove();
  151. $('body').prepend("<div id='dialog'><div id='dialog-inner'><img src='./pics/loadingAnimation.gif' style='display: block; margin: 50px auto;'/></div></div>");
  152. // Dependant on whether vars is set, use either POST (with vars) or GET (without vars).
  153. if (typeof(vars)=="undefined") {
  154. var requesttype = "GET";
  155. var vars = "";
  156. } else {
  157. var requesttype = "POST";
  158. }
  159. // Load the contents of the dialog.
  160. $.ajax({
  161. type: requesttype,
  162. url: href,
  163. data: vars,
  164. success: function(html){
  165. $('#dialog-inner').html(html);
  166. JT_init();
  167. }
  168. });
  169. // Open the dialog..
  170. $('#dialog').show().dialog({
  171. bgiframe:true,
  172. resizable: true,
  173. modal: true,
  174. draggable: true,
  175. width: parseInt(dialogwidth),
  176. height: parseInt(dialogheight),
  177. title: title
  178. });
  179. }
  180. function openDialogFrame(title, href, dialogwidth, dialogheight) {
  181. // Make sure we have a fresh #dialogframe..
  182. $('#dialogframe').remove();
  183. // Prepend the Dialog to the page..
  184. $('body').prepend('<iframe id="dialogframe" src="" border="0" scrolling="no" frameborder="0" style="width: ' +
  185. (parseInt(dialogwidth)-2) + 'px !important; display:none;" ><img src="./pics/loadingAnimation.gif" ' +
  186. 'style="display: block; margin: 50px auto;" alt="Loading.." /></iframe>');
  187. // Set the correct source, to load the actual dialog contents.
  188. $('#dialogframe').attr('src', href);
  189. // Open the dialog..
  190. $('#dialogframe').dialog({
  191. bgiframe:true,
  192. resizable: true,
  193. modal: true,
  194. draggable: true,
  195. width: parseInt(dialogwidth),
  196. height: parseInt(dialogheight),
  197. title: title,
  198. open: function() { $('#dialogframe').width( parseInt(dialogwidth) ); }
  199. });
  200. }
  201. var fileSelectionTarget = "";
  202. /**
  203. * Open the File selector
  204. */
  205. function openFileSelector(title, target, filetypes) {
  206. // Make sure we have a fresh #filedialog..
  207. $('#filedialog').remove();
  208. $('body').prepend("<div id='filedialog'><img src='./pics/loadingAnimation.gif' style='display: block; margin: 50px auto;'/></div>");
  209. fileSelectionTarget = target;
  210. $.ajax({
  211. type: "POST",
  212. url: "ajaxhelper.php",
  213. data: "function=fileSelector",
  214. success: function(html){
  215. $('#filedialog').html(html);
  216. },
  217. error: function (XMLHttpRequest, textStatus, errorThrown) {
  218. // Sometimes (mostly in Safari, it seems) the path is incorrect.. Try
  219. // to get it again, by guesstimating.
  220. $.ajax({
  221. type: "POST",
  222. url: "/pivotx/ajaxhelper.php",
  223. data: "function=fileSelector",
  224. success: function(html){
  225. $('#filedialog').html(html);
  226. },
  227. error: function (XMLHttpRequest, textStatus, errorThrown) {
  228. $.ajax({
  229. type: "POST",
  230. url: "../ajaxhelper.php",
  231. data: "function=fileSelector",
  232. success: function(html){
  233. $('#filedialog').html(html);
  234. },
  235. error: function (XMLHttpRequest, textStatus, errorThrown) {
  236. alert('couldn\'t load the fileselector..');
  237. }
  238. });
  239. }
  240. });
  241. }
  242. });
  243. // Open the dialog..
  244. $('#filedialog').dialog({
  245. bgiframe:true,
  246. resizable: true,
  247. modal: true,
  248. draggable: true,
  249. width: 600,
  250. height: 320,
  251. title: title,
  252. overlay: { opacity: 0.75, background: "#789" }
  253. });
  254. return false;
  255. }
  256. /**
  257. * Select a file in the Fileselector dialog, and place it in the 'target'. We also
  258. * Call a bunch of events, to make sure that if the target has some attached
  259. * events they will be processed.
  260. */
  261. function fileSelectorChoose(file) {
  262. console.log(file);
  263. $(fileSelectionTarget).val(file).trigger('click').trigger('focus').trigger('blur');
  264. $('#filedialog').dialog('close');
  265. return false;
  266. }
  267. function fileSelectorChangefolder(folder) {
  268. $.ajax({
  269. type: "POST",
  270. url: "ajaxhelper.php",
  271. data: "function=fileSelector&folder="+escape(folder),
  272. success: function(html){
  273. $('#filedialog').html(html);
  274. }
  275. });
  276. return false;
  277. }
  278. /**
  279. * Get the PivotX news to display on the dashboard.
  280. */
  281. function getPivotxNews() {
  282. $.ajax({
  283. type: "POST",
  284. url: "./ajaxhelper.php",
  285. data: "function=getPivotxNews",
  286. success: function(html){
  287. html = html.split(/--split--/g);
  288. jQuery('#newsholder').html( html[0] );
  289. jQuery('#forumpostholder').html( html[1] );
  290. }
  291. });
  292. }
  293. /**
  294. * Show more newsitems..
  295. */
  296. function moreNews() {
  297. jQuery('#newsmoreclick').slideUp('slow');
  298. jQuery('#newsmore').slideDown('slow');
  299. return false;
  300. }
  301. /**
  302. * Show more events..
  303. */
  304. function moreEvents() {
  305. jQuery('#eventsmoreclick').slideUp('slow');
  306. jQuery('#eventsmore').slideDown('slow');
  307. return false;
  308. }
  309. /**
  310. * Show more forumposts..
  311. */
  312. function moreForumPosts() {
  313. jQuery('#forumpostsmoreclick').slideUp('slow');
  314. jQuery('#forumpostsmore').slideDown('slow');
  315. return false;
  316. }
  317. /**
  318. * Make the 'all' link in suggested tags fetch all tags..
  319. */
  320. function getAllTags(amount, path) {
  321. amount = parseInt(amount);
  322. if (typeof(path)!="undefined") {
  323. var url = "../../ajaxhelper.php";
  324. } else {
  325. var url = "./ajaxhelper.php";
  326. }
  327. $.ajax({
  328. type: "POST",
  329. url: url,
  330. data: "function=getAllTags&amount="+amount,
  331. success: function(fetchedhtml) {
  332. $("#suggestedtags").html(fetchedhtml);
  333. $('#suggestedtags a[rel=tag]').bind('click', function() {
  334. var tagname=$(this).html();
  335. $('#keywords').val($('#keywords').val() + " " + tagname);
  336. });
  337. },
  338. error: function() {
  339. alert("Error fetching tags.")
  340. }
  341. });
  342. }
  343. /**
  344. * Simple javascript confirmation for various actions. If the user clicks cancel,
  345. * nothing happens.. If the user clicks 'ok', the browser is redirected to the
  346. * link, which is padded with the 'pivotxsession' cookie.
  347. */
  348. function confirmme(link, str) {
  349. if (confirm(str)) {
  350. var cookie = "&pivotxsession=" + $.cookie('pivotxsession')
  351. self.location = link + cookie;
  352. return true;
  353. } else {
  354. return false;
  355. }
  356. }
  357. /**
  358. * Simple javascript question for various actions. If the user clicks cancel,
  359. * nothing happens.. If the user clicks 'ok', the browser is redirected to the
  360. * link, which is padded with the 'pivotxsession' cookie and the given answer
  361. */
  362. function askme(link, str) {
  363. var answer = prompt(str, '');
  364. if (answer!=null) {
  365. var cookie = "&pivotxsession=" + $.cookie('pivotxsession') + "&answer=" + answer
  366. self.location = link + cookie;
  367. } else {
  368. return false;
  369. }
  370. }
  371. /**
  372. * Select a row in a tabular-nav table, such as the one we use for the entries.
  373. */
  374. function rowSelect(rownum) {
  375. if ($('#check-'+rownum)[0].checked) {
  376. $('#row-'+rownum).addClass('selectedrow');
  377. } else {
  378. $('#row-'+rownum).removeClass('selectedrow')
  379. }
  380. }
  381. /**
  382. * Select all rows in a tabular-nav table..
  383. */
  384. function rowSelectAll() {
  385. $("input[type='checkbox']").each(function() {
  386. if (!this.checked) { this.click(); }
  387. });
  388. }
  389. /**
  390. * Select no rows in a tabular-nav table..
  391. */
  392. function rowSelectNone() {
  393. $("input[type='checkbox']").each(function() {
  394. if (this.checked) { this.click(); }
  395. });
  396. }
  397. /**
  398. * Ask for confirmation if we're deleting multiple entries..
  399. */
  400. function entriesActionSubmit() {
  401. if ($('#entriesaction').val() == "delete" ) {
  402. return confirm("Are you sure you wish to delete these entries?");
  403. } else {
  404. return true;
  405. }
  406. }
  407. /**
  408. * Save an edited file (from the ajaxy editor)
  409. */
  410. function saveEdit() {
  411. var basedir = $('#editBasedir').val();
  412. var file = $('#editFile').val();
  413. var csrfcheck = $.cookie("pivotxsession");
  414. // if we're using a MarkItUp editor, get the contents from that.
  415. if ($('textarea[class*="markItUpEditor"]').is('*')) {
  416. var contents = $('textarea[class*="markItUpEditor"]').val();
  417. } else {
  418. var contents = $('#editContents').val();
  419. }
  420. $.ajax({
  421. type: "POST",
  422. url: "ajaxhelper.php",
  423. data: "function=save&csrfcheck=" + encodeURIComponent(csrfcheck) +
  424. "&basedir=" + encodeURIComponent(basedir) +
  425. "&file=" + encodeURIComponent(file) +
  426. "&contents=" + encodeURIComponent(contents),
  427. success: function(fetchedhtml) { humanMsg.displayMsg(fetchedhtml); $('#dialog').dialog('close'); },
  428. error: function() { alert("Error saving file.") }
  429. });
  430. }
  431. /**
  432. * Save an edited file (from the ajaxy editor), and keep it open..
  433. */
  434. function saveEditAndContinue() {
  435. var basedir = $('#editBasedir').val();
  436. var file = $('#editFile').val();
  437. var csrfcheck = $.cookie("pivotxsession");
  438. // if we're using a MarkItUp editor, get the contents from that.
  439. if ($('textarea[class*="markItUpEditor"]').is('*')) {
  440. var contents = $('textarea[class*="markItUpEditor"]').val();
  441. } else {
  442. var contents = $('#editContents').val();
  443. }
  444. $.ajax({
  445. type: "POST",
  446. url: "ajaxhelper.php",
  447. data: "function=save&csrfcheck=" + encodeURIComponent(csrfcheck) +
  448. "&basedir=" + encodeURIComponent(basedir) +
  449. "&file=" + encodeURIComponent(file) +
  450. "&contents=" + encodeURIComponent(contents),
  451. success: function(fetchedhtml) { humanMsg.displayMsg(fetchedhtml); },
  452. error: function() { alert("Error saving file.") }
  453. });
  454. }
  455. /**
  456. * Close a file (from the ajaxy editor)
  457. */
  458. function closeEdit() {
  459. $('#dialog').dialog('close');
  460. }
  461. /**
  462. * Show the message box with loading gif to the user..
  463. */
  464. function setMessageLoading() {
  465. humanMsg.displayMsg("<img src='pics/loadingAnimation.gif' alt='Loading...' width='208' height='13'>", true);
  466. }
  467. /**
  468. * Fills the 'internal name' field with the URI for the page/entry..
  469. */
  470. function setSafename(from, to, text) {
  471. // Get the string..
  472. var str = $('#'+from).val();
  473. // Declare the characters that need replacement.. Using hexadecimal encoding to prevent breakage.
  474. var accent = unescape("%C0%C1%C2%C3%C4%C5%C7%C8%C9%CA%CB%CC%CD%CE%CF%D0%D1%D2%D3%D4%D5%D6%D7%D8%D9%DA%DB%DC%DD%E0%E1%E2%E3%E4%E5%E7%E8%E9%EA%EB%EC%ED%EE%EF%F1%F2%F3%F4%F5%F6%F8%F9%FA%FB%FC%FD%FF%u0100%u0101%u0102%u0103%u0104%u0105%u0106%u0107%u0108%u0109%u010A%u010B%u010C%u010D%u010E%u010F%u0110%u0111%u0112%u0113%u0114%u0115%u0116%u0117%u0118%u0119%u011A%u011B%u011C%u011D%u011E%u011F%u0120%u0121%u0122%u0123%u0124%u0125%u0126%u0127%u0128%u0129%u012A%u012B%u012C%u012D%u012E%u012F%u0130%u0131%u0134%u0135%u0136%u0137%u0138%u0139%u013A%u013B%u013C%u013D%u013E%u013F%u0140%u0141%u0142%u0143%u0144%u0145%u0146%u0147%u0148%u0149%u014A%u014B%u014C%u014D%u014E%u014F%u0150%u0151%u0154%u0155%u0156%u0157%u0158%u0159%u015A%u015B%u015C%u015D%u015E%u015F%u0160%u0161%u0162%u0163%u0164%u0165%u0166%u0167%u0168%u0169%u016A%u016B%u016C%u016D%u016E%u016F%u0170%u0171%u0172%u0173%u0174%u0175%u0176%u0177%u0178%u0179%u017A%u017B%u017C%u017D%u017E");
  475. var sansAccent = "AAAAAACEEEEIIIIDNOOOOOxOUUUUYaaaaaaceeeeiiiinoooooouuuuyyAaAaAaCcCcCcCcDdDdEeEeEeEeEeGgGgGgGgHhHhIiIiIiIiIiJjKkkLlLlLlLlLlNnNnNnnNnOoOoOoRrRrRrSsSsSsSsTtTtTtUuUuUuUuUuUuWwYyYZzZzZz";
  476. // Loop through the string.. Not the most efficient way, but this is done client-side and not on long strings.
  477. for(var i=0; i<accent.length; i++) {
  478. var r = new RegExp(accent.charAt(i), 'g');
  479. str = str.replace(r, sansAccent.charAt(i));
  480. }
  481. // Some characters that need to be replaced by two letters..
  482. str = str.replace(unescape("%C6"), 'AE');
  483. str = str.replace(unescape("%E6"), 'ae');
  484. str = str.replace(unescape("%FE"), 'th');
  485. str = str.replace(unescape("%DE"), 'Th');
  486. str = str.replace(unescape("%DF"), 'ss');
  487. // If you're wondering why we replace uppercase accented letters, and then do a .toLowerCase:
  488. // This is because IE has problems lowercasing accented characters, so they would be stripped
  489. // out otherwise instead of replaced by their US-ASCII counterpart.
  490. str = str.toLowerCase();
  491. str = str.replace(/^\s*/, '').replace(/\s*$/, '');
  492. str = str.replace(/[ _]/g, "-");
  493. str = str.replace(/[^a-z0-9-]/g, "");
  494. str = str.replace(/-+/g, "-");
  495. $('#'+to).val( str );
  496. if (typeof(text)!="undefined") {
  497. $('#'+text).html(str);
  498. }
  499. }
  500. /**
  501. * Open the image editor window
  502. */
  503. function imageEdit(imagename) {
  504. window.open("./modules/module_image.php?image="+ encodeURIComponent(imagename), 'thumbnail',
  505. "toolbar=no,resizable=yes,scrollbars=yes,width=920,height=570");
  506. }
  507. /**
  508. * Open a window with the comments or trackbacks for an entry.
  509. */
  510. function openEntryExtra(type,uid){
  511. var oldaction = $('#form1').attr('action');
  512. // Open the preview.
  513. $('#form1').attr('target', '_blank');
  514. $('#form1').attr('action' , location.pathname + '?page=' + type + '&uid=' + uid);
  515. $('#form1').submit();
  516. // Reset the form action..
  517. $('#form1').attr('target', '_self');
  518. $('#form1').attr('action', oldaction);
  519. }
  520. /**
  521. * Open the preview for an Entry.
  522. */
  523. function openEntryPreview() {
  524. var oldaction = $('#form1').attr('action');
  525. // Open the preview.
  526. $('#form1').attr('target', '_blank');
  527. $('#form1').attr('action' , 'render.php?previewentry=true');
  528. $('#form1').submit();
  529. // Reset the form action..
  530. $('#form1').attr('target', '_self');
  531. $('#form1').attr('action', oldaction);
  532. }
  533. /**
  534. * Open the preview for an Page.
  535. */
  536. function openPagePreview() {
  537. var oldaction = $('#form1').attr('action');
  538. // Open the preview.
  539. $('#form1').attr('target', '_blank');
  540. $('#form1').attr('action' , 'render.php?previewpage=true');
  541. $('#form1').submit();
  542. // Reset the form action..
  543. $('#form1').attr('target', '_self');
  544. $('#form1').attr('action', oldaction);
  545. }
  546. /**
  547. * Save an entry and continue editing..
  548. */
  549. function saveEntryAndContinue() {
  550. // Submit to the hidden frame.
  551. $('#form1').attr('target', 'posthere');
  552. $('#postedfrom').val('continue');
  553. $('#form1').submit();
  554. // Reset the form action..
  555. $('#postedfrom').val('');
  556. $('#form1').attr('target', '_self');
  557. humanMsg.displayMsg("The Entry has been saved.");
  558. }
  559. /**
  560. * Save a page and continue editing..
  561. */
  562. function savePageAndContinue() {
  563. // Submit to the hidden frame.
  564. $('#form1').attr('target', 'posthere');
  565. $('#postedfrom').val('continue');
  566. $('#form1').submit();
  567. // Reset the form action..
  568. $('#postedfrom').val('');
  569. $('#form1').attr('target', '_self');
  570. humanMsg.displayMsg("The Page has been saved.");
  571. }
  572. /**
  573. * Delete an entry from the 'edit entry' screen.
  574. */
  575. function deleteEntry(msg) {
  576. if (confirm(msg)) {
  577. self.location = "index.php?page=entries&del=" + $('#uid').val() + "&pivotxsession=" + $.cookie('pivotxsession');
  578. }
  579. }
  580. /**
  581. * Delete a page from the 'edit page' screen.
  582. */
  583. function deletePage(msg) {
  584. if (confirm(msg)) {
  585. self.location = "index.php?page=pagesoverview&delpage=" + $('#uid').val() + "&pivotxsession=" + $.cookie('pivotxsession');
  586. }
  587. }
  588. /**
  589. * Open the thickbox window to upload more than three files at once.
  590. */
  591. function openUploadMore() {
  592. self.parent.tb_remove();
  593. setTimeout("$('#uploadmore').click();", 200);
  594. return false;
  595. }
  596. /**
  597. * General rebuild routine.
  598. */
  599. function ajaxRebuildCall(func, start, time) {
  600. $.ajax({
  601. type: "POST",
  602. url: "ajaxhelper.php",
  603. data: "function="+func+"&start="+start+"&time="+time,
  604. dataType: "json",
  605. success: rebuildHelper,
  606. error: function() { humanMsg.displayMsg("Error rebuilding index.") }
  607. });
  608. }
  609. /**
  610. * Helper rebuild routine.
  611. */
  612. function rebuildHelper(data) {
  613. if (data.done) {
  614. humanMsg.displayMsg(data.text);
  615. } else {
  616. humanMsg.displayMsg(data.text);
  617. ajaxRebuildCall(data.func,data.start,data.time);
  618. }
  619. }
  620. /**
  621. * Check all buttons in the comments moderation window..
  622. */
  623. function commentsCheckAll() {
  624. $("input[name^='checked']").attr('checked', true);
  625. return false;
  626. }
  627. /**
  628. * Uncheck all buttons in the comments moderation window..
  629. */
  630. function commentsCheckNone() {
  631. $("input[name^='checked']").attr('checked', false);
  632. return false;
  633. }
  634. /**
  635. * Open the window to insert (and/or upload) an image in an entry or page.
  636. */
  637. function openImageWindow(target) {
  638. var f_text = encodeURIComponent(getSel(target));
  639. if ($('#f_image').is('*')) {
  640. var f_image = $('#f_image').val();
  641. } else {
  642. var f_image = "";
  643. }
  644. var my_url = 'includes/editor/insert_image.php?f_image='+f_image+'&f_text='+ f_text +'&f_target='+target;
  645. openDialogFrame("Insert an Image", my_url, 680, 390);
  646. }
  647. /**
  648. * Open the window to insert (and/or upload) an image as popup in an entry or page.
  649. */
  650. function openImagePopupWindow(target) {
  651. var f_text = encodeURIComponent(getSel(target));
  652. if ($('#f_image').is('*')) {
  653. var f_image= $('#f_image').val();
  654. var f_hasthumb= $('#f_hasthumb').val();
  655. } else {
  656. var f_image = "";
  657. var f_hastumb = "";
  658. }
  659. var my_url = 'includes/editor/insert_popup.php?f_image='+f_image+'&f_text='+ f_text +'&f_hasthumb='+f_hasthumb+'&f_target='+target;
  660. openDialogFrame("Insert an Image Popup", my_url, 680, 470);
  661. }
  662. /**
  663. * Open the window to insert a download in an entry or page.
  664. */
  665. function openDownloadWindow(target) {
  666. var f_text = encodeURIComponent(getSel(target));
  667. if ($('#f_image').is('*')) {
  668. var f_image= $('#f_image').val();
  669. var f_hasthumb= $('#f_hasthumb').val();
  670. } else {
  671. var f_image = "";
  672. var f_hastumb = "";
  673. }
  674. var my_url = 'includes/editor/insert_download.php?f_image='+f_image+'&f_text='+ f_text +'&f_hasthumb='+f_hasthumb+'&f_target='+target;
  675. openDialogFrame("Insert a Download", my_url, 480, 440);
  676. }
  677. /**
  678. * Open the window to insert a tag in an entry or page.
  679. */
  680. function openTagWindow(target) {
  681. var f_text = encodeURIComponent(getSel(target));
  682. var my_url = 'includes/editor/insert_tag.php?text='+ f_text +'&f_target='+target;
  683. openDialogFrame("Insert a Tag", my_url, 480, 350);
  684. }
  685. var uploadWindowTarget = "";
  686. /**
  687. * Open the window to insert (and/or upload) an image.
  688. */
  689. function openUploadWindow(title, target, filter) {
  690. var my_url = 'includes/editor/insert_upload.php?f_image=' + $(target).val() +"&f_target=" + $(target).attr('id');
  691. openDialogFrame(title, my_url, 660, 340);
  692. }
  693. /**
  694. * Open the window to insert (and/or upload) a file.
  695. */
  696. function openFileUploadWindow(title, target, filter) {
  697. var my_url = 'includes/editor/insert_upload.php?f_image=' + $(target).val() +"&f_target=" + $(target).attr('id')+"&f_type=file";
  698. openDialogFrame(title, my_url, 660, 340);
  699. }
  700. /**
  701. * Get the value of a radiobutton. Return the val() of the one
  702. * that is 'checked'..
  703. */
  704. function getValue(name) {
  705. var value = $("input[name='"+name+"']:checked").val();
  706. return value;
  707. }
  708. /**
  709. * Trims a text: remove leading and trailing spaces..
  710. */
  711. function trim(value) {
  712. value = String(value);
  713. value = value.replace(/^\s+/,'');
  714. value = value.replace(/\s+$/,'');
  715. return value;
  716. }
  717. // We use a counter to keep track of the number of times we've resized the excerpts.
  718. var resizecounter = 0;
  719. /**
  720. * Do various things when the browser window is resized..
  721. */
  722. function pivotxResizeWindow(resetsize) {
  723. // don't do this when we're displaying the bookmarklet.
  724. if ($('#bookmarklet').is('*')) {
  725. return "";
  726. }
  727. // If the screen is less than 1020px wide, lose the borders.
  728. if ($('body').width()<1020) {
  729. $('body').css('margin-left', '0');
  730. $('body').css('margin-right', '0');
  731. $('#footer, #mainmenu').css('left', '0');
  732. $('#footer').css('right', '0');
  733. }
  734. if ($('td.dashboardclip1').is('*')) {
  735. // Set the width of the 'clipped' excerpts on the Dashboard.
  736. if (resetsize) {
  737. // We need to reset the size, after a browser window resize..
  738. resizecounter = 0;
  739. $('td.dashboardclip1 .clip').css('width', "250px");
  740. $('td.dashboardclip2 .clip').css('width', "210px");
  741. $('td.dashboardclip3 .clip').css('width', "290px");
  742. }
  743. var width = $('td.dashboardclip1').width();
  744. // If the difference between the width of the excerpt and the width of
  745. // the body is less than 550, we re-set the timeout, because the page
  746. // has not been properly rendered yet.
  747. if ( (width + 550) > $('body').width() ) {
  748. setTimeout( function(){ pivotxResizeWindow(false); }, 100 );
  749. } else {
  750. $('td.dashboardclip1 .clip').css('width', width+"px");
  751. width = $('td.dashboardclip2').width();
  752. $('td.dashboardclip2 .clip').css('width', width+"px");
  753. width = $('td.dashboardclip3').width();
  754. $('td.dashboardclip3 .clip').css('width', width+"px");
  755. // run again..
  756. resizecounter++;
  757. if (resizecounter<5) { pivotxResizeWindow(false); }
  758. }
  759. } else if ($('td.entriesclip').is('*')) {
  760. // Set the width of the 'clipped' excerpts on the Entries/Pages page.
  761. if (resetsize) {
  762. // We need to reset the size, after a browser window resize..
  763. resizecounter = 0;
  764. $('td.entriesclip .clip').css('width', "300px");
  765. //alert('reset');
  766. }
  767. // For Opera we need a few pixels correction when fixing the widths.
  768. if ($.browser.opera) {
  769. var delta = 20;
  770. } else {
  771. var delta = 0;
  772. }
  773. var width = $('td.entriesclip').width() + delta;
  774. // If the difference between the width of the excerpt and the width of
  775. // the body is less than 550, we re-set the timeout, because the page
  776. // has not been properly rendered yet.
  777. if ( (width + 300) > $('body').width() ) {
  778. setTimeout( function(){ pivotxResizeWindow(); }, 100 );
  779. } else {
  780. //alert('width: ' + width);
  781. $('td.entriesclip .clip').css('width', width+"px");
  782. // run again..
  783. resizecounter++;
  784. if (resizecounter<6) { pivotxResizeWindow(); }
  785. }
  786. }
  787. }
  788. /**
  789. * Check if cookies are enabled or disabled.
  790. *
  791. * @return boolean
  792. */
  793. function cookieEnabled() {
  794. var cookieEnabled = (navigator.cookieEnabled) ? true : false;
  795. if (typeof navigator.cookieEnabled == "undefined" && !cookieEnabled) {
  796. document.cookie="testcookie";
  797. cookieEnabled = (document.cookie.indexOf("testcookie") != -1) ? true : false;
  798. }
  799. return (cookieEnabled);
  800. }