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.

Custom Thread Prefix Button with a dropdown selection

View previous topic View next topic Go down

Custom Thread Prefix Button with a dropdown selection

Post by Lunaus on Sat Jan 28, 2017 8:14 pm

Technical Details


Forum version : #PunBB
Position : Founder
Concerned browser(s) : Google Chrome
Who the problem concerns : Yourself
Forum link : http://halvmane.forumotion.com/

Description of problem

I'm trying to turn this code here:

Code:
$(function(){
  var prefix = [
    'NEWS',
    'ANNOUNCEMENT',
    'UPDATE',
    'GUIDE',
    'TUTORIAL',
    'BOUNTY',
    'HELP WANTED',
    'RECRUITING',
    'LOOKING FOR',
  ],
  a = document.getElementsByTagName('A'), i = 0, j = a.length, l = prefix.length;
  for (; i<j; i++) for (var k = 0; k<l; k++) RegExp('^\\['+prefix[k]+'\\]').test(a[i].innerHTML) && (a[i].innerHTML = a[i].innerHTML.replace(RegExp('^\\['+prefix[k]+'\\]'), '<span class="topic-prefix prefix-'+prefix[k].toLowerCase()+'">'+prefix[k]+'</span>'));
});

But I want to add the drop-down feature from this code:

Code:
var prefixes = ["PENDING", "ACCEPTED", "DENIED", "PENDING ADMIN", "PENDING INV", "APPROVED"];
var _pm = false;
 
var chk = false;
function toMenu(a) {
  var htmlpre = '<select style="margin-right:5px" id="prefix" size="1"><option value="">(None)</option>';
  for (i in a)
  htmlpre += '<option value="' + a[i] + '">' + a[i] + '</option>';
  htmlpre += '</select>';
  return htmlpre;
}
 
function checkpre(ar, input) {
  for (i in ar) {
      var p = new RegExp("" + ar[i], "g");
      var title = input.substr(0, input.indexOf(']'));
      if (p.test(title)) return ar[i];
  }
  return "";
}
$(function () {
  if (_pm) chk = /\privmsg/.test(location.href);
  if (/\/post/.test(location.href) || chk) {
      $(toMenu(prefixes)).insertBefore("input[name='subject'][type='text']");
      var mw = $("#prefix").width() + 5;
      $("input[name='subject']").css("width", $("input[name='subject']").width() - mw);
      var t = $("[name='subject']").val();
      var cur = checkpre(prefixes, t);
      if (cur != "") {
        $("[value=" + cur + "]").attr("selected", "selected");
        $("input[name='subject']").val(t.replace('[' + cur + ']', '').trim())
      }
      $("input[name='post']").click(function () {
        var sub = $("input[name='subject']").val().trim();
        if (sub != "" && $("#prefix").val() != "") $("input[name='subject']").val("[" + $("#prefix").val() + "] " + sub)
      })
  }
});

Any help would be appreciated! Also is there a way to make all of these or a few group/role specific?
avatar
Lunaus
New Member

Posts : 7
Reputation : 1
Language : English

http://halvmane.forumotion.com/

Back to top Go down

Re: Custom Thread Prefix Button with a dropdown selection

Post by Jadster on Fri Feb 03, 2017 2:07 pm

@Lunaus wrote:

Technical Details


Forum version : #PunBB
Position : Founder
Concerned browser(s) : Google Chrome
Who the problem concerns : Yourself
Forum link : http://halvmane.forumotion.com/

Description of problem

I'm trying to turn this code here:

Code:
$(function(){
  var prefix = [
    'NEWS',
    'ANNOUNCEMENT',
    'UPDATE',
    'GUIDE',
    'TUTORIAL',
    'BOUNTY',
    'HELP WANTED',
    'RECRUITING',
    'LOOKING FOR',
  ],
  a = document.getElementsByTagName('A'), i = 0, j = a.length, l = prefix.length;
  for (; i<j; i++) for (var k = 0; k<l; k++) RegExp('^\\['+prefix[k]+'\\]').test(a[i].innerHTML) && (a[i].innerHTML = a[i].innerHTML.replace(RegExp('^\\['+prefix[k]+'\\]'), '<span class="topic-prefix prefix-'+prefix[k].toLowerCase()+'">'+prefix[k]+'</span>'));
});

But I want to add the drop-down feature from this code:

Code:
var prefixes = ["PENDING", "ACCEPTED", "DENIED", "PENDING ADMIN", "PENDING INV", "APPROVED"];
var _pm = false;
 
var chk = false;
function toMenu(a) {
  var htmlpre = '<select style="margin-right:5px" id="prefix" size="1"><option value="">(None)</option>';
  for (i in a)
  htmlpre += '<option value="' + a[i] + '">' + a[i] + '</option>';
  htmlpre += '</select>';
  return htmlpre;
}
 
function checkpre(ar, input) {
  for (i in ar) {
      var p = new RegExp("" + ar[i], "g");
      var title = input.substr(0, input.indexOf(']'));
      if (p.test(title)) return ar[i];
  }
  return "";
}
$(function () {
  if (_pm) chk = /\privmsg/.test(location.href);
  if (/\/post/.test(location.href) || chk) {
      $(toMenu(prefixes)).insertBefore("input[name='subject'][type='text']");
      var mw = $("#prefix").width() + 5;
      $("input[name='subject']").css("width", $("input[name='subject']").width() - mw);
      var t = $("[name='subject']").val();
      var cur = checkpre(prefixes, t);
      if (cur != "") {
        $("[value=" + cur + "]").attr("selected", "selected");
        $("input[name='subject']").val(t.replace('[' + cur + ']', '').trim())
      }
      $("input[name='post']").click(function () {
        var sub = $("input[name='subject']").val().trim();
        if (sub != "" && $("#prefix").val() != "") $("input[name='subject']").val("[" + $("#prefix").val() + "] " + sub)
      })
  }
});

Any help would be appreciated! Also is there a way to make all of these or a few group/role specific?

Hello have you tried changing the bottom code to this?

Code:
var prefixes = ["NEWS", "ANNOUNCEMENT", "UPDATE", "GUIDE", "TUTORIAL", "BOUNTY", "HELP WANTED", "RECRUITING", "LOOKING FOR"];
var _pm = false;
 
var chk = false;
function toMenu(a) {
  var htmlpre = '<select style="margin-right:5px" id="prefix" size="1"><option value="">(None)</option>';
  for (i in a)
  htmlpre += '<option value="' + a[i] + '">' + a[i] + '</option>';
  htmlpre += '</select>';
  return htmlpre;
}
 
function checkpre(ar, input) {
  for (i in ar) {
      var p = new RegExp("" + ar[i], "g");
      var title = input.substr(0, input.indexOf(']'));
      if (p.test(title)) return ar[i];
  }
  return "";
}
$(function () {
  if (_pm) chk = /\privmsg/.test(location.href);
  if (/\/post/.test(location.href) || chk) {
      $(toMenu(prefixes)).insertBefore("input[name='subject'][type='text']");
      var mw = $("#prefix").width() + 5;
      $("input[name='subject']").css("width", $("input[name='subject']").width() - mw);
      var t = $("[name='subject']").val();
      var cur = checkpre(prefixes, t);
      if (cur != "") {
        $("[value=" + cur + "]").attr("selected", "selected");
        $("input[name='subject']").val(t.replace('[' + cur + ']', '').trim())
      }
      $("input[name='post']").click(function () {
        var sub = $("input[name='subject']").val().trim();
        if (sub != "" && $("#prefix").val() != "") $("input[name='subject']").val("[" + $("#prefix").val() + "] " + sub)
      })
  }
});

I simply added the names of the prefixes that you wanted to have into the bottom code since you wanted something around that style.
avatar
Jadster
Forum Reviewer
Forum Reviewer

Male Posts : 903
Reputation : 121
Language : English
Location : United States

http://www.adminvortex.com

Back to top Go down

Re: Custom Thread Prefix Button with a dropdown selection

Post by Lunaus on Mon Feb 06, 2017 5:00 pm

Thanks for the reply! I'll check it out now, haven't had the time to check up on this thread. Smile

EDIT: So, it works! But there's one issue, the drop down shows but it doesn't display differently when viewing the forums, as in there's no custom box around the text like in the first bit of code I provided.
avatar
Lunaus
New Member

Posts : 7
Reputation : 1
Language : English

http://halvmane.forumotion.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