Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8966231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:58:56+00:00 2026-06-15T16:58:56+00:00

I’m building a live theme picker for a project of us and it works.

  • 0

I’m building a live theme picker for a project of us and it works. That’s great! But I’ve got one bug left, which I can’t solve and it drives me crazy.

This is the problem: On the moment you’ll load the theme picker page, the backbone app (it’s build with Backbone JS, Underscore JS and jQuery) is started. On the initialization the app looks up several things, and one of the things is: what color set do I need to use for the current theme (the current theme settings are stored in a DB).

This is the function that’s called on initialization:

    // Select the colorset for the first time a new theme is picked
    selectColorset: function( newTheme ) {
        // Check or this is a new theme or not
        var themeCheck = ( typeof newTheme !== "undefined" ) ? true : false,
            colorset = ( !themeCheck ) ? parseInt( $("#js-colorset-input").val() , 10 ) : 0;

        // Select the right list
        $("#js-theme-colors ul").eq( colorset ).addClass("selected-set");
        this.renderColorStyle( colorset );
    }

As you can see this function is used on two ways: First on initialization and when you switch to an other theme.

First I look up: why is this function called? Is it called on the change event, or is it called on initialization. If it’s called on initialization, the newTheme variable will not hold any data.

On initialization the color set number will be a number in an hidden field on the page. So now we’ve got the color set number, we can render the color set stylesheet (this.renderColorStyle( colorset )):

    // Insert the color stylesheet
    renderColorStyle: function( colorset ) {
        // Check or the colorset is given
        if( typeof colorset === "undefined" || colorset === "" ) {
            colorset = 0;
        }

        // Define the stylesheet for this theme
        if( $("#js-theme-iframe").contents().find("#js-theme-colorset").length > 0 ) {
            // Change the current stylesheet
            $("#js-theme-iframe")
                .contents()
                .find("head #js-theme-colorset")
                .attr("href", "stylesheets/themes/theme-" + this.themeID + "/theme-color-" + colorset + ".css");
        } else {
            // Insert a new stylesheet
            var stylesheet = $("<link />", {
                href: "stylesheets/themes/theme-" + this.themeID + "/theme-color-" + colorset + ".css",
                rel: "stylesheet",
                id: "js-theme-colorset"
            });

            // Append the stylesheet to the iframe
            $("#js-theme-iframe").contents().find("head").append( stylesheet );
        }
    }

As you can see, I first check or we’ve got an color set (just to be sure) and because we don’t have an color set stylesheet on initialization, we’re gonna build one. This is done with jQuery. As you can see, I’m building the element with a href, rel and an id (which is used to find the color set stylesheet).

But jQuery keeps giving me an empty array back on initialization.. So the stylesheet is not there.. All the data is there, and when I use the console.log() function to see or the data is really there, it turns out it is. So that’s not it.

But I really can’t find out why this happens. Because if I call these functions on a theme change, it all works and jQuery creates the stylesheet.. So only on initialization it doesn’t work and it drives me crazy..

Hopefully someone can explain me how it’s possible that the exact same functions are called every time, but on initialization it has an other output (with the same numbers and variables) than on theme change..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T16:58:57+00:00Added an answer on June 15, 2026 at 4:58 pm

    The whole problem was: I’d called the selectColorset() before I even initialized the iFrame. Thanks to @Leandro I figured out that, that was my mistake. Thanks for the help!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
I have a small JavaScript validation script that validates inputs based on Regex. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.