1

My mobile website dynamically adds the header bar to reduce code redundancy.

However, I'm stuck with styling header section of a jquery mobile page.

When I see the generated HTML tags, it looks okay,

but its element is not decorated by jQuery Mobile.

After adding the content, I invoked

$(pageId).trigger('create');

Do you have any ideas?

0

2 Answers 2

1

This worked for me : http://jsfiddle.net/emBxx/2/

HTML:

<script type="text/javascript" src="js/main.js"></script>

...

<div data-role="page" data-theme="b">
    <header></header>
    <div data-role="content">
        <div class="content-primary">
            <br />
            <ul data-role="listview" data-filter="true">
                <li><a href="index.html">Some</a></li>
                <li><a href="index.html">random</a></li>
                <li><a href="index.html">searchable</a></li>
                <li><a href="index.html">content</a></li>
                <li><a href="index.html">(list!)</a></li>
            </ul>
        </div><!--/content-primary -->  
    </div>
    <footer></footer>
</div><!-- page end-->
<script>      
    appendJQMHeader('Injected header !'); 
    appendJQMFooter('—Injected ftr!', 'JQM 1.3.1Beta');
</script>

JS, in js/main.js:

function appendJQMHeader(pageTitle) {
    $('header').replaceWith(
        '<header data-role="header" data-theme="f">'+
        '<h1>'+pageTitle+'</h1>'+
        '<a href="index.html"  data-transition="slide" data-rel="back" data-icon="home" data-iconpos="notext" data-ajax="true">Home</a>'+
        '</header><!-- /header -->');
}

function appendJQMFooter(left, right) {
    $('footer').replaceWith('<footer data-role="footer" data-theme="f" class="jqm-footer"><p>&copy;'+left+'!</p><p class="jqm-version">—'+right+'</p></footer>');
}

Note: for JSfiddle, it require 'Framework & extension > No wrap - in <head>'
For stand alone version, it worked fine with html head calling js/main.js containing the JS. Then html body with appendJQMHeader() & appendJQMFooter(). See the fiddle :)

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your answer. I applied jQM styles by invoking internal methods of jQM.
0

Instead of invoking the trigger method, I executed the below command, and it works well.

$('#pageHome').closest(":jqmData(role='page')").trigger('pagecreate');

2 Comments

May you share a jsfiddle ? so I explore and learn a bit from your approach.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.