Feeds:
Posts
Comments

In order to allow developer to use translator instance into validators, Zend Framework 2.2 add a new service call MvcTranslator, as quoted in documentation:

“A new service has also been registered with the MVC, MvcTranslator, which will return this specialized, bridge instance.

Most users should see no issues, as Zend\Validator\ValidatorPluginManager has been modified to use the MvcTranslator service internally, which is how most developers were getting the translator instance into validators in the first place. You will only need to change code if you were manually injecting the instance previously.”

However, we used to set the locale by a manually injected translator to allow users switching to different languages. After upgraded to 2.2.2 or later (the latest version at this time is 2.3.1), the switching languages function is no longer working properly.

In order to make sure function works properly no matter the version is, I updated the code to something like:

    public function setLocale($locale) {
        $sm = $this->getServiceLocator();
        if($sm->has("mvcTranslator")){
            $this->translator = $sm->get('mvcTranslator');
            $this->translator->setLocale($locale);
        }else if($sm->has("Translator")){
            $this->translator = $sm->get('translator');
            $this->translator->setLocale($locale);
        }
    }
Advertisements

Some content on this page was disabled on March 8, 2018 as a result of a DMCA takedown notice from Yahoo!. You can learn more about the DMCA here:

https://en.support.wordpress.com/copyright-and-the-dmca/

Continue Reading »

Twitter Typeahead is a fast and effective auto-complete jQuery plugin for form filling.

Twitter Typeahead 插件是一個jQuery 插件,用作快速而有效率的自動填表工具。

In desktop computer, this plugin (Twitter Typeahead) works properly. However, when this plugin is run on a mobile computer, it cannot detect the “blur” event properly. The suggested text cannot be closed when you click outside the suggestion box.

在正常的桌面電腦上,這個Twitter Typeahead插件能正常地運作。可是,一旦放在手機的瀏覽器上運行,卻因無法捕捉到“blur”的事件。如果輕觸瀏覽器的其他地方,無法可以正常關閉“提示列”。

One of the possible method is add a close button “x” to close the suggestion list. I’ve done an ugly example illustrate this: typeahead with close button “x”

其中一個可行的方法,就是在提示清單上加入一個關閉的按鈕”x”,小弟做了個核突的版本:typeahead with close button “x”

只要您修改第849行,
What you need to do is to change line 849:

 dropdown: '<span class="tt-dropdown-menu"></span>'

換成以下,
To

 dropdown: '<span class="tt-dropdown-menu"><a class="tt-dropdown-close" onclick="$(this).closest(\'span\').hide()">x</a></span>'

還有,只要修改CSS就能改善畫面。
If you feel this screen is ugly, what you need is to add CSS file.

如果您在使用Google DoubleClick for publsher(DFP Ad,Google 提供的公開的點擊廣告統計)來管理您自己網站的廣告。在時發覺看不到廣告時,總想找出問題的原因。Google DoubleClick for publisher所使用的程式碼叫做Google Publisher Tag,在運行過程中,會將所發生的問題的時間、狀況記錄下來。

If you are using “Google DoubleClick for publisher” to manage your own advertisement in your website, sometimes you may want to find out the reasons behind when your ads don’t work. The library for managing “Google DoubleClick for Publisher” is called “Google Publisher Tag”. During the operation of “Google Publisher Tag”, every error will be logged into its own logging system.

要如何查看Google Publisher Tag的運行的記錄呢?它放置在googletag.getEventLog().H之內。

The “Google Publisher Tag” store the event log in googletag.getEventLog().H

用Google Chrome打開Console打入以下的指令:
Use google chrome and turn on the “Console” and enter the following command:

console.log(googletag.getEventLog().H.join('\n'));

Google Publisher Tag Log

If you have installed mac port, it’s normal to install python and django under macport.

如果你安裝了macport,很自然地,你希望用macport去安裝python及django。

The latest python installed by macport should be 2.7.3, thus command for installation of python and django are:

由於在macport之下最新的python的版本是2.7.3。故此在macport下安裝python及django的指令:

sudo port install python
sudo port install py27-django

If you have installed previous version of python through macport, you should make sure which one is active, you can use the following command to check:

如果你之前曾用過macport安裝舊版本的python,你可以用以下的指令查看那一個版本才是預設的。

port select --list python

The result should be similar to the following:
如果會跟以下的差不多:

Available versions for python:
	none (active)
	python25-apple
	python26-apple
	python27
	python27-apple

If you want to ask macport to select the python 2.7.3 provided by macport as default python interpreter, you should use the following command:

如果你想指定用macport所提供的python 2.7,你需要用到以下的指令:

sudo port select python python27

If you want to see if you have set the active python interpreter correctly, type the following command to check the path of python:

如果你想測試之前能否成功地指定python interpreter,可以用以下的指令查看python的路徑:

which python

If you selected macport’s python, the path should be:
如果你選的是macport所提供的python,應看到以下的結果:

/opt/local/bin/python

Try to repeat the previous steps if you find the path is different.
如果你發現python的路徑不相同,請重覆以上的步驟。

Now, please check your path to django-admin.py:
現在請查看django-admin.py的路徑,

which django-admin.py

In my computer, the result is:
在我的電腦,django-admin的位置是:

/usr/local/bin/django-admin.py

If you execute django-admin.py, you will find out that python cannot find django.core. The problem is caused from the first line of django-admin.py

如果你執行django-admin.py你會發現python找不到django.core。問題源於django-admin.py的第一句。

#!/usr/bin/python
from django.core import management

if __name__ == "__main__":
    management.execute_from_command_line()

The first line tell shell to use the python installed by mac os instead of using the python provided by macport. Thus, we should use the following command to change the first line:
第一句告知shell使用由mac os所提供的python而不是macport 所提供的python。所以我們須用以下的指令更改第一句:

sudo nano /usr/local/bin/django-admin.py

The updated source code should look like:
更改後的django-admin.py應該是:

#!/opt/local/bin/python
from django.core import management

if __name__ == "__main__":
    management.execute_from_command_line()

Then, you can ran django-admin.py properly.
之後,你就可以正常地運行django-admin.py

However, next time if you update django, please repeat the process again.
下次你更新django時,請重覆整個步驟。

One of my colleague using Internet Explorer 10 to emulate IE 8 Standard mode. During calling slice() method for a String object. It shows the error “slice not found in object”.

我有位同事用Internet Explorer 10去模擬IE 8標準模式。在一句指令中,字串物件上執行slice()方法時,卻發生了問題,Internet Explorer顯示”slice not found in object”

This problem in weird since in microsoft website, it stated that string’s slice method is existed in all versions. (http://msdn.microsoft.com/en-us/library/ie/s4esdbwz(v=vs.94).aspx)
這是個奇怪的情況,因為在微軟的網站內寫著所有版本Internet Explorer都有String slice。

In order to avoid any similar problem, I wrote a custom slice() method whenever slice() is not found as default:
為了避免這問題,我寫了一段指令,當發現在字串物件中找不到slice()時,會用一個自訂的slice()方法.

if(typeof String.prototype["slice"]==="undefined"){String.prototype.slice=function(s,e){var l=this.length;return this.substr(s=s<0?l+s:s,typeof e==='number'?(e<0?l+e:e)-s:l-s)}}