Wednesday, 22 April 2020

How to Check if element is visible after scrolling?

jQuery.extend(jQuery.expr[':'], {  
    inview: function (elem) {
        var t = $(elem);
        var offset = t.offset();
        var win = $(window); 
        var winST = win.scrollTop();
        var elHeight = t.outerHeight(true);

        if ( offset.top > winST - elHeight && offset.top < winST + elHeight + win.height()) {
            return true;    
        }    
        return false;  
    }
});
$(".my-elem:inview"); //returns only element that is in view
$(".my-elem").is(":inview"); //check if element is in view
$(".my-elem:inview").length; //check how many elements are in view

Tuesday, 10 September 2019

Pull to refresh javascript


To implement pull to refresh functionality in your website follow the below steps:
  1. add script reference in your layout (https://www.cssscript.com/demo/easy-pull-to-refresh-library-with-pure-javascript-pulltorefresh-js/pulltorefresh.js)
  2. add below style in the layout (<style>.ptr--ptr { box-shadow: inset 0 -3px 5px rgba(0, 0, 0, 0.12); pointer-events: none; font-size: 0.85em; font-weight: bold; top: 0; height: 0; transition: height 0.3s, min-height 0.3s; text-align: center; width: 100%; overflow: hidden; display: flex; align-items: flex-end; align-content: stretch; } .ptr--box { padding: 10px; flex-basis: 100%; } .ptr--pull { transition: none; } .ptr--text { margin-top: .33em; color: rgba(0, 0, 0, 0.3); } .ptr--icon { color: rgba(0, 0, 0, 0.3); transition: transform .3s; } .ptr--release .ptr--icon { transform: rotate(180deg); }</style>)
  3. add below code in the layout under script tag ( PullToRefresh.init({  mainElement: '#main'})

Wednesday, 7 August 2019

(ID/ParentID) list to Hierarchical list


 public List<AppInfo> GetTotalAppsInfo()
        {
Action<classname> SetChildren = null;
                //Initialize the hierarchical list to root level items
                List<classname> hierarchicalItems = all
                    .Where(rootItem => rootItem.ParentId == 0)
                    .ToList();

                SetChildren = parent =>
                                {
                                    parent.ChildItems = all
                                    .Where(childItem => childItem.ParentId == parent.Id)
                                        .ToList();

                                    //Recursively call the SetChildren method for each child.
                                    parent.ChildItems
                                            .ForEach(SetChildren);
                                };

                //Call the SetChildren method to set the children on each root level item.
                hierarchicalItems.ForEach(SetChildren);
                return hierarchicalItems;
}

Friday, 22 March 2019

Create new table row for every 4th loop

<table>
    @for (int i = 0; i < ViewBag.MyItems.Count; i++)
    {
        var cells = 4;
        var item = ViewBag.MyItems[i];

        if ((i % cells) == 0)
        {
            @:<tr>
        }

        <td>
            @item.MyTextOrWhatever
        </td>

        if (i == (ViewBag.MyItems.Count - 1))
        {
            while ((i % cells) != 0)
            {
                @:<td></td>
                i++;
            }
        }

        if ((i % cells) == (cells - 1)) // aka: last row cell
        {
            @:</tr>
        }
    }
</table>

Thursday, 13 December 2018

Export and Import Application Pools, Sites, Applications on IIS


To Export the Application Pools on IIS:

%windir%\system32\inetsrv\appcmd list apppool /config /xml > c:\apppools.xml

To import the Application Pools:

%windir%\system32\inetsrv\appcmd add apppool /in < c:\apppools.xml

To Export all you’re website:

%windir%\system32\inetsrv\appcmd list site /config /xml > c:\sites.xml

To Import the website:

%windir%\system32\inetsrv\appcmd add site /in < c:\sites.xml

To Export all you’re application:

%windir%\system32\inetsrv\appcmd list app /config /xml > c:\app.xml

To Import the application:

%windir%\system32\inetsrv\appcmd add app /in < c:\app.xml

To export/import a single application pool:

%windir%\system32\inetsrv\appcmd list apppool “MyAppPool” /config /xml > c:\myapppool.xml

Extracting Nupkg files using command line

Rename it to zip first then extract files as below 1.     Rename-Item -Path A_Package.nupkg -NewName A_Package.zip 2.     Make sure to repla...