/    Sign up×
Community /Pin to ProfileBookmark

Javascript + CSS Prefix Code Help

I’m looking for a code that will allow me to use images (or CSS) as prefixes when creating a new post.
But I want to be able to edit the topic title (or post) and add a prefix (like if you forgot to add it when making the topic or editing an older topic). Also want it to show everywhere the topic title shows (the image/css).

I’d highly prefer to be able to use images via css instead of having to style each prefix I can just add the image url.

I have a code that was made for me but it didn’t quite work as planned. As you can see in the first 2 screenshots the code doesn’t take effect on those pages. And the dropdown menu that shows the prefixes when creating a new topic isn’t present at all.

[CODE]
<script type=”text/javascript”>
//<![CDATA[
$(function () {
var pos = $(‘table.posting input[name=”title”]’).position();

$(‘table.posting input[name=”title”]’).before(‘<a href=”javascript: void(0);” id=”aPrefix” style=”margin-right: 5px”>Add Prefix</a>’);
$(‘#main’).append(‘<div id=”prefixes” class=”meta_box” style=”display: none; position: absolute; left: ‘ + pos.left + ‘px; top: ‘ + (pos.top + 21) + ‘px”></div>’);

$(‘#aPrefix’).click(function () {
$(‘#prefixes’).fadeIn(‘slow’);
});

function addPrefix(prefix) {
$(‘#prefixes’).append(‘<div class=”prefix” style=”cursor: pointer”>’ + prefix + ‘</div>’);
}

addPrefix(‘Prefix 1’);
addPrefix(‘Prefix2’);
addPrefix(‘Prefix 3’);

$(‘#prefixes’).append(‘<div class=”no_prefix” style=”cursor: pointer”>No Prefix</div>’);

$(‘div.prefix’).each(function () {
$(this).attr(‘class’, ‘prefix’ + $(this).index());
});

$(‘div.no_prefix’).click(function () {
$(‘#prefixes’).fadeOut(‘slow’);
$(‘table.posting input[name=”title”]’).val($(‘table.posting input[name=”title”]’).val().replace(/[(.+?)]/ig, ”));
});

$(‘div[class*=”prefix”]:not(div.no_prefix)’).click(function () {
if ($(‘table.posting input[name=”title”]’).val().length === 0) {
$(‘table.posting input[name=”title”]’).val(‘[‘ + $(this).text() + ‘] ‘);
} else {
$(‘table.posting input[name=”title”]’).val(‘[‘ + $(this).text() + ‘] ‘ + $(‘table.posting input[name=”title”]’).val());
}

$(‘#prefixes’).fadeOut(‘slow’);
});
});

function stylePrefix(pName, cName) {
$(‘a:contains([‘ + pName + ‘])’).each(function () {
$(this).html($(this).html().replace(‘[‘ + pName + ‘]’, ‘<span class=”‘ + cName + ‘”>’ + pName + ‘</span>’));
});
}

stylePrefix(‘prefix1’, ‘prefix1’);
stylePrefix(‘Prefix2’, ‘Prefix2’);
stylePrefix(‘PREFIX3’, ‘PREFIX3’);
//]]>
</script>
[/CODE]

I’m using a Zetaboards forum/board.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@KankuroauthorSep 10.2014 — Screenshots:

Thread view: http://prntscr.com/45rcf5

Edit view: http://prntscr.com/45rcjg

Forum view: http://prntscr.com/45rcpp

Index View: http://prntscr.com/45rcto

New posts view: http://prntscr.com/45rcyq

Create new topic view (no drop down): http://prntscr.com/45rd8q
×

Success!

Help @Kankuro spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...