Skip to content

Commit

Permalink
TreeView, WSTreeView, Browser, Dom
Browse files Browse the repository at this point in the history
TreeView
 - Fixed ContextMenu positioning when opened using keyboard.

WSTreeView
 - Fixed loading indicator which got stuck when requesting
   children for multiple nodes simultaneously.

Browser
 - Fixed StorageSupported function which did not properly
   cache the result of the first call - result written to
   wrong internal property.
 - Renamed StorageSupported function to IsStorageSupported

Dom
 - Added Replace(oldElement, newElement) function
 - Fixed CreateElement function which did not include
   text nodes - e.g.: CreateElement(“<i>Hello</i> world”);
   The " world” portion would have been excluded.
 - Fixed GetPosition function which returned float
   values when requesting position relative to viewport.
  • Loading branch information
Jemt committed Jan 16, 2016
1 parent 78de179 commit 863891f
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 46 deletions.
2 changes: 1 addition & 1 deletion Controls/TreeView/TreeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ Fit.Controls.TreeView = function(ctlId)
if (ev.keyCode === 93 || (Fit.Events.GetModifierKeys().Shift === true && ev.keyCode === 121)) // Context menu button or Shift+F10
{
var label = node.GetDomElement().querySelector("span");
var pos = Fit.Dom.GetPosition(label);
var pos = Fit.Dom.GetPosition(label, true); // True argument = get position relative to viewport rather than document

pos.X = pos.X + label.offsetWidth - 10;
pos.Y = pos.Y + label.offsetHeight - 5;
Expand Down
47 changes: 22 additions & 25 deletions Controls/TreeView/WSTreeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ Fit.Controls.WSTreeView = function(ctlId)
var orgSelected = [];
var loadDataOnInit = true;
var selectAllMode = Fit.Controls.WSTreeView.SelectAllMode.Progressively;
var loading = null;
var onRequestHandlers = [];
var onResponseHandlers = [];
var onAbortHandlers = [];
Expand All @@ -54,14 +53,6 @@ Fit.Controls.WSTreeView = function(ctlId)
if (node.GetDomElement()._internal.WSHasChildren === false)
return;

// Loading indicator

var li = node.GetDomElement();

loading = document.createElement("i");
Fit.Dom.AddClass(loading, "FitUiControlLoadingIndicator");
Fit.Dom.Add(li, loading);

// Get data

node.GetDomElement()._internal.WSLoading = true;
Expand All @@ -82,23 +73,10 @@ Fit.Controls.WSTreeView = function(ctlId)
node.AddChild(createNodeFromJson(c));
});

// Remove loading indicator

Fit.Dom.Remove(loading);
loading = null;

node.GetDomElement()._internal.WSDone = true;
node.Expanded(true); // Unfortunately causes both OnToggle and OnToggled to be fired, although OnToggle has already been fired once (canceled below)
});

// Remove loading indicator if request was canceled

if (canceled === true)
{
Fit.Dom.Remove(loading);
loading = null;
}

return false; // Cancel toggle, will be "resumed" when data is loaded
});

Expand Down Expand Up @@ -889,6 +867,14 @@ Fit.Controls.WSTreeView = function(ctlId)

cb(node, eventArgs); // Callback is responsible for populating TreeView

// Remove loading indicator

if (request._loadingIndicator !== undefined) // Loading indicator not set when requesting root nodes
{
Fit.Dom.Remove(request._loadingIndicator);
delete request._loadingIndicator;
}

// Select nodes found in preselections

if (Fit.Core.IsEqual(preSelected, {}) === false) // Prevent nodes from being iterated if no preselections are found
Expand Down Expand Up @@ -922,10 +908,10 @@ Fit.Controls.WSTreeView = function(ctlId)

request.OnAbort(function(req)
{
if (loading !== null) // Loading indicator not set when requesting root nodes
if (request._loadingIndicator !== undefined) // Loading indicator not set when requesting root nodes
{
Fit.Dom.Remove(loading); // Remove loading indicator
loading = null;
Fit.Dom.Remove(request._loadingIndicator);
delete request._loadingIndicator;
}

if (node !== null) // Null when requesting root nodes
Expand All @@ -936,6 +922,17 @@ Fit.Controls.WSTreeView = function(ctlId)
fireEventHandlers(onAbortHandlers, eventArgs);
});

// Display loading indicator

if (node !== null) // Null when requesting root nodes
{
var li = node.GetDomElement();

request._loadingIndicator = document.createElement("i");
Fit.Dom.AddClass(request._loadingIndicator, "FitUiControlLoadingIndicator");
Fit.Dom.Add(li, request._loadingIndicator);
}

// Invoke request

request.Start();
Expand Down
11 changes: 6 additions & 5 deletions Core/Browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,15 @@ Fit.Browser.GetInfo = function()
return Fit.Core.Clone(Fit._internal.Browser.Info); // Clone to ensure values are not shared and potentially changed
}

/// <function container="Fit.Browser" name="StorageSupported" access="public" static="true" returns="boolean">
/// <function container="Fit.Browser" name="IsStorageSupported" access="public" static="true" returns="boolean">
/// <description> Returns value indicating whether Session and Local storage is supported or not </description>
/// </function>
Fit.Browser.StorageSupported = function()
Fit.Browser.IsStorageSupported = function()
{
if (Fit._internal.Browser.StorageSupported === undefined)
{
Fit._internal.Browser.StorageSupported = false;

try
{
if (window.localStorage && window.sessionStorage)
Expand All @@ -285,14 +287,13 @@ Fit.Browser.StorageSupported = function()
sessionStorage.setItem(x, x);
sessionStorage.removeItem(x);

Fit._internal.StorageSupported = true;
Fit._internal.Browser.StorageSupported = true;
}
}
catch (err)
{
Fit._internal.StorageSupported = false;
}
}

return Fit._internal.StorageSupported;
return Fit._internal.Browser.StorageSupported;
}
49 changes: 34 additions & 15 deletions Core/Dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,22 @@ Fit.Dom.InsertAt = function(container, position, newElm)
}
}

/// <function container="Fit.Dom" name="Replace" access="public" static="true">
/// <description> Replace element with another one </description>
/// <param name="oldElm" type="object"> Element to replace (Element or Text) </param>
/// <param name="newElm" type="object"> Replacement element (Element or Text) </param>
/// </function>
Fit.Dom.Replace = function(oldElm, newElm) // http://jsfiddle.net/Jemt/eu74o984/
{
Fit.Validation.ExpectContentNode(oldElm);
Fit.Validation.ExpectContentNode(newElm);

var container = oldElm.parentElement;
container.replaceChild(newElm, oldElm);
}

/// <function container="Fit.Dom" name="Add" access="public" static="true">
/// <description> Add DOMElement to container </description>
/// <description> Add element to container </description>
/// <param name="container" type="DOMElement"> Add element to this container </param>
/// <param name="elm" type="object"> Element or Text node to add to container </param>
/// </function>
Expand Down Expand Up @@ -257,7 +271,12 @@ Fit.Dom.CreateElement = function(html, containerTagName)
var container = document.createElement(((Fit.Validation.IsSet(containerTagName) === true) ? containerTagName : "div"));
container.innerHTML = html;

if (container.children.length === 1)
// Using childNodes property instead of children property to include text nodes,
// which the DOM functions in Fit.UI usually do not take into account.
// If text nodes are not included, a call like the following would exclude
// the " world" portion. We do not want to throw away data, naturally! Example:
// Fit.Dom.CreateElement("<span>Hello</span> world"); // Returns <div><span>Hello</span> world</div>
if (container.childNodes.length === 1)
return container.firstChild;

return container;
Expand Down Expand Up @@ -480,26 +499,26 @@ Fit.Dom.GetPosition = function(elm, relativeToViewport)
Fit.Validation.ExpectDomElement(elm);
Fit.Validation.ExpectBoolean(relativeToViewport, true);

// Return position within viewport
// Return position within viewport

if (relativeToViewport === true)
{
var res = elm.getBoundingClientRect();
return { X: res.left, Y: res.top };
}
if (relativeToViewport === true)
{
var res = elm.getBoundingClientRect(); // DOMRect object with float properties
return { X: Math.floor(res.left), Y: Math.floor(res.top) };
}

// Return position within document
// Return position within document

var pos = { X: 0, Y: 0 };
var pos = { X: 0, Y: 0 };

while (elm)
{
pos.X += elm.offsetLeft;
pos.Y += elm.offsetTop;
elm = elm.offsetParent;
{
pos.X += elm.offsetLeft;
pos.Y += elm.offsetTop;
elm = elm.offsetParent;
}

return pos;
return pos;
}

/// <function container="Fit.Dom" name="GetInnerPosition" access="public" static="true" returns="object">
Expand Down

0 comments on commit 863891f

Please sign in to comment.