Friday, May 12, 2017

Sitecore Admin Menus

Sitecore Admin Pages Explained, from the blog Fire Breaks Ice

Sitecore comes shipped with a plethora of admin pages that provide significant features to developers and administrators. Many of these pages aren’t exactly documented well or at all. I intend to identify and explain the admin pages that I know of and how they can be used to your advantage.

Read More:
http://firebreaksice.com/sitecore-admin-pages-explained/
Wednesday, May 10, 2017

Undoing a merge in Sourcetree/Git

Merging some changes into your master branch, then realizing you need an undo function, is stressful. Fortunately, whether or not you've pushed your merge, you can still reverse what you did. There's no actual "undo" in Git, but you can either reset the master branch, or reverse your changes.

If you haven't pushed to the origin master branch yet, you can reset the master branch to the previous commit before the merge. You'll want to reset using "Hard" mode so that your working copy of master will have the changes removed.

Sourcetree: 
Right-click the previous commit on the master branch, select "Reset current branch to this commit" and select "Hard" mode.

Git Command Line:
git reset --hard XXXXXXX (insert the Commit ID)

If your merge to master has been pushed, then you will need to do a reverse commit in the feature branch, which reverts everything in that commit, merge to master, then push master again. Later on, if you want to re-merge what was in the feature branch to master once again, you will have to reverse commit the reversion itself in the feature branch. This will reinstate the changes you had removed.
Monday, May 1, 2017

Using setInterval to run a script after element is finished loading from server

Sometimes I need to run a JS script on a set of HTML elements, but I run into problems when the script fires before elements or assets are finished loading from the server side.

For example, let's say I'm loading a grid of items, each of which has an image and some copy underneath. I want each item in the grid to be the same height, regardless of how much text it has. Generally I'd run a JS script to set the heights of all the items to the height of the tallest item.

However, since I'm loading the images through a CMS off the server, it sometimes takes a little bit before they are all loaded. If I run the script normally, it will fire before all the images finish loading, and it will resize the items to a height that is too short.

I've found that using the javascript function "setInterval" is a good solution; it runs at a frequency of your choosing, and each time it checks if the slower-loading element is loaded. If it isn't loaded, it will simply repeat the function; if the element is found to be finished loading, then it will run another JS script of your choosing, and clear the interval to stop checking.



// create your interval function as a named variable; having a name allows you to clear it later
var checkImages = setInterval(function () {

    // This checks the height of the last grid item's image, since it will be loaded last. 
    // Once it's loaded, the height will be more than 0.
    if ($('.grid:last img').height() > 0) {

        // if the image is done loading, clear out the interval
        clearInterval(checkImages); 
        
        // then run the script you want; this just happens to be the one I'm using
        equalizeHeights($('.grid__item')); 
    }
    else {
    }
}, 200); // run this every 200 ms