Reload current document?

Ask a Question related to Macromedia Exchange Dreamweaver Extensions, Design and Development.

  1. #1

    Default Reload current document?

    Running DW8, building an insertObject() extension; 2 problems that appear
    related to loading the current document.

    Problem 1:
    DW maintains the current document as it was loaded, even after making a change
    to it and saving; I have to reload the document (manually) for it to be treated
    properly with extension.

    Here's what's going on:
    I have a JavaScript function that reads a meta tag content in the current
    document. Between function calls, I change the meta tag content and save the
    file. DW still refers to the old content.

    Problem 2:
    The insertObject() function does not run if the document has unsaved changes.

    Here's what's going on:
    My insertObject() function inserts a line of text into the current document.
    It will run the first time on the document, when the document has not been
    edited. Thereafter, it fails.

    I've tried calling dw.releaseDocument(dom); at the end of each function
    explicitly, to no avail.

    When I run example code from the Extending Dreamweaver reference, it works as
    expected.

    Any ideas?

    srowe3 Guest

  2. Similar Questions and Discussions

    1. Print a pdf document with a current timestamp...
      I'd like to be able to print a pdf with the current date and time. I found a third party s/w to do the job but I believe Acrobat is capable of doing...
    2. Run the current document in a perticular browsere
      hi, I want to run my the current ducment in firefox, if it is not available alert ( Firefox is not found !) my code this way, but it parses...
    3. DocPreset from Current Document
      Hi, I have a related issue: Dave Saunders said: That's because you can't change the document preferences for the >margins after you've created...
    4. How to reload a <cfinclude> only document?
      Hi, I have a CFM page index.cfm that contains <cfinclude template="form.cfm">. Is it possible to reload just the form.cfm page without reloading the...
    5. How to change the current thread current culture at run time.
      I have created a new culture : Dim objCulture As New CultureInfo("he") //hebrew When I tried to assign it to the current thread. ...
  3. #2

    Default Re: Reload current document?

    For Problem 1, how are you adding and saving the file. If you're acting on the
    the dom object directly DW should update correctly. If you do string
    manipulations and use DWFile to save it, then we may not notice the file on
    disk has changed yet.

    For Problems 2, can you open another document and have your extension work.
    That is, does your application work correctly twice during the application
    session? You can also check the handlers you added to the insertbar.xml and
    make sure they're return true when you want to edit the document.

    If you're still having problems, please post some code samples as that will
    help narrow down the problem.

    Hope that helps,
    Chris
    Adobe Dreamweaver Engineering

    ChrisBank Guest

  4. #3

    Default Re: Reload current document?

    Thanks Chris, for the prompt reply!

    Running the extension on currentDoc1, then opening a second currentDoc2 works
    with the same limitations described
    below. So, "does your application work correctly twice during the application
    session?" Yes.

    Also, an update to problem 2:
    Although the initial run of the extension inserts the text correctly, if you
    enter a Return and attempt to repeat the insertion on the next line, no
    insertion takes place, the function fails. Otherwise, if you continue running
    the function on the same line, it keeps working, regardless of whether you save
    the document or not.

    To revisit problem 1:
    If you open the currentDoc, change it's SKU_Condition meta tag content and
    save the currentDoc, the function runs as if the change has not taken place;
    the dialog displays the SKU_Condition meta tag content that was in the previous
    version. You have to close the currentDoc, then reopen it, to get the function
    to read the updated SKU_Condition meta tag. Note, I'm not doing the
    close/reopen programatically.

    I've attached the JavaScript, but I'd like to send a zip file with the whole
    thing - at the risk of appearing presumptuous. A few code snippets might not
    help you understand the problem, and you'll have to be able to run the bloody
    thing. Can you give me an address where I can send you this?

    Thanks very much!
    -Scott

    function listValidSkuCond() {

    // Read current document's SKU_Condition meta tag and populate the fields
    //get the dom of the current document
    var dom = dw.getDocumentDOM();
    // get the current document's SKU_Condition meta tag
    var skuCondMeta = dom.getElementsByTagName("meta");

    // Problem 1:
    // why doesn't this update with edit to field? have to reload the doc
    //

    for ( counter = 0; counter < skuCondMeta.length; counter++)
    {
    if (skuCondMeta[counter].name == "SKU_Condition")
    {
    // get the XML file
    var xmlDOM = dw.getDocumentDOM("QBHelpSkuListForConditionalText .xml"); //
    fix this
    // get the array of TopicSkus
    for ( iter = 0; iter < xmlDOM.getElementsByTagName("TopicSku").length;
    iter++)
    {
    // find the TopicSku that matches the current doc's SKU_Condition meta
    tag
    if (xmlDOM.getElementsByTagName("TopicSku")[iter].conditionId ==
    skuCondMeta[counter].content)
    {
    // report the SKU_Condition in the
    dwscripts.findDOMObject("sku_cond").value =
    skuCondMeta[counter].content;

    // create a multi-select list for the valid SKU conditions from the
    parent TopicSku
    var condSkuList = "";
    var cslLength =
    xmlDOM.getElementsByTagName("TopicSku")[iter].childNodes.length;
    document.getElementsByTagName("div")[0].innerHTML =
    "<select multiple=\"multiple\" size=\"" +
    cslLength +
    "\" " +
    "width=\"\" editable=\"true\" name=\"skus\" >";
    // alert(document.getElementsByTagName("div")[0].innerHTML);

    // create an option for each valid SKU condition
    for ( t = 0; t < cslLength; t++)
    {
    condSkuList = condSkuList + "<option value =\"" +

    xmlDOM.getElementsByTagName("TopicSku")[iter].childNodes[t].condition
    Id +
    "\">" +

    xmlDOM.getElementsByTagName("TopicSku")[iter].childNodes[t].condition
    Id + "</option>";
    }
    document.getElementsByTagName("select")[0].innerHTML = condSkuList;
    // alert(condSkuList);
    // alert(document.getElementsByTagName("option")[1].value);
    }
    }

    dw.releaseDocument(dom); // doesn't seem to do anything
    }
    }

    return;
    }


    function insertObject(){

    // alert("calling insertObject()");

    var cslLength = document.getElementsByTagName("select")[0].childNodes.length;
    var selectList = "";

    for ( i = 0; i < cslLength; i++)
    {
    if (document.getElementsByTagName("option")[i].selected)
    {
    // alert(document.getElementsByTagName("option")[i].value);
    if (selectList.length != 0) { selectList += ","; }
    selectList = selectList +
    document.getElementsByTagName("option")[i].value;
    }
    }
    alert(selectList);

    var dom = dw.getDocumentDOM();
    dom.insertText(selectList);

    // Problem 2:
    // performing this insert doesn't work if the document has unsaved changes
    //

    dw.releaseDocument(dom); // again, no effect

    return;
    }

    srowe3 Guest

  5. #4

    Default Re: Reload current document?

    Sorry, i had a bit of a break. If you're still having problems zip up you
    files, put them on a website and post a link here. I'll look at the briefly to
    see what's up. Also, FWIW there is no dw.releaseDocument() so you don't need to
    call that (in fact you may try and remove that as it's probably causing a
    runtime error, though that should have been reported to you)

    Chris
    Adobe Dreamweaver Enginerring

    ChrisBank Guest

  6. #5

    Default Re: Reload current document?

    Thanks Chris,

    Here you go:

    [url]http://tech.groups.yahoo.com/group/scotts_group_group/files/[/url]

    There's only one file, scott.zip

    I really appreciate you're looking into this!

    -Scott
    srowe3 Guest

  7. #6

    Default Re: Reload current document?

    Chris,
    Here's the web page you requested:
    [url]http://www.geocities.com/srowe3/everything_50_percent.html[/url]
    The file is scott.zip
    Thanks for looking into this!
    -Scott
    srowe3 Guest

  8. #7

    Default Re: Reload current document?

    If you're changing the metatag in codeview and don't click into design view
    before you hit your extension, then the dom you get from dw.getDocumentDOM() is
    out of sync with the code view. We don't sync it automatically since some
    insert objects can just dump a string into code view (or they can use
    dom.source which is up to date). In this case, I think you just need to add:
    dom.synchronizeDocument();

    Also, I saw in our code that we do have a releaseDocument, so you call weren't
    hurting anything, but they probably weren't doing much either. You'd need to
    call that if you're getting a lot of DOMs and you want to give us a chance to
    free them, but we do that on idle anyway so you don't have to worry.

    Hope that helps,
    Chris
    Adobe Dreamweaver Engineering

    ChrisBank Guest

  9. #8

    Default Re: Reload current document?

    Hallelujah!!!

    That's the ticket, Chris!

    Thanks!!!!!

    -Scott
    srowe3 Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139