Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 10-31-2010, 05:00 PM
SBlueman SBlueman is offline
 
Join Date: Jan 2006
Posts: 717
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Odd error from script in header

This script which is in my header include template is this:

Code:
<script type="text/javascript">

Array.prototype.contains = function (ele) {
    for (var i = 0; i < this.length; i++) {
        if (this[i] == ele) {
            return true;
        }
    }
    return false;
};

Array.prototype.remove = function (ele) {
    var arr = new Array();
    var count = 0;
    for (var i = 0; i < this.length; i++) {
        if (this[i] != ele) {
            arr[count] = this[i];
            count++;
        }
    }
    return arr;
};

window.onload = function () {
        var taglist = document.getElementById('tags');
	taglist.value = taglist.value.replace (/\s+/g,'');  // strip space
        var tags = taglist.value.split(',');
        
        var populartags = document.getElementById('popularTags').getElementsByTagName('span');
        
        for (var i = 0; i < populartags.length; i++) {
            if (tags.contains(populartags[i].innerHTML)) {
                populartags[i].className = 'selected';
            }
        }
}

function doTag(ele) {
    var thisTag = ele.innerHTML;
    var taglist = document.getElementById('tags');
    var tags = taglist.value.split(',');
 
    // If tag is already listed, remove it
    if (tags.contains(thisTag)) {
        tags = tags.remove(thisTag);
        ele.className = 'unselected';
        
    // Otherwise add it
    } else {
        tags.splice(tags.length-1, 0, thisTag);
        ele.className = 'selected';
    }
    
    taglist.value = tags.join(',');
    document.getElementById('tags').focus();
}
</script>
I have to have this code because it is key to critical feature on the site. Unfortunately it seems to be causing some issues to my message editor. When I go to select a font or font size, I am getting this odd link at the bottom of my font drop-down:



I am also getting an error with the font size drop-down menu:


Is there a way to isolate the script and have it called from somewhere else other than the template and would this fix the template error I am experiencing?

Also....and I don't know if this is related.....

I am getting this error when selecting threads:



I have two checked.....and the counter says four. I uncheck them, and the number changes. It's acting all squirrelly.
Reply With Quote
  #2  
Old 10-31-2010, 05:29 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Where in the headinclude template did you add that code? I just added it to mine with no problem... the page is just fine for me.
Reply With Quote
  #3  
Old 10-31-2010, 05:40 PM
SBlueman SBlueman is offline
 
Join Date: Jan 2006
Posts: 717
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I added it at the very end of my headinclude template.

--------------- Added [DATE]1288550490[/DATE] at [TIME]1288550490[/TIME] ---------------

BTW, it also seems like I can't seem to use the advanced WYSIWYG editor without issues either.
Reply With Quote
  #4  
Old 10-31-2010, 05:50 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I think the problem is that the javascript code that builds the color and font menus (in clientscript/vbulletin_textedit.js) uses for...in loops to add the items, and that kind of loop gets all properties of an object, including anything added to the prototype. (As explained here: http://www.prototypejs.org/api/array).

So maybe the easiest thing to do is to change that JS code that you've added. It wouldn't be that hard to move the "contains" and "remove" code in to the code below where they're called (assuming of course that there isn't any more JS code on that page that relies on those functions).
Reply With Quote
  #5  
Old 10-31-2010, 06:12 PM
SBlueman SBlueman is offline
 
Join Date: Jan 2006
Posts: 717
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The script is for this modification:

https://vborg.vbsupport.ru/showthread.php?t=159646

I use it to create pre-defined topic tags that members can click once on to select. The problem is that this code was setup by a former member of the site who we have lost touch with.
Reply With Quote
  #6  
Old 10-31-2010, 06:25 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

OK, I haven't tried it at all, but maybe try this code instead of what you originally posted:

Code:
<script type="text/javascript">

function contains(a, ele) {
    for (var i = 0; i < a.length; i++) {
        if (a[i] == ele) {
            return true;
        }
    }
    return false;
};

function remove(a, ele) {
    var arr = new Array();
    var count = 0;
    for (var i = 0; i < a.length; i++) {
        if (a[i] != ele) {
            arr[count] = a[i];
            count++;
        }
    }
    return arr;
};

window.onload = function () {
        var taglist = document.getElementById('tags');
	taglist.value = taglist.value.replace (/\s+/g,'');  // strip space
        var tags = taglist.value.split(',');
        
        var populartags = document.getElementById('popularTags').getElementsByTagName('span');
        
        for (var i = 0; i < populartags.length; i++) {
            if (contains(tags, populartags[i].innerHTML)) {
                populartags[i].className = 'selected';
            }
        }
}

function doTag(ele) {
    var thisTag = ele.innerHTML;
    var taglist = document.getElementById('tags');
    var tags = taglist.value.split(',');
 
    // If tag is already listed, remove it
    if (contains(tags, thisTag)) {
        tags = remove(tags, thisTag);
        ele.className = 'unselected';
        
    // Otherwise add it
    } else {
        tags.splice(tags.length-1, 0, thisTag);
        ele.className = 'selected';
    }
    
    taglist.value = tags.join(',');
    document.getElementById('tags').focus();
}
</script>
Reply With Quote
  #7  
Old 10-31-2010, 10:04 PM
SBlueman SBlueman is offline
 
Join Date: Jan 2006
Posts: 717
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That fixed all the issues I was having with this modification. Thank you so much!

What was the change that you made and why? I'd love to know to learn.
Reply With Quote
  #8  
Old 10-31-2010, 10:25 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well the "Array.prototype.contains = function (ele)..." from the original code adds a function to the javascript 'Array' class so that later you can do something like

PHP Code:
var = new Array();
...
if (
x.contains('foo'))

to check if the array contains the value 'foo'. But adding the functions to the class was causing the problem because of the use of for..in loops by the code that builds the editor menus (see the link I posted above). So I changed it to


PHP Code:
function contains(aele)...

var 
= new Array();
...
if (
contains(x'foo'))

which does the same thing by adding a parameter to a normal function instead of adding a function to the class.

Hopefully this makes some sense.
Reply With Quote
  #9  
Old 11-01-2010, 01:30 AM
SBlueman SBlueman is offline
 
Join Date: Jan 2006
Posts: 717
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Looks like it's time for me to learn some things about java. Thank you for pointing me in the right direction.
Reply With Quote
  #10  
Old 11-01-2010, 02:27 AM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

First thing to learn is that java and javascript are NOT the same language. (I just don't want you to get a book about java when what you really want is a book about javascript. )
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:59 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04125 seconds
  • Memory Usage 2,264KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_code
  • (2)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete