Changeset 23067


Ignore:
Timestamp:
2013/08/15 09:08:21 (11 years ago)
Author:
pineray
Message:

#2342 JavaScript?のグローバルな宣言を減らす
スマートフォン.

Location:
branches/version-2_13-dev
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/version-2_13-dev/data/Smarty/templates/sphone/products/detail.tpl

    r23066 r23067  
    302302                    <!--{if !$is_favorite}--> 
    303303                        <div class="btn_favorite"> 
    304                             <p><a rel="external" href="javascript:void(0);" onclick="fnAddFavoriteSphone(<!--{$arrProduct.product_id|h}-->); return false;" class="btn_sub">お気に入りに追加</a></p> 
     304                            <p><a rel="external" href="javascript:void(0);" onclick="eccube.addFavoriteSphone(<!--{$arrProduct.product_id|h}-->); return false;" class="btn_sub">お気に入りに追加</a></p> 
    305305                        </div> 
    306306                    <!--{else}--> 
  • branches/version-2_13-dev/html/user_data/packages/sphone/js/eccube_sphone.js

    r23058 r23067  
    2121 */ 
    2222 
    23 function setTopButton(topURL) { 
    24     if(!topURL){ 
    25         topURL = "/"; 
     23(function( window, undefined ){ 
     24 
     25    // 名前空間の重複を防ぐ 
     26    if (window.eccube === undefined) { 
     27        window.eccube = {}; 
    2628    } 
    27     var buttonText = "TOPへ"; 
    28     var buttonId = "btn-top"; 
    2929 
    30     //ボタンの生成・設定 
    31     var btn = document.createElement('div'); 
    32     var a = document.createElement('a'); 
    33     btn.id = buttonId; 
    34     btn.onclick = function(){location=topURL;}; 
    35     a.href = topURL; 
    36     a.innerText = buttonText; 
     30    var eccube = window.eccube; 
    3731 
    38     /* 背景色の設定 ---------------------*/ 
    39     //最初の見出しの背景色を取得、設定 
    40     var obj = document.getElementsByTagName('h2')[0]; 
    41     var col = document.defaultView.getComputedStyle(obj,null).getPropertyValue('background-color'); 
    42     btn.style.backgroundColor = col; 
     32    eccube.smartRollover = function() { 
     33        if (document.getElementsByTagName) { 
     34            var images = document.getElementsByTagName("img"); 
    4335 
    44     //省略表示用テキストの生成 
    45     var spn = document.createElement('span'); 
    46     spn.innerText = obj.innerText; 
    47     obj.innerText = ""; 
    48     spn.style.display = "inline-block"; 
    49     spn.style.maxWidth = "50%"; 
    50     spn.style.overflow = "hidden"; 
    51     spn.style.textOverflow = "ellipsis"; 
    52     obj.appendChild(spn); 
    53  
    54     //ボタンを追加 
    55     btn.appendChild(a); 
    56     document.getElementsByTagName('body')[0].appendChild(btn);; 
    57 } 
    58  
    59 function smartRollover() { 
    60     if (document.getElementsByTagName) { 
    61         var images = document.getElementsByTagName("img"); 
    62  
    63         for (var i=0; i < images.length; i++) { 
    64             if (images[i].getAttribute("src").match("_off.")) { 
    65                 images[i].onmouseover = function() { 
    66                     this.setAttribute("src", this.getAttribute("src").replace("_off.", "_on.")); 
    67                 } 
    68                 images[i].onmouseout = function() { 
    69                     this.setAttribute("src", this.getAttribute("src").replace("_on.", "_off.")); 
     36            for (var i=0; i < images.length; i++) { 
     37                if (images[i].getAttribute("src").match("_off.")) { 
     38                    images[i].onmouseover = function() { 
     39                        this.setAttribute("src", this.getAttribute("src").replace("_off.", "_on.")); 
     40                    }; 
     41                    images[i].onmouseout = function() { 
     42                        this.setAttribute("src", this.getAttribute("src").replace("_on.", "_off.")); 
     43                    }; 
    7044                } 
    7145            } 
    7246        } 
     47    }; 
     48 
     49    if (window.addEventListener) { 
     50        window.addEventListener("load", eccube.smartRollover, false); 
     51    } else if (window.attachEvent) { 
     52        window.attachEvent("onload", eccube.smartRollover); 
    7353    } 
    74 } 
    7554 
    76 if (window.addEventListener) { 
    77     window.addEventListener("load", smartRollover, false); 
    78 } else if (window.attachEvent) { 
    79     window.attachEvent("onload", smartRollover); 
    80 } 
     55    /*------------------------------------------ 
     56     お気に入りを登録する 
     57     ------------------------------------------*/ 
     58    eccube.addFavoriteSphone = function(favoriteProductId) { 
     59        $.mobile.showPageLoadingMsg(); 
     60        //送信データを準備 
     61        var postData = {}; 
     62        var form = $("#form1"); 
     63        form.find(':input').each(function(){ 
     64            postData[$(this).attr('name')] = $(this).val(); 
     65        }); 
     66        postData["mode"] = "add_favorite_sphone"; 
     67        postData["favorite_product_id"] = favoriteProductId; 
    8168 
    82 /*------------------------------------------ 
    83  お気に入りを登録する 
    84  ------------------------------------------*/ 
    85 function fnAddFavoriteSphone(favoriteProductId) { 
    86     $.mobile.showPageLoadingMsg(); 
    87     //送信データを準備 
    88     var postData = {}; 
    89     $("#form1").find(':input').each(function(){ 
    90         postData[$(this).attr('name')] = $(this).val(); 
     69        $.ajax({ 
     70            type: "POST", 
     71            url: form.attr('action'), 
     72            data: postData, 
     73            cache: false, 
     74            dataType: "text", 
     75            error: function(XMLHttpRequest, textStatus, errorThrown){ 
     76                alert(textStatus); 
     77                $.mobile.hidePageLoadingMsg(); 
     78            }, 
     79            success: function(result){ 
     80                if (result == "true") { 
     81                    alert("お気に入りに登録しました"); 
     82                    $(".btn_favorite").html("<p>お気に入り登録済み</p>"); 
     83                } else { 
     84                    alert("お気に入りの登録に失敗しました"); 
     85                } 
     86                $.mobile.hidePageLoadingMsg(); 
     87            } 
     88        }); 
     89    }; 
     90 
     91    // グローバルに使用できるようにする 
     92    window.eccube = eccube; 
     93 
     94    /*------------------------------------------ 
     95     初期化 
     96     ------------------------------------------*/ 
     97    $(function(){ 
     98        //level?クラスを持つノード全てを走査し初期化 
     99        $("#categorytree li").each(function(){ 
     100            if ($(this).children("ul").length) { 
     101                //▶を表示し、リストオープンイベントを追加 
     102                var tgt = $(this).children('span.category_header'); 
     103                var linkObj = $("<a>"); 
     104                linkObj.text('+'); 
     105                tgt 
     106                    .click(function(){ 
     107                        $(this).siblings("ul").toggle('fast', function(){ 
     108                            if ($(this).css('display') === 'none') { 
     109                                tgt.children('a').text('+'); 
     110                            } else { 
     111                                tgt.children('a').text('-'); 
     112                            } 
     113                        }); 
     114                    }) 
     115                    .addClass('plus') 
     116                    .append(linkObj); 
     117            } 
     118        }); 
    91119    }); 
    92     postData["mode"] = "add_favorite_sphone"; 
    93     postData["favorite_product_id"] = favoriteProductId; 
    94  
    95     $.ajax({ 
    96         type: "POST", 
    97         url: $("#form1").attr('action'), 
    98         data: postData, 
    99         cache: false, 
    100         dataType: "text", 
    101         error: function(XMLHttpRequest, textStatus, errorThrown){ 
    102             alert(textStatus); 
    103             $.mobile.hidePageLoadingMsg(); 
    104         }, 
    105         success: function(result){ 
    106             if (result == "true") { 
    107                 alert("お気に入りに登録しました"); 
    108                 $(".btn_favorite").html("<p>お気に入り登録済み</p>"); 
    109             } else { 
    110                 alert("お気に入りの登録に失敗しました"); 
    111             } 
    112             $.mobile.hidePageLoadingMsg(); 
    113         } 
    114     }); 
    115 } 
    116  
    117 /*------------------------------------------ 
    118  初期化 
    119  ------------------------------------------*/ 
    120 $(function(){ 
    121     //level?クラスを持つノード全てを走査し初期化 
    122     $("#categorytree li").each(function(){ 
    123         if ($(this).children("ul").length) { 
    124             //▶を表示し、リストオープンイベントを追加 
    125             var tgt = $(this).children('span.category_header'); 
    126             var linkObj = $("<a>"); 
    127             linkObj.text('+'); 
    128             tgt 
    129                 .click(function(){ 
    130                     $(this).siblings("ul").toggle('fast', function(){ 
    131                         if ($(this).css('display') === 'none') { 
    132                             tgt.children('a').text('+'); 
    133                         } else { 
    134                             tgt.children('a').text('-'); 
    135                         } 
    136                     }); 
    137                 }) 
    138                 .addClass('plus') 
    139                 .append(linkObj); 
    140         } 
    141     }); 
    142 }); 
     120})(window); 
Note: See TracChangeset for help on using the changeset viewer.