We can find plenty of answers about how to check if an element is visible. In my case the one which works with opacity, and into a scrollable area, is this one (that I have optimized): function isScrolledIntoView(el, holder) { var bndElem = el.getBoundingClientRect(); var bndHolder = holder.getBoundingClientRect(); return bndElem.top <= bndHolder.top ? !(bndHolder.top – […]
Auteur/autrice : Aymeric
Resolve Promise one after another, in sequence
Below is the code that is handy when you want to execute several Promise actions in sequence: function PromiseChain(arr, fct) { var dfd = Promise.resolve(); var res = arr.map(function(item,idx) { dfd = dfd.then(function() { return fct(item,idx) }); return dfd }); return Promise.all(res) } // for short version: // function PromiseChain(n,r){var e=Promise.resolve(),i=n.map(function(n,i){return e=e.then(function(){return r(n,i)})});return Promise.all(i)} And […]
Deep clone an object in JavaScript
We can find many discussions and solutions about this issue. In my case the one that worked is this code. Below you’ll find a compressed version of the extend() function (with a fix): function extend(){var r,t,n,o,e=arguments[0]||{},f=1,i=arguments.length,u=!1,y=function(r){if(null===r|| »object »!=typeof r||r.nodeType||null!==r&&r===r.window)return!1;try{if(r.constructor&&!this.hasOwnProperty.call(r.constructor.prototype, »isPrototypeOf »))return!1}catch(t){return!1}return!0};for(« boolean »==typeof e&&(u=e,e=arguments[f]||{},f++), »object »!=typeof e&& »function »!=typeof e&&(e={}),!1;i>f;f+=1)if(null!==(r=arguments[f]))for(t in r)e!==r[t]&& »undefined »==typeof e[t]&&(u&&r[t]&&(y(r[t])||(n=Array.isArray(r[t])))?(n?(n=!1,o=e[t]&&Array.isArray(e[t])?e[t]:[]):o=e[t]&&y(e[t])?e[t]:{},e[t]=extend(u,o,r[t])):void 0!==r[t]&&(e[t]=r[t]));return e} And here an example: var object_a = { value_1: ‘a’, […]
Check permissions in Sharepoint based on a PermMask
In some cases you could get this kind of hexadecimal numbers from Sharepoint for the PermMask: 0xb008431061, or 0x1b03c4313ff, and so on. To verify the PermMask against the different level of permissions you can proceed with the below method (using functions from core.js): var permMask = ‘0x1b03c4313ff’; var permissions = new SP.BasePermissions(); permissions.initPropertiesFromJson({High:GetPermMaskH(permMask), Low:GetPermMaskL(permMask)}); // […]
Decode Sharepoint unicode URL
Sharepoint encodes the URLs with unicode, so we’ll see many \u002f to represent /. If you want to decode those unicode strings, you can use this short code: unescape(JSON.parse(‘ »‘ + s.replace(‘ »‘, ‘\\ »‘) + ‘ »‘))
Redirect after Deleting [Sharepoint]
When I open a dialog for an EditFrom and use the « Delete Item » button from the ribbon, then the main page is redirected to the related Sharepoint list. This behavior is very bad for the user experience. To change it I used the below Javascript code: // replace the Delete Item default action when into […]
How to open an Excel document from SharePoint into Chrome/Firefox in readonly/edit mode
With Sharepoint 2010, when you use Internet Explorer you can open an Office document in readonly or in edit mode. Also, when trying to open an Excel file in Firefox/Chrome it will probably open the ugly xslviewer and won’t let you deal with your file. After searching a bit about it, I found a clue […]
[2] Bypass a lookup field not displayed because of threshold on NewForm and EditForm [Sharepoint 2013]
This is an update of this article. This time the JS Link file’s content is the one below: // loadExt permits to load JS and CSS files // https://gist.github.com/Aymkdn/98acfbb46fbe7c1f00cdd3c753520ea8 function loadExt(e,t){var s=this;s.files=e,s.js=[],s.head=document.getElementsByTagName(« head »)[0],s.after=t||function(){},s.loadStyle=function(e){var t=document.createElement(« link »);t.rel= »stylesheet »,t.type= »text/css »,t.href=e,s.head.appendChild(t)},s.loadScript=function(e){var t=document.createElement(« script »);t.type= »text/javascript »,t.src=s.js[e];var a=function(){++e<s.js.length?s.loadScript(e):s.after()};t.onload=function(){a()},s.head.appendChild(t)};for(var a=0;a<s.files.length;a++)/\.js$|\.js\?/.test(s.files[a])&&s.js.push(s.files[a]),/\.css$|\.css\?/.test(s.files[a])&&s.loadStyle(s.files[a]);s.js.length>0?s.loadScript(0):s.after()} (function() { // some « global » variables var lookupFieldsToFix = []; var storageThrottledLookup = localStorage.getItem(« ThrottledLookup »); if (storageThrottledLookup) storageThrottledLookup=JSON.parse(storageThrottledLookup); // onLoad() […]
Yes, you can be lazy and get more than 5000 SharePoint Items
To reply to this blog post I wanted to share the same thing but with SharepointPlus. To use the paging option and get all the content from a large Sharepoint list you can simply do the below code: $SP().list(« My List »).get({ fields: »ID,Title », rowlimit:5000, paging:true, progress:function progress(nbItemsLoaded) { // for each new page this function will be […]
Détecter si le Freebox Player est allumé ou éteint (en veille) via les API de Free [Programmation]
Il n’existe pas de commande directe qui permette de savoir si le Player est éteint (en veille) ou allumé… Cependant il existe une astuce qui consiste à faire une requête en utilisant les paramètres suivants : { url: »http://mafreebox.freebox.fr/api/v3/airmedia/receivers/Freebox%20Player/ », headers:{ « X-Fbx-App-Auth »: client.app.session_token }, method: »POST », json: { « action »: »stop », « media_type »: »video » }, encode: »utf-8″ } La Freebox va alors retourner […]