Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Mar 12, 2016

Javascript pow() function

In Javascript if you want to rise a number to a power then you have to use one of the functions from Math module: Math.pow()

The Math.pow() function returns the base to the exponent power, that is, base exponent.

Syntax

Math.pow(base, exponent)

Parameters

base
The base number.
exponent
The exponent used to raise the base.

Description

Because pow() is a static method of Math, you always use it as Math.pow(), rather than as a method of aMath object you created (Math has no constructor).
Examples:
Math.pow(4,3);   // 4 * 4 * 4 = 48

Nov 9, 2015

HTML5 mobile app

I tried to develop an mobile app using HTML5 on Intel SDK. The app is quite ok on my old mobile phone a Samsung 6 years old. But on my actual phone which is an Nexus 5 the app has the font too small and the images are too small, as  well. So, I started to a lot of documentation on internet and I had to accumulate a lot of frustration with it. Nothing to help me, indeed. A lot of solutions consisting in modifying css to build 2 or 3 files for css just to increase the font when you have high density of pixels as for Retina display.
But, some of the solutions were with  viewport solution. But most of them haven't work for me.
And, after 3 day research I found something that helped me.

This page helped me: http://ariya.ofilabs.com/2011/08/mobile-web-logical-pixel-vs-physical-pixel.html
But they have something wrong in their code. So, I had to modify this to work well for me.

For Android, we apply the density DPI approach and now it becomes:
Here I had to modify like this:

2 maximum-scale=2 user-scalable=no”> 
And, also, I had to use this javascript function at onLoad body:
function schimbaPixelii(){
    var el, width, height;
    if (window.devicePixelRatio === 1) {
    if (window.innerWidth === 2 * screen.width ||
        window.innerWidth === 2 * screen.height) {
        el = document.getElementById('viewport');
        el.setAttribute('content', 'width=device-width, target-densityDpi=device-dpi ' +
            'initial-scale=1, maximum-scale=1, user-scalable=no');
        document.head.appendChild(el);
        width = window.innerWidth;
        height = window.innerHeight;
        if (width === 2 * screen.width) {
            width /= 2;
            height /= 2;
        }
    }
}
}

Jul 23, 2015

Javascript redirect for mobile devices

The best method to redirect for mobile that I found is following:


<script type="text/javascript">
if (screen.width < 1081) {
 var ref = document.referrer;
 var urls = new Array("http://www.mymainsite.com","http://m.mymobilesite.com");
 var n = ref.match(urls[0]);
 var m = ref.match(urls[1]);
 if ((m!==null) || (n!==null)) {
 stop;
 }
 else if (ref=='') {
 var r = confirm("Small Display is Detected.\nClick \"OK\" for MOBILE SITE.");
 if (r==true) {
  window.location = "http://m.mymobilesite.com";
  }
  else {
  stop ;
 }
 }
 else
 {
 window.location = "http://m.mymobilesite.com";
 } 
}
</script>

Angular JS

Last days I was struggling with implementation of Angular JS on one  my websites: www.pensiunealajura.ro/mobil/

The big issue with this was to list HTML code without listing HTML tags like < or >. For instance, I wanted to have

    This is a bold text.

not

  This is a <b>bold text</b>.

So, I tried to have this with the module ngSanitize and $sanitize and $sce with  $sce.trustAsHtml.

But all of these were not good. And i dug more. And I found out that the best way to write formatted HTML code into a web page using Angular JS  is using directive ngBindHtml as is explained here: 
https://docs.angularjs.org/api/ng/directive/ngBindHtml

Now, everything is ok with my page.
:)

Feb 28, 2012

New project

Today, we lance a new project. It is BETA version. But the website is Up. It's about http://www.dentaldirectorylinks.com. It is a link directory with/for dentists and dental network in the world.

It's all withh html, css javascript, jQuery, Mysql and PHP.

Jan 26, 2012

The best Rich Text Editors to use in web CMS

I found an nice article about Rich Text Editors to use in HTML with PHP. It's about Yahoo! UI Library: Rich Text Editor, FCKeditors and others.


The article is not so newest but it's helpfuly: http://woork.blogspot.com/2009/02/best-rich-text-editors-ready-to-use-in.html