Created
December 16, 2013 20:37
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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'); | |
} | |
}); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Need to attach some type of
init()
handler to a global object with the current webpartid and ensure our.ready()
is only called once. Whenready
fires it should do a lookup into the global object to see if there is a handler to be called.