Skip to content

Instantly share code, notes, and snippets.

@bkoopman
Last active August 29, 2015 14:11
Show Gist options
  • Save bkoopman/4748ea17be3a15bf2fb6 to your computer and use it in GitHub Desktop.
Save bkoopman/4748ea17be3a15bf2fb6 to your computer and use it in GitHub Desktop.
Updated version of xpm-jquery-plugin.js
/**
* XPM specific functions
*/
(function($) {
// initialize global variable
SDL_ENV.isInXpm = false;
// check and set global variable
$.fn.checkIfInXpm = function() {
// check via availability of Tridion objects
if (typeof Tridion != "undefined" && typeof Tridion.Web.UI.SiteEdit != "undefined") {
console.log("in XPM");
SDL_ENV.isInXpm = true;
// display elements specifically for experience manager
$(".xpm-only").show();
} else {
console.log("not in XPM");
SDL_ENV.isInXpm = false;
// hide elements specifically for experience manager
$(".xpm-only").hide();
}
};
}(jQuery));
$(document).ready(function() {
// wait 5 seconds after document ready (to complete XPM load) and check if we are in XPM (setting global variable)
setTimeout(function() {
$().checkIfInXpm();
}, 5000);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment