diff options
Diffstat (limited to 'view/js')
-rw-r--r-- | view/js/autocomplete.js | 127 | ||||
-rw-r--r-- | view/js/main.js | 9 | ||||
-rw-r--r-- | view/js/mod_chat.js | 3 | ||||
-rw-r--r-- | view/js/mod_events.js | 3 | ||||
-rw-r--r-- | view/js/mod_mail.js | 1 | ||||
-rw-r--r-- | view/js/mod_photos.js | 2 | ||||
-rw-r--r-- | view/js/mod_profiles.js | 1 |
7 files changed, 144 insertions, 2 deletions
diff --git a/view/js/autocomplete.js b/view/js/autocomplete.js index 437425a0e..a4a1fdf51 100644 --- a/view/js/autocomplete.js +++ b/view/js/autocomplete.js @@ -100,6 +100,66 @@ function submit_form(e) { $(e).parents('form').submit(); } +function getWord(text, caretPos) { + var index = text.indexOf(caretPos); + var postText = text.substring(caretPos, caretPos+8); + if ((postText.indexOf("[/list]") > 0) || postText.indexOf("[/ul]") > 0 || postText.indexOf("[/ol]") > 0) { + return postText; + } +} + +function getCaretPosition(ctrl) { + var CaretPos = 0; // IE Support + if (document.selection) { + ctrl.focus(); + var Sel = document.selection.createRange(); + Sel.moveStart('character', -ctrl.value.length); + CaretPos = Sel.text.length; + } + // Firefox support + else if (ctrl.selectionStart || ctrl.selectionStart == '0') + CaretPos = ctrl.selectionStart; + return (CaretPos); +} + +function setCaretPosition(ctrl, pos){ + if(ctrl.setSelectionRange) { + ctrl.focus(); + ctrl.setSelectionRange(pos,pos); + } + else if (ctrl.createTextRange) { + var range = ctrl.createTextRange(); + range.collapse(true); + range.moveEnd('character', pos); + range.moveStart('character', pos); + range.select(); + } +} + +function listNewLineAutocomplete(id) { + var text = document.getElementById(id); + var caretPos = getCaretPosition(text) + var word = getWord(text.value, caretPos); + if (word != null) { + var textBefore = text.value.substring(0, caretPos); + var textAfter = text.value.substring(caretPos, text.length); + $('#' + id).val(textBefore + '\r\n[*] ' + textAfter); + setCaretPosition(text, caretPos + 5); + return true; + } +} + +function string2bb(element) { + if(element == 'bold') return 'b'; + else if(element == 'italic') return 'i'; + else if(element == 'underline') return 'u'; + else if(element == 'overline') return 'o'; + else if(element == 'strike') return 's'; + else if(element == 'superscript') return 'sup'; + else if(element == 'subscript') return 'sub'; + else return element; +} + /** * jQuery plugin 'editor_autocomplete' */ @@ -197,3 +257,70 @@ function submit_form(e) { a.on('textComplete:select', function(e, value, strategy) { onselect(value); }); }; })( jQuery ); + +(function( $ ) { + $.fn.bbco_autocomplete = function(type) { + + if(type=='bbcode') { + var open_close_elements = ['bold', 'italic', 'underline', 'overline', 'strike', 'superscript', 'subscript', 'quote', 'code', 'spoiler', 'map', 'nobb', 'list', 'ul', 'ol', 'li', 'table', 'tr', 'th', 'td', 'center', 'color', 'font', 'size', 'zrl', 'zmg', 'rpost', 'qr', 'observer']; + var open_elements = ['observer.baseurl', 'observer.address', 'observer.photo', 'observer.name', 'observer.webname', 'observer.url', '*', 'hr', ]; + + var elements = open_close_elements.concat(open_elements); + } + + if(type=='comanche') { + var open_close_elements = ['region', 'layout', 'template', 'theme', 'widget', 'block', 'menu', 'var', 'css', 'js', 'authored', 'comment', 'webpage']; + var open_elements = []; + + var elements = open_close_elements.concat(open_elements); + } + + if(type=='comanche-block') { + var open_close_elements = ['menu', 'var']; + var open_elements = []; + + var elements = open_close_elements.concat(open_elements); + } + + bbco = { + match: /\[(\w*\**)$/, + search: function (term, callback) { + callback($.map(elements, function (element) { + return element.indexOf(term) === 0 ? element : null; + })); + }, + index: 1, + replace: function (element) { + element = string2bb(element); + if(open_elements.indexOf(element) < 0) { + if(element === 'list' || element === 'ol' || element === 'ul') { + return ['\[' + element + '\]' + '\n\[*\] ', '\n\[/' + element + '\]']; + } + else if(element === 'table') { + return ['\[' + element + '\]' + '\n\[tr\]', '\[/tr\]\n\[/' + element + '\]']; + } + else { + return ['\[' + element + '\]', '\[/' + element + '\]']; + } + } + else { + return '\[' + element + '\] '; + } + } + }; + + this.attr('autocomplete','off'); + var a = this.textcomplete([bbco], {className:'acpopup', zIndex:1020}); + + a.on('textComplete:select', function(e, value, strategy) { value; }); + + $(this).keypress(function(e){ + if (e.keyCode == 13) { + x = listNewLineAutocomplete(this.id); + if(x) + e.preventDefault(); + } + }); + }; +})( jQuery ); + diff --git a/view/js/main.js b/view/js/main.js index 04b317914..799ae82bc 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -491,6 +491,7 @@ function updateConvItems(mode,data) { if(isVisible) showHideComments(itmId); $("> .wall-item-outside-wrapper .autotime, > .thread-wrapper .autotime",this).timeago(); + $("> .shared_header .autotime",this).timeago(); } else { $('img',this).each(function() { @@ -502,6 +503,7 @@ function updateConvItems(mode,data) { if(isVisible) showHideComments(itmId); $("> .wall-item-outside-wrapper .autotime, > .thread-wrapper .autotime",this).timeago(); + $("> .shared_header .autotime",this).timeago(); } prev = ident; }); @@ -529,6 +531,7 @@ function updateConvItems(mode,data) { if(isVisible) showHideComments(itmId); $("> .wall-item-outside-wrapper .autotime, > .thread-wrapper .autotime",this).timeago(); + $("> .shared_header .autotime",this).timeago(); } else { $('img',this).each(function() { @@ -540,6 +543,7 @@ function updateConvItems(mode,data) { if(isVisible) showHideComments(itmId); $("> .wall-item-outside-wrapper .autotime, > .thread-wrapper .autotime",this).timeago(); + $("> .shared_header .autotime",this).timeago(); } }); @@ -573,6 +577,7 @@ function updateConvItems(mode,data) { if(isVisible) showHideComments(itmId); $("> .wall-item-outside-wrapper .autotime, > .thread-wrapper .autotime",this).timeago(); + $("> .shared_header .autotime",this).timeago(); } prev = ident; }); @@ -617,6 +622,8 @@ function updateConvItems(mode,data) { /* autocomplete @nicknames */ $(".comment-edit-form textarea").editor_autocomplete(baseurl+"/acl?f=&n=1"); + /* autocomplete bbcode */ + $(".comment-edit-form textarea").bbco_autocomplete('bbcode'); var bimgs = ((preloadImages) ? false : $(".wall-item-body img").not(function() { return this.complete; })); var bimgcount = bimgs.length; @@ -1046,6 +1053,7 @@ function preview_comment(id) { function(data) { if(data.preview) { $("#comment-edit-preview-" + id).html(data.preview); + $("#comment-edit-preview-" + id + " .autotime").timeago(); $("#comment-edit-preview-" + id + " a").click(function() { return false; }); } }, @@ -1076,6 +1084,7 @@ function preview_post() { function(data) { if(data.preview) { $("#jot-preview-content").html(data.preview); + $("#jot-preview-content .autotime").timeago(); $("#jot-preview-content" + " a").click(function() { return false; }); } }, diff --git a/view/js/mod_chat.js b/view/js/mod_chat.js index 0d47e3e77..f9d2a599c 100644 --- a/view/js/mod_chat.js +++ b/view/js/mod_chat.js @@ -15,4 +15,7 @@ $(document).ready(function() { $('#jot-public').show(); } }).trigger('change'); + + $('#chatText').bbco_autocomplete('bbcode'); + }); diff --git a/view/js/mod_events.js b/view/js/mod_events.js index 0b7b3d24c..74b811dd6 100644 --- a/view/js/mod_events.js +++ b/view/js/mod_events.js @@ -3,9 +3,8 @@ */ $(document).ready( function() { - enableDisableFinishDate(); - + $('#comment-edit-text-desc, #comment-edit-text-loc').bbco_autocomplete('bbcode'); }); function enableDisableFinishDate() { diff --git a/view/js/mod_mail.js b/view/js/mod_mail.js index 561df7229..3e55c8aeb 100644 --- a/view/js/mod_mail.js +++ b/view/js/mod_mail.js @@ -3,4 +3,5 @@ $(document).ready(function() { $("#recip-complete").val(data.xid); }); $(".autotime").timeago() + $('#prvmail-text').bbco_autocomplete('bbcode'); }); diff --git a/view/js/mod_photos.js b/view/js/mod_photos.js index d371c3f2f..34e2e3f25 100644 --- a/view/js/mod_photos.js +++ b/view/js/mod_photos.js @@ -11,6 +11,8 @@ $(document).ready(function() { $("#photo-edit-newtag").val('@' + data.name); }); + $('#id_body').bbco_autocomplete('bbcode'); + $('#contact_allow, #contact_deny, #group_allow, #group_deny').change(function() { var selstr; $('#contact_allow option:selected, #contact_deny option:selected, #group_allow option:selected, #group_deny option:selected').each( function() { diff --git a/view/js/mod_profiles.js b/view/js/mod_profiles.js index aad2ca902..a7754e0c5 100644 --- a/view/js/mod_profiles.js +++ b/view/js/mod_profiles.js @@ -1,3 +1,4 @@ $(document).ready(function() { $('form').areYouSure(); // Warn user about unsaved settings + $('textarea').bbco_autocomplete('bbcode'); }); |