Tuesday, November 26, 2013

Clear format for Kendo editor

Kendo UI with a clearing format function.

How?

  1. When text was selected the button will active then deactivate it!
  2. Clear style customly.. recommended font,color,background
  3. Keep history when undo (Ctrl + Z)
    • exec function will keep history for each executed
  4. Enjoy!
(http://jsfiddle.net/cetU3/)

Wednesday, September 26, 2012

My rewrite url for apache and iis

This rewrite will remove index.php from URL

Apache
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]



IIS (edit web.config file)
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Imported Rule 1" stopProcessing="true">
          <match url="^(.*)$" ignoreCase="false" />
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
          </conditions>
          <action type="Rewrite" url="index.php/{R:1}" appendQueryString="true" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

note: if you use iis7, you should try IIS7 URLRewrite module

Monday, September 24, 2012

[JS] Youtube video uploading api using oauth 2.0 method step by step

There are 2 method for uploading video, one is Direct uploading and here is Browser-based uploading

Here is the flow for Browser-based uploading method
(https://developers.google.com/youtube/2.0/developers_guide_protocol_browser_based_uploading#Browser_Upload_Process)

1. Signup google account
2. Create your client_id then assign redirect_uri
3. Create your developer_key
4. Try my example code :)
  • authenticate & get access token
  • send video metadata(title,description,category,keywords,developertags) & get upload access token
  • now you can upload the video
Download

Important!
your upload will not show in feed immediately google has delay in searching your upload by using the api

[JS] Simple countdown

Adapt from here

source code
var tinterval=1000/250fnCountdown=null;

function component(x,v){
    return Math.floor(x/v);
}
function countDown(){
    t=t-interval;
    var days component(t24 60 60 1000),
        hours component(t60 60 100024,
        minutes component(t60 100060,
        seconds component(t100060,
        milliseconds 1000;
    if(t<=500){
        $('#countdown').html('Over!!');
        clearInterval(fnCountdown);
    }
    else{
        if(days<10days '0'+days;
        if(hours<10hours '0'+hours;
        if(minutes<10minutes '0'+minutes;
        if(seconds<10seconds '0'+seconds;
        milliseconds (milliseconds+'').substr(0,3);
        //if(milliseconds<10) milliseconds= '00'+milliseconds;
        //else if(milliseconds<100) milliseconds= '0'+milliseconds;
        $('#countdown').html(days ' : ' hours ' : ' minutes ' : ' seconds '.' milliseconds);
    }
}

example (http://jsfiddle.net/X8MXr/)
<div id="countdown"></div>
<script>
var start=new Date('2012/01/20 10:00:00'),
    end=new Date('2012/01/20 10:01:00');
t=end-start;

fnCountdown=setInterval(function(){countDown();}interval);
</script>

Sunday, September 23, 2012

[CSS] @fontface tools

Auto hinting TTF font with several options (now is better support for GDI ClearType)
http://www.freetype.org/ttfautohint/

ttf to eot (eot format work in IE6, IE7, IE8, Safari 3/4 and Firefox 3.1+)
http://eotfast.com/
EOTFAST-1 myFont.ttf
http://code.google.com/p/ttf2eot/
ttf2eot myFont.ttf

ttf to woff
http://people.mozilla.com/~jkew/woff/
sfnt2woff myFont.ttf

ttf to svg
http://xmlgraphics.apache.org/batik/index.html
java -jar batik-ttf2svg.jar myFont.ttf -l 32 -h 63616 -id MySVGFont -o myFont.svg

Various webfont for your site & webfont generator
http://www.fontsquirrel.com/

Example to use google urlshortener

source code
var sUrl={
    fn:null,
    url:'',
    create:function(u,cb){
        sUrl.fn=null;
        sUrl.url='';
        sUrl.fn=setInterval(function(){
            if(sUrl.url!=''){
                sUrl.clear();
                cb(sUrl.url);
                return;
            }
            sUrl.get(u);
        },500);
    },
    get:function(u){
        if(sUrl.url!=''return;
        var request=gapi.client.urlshortener.url.insert({'resource':{'longUrl':u}});
        request.execute(function(resp){
            if(typeof(resp.id)!='undefined'){
                sUrl.url=resp.id;
            }
            else{
                sUrl.url=u;
            }
        });
    },
    clear:function(){
        clearInterval(sUrl.fn);
    }
};

example (http://jsfiddle.net/ueszM/1/)
<script>
function initGAPI(){
    gapi.client.load('urlshortener''v1');
}

function getUrl(){
    sUrl.create(document.getElementById('url').value,function(u){
        alert(u);
    });
}

</script>
<script src="https://apis.google.com/js/client.js?onload=initGAPI"></script>

<input id="url" value="http://www.google.com" />
<href="#" onclick="getUrl();return false;">get url</a>