The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Javascript for wikimized keyword

3 posters

Go down

Javascript for wikimized keyword Empty Javascript for wikimized keyword

Post by congdantoancau 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!
congdantoancau
congdantoancau
Forumember

Male Posts : 77
Reputation : 4
Language : Vietnamese
Location : Vietnam

http://learn.forumvi.com

Back to top Go down

Javascript for wikimized keyword Empty Re: Javascript for wikimized keyword

Post by Kyo Panda 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));
Kyo Panda
Kyo Panda
Forumember

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

http://pt.rpgmaker.io

Back to top Go down

Javascript for wikimized keyword Empty Re: Javascript for wikimized keyword

Post by SLGray 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]


Javascript for wikimized keyword Slgray10

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

Male Posts : 51464
Reputation : 3519
Language : English
Location : United States

https://forumsclub.com/gc/128-link-directory/

Back to top Go down

Javascript for wikimized keyword Empty Re: Javascript for wikimized keyword

Post by congdantoancau 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
congdantoancau
congdantoancau
Forumember

Male Posts : 77
Reputation : 4
Language : Vietnamese
Location : Vietnam

http://learn.forumvi.com

Back to top Go down

Javascript for wikimized keyword Empty Re: Javascript for wikimized keyword

Post by Kyo Panda 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?
Kyo Panda
Kyo Panda
Forumember

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

http://pt.rpgmaker.io

Back to top Go down

Javascript for wikimized keyword Empty Re: Javascript for wikimized keyword

Post by congdantoancau 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
congdantoancau
congdantoancau
Forumember

Male Posts : 77
Reputation : 4
Language : Vietnamese
Location : Vietnam

http://learn.forumvi.com

Back to top Go down

Back to top


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