Changeset 7769


Ignore:
Timestamp:
Feb 7, 2020, 11:30:23 AM (22 months ago)
Author:
Nicklas Nordborg
Message:

References #2202: Include information from parent items in list pages

Events handlers are now attached to the lazy-loaded content by calling Doc.autoInitElements(). Basically this means that links to other items now works as expected.

Location:
trunk/www/include/scripts
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/www/include/scripts/lazy-parent-items.js

    r7768 r7769  
    110110          e.innerHTML = item.data[col];
    111111          Doc.removeClass(e, 'not-loaded');
     112          Doc.autoInitElements(e);
    112113        }
    113114      }
  • trunk/www/include/scripts/main-2.js

    r7616 r7769  
    515515 
    516516  /**
     517    Run all 'auto-init' event handlers on child
     518    elements to the given element.
     519  */
     520  doc.autoInitElements = function(element)
     521  {
     522    element = Doc.element(element);
     523    internal.invokeElementInitializers(element);
     524  }
     525 
     526  /**
    517527    Register a function that should be called whenever the document DOM is
    518528    ready. Eg. when the 'DOMContentLoaded' event is fired. The functions are
     
    546556    if (document.body == null) return;
    547557    internal.blockFormSubmission();
    548     internal.invokeElementInitializers();
     558    internal.invokeElementInitializers(document);
    549559    internal.invokeOnLoadFunctions();
    550560    internal.invokeFinalizers();
     
    574584    For each found element, call the registered element initialization callbacks.
    575585  */
    576   internal.invokeElementInitializers = function()
    577   {
    578     if (elementInitializers.length == 0) return;
    579     var autoElements = document.getElementsByClassName('auto-init');
     586  internal.invokeElementInitializers = function(rootElement)
     587  {
     588    if (!rootElement || elementInitializers.length == 0) return;
     589    var autoElements = rootElement.getElementsByClassName('auto-init');
    580590    for (var i = 0; i < autoElements.length; i++)
    581591    {
    582592      var element = autoElements[i];
    583       var autoInit = Data.get(element, 'auto-init');
    584       for (var j = 0; j < elementInitializers.length; j++)
    585       {
    586         try
     593      if (!element.autoInitDone)
     594      {
     595        element.autoInitDone = true;
     596        var autoInit = Data.get(element, 'auto-init');
     597        for (var j = 0; j < elementInitializers.length; j++)
    587598        {
    588           elementInitializers[j].call(element, element, autoInit);
     599          try
     600          {
     601            elementInitializers[j].call(element, element, autoInit);
     602          }
     603          catch (err)
     604          {
     605            var msg = err;
     606            if (err.toString)
     607            {
     608              msg = err.toString() + '\n' + err.stack;
     609            }
     610            console.error(msg);
     611          }
    589612        }
    590         catch (err)
    591         {
    592           var msg = err;
    593           if (err.toString)
    594           {
    595             msg = err.toString() + '\n' + err.stack;
    596           }
    597           console.error(msg);
    598         }
    599       }
    600     }
    601     elementInitializers = null;
     613      }
     614    }
    602615  }
    603616
Note: See TracChangeset for help on using the changeset viewer.