{"id":182,"date":"2015-07-16T19:07:00","date_gmt":"2015-07-16T19:07:00","guid":{"rendered":"https:\/\/itgroove.net\/bangimportant\/?p=182"},"modified":"2023-02-24T21:39:42","modified_gmt":"2023-02-24T21:39:42","slug":"detecting-edit-mode-with-javascript-css","status":"publish","type":"post","link":"https:\/\/regroove.ca\/archive\/2015\/07\/16\/detecting-edit-mode-with-javascript-css\/","title":{"rendered":"Detecting Edit Mode with JavaScript \/ CSS"},"content":{"rendered":"\n<p>One challenge we often need to overcome working with Publishing mode in SharePoint is quickly and effectively knowing if a page is in edit mode.<\/p>\n\n\n\n<p>This lets us apply different CSS styles or quite often disable functionality that is not needed in Edit Mode. (Especially surrounding Responsive Design).<\/p>\n\n\n\n<p>While SharePoint gives some great MasterPage level controls to detect this sometimes we want to do it quickly client side either with JavaScript or ideally right in a CSS rule.<\/p>\n\n\n\n<p>What we do is use JQuery&#8217;s AddClass and using an EditModel Panel add a class to the page&#8217;s body onload. Then we can use HasClass on the body tag anywhere in our code to determine if we are in edit mode.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;PublishingWebControls:EditModePanel runat=\"server\" id=\"SetEditModeClass\"&gt;<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;script language=\"javascript\"&gt;<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">$(\"body\").addClass(\"edit-mode\");<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;\/script&gt;<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;\/PublishingWebControls:EditModePanel&gt;<\/pre>\n\n\n\n<p>Then later on we can do:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">If (!$(\"body\").hasClass(\"edit-mode\")) {<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">\/\/ we are not in edit mode<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">} else {<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">\/\/ we are in edit mode<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">}<\/pre>\n\n\n\n<p>Or in CSS:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">body.edit-mode {<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">\/* hide whatever needs to be hidden *\/<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>One challenge we often need to overcome working with Publishing mode in SharePoint is quickly and effectively knowing if a page is in edit mode. This lets us apply different CSS styles or quite often disable functionality that is not needed in Edit Mode. (Especially surrounding Responsive Design). While SharePoint gives some great MasterPage level &hellip; <a href=\"https:\/\/regroove.ca\/archive\/2015\/07\/16\/detecting-edit-mode-with-javascript-css\/\"><\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[4,7,9],"tags":[],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v23.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Detecting Edit Mode with JavaScript \/ CSS - Archive<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/regroove.ca\/archive\/2015\/07\/16\/detecting-edit-mode-with-javascript-css\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Detecting Edit Mode with JavaScript \/ CSS - Archive\" \/>\n<meta property=\"og:description\" content=\"One challenge we often need to overcome working with Publishing mode in SharePoint is quickly and effectively knowing if a page is in edit mode. This lets us apply different CSS styles or quite often disable functionality that is not needed in Edit Mode. (Especially surrounding Responsive Design). While SharePoint gives some great MasterPage level &hellip;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/regroove.ca\/archive\/2015\/07\/16\/detecting-edit-mode-with-javascript-css\/\" \/>\n<meta property=\"og:site_name\" content=\"Archive\" \/>\n<meta property=\"article:published_time\" content=\"2015-07-16T19:07:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-02-24T21:39:42+00:00\" \/>\n<meta name=\"author\" content=\"Matt Lonpre (Alumni)\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Matt Lonpre (Alumni)\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/regroove.ca\/archive\/2015\/07\/16\/detecting-edit-mode-with-javascript-css\/\",\"url\":\"https:\/\/regroove.ca\/archive\/2015\/07\/16\/detecting-edit-mode-with-javascript-css\/\",\"name\":\"Detecting Edit Mode with JavaScript \/ CSS - Archive\",\"isPartOf\":{\"@id\":\"https:\/\/regroove.ca\/archive\/#website\"},\"datePublished\":\"2015-07-16T19:07:00+00:00\",\"dateModified\":\"2023-02-24T21:39:42+00:00\",\"author\":{\"@id\":\"https:\/\/regroove.ca\/archive\/#\/schema\/person\/0deb86ff016aebc76f86a79a0e7236d0\"},\"breadcrumb\":{\"@id\":\"https:\/\/regroove.ca\/archive\/2015\/07\/16\/detecting-edit-mode-with-javascript-css\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/regroove.ca\/archive\/2015\/07\/16\/detecting-edit-mode-with-javascript-css\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/regroove.ca\/archive\/2015\/07\/16\/detecting-edit-mode-with-javascript-css\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog Archive\",\"item\":\"https:\/\/regroove.ca\/archive\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Detecting Edit Mode with JavaScript \/ CSS\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/regroove.ca\/archive\/#website\",\"url\":\"https:\/\/regroove.ca\/archive\/\",\"name\":\"Archive\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/regroove.ca\/archive\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/regroove.ca\/archive\/#\/schema\/person\/0deb86ff016aebc76f86a79a0e7236d0\",\"name\":\"Matt Lonpre (Alumni)\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/regroove.ca\/archive\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/f084e0ef8fd6992834b5b085b737a7a2?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/f084e0ef8fd6992834b5b085b737a7a2?s=96&d=mm&r=g\",\"caption\":\"Matt Lonpre (Alumni)\"},\"url\":\"https:\/\/regroove.ca\/archive\/author\/mlongpre\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Detecting Edit Mode with JavaScript \/ CSS - Archive","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/regroove.ca\/archive\/2015\/07\/16\/detecting-edit-mode-with-javascript-css\/","og_locale":"en_US","og_type":"article","og_title":"Detecting Edit Mode with JavaScript \/ CSS - Archive","og_description":"One challenge we often need to overcome working with Publishing mode in SharePoint is quickly and effectively knowing if a page is in edit mode. This lets us apply different CSS styles or quite often disable functionality that is not needed in Edit Mode. (Especially surrounding Responsive Design). While SharePoint gives some great MasterPage level &hellip;","og_url":"https:\/\/regroove.ca\/archive\/2015\/07\/16\/detecting-edit-mode-with-javascript-css\/","og_site_name":"Archive","article_published_time":"2015-07-16T19:07:00+00:00","article_modified_time":"2023-02-24T21:39:42+00:00","author":"Matt Lonpre (Alumni)","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Matt Lonpre (Alumni)","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/regroove.ca\/archive\/2015\/07\/16\/detecting-edit-mode-with-javascript-css\/","url":"https:\/\/regroove.ca\/archive\/2015\/07\/16\/detecting-edit-mode-with-javascript-css\/","name":"Detecting Edit Mode with JavaScript \/ CSS - Archive","isPartOf":{"@id":"https:\/\/regroove.ca\/archive\/#website"},"datePublished":"2015-07-16T19:07:00+00:00","dateModified":"2023-02-24T21:39:42+00:00","author":{"@id":"https:\/\/regroove.ca\/archive\/#\/schema\/person\/0deb86ff016aebc76f86a79a0e7236d0"},"breadcrumb":{"@id":"https:\/\/regroove.ca\/archive\/2015\/07\/16\/detecting-edit-mode-with-javascript-css\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/regroove.ca\/archive\/2015\/07\/16\/detecting-edit-mode-with-javascript-css\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/regroove.ca\/archive\/2015\/07\/16\/detecting-edit-mode-with-javascript-css\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Archive","item":"https:\/\/regroove.ca\/archive\/"},{"@type":"ListItem","position":2,"name":"Detecting Edit Mode with JavaScript \/ CSS"}]},{"@type":"WebSite","@id":"https:\/\/regroove.ca\/archive\/#website","url":"https:\/\/regroove.ca\/archive\/","name":"Archive","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/regroove.ca\/archive\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/regroove.ca\/archive\/#\/schema\/person\/0deb86ff016aebc76f86a79a0e7236d0","name":"Matt Lonpre (Alumni)","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/regroove.ca\/archive\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/f084e0ef8fd6992834b5b085b737a7a2?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f084e0ef8fd6992834b5b085b737a7a2?s=96&d=mm&r=g","caption":"Matt Lonpre (Alumni)"},"url":"https:\/\/regroove.ca\/archive\/author\/mlongpre\/"}]}},"_links":{"self":[{"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/posts\/182"}],"collection":[{"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/comments?post=182"}],"version-history":[{"count":1,"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/posts\/182\/revisions"}],"predecessor-version":[{"id":2794,"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/posts\/182\/revisions\/2794"}],"wp:attachment":[{"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/media?parent=182"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/categories?post=182"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/tags?post=182"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}