Catégorie : Programmation

Dynamically inject a CSS code into the page [JavaScript]

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 } »)

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) })

Show the full content of a Sharepoint Calendar event box

With a Sharepoint Calendar the events with a long title/description are cropped and you cannot see the full description, except if you move your mouse over it. Example: So I’ve had to do some CSS and a complicated JavaScript code to be able to create some large boxes. Now we are able to see the […]

Override SharePoint OOTB Upload.aspx default for « Add as a new version to existing files » checkbox

With Sharepoint, when we want to upload a file, the « Add as a new version to existing file » is checked by default, and that could be an issue for you. Here is a JavaScript fix to add into your masterpage, just before the </head> tag : <script type= »text/javascript »> function DefaultUploadOverwriteOff() { if (document.title.indexOf(« Upload Document ») > […]

Requête MySQL insensible aux accents

Pour effectuer une requête MySQL qui ne sera pas sensible aux accents (par exemple ‘ö’ = ‘o’ ou ‘à’ = ‘a’) il faut rajouter le mot clé COLLATE avec la bonne collection. Après plusieurs tests, j’utilise la collection utf8_general_ci. Ce qui donnera : SELECT ID, Nom FROM Inscrits WHERE Nom LIKE ‘%heracles%’ COLLATE utf8_general_ci ORDER […]

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 […]

Encode accented characters of an URL to the hexadecimal version [PHP]

I’m facing an issue with some accented characters (like ‘é’, ‘è’, ‘à’, …) in an URL and I wanted to convert them to an hex value in PHP. I found nothing on Google so I have finally created my own function for my needs : function encodeURIHex($str) { $len=strlen($str); $ret= » »; for ($i=0; $i 191 && […]

Vérifier du code HTML en PHP

Supposons que vos utilisateurs peuvent entrer du code HTML et que vous souhaitiez vous assurer que les tags sont correctement fermés. Alors vous pouvez utiliser PHP pour faire ça : $codeUtilisateur = ‘<p><b>Mon texte</b>’; // il manque ‘</p>’ $doc = new DOMDocument(); // on utilise DOMDocument qui est installé par défaut avec PHP $doc->loadHTML($codeUtilisateur); $codeRetour […]

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 […]