jot-header.tpl 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. <script language="javascript" type="text/javascript">
  2. var editor = false;
  3. var plaintext = '{{$editselect}}';
  4. var pretext = '{{$pretext}}';
  5. function initEditor(cb){
  6. if(editor == false){
  7. $("#profile-jot-text-loading").show();
  8. $("#profile-jot-reset").removeClass('d-none');
  9. {{$geotag}}
  10. if(plaintext == 'none') {
  11. $("#profile-jot-text-loading").hide();
  12. $(".jothidden").show();
  13. $("#profile-jot-text").addClass('jot-expanded');
  14. $("#profile-jot-summary").addClass('jot-expanded');
  15. {{if $bbco_autocomplete}}
  16. $("#profile-jot-text").bbco_autocomplete('{{$bbco_autocomplete}}'); // autocomplete bbcode
  17. $("#profile-jot-summary").bbco_autocomplete('{{$bbco_autocomplete}}'); // autocomplete bbcode
  18. {{/if}}
  19. {{if $editor_autocomplete}}
  20. if(typeof channelId === 'undefined') {
  21. $("#profile-jot-text").editor_autocomplete(baseurl+"/acl");
  22. $("#profile-jot-summary").editor_autocomplete(baseurl+"/acl");
  23. }
  24. else {
  25. $("#profile-jot-text").editor_autocomplete(baseurl+"/acl",[channelId]); // Also gives suggestions from current channel's connections
  26. $("#profile-jot-summary").editor_autocomplete(baseurl+"/acl",[channelId]); // Also gives suggestions from current channel's connections
  27. }
  28. {{/if}}
  29. editor = true;
  30. if (typeof cb!="undefined") cb();
  31. if(pretext.length)
  32. addeditortext(pretext);
  33. return;
  34. }
  35. editor = true;
  36. } else {
  37. if (typeof cb!="undefined") cb();
  38. }
  39. }
  40. function enableOnUser(){
  41. if(editor)
  42. return;
  43. initEditor();
  44. }
  45. </script>
  46. <script src="library/blueimp_upload/js/vendor/jquery.ui.widget.js"></script>
  47. <script src="library/blueimp_upload/js/jquery.iframe-transport.js"></script>
  48. <script src="library/blueimp_upload/js/jquery.fileupload.js"></script>
  49. <script>
  50. var activeCommentID = 0;
  51. var activeCommentText = '';
  52. $(document).ready(function() {
  53. $("#profile-jot-text").focus(enableOnUser);
  54. $("#profile-jot-text").click(enableOnUser);
  55. $('#id_mimetype').on('load', jotSetMime);
  56. $('#id_mimetype').on('change', jotSetMime);
  57. {{if $webpage === 8}}
  58. $("#jot-pagetitle").name_autocomplete(baseurl + '/acl', 'm', false, function(data) {
  59. $("#recip-complete").val(data.xid);
  60. });
  61. {{/if}}
  62. function jotSetMime() {
  63. var mtype = $('#id_mimetype').val();
  64. if(mtype == 'text/bbcode')
  65. $('#profile-jot-submit-left').show();
  66. else
  67. $('#profile-jot-submit-left').hide();
  68. }
  69. $('#invisible-wall-file-upload').fileupload({
  70. url: 'wall_attach/{{$nickname}}',
  71. dataType: 'json',
  72. dropZone: $('#profile-jot-text'),
  73. maxChunkSize: 4 * 1024 * 1024,
  74. add: function(e,data) {
  75. $('#profile-rotator').show();
  76. data.submit();
  77. },
  78. done: function(e,data) {
  79. addeditortext(data.result.message);
  80. $('#jot-media').val($('#jot-media').val() + data.result.message);
  81. },
  82. stop: function(e,data) {
  83. preview_post();
  84. $('#profile-rotator').hide();
  85. },
  86. });
  87. $('#wall-file-upload').click(function(event) { event.preventDefault(); $('#invisible-wall-file-upload').trigger('click'); return false;});
  88. $('#wall-file-upload-sub').click(function(event) { event.preventDefault(); $('#invisible-wall-file-upload').trigger('click'); return false;});
  89. // call initialization file
  90. if (window.File && window.FileList && window.FileReader) {
  91. DragDropUploadInit();
  92. }
  93. $('#invisible-comment-upload').fileupload({
  94. url: 'wall_attach/{{$nickname}}',
  95. dataType: 'json',
  96. dropZone: $(),
  97. maxChunkSize: 4 * 1024 * 1024,
  98. add: function(e,data) {
  99. var tmpStr = $("#comment-edit-text-" + activeCommentID).val();
  100. if(tmpStr == activeCommentText) {
  101. tmpStr = "";
  102. $("#comment-edit-text-" + activeCommentID).addClass("comment-edit-text-full");
  103. $("#comment-edit-text-" + activeCommentID).removeClass("comment-edit-text-empty");
  104. openMenu("comment-tools-" + activeCommentID);
  105. $("#comment-edit-text-" + activeCommentID).val(tmpStr);
  106. }
  107. data.submit();
  108. },
  109. done: function(e,data) {
  110. textarea = document.getElementById("comment-edit-text-" + activeCommentID);
  111. textarea.value = textarea.value + data.result.message;
  112. },
  113. stop: function(e,data) {
  114. $('body').css('cursor', 'auto');
  115. preview_comment(activeCommentID);
  116. activeCommentID = 0;
  117. },
  118. });
  119. });
  120. function deleteCheckedItems() {
  121. var checkedstr = '';
  122. $('.item-select').each( function() {
  123. if($(this).is(':checked')) {
  124. if(checkedstr.length != 0) {
  125. checkedstr = checkedstr + ',' + $(this).val();
  126. }
  127. else {
  128. checkedstr = $(this).val();
  129. }
  130. }
  131. });
  132. $.post('item', { dropitems: checkedstr }, function(data) {
  133. window.location.reload();
  134. });
  135. }
  136. function jotGetLink() {
  137. textarea = document.getElementById('profile-jot-text');
  138. if (textarea.selectionStart || textarea.selectionStart == "0") {
  139. var start = textarea.selectionStart;
  140. var end = textarea.selectionEnd;
  141. if (end > start) {
  142. reply = prompt("{{$linkurl}}");
  143. if(reply && reply.length) {
  144. textarea.value = textarea.value.substring(0, start) + "[url=" + reply + "]" + textarea.value.substring(start, end) + "[/url]" + textarea.value.substring(end, textarea.value.length);
  145. }
  146. } else {
  147. reply = prompt("{{$linkurl}}");
  148. if(reply && reply.length) {
  149. reply = bin2hex(reply);
  150. $('#profile-rotator').show();
  151. $.get('{{$baseurl}}/linkinfo?f=&binurl=' + reply, function(data) {
  152. addeditortext(data);
  153. preview_post();
  154. $('#profile-rotator').hide();
  155. });
  156. }
  157. }
  158. }
  159. }
  160. function jotGetLocation() {
  161. reply = prompt("{{$whereareu}}", $('#jot-location').val());
  162. if(reply && reply.length) {
  163. $('#jot-location').val(reply);
  164. }
  165. }
  166. function jotGetExpiry() {
  167. //reply = prompt("{{$expirewhen}}", $('#jot-expire').val());
  168. $('#expiryModal').modal();
  169. $('#expiry-modal-OKButton').on('click', function() {
  170. reply=$('#expiration-date').val();
  171. if(reply && reply.length) {
  172. $('#jot-expire').val(reply);
  173. $('#expiryModal').modal('hide');
  174. }
  175. })
  176. }
  177. function jotGetPubDate() {
  178. //reply = prompt("{{$expirewhen}}", $('#jot-expire').val());
  179. $('#createdModal').modal();
  180. $('#created-modal-OKButton').on('click', function() {
  181. reply=$('#created-date').val();
  182. if(reply && reply.length) {
  183. $('#jot-created').val(reply);
  184. $('#createdModal').modal('hide');
  185. }
  186. })
  187. }
  188. function jotShare(id,post_type) {
  189. $('#like-rotator-' + id).show();
  190. $.get('{{$baseurl}}/share/' + id, function(data) {
  191. $('#like-rotator-' + id).hide();
  192. notificationsUpdate();
  193. });
  194. }
  195. function linkdropper(event) {
  196. var linkFound = event.dataTransfer.types.contains("text/uri-list");
  197. if(linkFound) {
  198. event.preventDefault();
  199. var editwin = '#' + event.target.id;
  200. var commentwin = false;
  201. if(editwin) {
  202. commentwin = ((editwin.indexOf('comment') >= 0) ? true : false);
  203. if(commentwin) {
  204. var commentid = editwin.substring(editwin.lastIndexOf('-') + 1);
  205. $('#comment-edit-text-' + commentid).addClass('hover');
  206. }
  207. }
  208. }
  209. }
  210. function linkdropexit(event) {
  211. var editwin = '#' + event.target.id;
  212. var commentwin = false;
  213. if(editwin) {
  214. commentwin = ((editwin.indexOf('comment') >= 0) ? true : false);
  215. if(commentwin) {
  216. var commentid = editwin.substring(editwin.lastIndexOf('-') + 1);
  217. $('#comment-edit-text-' + commentid).removeClass('hover');
  218. }
  219. }
  220. }
  221. function linkdrop(event) {
  222. var reply = event.dataTransfer.getData("text/uri-list");
  223. if(reply) {
  224. event.preventDefault();
  225. var editwin = '#' + event.target.id;
  226. var commentwin = false;
  227. if(editwin) {
  228. commentwin = ((editwin.indexOf('comment') >= 0) ? true : false);
  229. if(commentwin) {
  230. var commentid = editwin.substring(editwin.lastIndexOf('-') + 1);
  231. commentOpen(document.getElementById(event.target.id),commentid);
  232. }
  233. }
  234. }
  235. if(reply && reply.length) {
  236. reply = bin2hex(reply);
  237. $('#profile-rotator').show();
  238. $.get('{{$baseurl}}/linkinfo?f=&binurl=' + reply, function(data) {
  239. if(commentwin) {
  240. $(editwin).val( $(editwin).val() + data );
  241. $('#profile-rotator').hide();
  242. }
  243. else {
  244. if (!editor) $("#profile-jot-text").val("");
  245. initEditor(function(){
  246. addeditortext(data);
  247. $('#profile-rotator').hide();
  248. });
  249. }
  250. });
  251. }
  252. }
  253. function itemTag(id) {
  254. reply = prompt("{{$term}}");
  255. if(reply && reply.length) {
  256. reply = reply.replace('#','');
  257. if(reply.length) {
  258. commentBusy = true;
  259. $('body').css('cursor', 'wait');
  260. $.get('{{$baseurl}}/tagger/' + id + '?term=' + reply);
  261. if(timer) clearTimeout(timer);
  262. timer = setTimeout(updateInit,3000);
  263. liking = 1;
  264. }
  265. }
  266. }
  267. function itemCancel() {
  268. $("#jot-title").val('');
  269. $("#profile-jot-text").val('');
  270. $("#jot-category").tagsinput('removeAll');
  271. postSaveChanges('clean');
  272. {{if $reset}}
  273. $(".jothidden").hide();
  274. $("#profile-jot-text").removeClass('jot-expanded');
  275. $("#profile-jot-reset").addClass('d-none');
  276. $("#jot-preview-content").html('').hide();
  277. editor = false;
  278. {{else}}
  279. window.history.back();
  280. {{/if}}
  281. }
  282. function itemFiler(id) {
  283. if($('#item-filer-dialog').length)
  284. $('#item-filer-dialog').remove();
  285. $.get('filer/', function(data){
  286. $('body').append(data);
  287. $('#item-filer-dialog').modal('show');
  288. $("#filer_save").click(function(e){
  289. e.preventDefault();
  290. reply = $("#id_term").val();
  291. if(reply && reply.length) {
  292. commentBusy = true;
  293. $('body').css('cursor', 'wait');
  294. $.get('{{$baseurl}}/filer/' + id + '?term=' + reply, updateInit);
  295. liking = 1;
  296. $('#item-filer-dialog').modal('hide');
  297. }
  298. return false;
  299. });
  300. });
  301. }
  302. function itemBookmark(id) {
  303. $.get('{{$baseurl}}/bookmarks?f=&item=' + id);
  304. if(timer) clearTimeout(timer);
  305. timer = setTimeout(updateInit,1000);
  306. }
  307. function itemAddToCal(id) {
  308. $.get('{{$baseurl}}/events/add/' + id);
  309. if(timer) clearTimeout(timer);
  310. timer = setTimeout(updateInit,1000);
  311. }
  312. function toggleVoting() {
  313. if($('#jot-consensus').val() > 0) {
  314. $('#jot-consensus').val(0);
  315. $('#profile-voting, #profile-voting-sub').removeClass('fa-check-square-o').addClass('fa-square-o');
  316. }
  317. else {
  318. $('#jot-consensus').val(1);
  319. $('#profile-voting, #profile-voting-sub').removeClass('fa-square-o').addClass('fa-check-square-o');
  320. }
  321. }
  322. function toggleNoComment() {
  323. if($('#jot-nocomment').val() > 0) {
  324. $('#jot-nocomment').val(0);
  325. $('#profile-nocomment, #profile-nocomment-sub').removeClass('fa-comments-o').addClass('fa-comments');
  326. $('#profile-nocomment-wrapper').attr('title', '{{$nocomment_enabled|escape:'javascript'}}');
  327. }
  328. else {
  329. $('#jot-nocomment').val(1);
  330. $('#profile-nocomment, #profile-nocomment-sub').removeClass('fa-comments').addClass('fa-comments-o');
  331. $('#profile-nocomment-wrapper').attr('title', '{{$nocomment_disabled|escape:'javascript'}}');
  332. }
  333. }
  334. function jotReact(id,icon) {
  335. if(id && icon) {
  336. $.get('{{$baseurl}}/react?f=&postid=' + id + '&emoji=' + icon);
  337. if(timer) clearTimeout(timer);
  338. timer = setTimeout(updateInit,1000);
  339. }
  340. }
  341. function jotClearLocation() {
  342. $('#jot-coord').val('');
  343. $('#profile-nolocation-wrapper').attr('disabled', true);
  344. }
  345. var initializeEmbedPhotoDialog = function () {
  346. $('.embed-photo-selected-photo').each(function (index) {
  347. $(this).removeClass('embed-photo-selected-photo');
  348. });
  349. getPhotoAlbumList();
  350. $('#embedPhotoModalBodyAlbumDialog').off('click');
  351. $('#embedPhotoModal').modal('show');
  352. };
  353. var choosePhotoFromAlbum = function (album) {
  354. $.post("embedphotos/album", {name: album},
  355. function(data) {
  356. if (data['status']) {
  357. $('#embedPhotoModalLabel').html("{{$modalchooseimages}}");
  358. $('#embedPhotoModalBodyAlbumDialog').html('\
  359. <div><div class="nav nav-pills flex-column">\n\
  360. <li class="nav-item"><a class="nav-link" href="#" onclick="initializeEmbedPhotoDialog();return false;">\n\
  361. <i class="fa fa-chevron-left"></i>&nbsp\n\
  362. {{$modaldiffalbum}}\n\
  363. </a>\n\
  364. </li>\n\
  365. </div><br></div>')
  366. $('#embedPhotoModalBodyAlbumDialog').append(data['content']);
  367. $('#embedPhotoModalBodyAlbumDialog').click(function (evt) {
  368. evt.preventDefault();
  369. var image = document.getElementById(evt.target.id);
  370. if (typeof($(image).parent()[0]) !== 'undefined') {
  371. var imageparent = document.getElementById($(image).parent()[0].id);
  372. $(imageparent).toggleClass('embed-photo-selected-photo');
  373. var href = $(imageparent).attr('href');
  374. $.post("embedphotos/photolink", {href: href},
  375. function(ddata) {
  376. if (ddata['status']) {
  377. addeditortext(ddata['photolink']);
  378. preview_post();
  379. } else {
  380. window.console.log("{{$modalerrorlink}}" + ':' + ddata['errormsg']);
  381. }
  382. return false;
  383. },
  384. 'json');
  385. $('#embedPhotoModalBodyAlbumDialog').html('');
  386. $('#embedPhotoModalBodyAlbumDialog').off('click');
  387. $('#embedPhotoModal').modal('hide');
  388. }
  389. });
  390. $('#embedPhotoModalBodyAlbumListDialog').addClass('d-none');
  391. $('#embedPhotoModalBodyAlbumDialog').removeClass('d-none');
  392. } else {
  393. window.console.log("{{$modalerroralbum}} " + JSON.stringify(album) + ':' + data['errormsg']);
  394. }
  395. return false;
  396. },
  397. 'json');
  398. };
  399. var getPhotoAlbumList = function () {
  400. $.post("embedphotos/albumlist", {},
  401. function(data) {
  402. if (data['status']) {
  403. var albums = data['albumlist']; //JSON.parse(data['albumlist']);
  404. $('#embedPhotoModalLabel').html("{{$modalchoosealbum}}");
  405. $('#embedPhotoModalBodyAlbumList').html('<ul class="nav nav-pills flex-column"></ul>');
  406. for(var i=0; i<albums.length; i++) {
  407. var albumName = albums[i].text;
  408. var jsAlbumName = albums[i].jstext;
  409. var albumLink = '<li class="nav-item">';
  410. albumLink += '<a class="nav-link" href="#" onclick="choosePhotoFromAlbum(\'' + jsAlbumName + '\'); return false;">' + albumName + '</a>';
  411. albumLink += '</li>';
  412. $('#embedPhotoModalBodyAlbumList').find('ul').append(albumLink);
  413. }
  414. $('#embedPhotoModalBodyAlbumDialog').addClass('d-none');
  415. $('#embedPhotoModalBodyAlbumListDialog').removeClass('d-none');
  416. } else {
  417. window.console.log("{{$modalerrorlist}}" + ':' + data['errormsg']);
  418. }
  419. return false;
  420. },
  421. 'json');
  422. };
  423. //
  424. // initialize drag-drop
  425. function DragDropUploadInit() {
  426. var filedrag = $("#profile-jot-text");
  427. // file drop
  428. filedrag.on("dragover", DragDropUploadFileHover);
  429. filedrag.on("dragleave", DragDropUploadFileHover);
  430. filedrag.on("drop", DragDropUploadFileSelectHandler);
  431. }
  432. // file drag hover
  433. function DragDropUploadFileHover(e) {
  434. if(e.type == 'dragover')
  435. $(e.target).addClass('hover');
  436. else
  437. $(e.target).removeClass('hover');
  438. }
  439. // file selection
  440. function DragDropUploadFileSelectHandler(e) {
  441. // cancel event and hover styling
  442. DragDropUploadFileHover(e);
  443. // open editor if it isn't yet initialised
  444. if (!editor) {
  445. enableOnUser();
  446. }
  447. linkdrop(e);
  448. }
  449. </script>
  450. <script>
  451. $( document ).on( "click", ".wall-item-delete-link,.page-delete-link,.layout-delete-link,.block-delete-link", function(e) {
  452. var link = $(this).attr("href"); // "get" the intended link in a var
  453. if (typeof(eval($.fn.modal)) === 'function'){
  454. e.preventDefault();
  455. bootbox.confirm("<h4>{{$confirmdelete}}</h4>",function(result) {
  456. if (result) {
  457. document.location.href = link;
  458. }
  459. });
  460. } else {
  461. return confirm("{{$confirmdelete}}");
  462. }
  463. });
  464. </script>
  465. <script>
  466. var postSaveTimer = null;
  467. function postSaveChanges(action) {
  468. if({{$auto_save_draft}}) {
  469. var doctype = $('#jot-webpage').val();
  470. var postid = '-' + doctype + '-' + $('#jot-postid').val();
  471. if(action != 'clean') {
  472. localStorage.setItem("post_title" + postid, $("#jot-title").val());
  473. localStorage.setItem("post_body" + postid, $("#profile-jot-text").val());
  474. if($("#jot-category").length)
  475. localStorage.setItem("post_category" + postid, $("#jot-category").val());
  476. }
  477. if(action == 'start') {
  478. postSaveTimer = setTimeout(function () {
  479. postSaveChanges('start');
  480. },10000);
  481. }
  482. if(action == 'stop') {
  483. clearTimeout(postSaveTimer);
  484. postSaveTimer = null;
  485. }
  486. if(action == 'clean') {
  487. clearTimeout(postSaveTimer);
  488. postSaveTimer = null;
  489. localStorage.removeItem("post_title" + postid);
  490. localStorage.removeItem("post_body" + postid);
  491. localStorage.removeItem("post_category" + postid);
  492. }
  493. }
  494. }
  495. $(document).ready(function() {
  496. var cleaned = false;
  497. if({{$auto_save_draft}}) {
  498. var doctype = $('#jot-webpage').val();
  499. var postid = '-' + doctype + '-' + $('#jot-postid').val();
  500. var postTitle = localStorage.getItem("post_title" + postid);
  501. var postBody = localStorage.getItem("post_body" + postid);
  502. var postCategory = (($("#jot-category").length) ? localStorage.getItem("post_category" + postid) : '');
  503. var openEditor = false;
  504. if(postTitle) {
  505. $('#jot-title').val(postTitle);
  506. openEditor = true;
  507. }
  508. if(postBody) {
  509. $('#profile-jot-text').val(postBody);
  510. openEditor = true;
  511. }
  512. if(postCategory) {
  513. var categories = postCategory.split(',');
  514. categories.forEach(function(cat) {
  515. $('#jot-category').tagsinput('add', cat);
  516. });
  517. openEditor = true;
  518. }
  519. if(openEditor) {
  520. enableOnUser();
  521. }
  522. } else {
  523. postSaveChanges('clean');
  524. }
  525. $(document).on('submit', '#profile-jot-form', function() {
  526. postSaveChanges('clean');
  527. cleaned = true;
  528. });
  529. $(document).on('focusout',"#profile-jot-wrapper",function(e){
  530. if(! cleaned)
  531. postSaveChanges('stop');
  532. });
  533. $(document).on('focusin',"#profile-jot-wrapper",function(e){
  534. postSaveTimer = setTimeout(function () {
  535. postSaveChanges('start');
  536. },10000);
  537. });
  538. });
  539. </script>