{"id":635,"date":"2013-05-15T20:10:05","date_gmt":"2013-05-15T20:10:05","guid":{"rendered":"http:\/\/www.myfatblog.co.uk\/?p=635"},"modified":"2013-05-15T21:02:44","modified_gmt":"2013-05-15T21:02:44","slug":"preventing-the-sharepoint-context-ribbon-from-appearing","status":"publish","type":"post","link":"http:\/\/www.myfatblog.co.uk\/index.php\/2013\/05\/preventing-the-sharepoint-context-ribbon-from-appearing\/","title":{"rendered":"Preventing the context ribbon from appearing."},"content":{"rendered":"<h1>Selectively preventing the \u2018inconvenient\u2019 context ribbon.<\/h1>\n<p>Quite often I use list views to display summary data to the end users. This data often takes many forms from either a simple single list item displaying information about a site (I use this quite often in project sites.), to a full featured kpi display from multiple list items.<\/p>\n<p>The common issue that I come across is the inconvenient behaviour of the context ribbon when the user clicks on the web part containing my list data. In this instance, because I&#8217;ve stripped out a lot of the default list behaviours in the xslt, the appearance of the context ribbon just serves to confuse the user, as well as highlighting my display web part in a big blue box that again serves no purpose.<\/p>\n<p>Many blogs across the Internet will tell you that resolving this is easy thanks to the way JavaScript defines functions based on \u2018last loaded wins\u2019 theory, with this in mind we can just create blank functions for the key and mouse press events (WpClick() and WpKeyUp()) that come from list view web parts. This does indeed work very well except for when you have more than one list view web part on the page. If you use this method, then all of the web parts lose this functionality. <\/p>\n<p>In my example project page, I have 2 list view web parts, the first is a project summary which uses a single list item to display the name of the project, a description, a link to the project manager and the current RAG status. My second web part is a standard list view of the projects document library for which I want to retain full SharePoint behaviour.<\/p>\n<p><a href=\"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/Preventing-the-SharePoint-context-ribbo_11EE5\/image.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"margin: 5px; border: 0px currentcolor; display: inline; background-image: none;\" border=\"0\" alt=\"image\" src=\"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/Preventing-the-SharePoint-context-ribbo_11EE5\/image_thumb.png\" width=\"523\" height=\"263\" \/><\/a><\/p>\n<p>If we click on either web part, we get the usual blue highlight around the perimeter of the web part, and the context ribbon appears above.<\/p>\n<p><a href=\"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/Preventing-the-SharePoint-context-ribbo_11EE5\/image_3.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"margin: 5px; border: 0px currentcolor; display: inline; background-image: none;\" border=\"0\" alt=\"The context ribbon appearing where we don't want it.\" src=\"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/Preventing-the-SharePoint-context-ribbo_11EE5\/image_thumb_3.png\" width=\"518\" height=\"248\" \/><\/a><\/p>\n<p>So whilst we can\u2019t use the typically suggested method of overriding the functions WpClick() and WpKeyUp(), thankfully jQuery comes to our aid here with some simple DOM manipulation, we have simply to find the Id of our web part and then to remove the onmouseup and onkeyup events from it.<\/p>\n<p>For these sites, the web parts won\u2019t be changing position as the contributors don\u2019t have the rights, so I don\u2019t need to worry about the ID of the web parts changing and we can thus just use the ID generated by SharePoint when the web part was added to the page. If there was a likelihood of the ID changing, then we\u2019d need some fancy jQuery trickery to find our web part ID.<\/p>\n<p>Instead, I\u2019m just going to use the Developer Toolbar in IE and use the \u201cSelect Element by Click\u201d to select the web part and find the ID.<\/p>\n<p><a href=\"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/Preventing-the-SharePoint-context-ribbo_11EE5\/image_4.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"margin: 5px; border: 0px currentcolor; display: inline; background-image: none;\" border=\"0\" alt=\"image\" src=\"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/Preventing-the-SharePoint-context-ribbo_11EE5\/image_thumb_4.png\" width=\"525\" height=\"289\" \/><\/a><\/p>\n<p>Else where on this page I already have some jQuery scripts collecting information from a list in the parent site using Ajax and the SharePoint web services, so I\u2019ve called the following function from the $(document).Ready() delegate, passing in the ID of our web part.<\/p>\n<div id=\"scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:fb3d83ad-302a-4543-ac60-8c81634d5917\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px; padding: 0px; float: none; display: inline;\">\n<pre style=white-space:normal>\r\n<pre class=\"brush: jscript; html-script: true; pad-line-numbers: true; title: ; notranslate\" title=\"\">\r\nfunction removeContextRibbonEvents(webPartID)\r\n{\r\n\tif(webPartID.charAt(0) != &quot;#&quot;)\r\n\t{\r\n\t\twebPartID = &quot;#&quot; + webPartID;\r\n\t}\r\n\t\r\n\t$(webPartID).removeAttr(&quot;onkeyup&quot;).removeAttr(&quot;onmouseup&quot;);\r\n}\r\n<\/pre>\n<\/div>\n<p>&#160;<\/p>\n<p>With that code in place, clicking anywhere on the project information item doesn\u2019t trigger the blue border or the context ribbon. Clicking on the documents list view however behaves as expected.<\/p>\n<p>I hope this proves useful to you.<\/p>\n<p>Paul.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Selectively preventing the \u2018inconvenient\u2019 context ribbon. Quite often I use list views to display summary data to the end users. This data often takes many forms from either a simple single list item displaying information about a site (I use this quite often in project sites.), to a full featured kpi display from multiple list &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/www.myfatblog.co.uk\/index.php\/2013\/05\/preventing-the-sharepoint-context-ribbon-from-appearing\/\">Continue reading<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[29,26,73,31],"tags":[168,105,169],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Preventing the context ribbon from appearing. - Blog of an overweight SharePoint addict<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/www.myfatblog.co.uk\/index.php\/2013\/05\/preventing-the-sharepoint-context-ribbon-from-appearing\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Preventing the context ribbon from appearing. - Blog of an overweight SharePoint addict\" \/>\n<meta property=\"og:description\" content=\"Selectively preventing the \u2018inconvenient\u2019 context ribbon. Quite often I use list views to display summary data to the end users. This data often takes many forms from either a simple single list item displaying information about a site (I use this quite often in project sites.), to a full featured kpi display from multiple list &hellip; Continue reading\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.myfatblog.co.uk\/index.php\/2013\/05\/preventing-the-sharepoint-context-ribbon-from-appearing\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog of an overweight SharePoint addict\" \/>\n<meta property=\"article:published_time\" content=\"2013-05-15T20:10:05+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2013-05-15T21:02:44+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/Preventing-the-SharePoint-context-ribbo_11EE5\/image_thumb.png\" \/>\n<meta name=\"author\" content=\"Cimares\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@cimares\" \/>\n<meta name=\"twitter:site\" content=\"@cimares\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Cimares\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"http:\/\/www.myfatblog.co.uk\/index.php\/2013\/05\/preventing-the-sharepoint-context-ribbon-from-appearing\/\",\"url\":\"http:\/\/www.myfatblog.co.uk\/index.php\/2013\/05\/preventing-the-sharepoint-context-ribbon-from-appearing\/\",\"name\":\"Preventing the context ribbon from appearing. - Blog of an overweight SharePoint addict\",\"isPartOf\":{\"@id\":\"http:\/\/www.myfatblog.co.uk\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\/\/www.myfatblog.co.uk\/index.php\/2013\/05\/preventing-the-sharepoint-context-ribbon-from-appearing\/#primaryimage\"},\"image\":{\"@id\":\"http:\/\/www.myfatblog.co.uk\/index.php\/2013\/05\/preventing-the-sharepoint-context-ribbon-from-appearing\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/Preventing-the-SharePoint-context-ribbo_11EE5\/image_thumb.png\",\"datePublished\":\"2013-05-15T20:10:05+00:00\",\"dateModified\":\"2013-05-15T21:02:44+00:00\",\"author\":{\"@id\":\"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/55ae8f6885bb5b8390dad001f3da83c6\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/www.myfatblog.co.uk\/index.php\/2013\/05\/preventing-the-sharepoint-context-ribbon-from-appearing\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/www.myfatblog.co.uk\/index.php\/2013\/05\/preventing-the-sharepoint-context-ribbon-from-appearing\/#primaryimage\",\"url\":\"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/Preventing-the-SharePoint-context-ribbo_11EE5\/image_thumb.png\",\"contentUrl\":\"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/Preventing-the-SharePoint-context-ribbo_11EE5\/image_thumb.png\"},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/www.myfatblog.co.uk\/#website\",\"url\":\"http:\/\/www.myfatblog.co.uk\/\",\"name\":\"Blog of an overweight SharePoint addict\",\"description\":\"The rantings of a (not so) food obsessed IT consultant!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/www.myfatblog.co.uk\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/55ae8f6885bb5b8390dad001f3da83c6\",\"name\":\"Cimares\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/About_D057\/TopOfTheWorld.jpg\",\"contentUrl\":\"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/About_D057\/TopOfTheWorld.jpg\",\"caption\":\"Cimares\"},\"sameAs\":[\"http:\/\/www.myfatblog.co.uk\"],\"url\":\"http:\/\/www.myfatblog.co.uk\/index.php\/author\/reginald\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Preventing the context ribbon from appearing. - Blog of an overweight SharePoint addict","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":"http:\/\/www.myfatblog.co.uk\/index.php\/2013\/05\/preventing-the-sharepoint-context-ribbon-from-appearing\/","og_locale":"en_US","og_type":"article","og_title":"Preventing the context ribbon from appearing. - Blog of an overweight SharePoint addict","og_description":"Selectively preventing the \u2018inconvenient\u2019 context ribbon. Quite often I use list views to display summary data to the end users. This data often takes many forms from either a simple single list item displaying information about a site (I use this quite often in project sites.), to a full featured kpi display from multiple list &hellip; Continue reading","og_url":"http:\/\/www.myfatblog.co.uk\/index.php\/2013\/05\/preventing-the-sharepoint-context-ribbon-from-appearing\/","og_site_name":"Blog of an overweight SharePoint addict","article_published_time":"2013-05-15T20:10:05+00:00","article_modified_time":"2013-05-15T21:02:44+00:00","og_image":[{"url":"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/Preventing-the-SharePoint-context-ribbo_11EE5\/image_thumb.png"}],"author":"Cimares","twitter_card":"summary_large_image","twitter_creator":"@cimares","twitter_site":"@cimares","twitter_misc":{"Written by":"Cimares","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"http:\/\/www.myfatblog.co.uk\/index.php\/2013\/05\/preventing-the-sharepoint-context-ribbon-from-appearing\/","url":"http:\/\/www.myfatblog.co.uk\/index.php\/2013\/05\/preventing-the-sharepoint-context-ribbon-from-appearing\/","name":"Preventing the context ribbon from appearing. - Blog of an overweight SharePoint addict","isPartOf":{"@id":"http:\/\/www.myfatblog.co.uk\/#website"},"primaryImageOfPage":{"@id":"http:\/\/www.myfatblog.co.uk\/index.php\/2013\/05\/preventing-the-sharepoint-context-ribbon-from-appearing\/#primaryimage"},"image":{"@id":"http:\/\/www.myfatblog.co.uk\/index.php\/2013\/05\/preventing-the-sharepoint-context-ribbon-from-appearing\/#primaryimage"},"thumbnailUrl":"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/Preventing-the-SharePoint-context-ribbo_11EE5\/image_thumb.png","datePublished":"2013-05-15T20:10:05+00:00","dateModified":"2013-05-15T21:02:44+00:00","author":{"@id":"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/55ae8f6885bb5b8390dad001f3da83c6"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.myfatblog.co.uk\/index.php\/2013\/05\/preventing-the-sharepoint-context-ribbon-from-appearing\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.myfatblog.co.uk\/index.php\/2013\/05\/preventing-the-sharepoint-context-ribbon-from-appearing\/#primaryimage","url":"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/Preventing-the-SharePoint-context-ribbo_11EE5\/image_thumb.png","contentUrl":"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/Preventing-the-SharePoint-context-ribbo_11EE5\/image_thumb.png"},{"@type":"WebSite","@id":"http:\/\/www.myfatblog.co.uk\/#website","url":"http:\/\/www.myfatblog.co.uk\/","name":"Blog of an overweight SharePoint addict","description":"The rantings of a (not so) food obsessed IT consultant!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/www.myfatblog.co.uk\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/55ae8f6885bb5b8390dad001f3da83c6","name":"Cimares","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/image\/","url":"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/About_D057\/TopOfTheWorld.jpg","contentUrl":"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/About_D057\/TopOfTheWorld.jpg","caption":"Cimares"},"sameAs":["http:\/\/www.myfatblog.co.uk"],"url":"http:\/\/www.myfatblog.co.uk\/index.php\/author\/reginald\/"}]}},"_links":{"self":[{"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/635"}],"collection":[{"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/comments?post=635"}],"version-history":[{"count":17,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/635\/revisions"}],"predecessor-version":[{"id":652,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/635\/revisions\/652"}],"wp:attachment":[{"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/media?parent=635"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/categories?post=635"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/tags?post=635"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}