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.

Type of Site:

3 posters

Go down

In progress Type of Site:

Post by Mati October 2nd 2015, 6:01 pm

I want a select script code to show above the "Title of the topic" when members open a new topic they choose what type of sites they have just for one section Request Center. -> http://forumdirectory.forumotion.net/f16-request-center

Is your site a website, blog, or forum? with 3 option

Website
Blog
Forum



Mati
Mati
Hyperactive

Posts : 2020
Reputation : 330
Language : HTML, CSS & JavaScript
Location : Forum Services

https://forumservice.forumotion.com/

Back to top Go down

In progress Re: Type of Site:

Post by Mati October 4th 2015, 12:02 pm

Anyone knows...
Mati
Mati
Hyperactive

Posts : 2020
Reputation : 330
Language : HTML, CSS & JavaScript
Location : Forum Services

https://forumservice.forumotion.com/

Back to top Go down

In progress Re: Type of Site:

Post by Ange Tuteur October 4th 2015, 4:08 pm

Hi @Mati,

Just to clarify ; You want a selection drop down before the topic title input field, and when you select an option it'll add it to the beginning of the topic title, correct ?
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13246
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

In progress Re: Type of Site:

Post by Mati October 4th 2015, 7:14 pm

That's correct. thumleft
Mati
Mati
Hyperactive

Posts : 2020
Reputation : 330
Language : HTML, CSS & JavaScript
Location : Forum Services

https://forumservice.forumotion.com/

Back to top Go down

In progress Re: Type of Site:

Post by Ange Tuteur October 5th 2015, 11:20 am

Try the following. Smile

Go to Modules > JavaScript codes management > Create a new script

Placement : In all the pages
Code:
$(function() {
  var config = {
    name : '<strong>Select your website type :</strong> ',
    option : {
      'Is your site a website, blog, or forum?' : 'DEFAULT',
      'Website' : 'Website',
      'Blog' : 'Blog',
      'Forum' : 'Forum'
    }
  },
  bloc, select, i;

  if (document.post && document.post.f && document.post.f.value == 16) {
    select = document.createElement('SELECT');
    bloc = document.createElement('DL');

    for (i in config.option) select.innerHTML += '<option value="' + config.option[i] + '">' + i + '</option>';
   
    select.onchange = function() {
      var sujet = document.post.subject;
     
      if (this.value == 'DEFAULT') sujet.value = sujet.value.replace(/^\[.*?\]\s/, '');
      else {
        if (/^\[.*?\]\s/.test(sujet.value)) sujet.value = sujet.value.replace(/^\[.*?\]\s/, '');
        sujet.value = '[' + this.value + '] ' + sujet.value;
      }
    };


    bloc.innerHTML = '<dt><label>' + config.name + '</label></dt><dd></dd>';
    bloc.getElementsByTagName('DD')[0].appendChild(select);

    document.post.subject.parentNode.parentNode.parentNode.insertBefore(bloc, document.post.subject.parentNode.parentNode);
  }
});

At the top you can change the label, and option names : values.

If any questions let me know. Smile
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13246
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

In progress Re: Type of Site:

Post by Mati October 5th 2015, 4:36 pm

Works perfect how I wanna it xD but is it possible to add classes for each of them

Code:
<div class="text_forum">Forum</div>
<div class="text_blog">Blog</div>
<div class="text_web">Website</div>

So I can style it with CSS.
Mati
Mati
Hyperactive

Posts : 2020
Reputation : 330
Language : HTML, CSS & JavaScript
Location : Forum Services

https://forumservice.forumotion.com/

Back to top Go down

In progress Re: Type of Site:

Post by Ange Tuteur October 5th 2015, 6:09 pm

Replace the script with this :
Code:
$(function() {
  var config = {
    name : '<strong>Select your website type :</strong> ',
    option : {
      'Is your site a website, blog, or forum?' : ['DEFAULT', 'text_default'],
      'Website' : ['Website', 'text_web'],
      'Blog' : ['Blog', 'text_blog'],
      'Forum' : ['Forum', 'text_forum']
    }
  },
  bloc, select, i;

  if (document.post && document.post.f && document.post.f.value == 16) {
    select = document.createElement('SELECT');
    bloc = document.createElement('DL');

    for (i in config.option) select.innerHTML += '<option value="' + config.option[i][0] + '" '+ (config.option[i][1] ? 'class="' + config.option[i][1] + '"' : '') +'>' + i + '</option>';
   
    select.onchange = function() {
      var sujet = document.post.subject;
     
      if (this.value == 'DEFAULT') sujet.value = sujet.value.replace(/^\[.*?\]\s/, '');
      else {
        if (/^\[.*?\]\s/.test(sujet.value)) sujet.value = sujet.value.replace(/^\[.*?\]\s/, '');
        sujet.value = '[' + this.value + '] ' + sujet.value;
      }
    };


    bloc.innerHTML = '<dt><label>' + config.name + '</label></dt><dd></dd>';
    bloc.getElementsByTagName('DD')[0].appendChild(select);

    document.post.subject.parentNode.parentNode.parentNode.insertBefore(bloc, document.post.subject.parentNode.parentNode);
  }
});

I changed the value into an array :
['VALUE', 'CLASSNAME']

class name is optional of course. Smile
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13246
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

In progress Re: Type of Site:

Post by Mati October 5th 2015, 6:35 pm

Ain't working I have made a topic as you can see http://forumdirectory.forumotion.net/f16-request-center there is no class?
Mati
Mati
Hyperactive

Posts : 2020
Reputation : 330
Language : HTML, CSS & JavaScript
Location : Forum Services

https://forumservice.forumotion.com/

Back to top Go down

In progress Re: Type of Site:

Post by Ange Tuteur October 5th 2015, 7:35 pm

Oh, you mean style the texts in the title ? You'd need to set a JavaScript in the sub-forums. Use this :
Code:
$(function() {
  var keywords = {
    '[Forum]' : 'tag-forum',
    '[Blog]' : 'tag-blog',
    '[Website]' : 'tag-website'
  },
  title = $('a.topictitle'), i = 0, j = title.length, k, str, reg;

  for (; i < j; i++) {
    str = title[i].innerHTML;
    for (k in keywords) {
      reg = new RegExp('^' + k.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), 'i');
      if (reg.test(str)) {
        title[i].innerHTML = str.replace(reg, '<span class="' + keywords[k] + '">' + k.replace(/\[|\]/g, '') + '</span>');
        break;
      }
    }
  }
});

At the top is an object which contains the tag name + the class you want applied to it. Then you just need to use CSS to style the texts.
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13246
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

In progress Re: Type of Site:

Post by brandon_g October 11th 2015, 3:53 pm

Is this solved @Mati or still on going?

-Brandon


Type of Site: Brando10
Remember to mark your topic Type of Site: Solved15 when a solution is found.
General Rules | Tips & Tricks | FAQ | Forgot Founder Password?

Type of Site: Scre1476
Team Leader
Review Section Rules | Request A Review | Sticker Points
brandon_g
brandon_g
Manager
Manager

Male Posts : 10106
Reputation : 923
Language : English
Location : USA

https://www.broadcastingduo.com

Back to top Go down

Back to top

- Similar topics

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