The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

Javascript for wikimized keyword

View previous topic View next topic Go down

Javascript for wikimized keyword

Post by congdantoancau on April 11th 2017, 1:32 pm

Hi every body!

I want each time I put a keywork to a code tag like
Code:
[wiki]keyword[/wiki]
It will show like this in the post: keyword

Can it done with JS? And can I put it to the Editor as a button?

Thanks in advance!
avatar
congdantoancau
Forumember

Male Posts : 68
Reputation : 3
Language : Vietnamese
Location : Vietnam

http://learn.forumvi.com

Back to top Go down

Re: Javascript for wikimized keyword

Post by Kyo Panda on April 11th 2017, 3:44 pm

Try adding to a new Javascript:

Code:
(function($) {
   'use strict';
   
   $(function() {
      var lang = window._userdata && _userdata.user_lang ?
         _userdata.user_lang : 'en'
      ;
      
      var base = 'https://' + lang + '.wikipedia.org/wiki/';
   
      $([
         '.post-entry > div',
         '.content > div',
         '#preview .postbody > div',
      ].join(', ')).each(function() {
         var $this = $(this);
         
         $this.html($this.html().replace(
            /\[wiki\]([^\]]+)\[\/wiki\]/gi, function(text, match) {
               return $('<a>', {
                  'href': base + match,
                  'text': match,
                  'class': 'fa-wiki-link',
               }).prop('outerHTML');
            }
         ));
      });
   });
   
   $(window).on('load', function() {
      var $sceditor = $("#text_editor_textarea");
      
      if (!$sceditor.length) {
         return;
      }
      
      $([
         '<a ',
         '    class="sceditor-button sceditor-button-fawiki"',
         '    data-sceditor-command="fawiki"',
         '    unselectable="on">',
         '    <div unselectable="on">',
         '        Wikipedia',
         '    </div>',
         '</a>',
      ].join('\n'))
         .on('click', function() {
            $sceditor.sceditor('instance').insertText('[wiki]', '[/wiki]');
         })
         .prependTo('.sceditor-group:last')
      ;

      $('<style>', { html: [
         '#main .sceditor-button-fawiki > div {',
         '    background-image: url(\'https://vi.wikipedia.org/static/favicon/wikipedia.ico\');',
         '    background-position: center center;',
         '    background-size: contain;',
         '}',
      ].join('\n') })
         .appendTo('head')
      ;
   });
}(jQuery));
avatar
Kyo Panda
Forumember

Male Posts : 33
Reputation : 19
Language : Portuguese, English
Location : Brazil

http://pt.rpgmaker.io

Back to top Go down

Re: Javascript for wikimized keyword

Post by SLGray on April 11th 2017, 11:57 pm

Are you trying to link certain terms/words to the Wikipedia? I mean you want members to click the word and the Wikipedia page load.

You should do this then:
Code:
[url=PAGE TO A CERTAIN WIKIPEDIA PAGE]TERM OR WORD[/url]


When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.

avatar
SLGray
Administrator
Administrator

Male Posts : 40872
Reputation : 2775
Language : English
Location : United States

https://fmthemes.forumotion.com/

Back to top Go down

Re: Javascript for wikimized keyword

Post by congdantoancau on April 15th 2017, 6:09 am

Thank you two.
The code of @Kyo Panda work well. However, it would be perfectly if it have a button in Editor allow user to click and wikimize keyword after highlighted it. Just like this button message button
avatar
congdantoancau
Forumember

Male Posts : 68
Reputation : 3
Language : Vietnamese
Location : Vietnam

http://learn.forumvi.com

Back to top Go down

Re: Javascript for wikimized keyword

Post by Kyo Panda on April 17th 2017, 6:57 pm

The code I passed you adds a button to the last group in the editor. Isn't it working?
avatar
Kyo Panda
Forumember

Male Posts : 33
Reputation : 19
Language : Portuguese, English
Location : Brazil

http://pt.rpgmaker.io

Back to top Go down

Re: Javascript for wikimized keyword

Post by congdantoancau on April 19th 2017, 5:06 pm

@Kyo Panda
Yes, I haven't found the button in the Editor
Here is the forum:
http://learn.forumvi.com/f33-ngan-du-phong
id: testaccount
pass: test1234
avatar
congdantoancau
Forumember

Male Posts : 68
Reputation : 3
Language : Vietnamese
Location : Vietnam

http://learn.forumvi.com

Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum