2017年5月26日 星期五

$.closestChildren 找到符合過濾條件最接近的子孫

 //for backbone(取代 find)
(function ($) {
    // 找到符合過濾條件最接近的子孫
    $.fn.closestChildren = function (selector) {
        debugger;
        var self = this;
        this.each(function (i, dom) {

            $find = $.closestChildren(dom, selector);
            self[i] = $find.get(0);
        });
        /*------------------------------------*/
        var resultList = this.toArray().filter(function (item) {
            return (item != null);
        });
        for (var i = 0; i < this.length; i++) {
            if (resultList[i]) {
                this[i] = resultList[i];
            } else {
                delete this[i];
            }
        }

        this.length = resultList.length;
      
        return this;
    };
    /* ====================================================================== */
    $.closestChildren = function (dom, selector) {
        var domList = [];
        var target = find(dom);
        /* ---------------------------------- */
        if (target.length) {
            // 第一輪就找到
        } else {
            // 廣域搜尋
            for (var i = 0; i < domList.length; i++) {
                target = find(domList[i]);
                if (target.length > 0) {
                    break;
                }
            }
        }
        /* ---------------------------------- */
        function find(dom) {
            var $findList = $(dom).children(selector);

            if ($findList.length) {
                // 有找到
            } else {
                // 沒找到
                var childList = $(dom).children().toArray();
                domList = domList.concat(childList);
            }
            return $findList;
        }

        domList = [];
        return target;
    };
})(jQuery);

(js)編寫含式變項,常會遇到的問題

function test_1() {
            var data = {};

            var y;
            if(data.age){
                    y = data.age;
            }else{
                y = 5
            }

            alert(y);
        }

        function test_2() {
            var data = [];

            var y;

             if(data[0]){
                 y = data[0];
             }else{
                 y = 5;
             }

            alert(y);
        }

function test_3() {           
            var data;

            var y;

            // 以下不行
            if(data.age){
                    y = data.age;
            }else{
                y = 5
            }

            alert(y);
        }

2017年5月25日 星期四

alert視窗如何換行?

在要斷行的地方插入一個 "\n" , 要斷幾行就插幾個 "\n

<script>
alert("第一行\n第二行\n\n第四行")
</script>

2017年5月16日 星期二

mustache

if
{{#print}}
    {{#beatles}}
        <p>{{name}}</p>
    {{/beatles}}
{{/print}}
------------------------------------
else
{{^print}}
    {{#beatles}}
        <p>no print: {{name}}</p>
    {{/beatles}}
{{/print}}

viewData =
{
            print: true,
            beatles: [
                { "firstName": "John", "lastName": "Lennon" },
                { "firstName": "Paul", "lastName": "McCartney" },
                { "firstName": "George", "lastName": "Harrison" },
                { "firstName": "Ringo", "lastName": "Starr" }
            ],
            name: function () {
                return this.firstName + " " + this.lastName;
            }
        }

2017年5月15日 星期一

atom 設定

'.platform-win32':
    'ctrl-\\': 'unset!'
    'ctrl-alt-l': 'unset!'
    'ctrl-`':'tree-view:toggle'
    'alt-`':'symbols-list:toggle'

'atom-text-editor':
    'ctrl-space': 'unset!'
    'ctrl-\\': 'autocomplete-plus:activate'
    # 'ctrl-\\': 'autocomplete:toggle'
    'alt-/': 'autocomplete:toggle'

'.active.pane':
    'alt-\'': 'autocomplete:toggle'


'atom-workspace':
    'ctrl-alt-g': 'git-control:toggle'

 

comic mono,jetbrains mono nl, Menlo, Consolas, DejaVu Sans Mono, monospace 

2017年5月3日 星期三

(codeIgniter)筆記

網頁緩衝 >>

寫在 controller

$this­>output­>cache(5);

-----------------------------------------------------------------------
路由 >>

$route['test/([a-zA-Z]+)/\\1'] = 'test_2/classTest';

url(test/a/a) => 'test_2/classTest';


$route['test/\w+/\w+/(.*)'] = 'test_2/classTest/$1';  ($1區塊為收到的參數)

test1/5/6/..... => 'test_2/classTest/$1'

$route['test/\w+/\w+/(:any)'] = 'test_2/classTest/$1'; ($1區塊為收到的參數)

test1/5/6/..... => 'test_2/classTest/$1'