Mozilla created a function that permits to inject some CSS into the document: addStylesheetRules() But if you use jQuery you may want to use this function: function injectCSS(rule) { $(« head »).append(‘<style>’ + rule + ‘</style>’) } // example injectCSS(« div { padding:5px } »)
Étiquette : javascript
Tiny AJAX
This is a very tiny javascript code to do an AJAX Request: /* m: method (« get », « post ») u: url a: async (true) or sync (false) c: callback (with ‘xhr’ as a parameter) d: post_data (the data to post) */ function tiny_ajax(m,u,a,c,d){with(new(this.XMLHttpRequest||ActiveXObject)(« Microsoft.XMLHTTP »))onreadystatechange=function(){readyState^4||c(this)},open(m,u,a),send(d)} And an example: tiny_ajax(‘get’, ‘http://www.google.com’, true, function(xhr) { alert(xhr.responseText) })
Google Analytics : les recommandations de la CNIL [JavaScript]
La loi a changé concernant les cookies déposés chez les utilisateurs. Pour cela la CNIL a créé une page qui explique ce qu’il en est. Ils proposent même un bout de code pour le opt-in et le opt-out, que j’ai légèrement modifié : // Remplacez la valeur UA-XXXXXX-Y par l’identifiant analytics de votre site. var […]
Simple Org Chart in HTML/CSS/JS for Sharepoint
In my job I’ve had to create an organizational chart on our Sharepoint. Find more on the Github Repository I opened for this little project: OrgChart-JS-Sharepoint
Sharepoint 2010 and IE in standard mode (issues with IE9/IE10)
I wanted to have a masterpage for Sharepoint 2010 with a HTML5 Doctype… unfortunately Sharepoint 2010 has been coded without standards, so lot of things are now broken. I spent some time to find the broken functions. I’ve created a file that is called just after <SharePoint:ScriptLink language= »javascript » name= »core.js » OnDemand= »true » runat= »server »/>, and you can download […]
gRaphaël pie chart animated to change the values [JavaScript]
I wanted to be able to change the values for a pie chart created with gRaphaël. After some tries I finally created a new method called changeValues that is available in my fork of gRaphaël. Below is an example: Move your mouse over one slice from the first chart to see the second one that […]
JavaScript APIs you’ve never heard of (And some you have)
From this video I’ve discovered several JS API I didn’t know. Let’s list them: 1) Use children instead of childNodes to list the children nodes of a DOM element: <ul> <li>Hello</li> <li>world</li> <li>!</li> </ul> <script> document.getElementById(‘test’).childNodes.length; // 7 -> because it also returns the text nodes document.getElementById(‘test’).children.length; // 3 </script> Support: all browsers, but from […]
Raphaëljs plugins for different charts [gRaphaël]
There is gRaphaël that provides several useful plugins to create some different charts like the pie charts, the line charts and so on, based on the Raphaël JS library. unfortunately, the owner doesn’t update his files very often, even if there are several pull requests from the users. So I decided to fork the main […]
How to trigger the window.resize event on IE8
For the modern browsers it’s easy to fire the window.resize event, but not for IE8…. After several hours of searching, I didn’t find anything. The only solution I found is the one to resize the HTML that will trigger the event: function triggerEvent(element, eventName) { var event; if (document.createEvent) { event = document.createEvent(« HTMLEvents »); event.initEvent(eventName, true, […]
WebPart doesn’t work with IE8 in standard mode under Sharepoint 2010
The Microsoft developers are not really good, and we can see it if you use IE8 in standard mode with Sharepoint 2010: the web parts don’t work anymore due to an error with the wpadder.js file. After few hours trying to find the problem I’ve finally discovered that the WPAdder class uses the for..in statement […]