{"id":1562,"date":"2015-11-02T16:16:32","date_gmt":"2015-11-02T15:16:32","guid":{"rendered":"http:\/\/blog.kodono.info\/wordpress\/?p=1562"},"modified":"2015-11-02T16:18:21","modified_gmt":"2015-11-02T15:18:21","slug":"how-to-expand-sharepoint-2013-calendar-by-default-javascript","status":"publish","type":"post","link":"https:\/\/blog.kodono.info\/wordpress\/2015\/11\/02\/how-to-expand-sharepoint-2013-calendar-by-default-javascript\/","title":{"rendered":"How to expand Sharepoint 2013 calendar by default [JavaScript]"},"content":{"rendered":"<p>This code has been tested for Sharepoint 2013 only. It permits to expand by default (so as soon as the page is loaded) the events in the Month calendar view.<\/p>\n<p><a href=\"http:\/\/blog.kodono.info\/wordpress\/2014\/12\/18\/how-to-expand-sharepoint-2010-calendar-by-default-javascript\/\">See here a solution for Sharepoint 2010<\/a>.<\/p>\n<p>Tested with IE8 and Firefox 41. You&#8217;ll have to add the below JavaScript code into your calendar page:<\/p>\n<pre class=\"brush:javascript\">\r\n\/\/ the below function simulate a click on a link\r\nfunction fireEventClick(elem){\r\n    if(document.createEvent){                                                 \r\n      var e = document.createEvent('MouseEvents');\r\n      e.initMouseEvent('click', \/* Event type *\/\r\n      true, \/* Can bubble *\/\r\n      true, \/* Cancelable *\/\r\n      document.defaultView, \/* View *\/\r\n      1, \/* Mouse clicks *\/\r\n      0, \/* Screen x *\/\r\n      0, \/* Screen y *\/\r\n      0, \/* Client x *\/\r\n      0, \/* Client y *\/\r\n      false, \/* Ctrl *\/\r\n      false, \/* Alt *\/\r\n      false, \/* Shift *\/\r\n      false, \/* Meta *\/\r\n      0, \/* Button *\/\r\n      null); \/* Related target *\/\r\n      elem.dispatchEvent(e);                     \r\n    } else { \/\/ pour IE\r\n      elem.click();\r\n    }\r\n}\r\n\r\n\/\/ Expand the events\r\n\/\/ because Sharepoint redraw ALL the events when we click on Expand, then we need a special recurrent function\r\nfunction ExpandEvents(idx) {\r\n  var a = document.querySelectorAll('a[evtid=\"expand_collapse\"]');\r\n  if (idx &lt; a.length) {\r\n    if (a[idx].parentNode.getAttribute(\"_expand\") !== \"collapse\") fireEventClick(a[idx]);\r\n    ExpandEvents(++idx);\r\n  }\r\n}\r\n\r\nfunction onCalendarGridsRendered(){\r\n  setTimeout(function() {\r\n    ExpandEvents(0)\r\n  }, 250)\r\n}\r\n\r\n\/\/ some code reused from http:\/\/www.codeproject.com\/Tips\/759006\/Enhancing-SharePoint-Calendar-sp-ui-applicationpag\r\nSP.SOD.executeOrDelayUntilScriptLoaded(function () {\r\n    \/\/Week or Day Calendar View\r\n    SP.UI.ApplicationPages.DetailCalendarView.prototype.renderGrids_Old = SP.UI.ApplicationPages.DetailCalendarView.prototype.renderGrids;\r\n    SP.UI.ApplicationPages.DetailCalendarView.prototype.renderGrids = function SP_UI_ApplicationPages_DetailCalendarView$renderGrids($p0) {\r\n      this.renderGrids_Old($p0);\r\n      onCalendarGridsRendered();\r\n    };\r\n    \r\n    \/\/Month Calendar View\r\n    SP.UI.ApplicationPages.SummaryCalendarView.prototype.renderGrids_Old = SP.UI.ApplicationPages.SummaryCalendarView.prototype.renderGrids;\r\n    SP.UI.ApplicationPages.SummaryCalendarView.prototype.renderGrids = function SP_UI_ApplicationPages_SummaryCalendarView$renderGrids($p0) {\r\n      this.renderGrids_Old($p0);\r\n      onCalendarGridsRendered();\r\n    };\r\n    \r\n    ExpandEvents(0)\r\n}, \"SP.UI.ApplicationPages.Calendar.js\");\r\n<\/pre>\n<p>And we can hide the &#8220;Collapse&#8221; links with one line of CSS:<\/p>\n<pre class=\"brush:css\">\r\n.ms-cal-nav[evtid=\"expand_collapse\"] { display: none !important }\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This code has been tested for Sharepoint 2013 only. It permits to expand by default (so as soon as the page is loaded) the events in the Month calendar view. See here a solution for Sharepoint 2010. Tested with IE8 and Firefox 41. You&#8217;ll have to add the below JavaScript code into your calendar page: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","hide_page_title":"","footnotes":""},"categories":[13,33],"tags":[24,152,117,166],"class_list":["post-1562","post","type-post","status-publish","format-standard","hentry","category-niveau-intermediaire","category-programmation","tag-javascript","tag-niveau-intermediaire","tag-sharepoint","tag-sharepoint-2013"],"_links":{"self":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts\/1562","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/comments?post=1562"}],"version-history":[{"count":3,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts\/1562\/revisions"}],"predecessor-version":[{"id":1566,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts\/1562\/revisions\/1566"}],"wp:attachment":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/media?parent=1562"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/categories?post=1562"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/tags?post=1562"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}