On Sharepoint 2013 I was trying to hide a field (the complete row) based on some elements into its description. To do so we will call our file using the JSLink (see my previous post about it). The JS file looks like that: (function() { // do some actions as soon as the fields are […]
Étiquette : javascript
Load a script once a DispForm is fully shown in Sharepoint 2013
Sharepoint 2013 introduced the JSLink. This is very useful to play with forms and views. My attempt here is to remove some rows from the DispForm. To do so I needed to trigger an action as soon as the fields rendering has been done. After different tries, I finally came up with the PostRender option. […]
Play with ribbon on Sharepoint
In Sharepoint 2010 and 2013, there are some existing functions to deal with the ribbon. Below an example of what we can do: // we need the file « sp.ribbon.js » SP.SOD.executeOrDelayUntilScriptLoaded(function () { // use PageManager var pm = SP.Ribbon.PageManager.get_instance(); // define a function to call when the ribbon is loaded var DoSomethingWithRibbon=function(ribbon) { // For […]
Quickly find if an object is an array [JavaScript]
You could use Array.isArray(obj) but it’s not available for IE8 and it doesn’t seem very good on the performance side. The best one on the different browsers is to test: obj instanceof Array
Pure Javascript Drag and Drop cross browser from IE8
I was looking for a simple JavaScript to drag a div element around, and that would work with IE8 and without any third party libraries (like jQuery). It’s been very difficult to find a simple code ! Finally http://news.qooxdoo.org/mouse-capturing saved me with some code… but there was still a problem with IE8 due to the […]
How to expand Sharepoint 2013 calendar by default [JavaScript]
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’ll have to add the below JavaScript code into your calendar page: […]
Transform pseudo currency to number in JavaScript
In JavaScript I want to change some formatted numbers to a regular number. The code might be look like that: var aNb=[ 1500, « 1,500 », « 15,00 », « 1,500,000 », « 1,500,000.25 », « 1000.25 », « 1 000 000 »]; for (var i=0; i < aNb.length; i++) { var nb = aNb[i] + « »; if (nb.split(« , »).length <= 2) nb = nb.replace(/,(\d{2})$/, ».$1″); nb = nb.replace(/[^\d\.\-]/g, […]
Détecter la version d’IE [JavaScript]
Via http://tanalin.com/en/articles/ie-version-js/ on trouve un moyen simple de détecter la version d’IE : var IE8 = !!(document.all && document.querySelector && !document.addEventListener); // -> true/false var IE9 = !!(document.all && document.addEventListener && !window.atob); // -> true/false var IE10 = !!(document.all && window.atob); // -> true/false On peut aussi utiliser les conditionals compilation: var ieVersion = /*@cc_on […]
Get window/viewport/document height and width [JavaScript]
Via andylangton and james.padolsey we can find the viewport and document height/width in JavaScript: function getPageSize() { var vw = {width:0, height:0}; var doc = {width:0, height:0}; var w=window, d=document, dde=d.documentElement, db=d.getElementsByTagName(‘body’)[0]; // viewport size vw.width = w.innerWidth||dde.clientWidth||db.clientWidth; vw.height = w.innerHeight||dde.clientHeight||db.clientHeight; // document size doc.width = Math.max(db.scrollWidth, dde.scrollWidth, db.offsetWidth, dde.offsetWidth, db.clientWidth, dde.clientWidth); doc.height = Math.max(db.scrollHeight, […]
Autosize a text to fit into a div in pure/native JavaScript
I was looking for a very tiny and light solution to fit a text inside a box. The box’ height and width are fixed. I only found some great solutions like BigText but I didn’t want to have jQuery loaded. Finally I found some code on StackOverflow and also at Coderwall. I created my own […]