Was this page helpful?

Reload a DOM element using MindTouch.Deki.Reload()

    This page is designed to demonstrate the MindTouch.Deki.Reload() function in the DekiAPI extension.

    The MindTouch.Deki.Reload() and other functions contained in the MindTouch.Deki.js file require the Deki API ajax extension.

    Click the buttons to reload the various portions of the example table. The top row contains a randomly-generated Venn diagram from Google Charts. The second contains the number of seconds that have passed since the page was last edited. Note the different behaviors displayed when the elements are reloaded.

    The image, when reloaded, causes the entire table to move. This happens because the row resizes first when the image is being called for, then once again when the image is retrieved.

    The bottom row does not resize in this example, because it happens so quickly.

    Example Table
    Seconds Since This Page's Last Edit:
    86052082

    The code:

    dekiapi(); 
    <table id="wholetable" class="table">
            <tbody>
                <tr>
                    <th>"Example Table";</th>
                </tr>
                <tr id="toptr">
                    <td>
                        web.image('http://chart.apis.google.com/chart?chs=245x145&cht=v&chd=t:' .. num.int(num.random()*100) ..',' .. num.int(num.random()*100) ..',' .. num.int(num.random()*100) ..',' .. num.int(num.random()*100) ..',' .. num.int(num.random()*100) ..',' .. num.int(num.random()*100));
                    </td>
                </tr>
                <tr id="bottomtr">
                    <td>
                        "Seconds Since This Page's Last Edit";
                        <br />
                        date.diffSeconds(page.revisions[-1].date, date.now);
                    </td>
                </tr>
           </tbody>
        </table>
        <input type="button" class="btn" id="reloadTop" value="Reload Top Row" ctor="when($this.click){
            MindTouch.Deki.Reload(#toptr);
        }"/>
        <input type="button" class="btn" id="reloadBottom" value="Reload Bottom Row" ctor="when($this.click){
            MindTouch.Deki.Reload(#bottomtr);
        }"/>
        <input type="button" class="btn" id="reloadWholeTable" value="Reload Entire Table" ctor="when($this.click){
            MindTouch.Deki.Reload(#wholetable);
        }"/>

    Was this page helpful?
    Tag page
    Viewing 3 of 3 comments: view all
    @robertm
    I've had two problems reloading page elements in the past, which both relate to elements that have dynamic behaviors. (1) elements that use unique ids (@id), which I use a lot of necessity, don't work, because they reload with new @id, and (2) event linkages break. If I have a CTOR element inside the reloaded element, the JavaScript code doesn't come with it upon reload. If I have other events helper bound to the element via jQuery, those all break and must be re-bound afterwords. Are there any best practices how to handle reload of dynamic elements in the wiki environment?
    Posted 09:38, 2 Feb 2010
    I have the same issue that neilw is describing. I am using CTOR elements for event linkages in content that is being reloaded with Deki.Reload. Nothing works after the first time the Reload function gets called.
    Posted 21:50, 12 Feb 2010
    @neilw @rocIT unfortunately, the way reload currently works doesn't allow javascript to be attached to the dynamically loaded html; you'll have to instead define a function that attaches the event hooks dynamically and call it each time after reload. See the todo template as an example how to do this.
    Posted 06:58, 13 Feb 2010
    Viewing 3 of 3 comments: view all
    You must login to post a comment.

    Copyright © 2011 MindTouch, Inc. Powered by