Skip to content

Instantly share code, notes, and snippets.

@RyanHirsch
Created December 16, 2013 20:37
Show Gist options
  • Save RyanHirsch/7993922 to your computer and use it in GitHub Desktop.
Save RyanHirsch/7993922 to your computer and use it in GitHub Desktop.
An first attempt to make a 100% client side web part know that it's being edited.
(function() {
var $wrappingDiv = $('div[webpartid]').last();
//console.log($wrappingDiv.attr('webpartid'));
$(document).ready(function() {
var inDesignMode = null;
if($('#MSOLayout_InDesignMode')) {
inDesignMode = $('#MSOLayout_InDesignMode').val();
}
var wikiInEditMode = null;
if(typeof document.forms[MSOWebPartPageFormName]._wikiPageMode !== "undefined") {
wikiInEditMode = document.forms[MSOWebPartPageFormName]._wikiPageMode.value;
}
if (inDesignMode === "1" || wikiInEditMode === "Edit" || $('div[webpartid][selectedwebpart="true"]'))
{
// page is in edit mode
//console.log('edit mode');
if($('div[webpartid][selectedwebpart="true"]')) {
if($('div[webpartid][selectedwebpart="true"]').attr('webpartid') === $wrappingDiv.attr('webpartid')) {
console.log("EDITING OUR WEBPART!!!");
};
}
//.ms-WPSelected ?
}
else
{
// page is in browse mode
console.log('browse mode');
}
});
}());
@RyanHirsch
Copy link
Author

Need to attach some type of init() handler to a global object with the current webpartid and ensure our .ready() is only called once. When ready fires it should do a lookup into the global object to see if there is a handler to be called.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment