topic.js 2.53 KB
define(['jquery', 'underscore'], function() {
    var Topic = {
        wap: false,
        initialize: function() {
            this.bindEvents();
            this.render();
        },
        bindEvents: function() {
            $(document).on('touchstart', '.m-to-top', function(e) {
                e.preventDefault();
                $('body').animate({
                    scrollTop: 0
                }, 300);
            });
        },
        getParameterByName: function(name) {
            name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
            var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
                results = regex.exec(location.search);
            return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
        },
        render: function() {
            var _this = this,
                source = this.getParameterByName('source'),
                banner = this.getParameterByName('banner'),
                title = this.getParameterByName('title'),
                tplName = this.getParameterByName('tplName'),
                fullScreenBanner = this.getParameterByName('fullScreenBanner'),
                modelCode = this.getParameterByName('modelCode');

            if (source != '' && source.length > 0) {
                if (source && source.toLowerCase() == 'wap') {
                    this.wap = true;
                }
            }

            if (tplName == '' && tplName.length <= 0) {
                tplName = 'product';
            }

            if (title == '' && title.length <= 0) {
                title = '活动专题';
            }

            if (modelCode == '' || modelCode.length <= 0) {
                alert('模块标示[modelCode]不能为空!');
                return;
            }

            if (banner == '' || banner.length <= 0) {
                alert('专题banner图[banner]不能为空!');
                return;
            }

            if(tplName.toLowerCase() == 'activity'){
                if(fullScreenBanner == '' || fullScreenBanner.length <= 0){
                    alert('专题全屏banner图[fullScreenBanner]不能为空!');
                    return;
                }
            }

            require([tplName], function(Ctrl) {
                Ctrl.initialize({
                    wap: _this.wap,
                    banner: banner,
                    title: title,
                    modelCode: modelCode,
                    fullScreenBanner: fullScreenBanner
                });
            });
        }
    };
    return Topic;
});