*/
_ui_pvt_m.directive('blogListProplugin', function($rootScope, $routeParams, $location, sliderProvider) {
var templateName = 'blogListProplugin';
var templatePathUrl = _ui_host + templateName + '/' + templateName + '.html';
var promise = {};
promise.restrict = 'AE';
promise.scope = {
name: '@name',
all: '@all',
imgpath: '@imgpath',
type: '@type',
blogid: '@blogid',
limitdata: '@limitdata',
sortby: '@sortby',
curpage: '=curpage',
perpage: '@perpage',
typelist: '=typelist',
callback: '@callback',
addparams: '@addparams',
feature: '@feature',
blogimage: '@blogimage',
loadmore: '@loadmore',
carousel: '@carousel',
textloadmore: '@textloadmore',
};
promise.templateUrl = templatePathUrl;
promise.transclude = true;
promise.link = function(scope, element, attr) {};
promise.controller = function($scope, $timeout, $interval, $q, $window) {
/* Declare variables */
console.log("blogListProplugin");
$scope.forbidden = false;
$scope._config = [];
$scope._host = _ui_host + templateName + '/';
$scope._params = $routeParams;
$scope.assetsPath = 'extensions/themes/assets/';
$scope.all = (typeof $scope.all !== 'undefined' && $scope.all !== '') ? $scope.all : 'all';
$scope.example = (typeof $scope.callback !== 'undefined' && $scope.callback !== '') ? true : false;
$scope.useFeature = (typeof $scope.feature !== 'undefined' && $scope.feature != '') ? true : false;
$scope._blogimage = (typeof $scope.blogimage !== 'undefined' && $scope.blogimage != '') ? true : false;
$scope.useLoadmore = (typeof $scope.loadmore !== 'undefined' && $scope.loadmore != '') ? true : false;
$scope.useCarousel = (typeof $scope.carousel !== 'undefined' && $scope.carousel != '') ? true : false;
/* UNIQUE KEY */
$scope._uniqueKey = '';
$scope._key = function() {
if ($scope._uniqueKey === '') {
$scope._uniqueKey = Math.floor((Math.random() * 9999) + 1000);
return $scope._uniqueKey;
} else {
return $scope._uniqueKey;
}
};
/* get some id from address url */
$scope._getIdFromUrl = function() {
var test = $scope.id;
var a = $scope.id;
if (typeof $routeParams.product_id !== 'undefined') {
test = parseInt($routeParams.product_id);
a = $routeParams.product_id;
}
if (typeof test === 'number' && test > 0) {
return test;
} else {
var b = a.split("-");
return b[0];
}
};
/* Return Item Request Perpage By Type */
$scope._getPerPage = function(type, blogTypeId) {
if (typeof $scope.perpage !== 'undefined') {
var r = $scope.perpage;
} else {
var r = 9;
}
switch (type) {
case 'blog-boxed-standard':
r = 5;
break;
default:
break;
}
return (blogTypeId > 0) ? r : 9;
};
/* Get blog list*/
$scope.datatypelist = [];
$scope.getTypeList = function() {
$scope.array_blog = [];
$scope.array_blog.blog_id = [];
$scope.array_blog.blog_name = [];
GAEAPI.get('blog/lists', {
'cur_page': 1,
'per_page': 4
}, $scope).then(function(e) {
if (e.ok == 1) {
$scope.datatypelist = e.data.dataList;
for (var i = 0; i < e.data.dataList.length; i++) {
$scope.array_blog.blog_id.push(e.data.dataList[i].blog_id);
$scope.array_blog.blog_name.push(e.data.dataList[i].blog_name);
}
/*console.log("test_blog_array", $scope.array_blog + "");*/
$scope.getPostArray_inblog($scope.array_blog, e.data.dataList);
}
});
};
$scope.PostArray_inblog = [];
$scope.PostArray_inblogDone = false;
$scope.array_fill_post = [];
$scope.getPostArray_inblog = function(array_blog, blogArrayTwo) {
/*console.log("test_blog_array : post_first", array_blog.blog_id);*/
var filter_ar_blog = array_blog.blog_id + "";
for (var k = 0; k < array_blog.blog_id.length; k++) {
$scope.array_fill_post[k] = [];
$scope.array_fill_post[k].blog_name_2 = [];
}
/*console.log("test_blog_array : post_first_2", filter_ar_blog);*/
$scope.blog_array_test = array_blog.blog_id;
var filter_json_d = {
'blog_id_array': [filter_ar_blog],
}
var d = {
'cur_page': 1,
'per_page': 100,
'txt_filter_json': JSON.stringify(filter_json_d)
};
var dd = {};
dd.cur_page = 1;
dd.per_page = 100;
dd.txt_filter_json = JSON.stringify({
'blog_id_array': array_blog.blog_id
});
GAEAPI.get("post/lists", dd, $scope).then(function(e) {
/*console.log("test_blog_array : all data : dd", dd);
console.log("test_blog_array : all data : blog array", array_blog);
console.log("test_blog_array : all data", e.data.dataList);*/
if (e.ok == 1) {
$scope.PostArray_inblog = e.data.dataList;
for (var i = 0; i < array_blog.blog_id.length; i++) {
for (var j = 0; j < e.data.dataList.length; j++) {
/*console.log("test_blog_array : post pre 3", e.data.dataList[j].blog[0].blog_id);*/
if (array_blog.blog_id[i] == e.data.dataList[j].blog[0].blog_id) {
$scope.array_fill_post[i].push(e.data.dataList[j]);
$scope.array_fill_post[i].blog_name_2.push(array_blog.blog_name[i]);
/*console.log("test_blog_array : post pre 1", array_blog.blog_id[i]);
console.log("test_blog_array : post pre 2", e.data.dataList[j]);*/
}
}
}
$scope.PostArray_inblogDone = true;
/*console.log("test_blog_array : post", $scope.PostArray_inblog);
console.log("test_blog_array : post 2", $scope.array_fill_post);*/
}
});
};
$scope.PostArray_inblog2 = [];
/*// $scope.PostArray_inblogDone2 = false;
// $scope.array_fill_post2 = [];*/
$scope.getPostArray_inblog2 = function() {
/*console.log("test_blog_array : post_first ooo", $scope.blogid);*/
/*// var filter_ar_blog = array_blog.blog_id+"";
// for (var k = 0; k < array_blog.blog_id.length; k++) {
// $scope.array_fill_post[k] = [];
// $scope.array_fill_post[k].blog_name_2 = [];
// }
// console.log("test_blog_array : post_first_2",filter_ar_blog);
// $scope.blog_array_test = array_blog.blog_id;*/
var filter_json_d = {
'blog_id_array': [$scope.blogid],
}
var d = {
'cur_page': 1,
'per_page': (typeof $scope.limitdata !== 'undefined' && $scope.limitdata !== '') ? $scope.limitdata : 100,
'txt_sortby': (typeof $scope.sortby !== 'undefined' && $scope.sortby !== '') ? $scope.sortby : '',
'txt_filter_json': JSON.stringify(filter_json_d)
};
console.log("txt_sortby d : ", d, " BlogID : ", $scope.blogid);
/*// var array_d = {};
// array_d.cur_page=1;
// array_d.per_page=100;
// array_d.txt_filter_json = JSON.stringify({'blog_id_array':array_blog.blog_id});*/
GAEAPI.get("post/lists", d, $scope).then(function(e) {
console.log("test_blog_array : all data : d", d);
/*/ console.log("test_blog_array : all data : blog array",array_blog);
// console.log("test_blog_array : all data",e.data.dataList);*/
if (e.ok == 1) {
$scope.PostArray_inblog2 = e.data.dataList;
/*// for (var i = 0; i < array_blog.blog_id.length; i++) {
// for (var j = 0; j < e.data.dataList.length; j++) {
// console.log("test_blog_array : post pre 3",e.data.dataList[j].blog[0].blog_id);
// if(array_blog.blog_id[i] == e.data.dataList[j].blog[0].blog_id){
// $scope.array_fill_post[i].push(e.data.dataList[j]);
// $scope.array_fill_post[i].blog_name_2.push(array_blog.blog_name[i]);
// console.log("test_blog_array : post pre 1",array_blog.blog_id[i]);
// console.log("test_blog_array : post pre 2",e.data.dataList[j]);
// }
// }
// }
// $scope.PostArray_inblogDone = true;
// console.log("test_blog_array : post",$scope.PostArray_inblog);
// console.log("test_blog_array sdsdsdsd : post 2",PostArray_inblog2);*/
}
});
};
/* check if dont have blog typelist data */
if ($scope.typelist == undefined) {
$scope.getTypeList();
}
/*// if($scope.blogid != undefined){
// }*/
/* get dummy data */
$scope.typelistDummy = [];
$scope._getBlogArrayDummy = function() {
for (var i = 0; i < 5; i++) {
$scope.typelistDummy.push({
'blog_id': 999999,
'blog_name': 'Category ' + (i + 1)
});
}
var dummyArray = [];
var d = new Date();
var n = d.getTime() / 1000;
for (var i = 0; i < 5; i++) {
dummyArray.push({
'post_id': 999999,
'post_title': 'Your blog title number ' + (i + 1),
'post_excerpt': 'มีท่อนต่างๆ ของ Lorem Ipsum ให้หยิบมาใช้งานได้มากมาย แต่ส่วนใหญ่แล้วจะถูกนำไปปรับให้เป็นรูปแบบอื่นๆ',
'post_create_time': n,
'post_image': [{
'image_url': 'extensions/themes/gae_default301/staticfiles/images/default/490x490.gif'
}],
'post_badge': [{
'badge_id': 18
}]
});
}
$scope._blogArray = dummyArray;
};
/* get blog data (real data) */
$scope._blogArray = [];
$scope._blogArrayDone = false;
$scope.fetchTimes = 1;
$scope._blogType = "";
$scope._getBlogArray = function(filter) {
$scope._blogArrayDone = false;
if ($scope.fetchTimes <= 1) {
$('.load-effect').addClass('is-active');
}
var txt_filter_json = {},
isFilter = false;
if (typeof filter !== 'undefined' && filter !== '') {
isFilter = true;
if (typeof filter.tags !== 'undefined' && filter.tags != "") {
txt_filter_json.tags = filter.tags;
// alert(filter.tags);
}
if (typeof filter.search !== 'undefined' && filter.search != "") {
txt_filter_json.search = filter.search;
}
}
/* Check Feature */
if ($scope.useFeature) {
txt_filter_json.badge_id_array = [16, 18];
}
if (typeof filter.id !== "undefined" && filter.id !== "") {
if ($scope._blogType !== parseInt(filter.id)) {
$scope._blogArray = [];
$scope._blogType = '';
$scope.fetchTimes = 1;
}
txt_filter_json.blog_id_array = [filter.id];
}
if ($scope._blogArray.length > 0 && typeof filter.id === "undefined" && $scope._blogType != "") {
$scope._blogArray = [];
$scope._blogType = '';
$scope.fetchTimes = 1;
}
if ($scope._params.id == 'collections' || $scope._params.id == 'Collections')
return
txt_filter_json.display_on_today = 1;
var dataSend = {
'cur_page': $scope.fetchTimes,
'per_page': $scope._getPerPage($scope.type, parseInt(filter.id)),
'txt_sortby': 'post_update_time_DESC',
'txt_filter_json': (isFilter) ? JSON.stringify(txt_filter_json) : ''
};
console.log("_getBlogArray : dataSend : ", dataSend);
GAEAPI.get('post/lists', dataSend).then(function(res) {
$scope.sumpost = "";
console.log("_getBlogArray", dataSend, res);
console.log("_getBlogArray : res : ", res);
var dummyArray = [];
if (res.ok === 1) {
$scope.sumpost = res.data.total_rows;
if (typeof filter.id !== "undefined" && filter.id !== "") {
var _data = [];
var currentFilterId = parseInt(filter.id);
$scope._blogType = currentFilterId;
angular.forEach(res.data.dataList, function(item, key) {
var blog_id = parseInt(item.blog[0].blog_id);
if (blog_id == currentFilterId && $scope._showWeb(item.post_badge) && $scope.postLifeTime(item.post_lifetime)) {
dummyArray.push(item);
}
});
/* check callback data */
if (!$scope._blogArray.length) {
$scope._blogArray = dummyArray;
} else {
var currentData = $scope._blogArray;
$scope._blogArray = currentData.concat(dummyArray);
}
} else {
$scope._blogType = "";
angular.forEach(res.data.dataList, function(i, k) {
if ($scope._showWeb(i.post_badge) && $scope.postLifeTime(i.post_lifetime)) {
dummyArray.push(i);
}
});
/* check callback data */
if (!$scope._blogArray.length) {
$scope._blogArray = dummyArray;
} else {
var currentData = $scope._blogArray;
$scope._blogArray = currentData.concat(dummyArray);
}
}
if ($('#feature-post-header').hasClass('hide')) {
$('#feature-post-header').removeClass('hide');
};
/* Other Query */
switch ($scope.type) {
case 'blog-boxed-standard':
case 'blog-boxed-sidebar':
$scope.getRecentPost();
break;
case 'kpopmap':
$scope.getRelatePostEach();
break;
default:
break;
}
console.log("sumpost :", $scope.sumpost, $scope._blogArray.length, $scope._getPerPage($scope.type, parseInt(filter.id)));
}
/* check callback data */
if ($scope.example && !$scope._blogArray.length) {
/* use dummy data */
console.log('test_blog_array :', $scope.example);
console.log('test_blog_array :', $scope._blogArray.length);
$scope._getBlogArrayDummy();
}
/* finish load */
$scope._blogArrayDone = true;
/* load more increment */
$scope.fetchTimes++;
$timeout(function() {
$('.load-effect').addClass('de-active');
}, 100);
$timeout(function() {
$('.load-effect').addClass('loaded').removeClass('is-active de-active').removeClass('loaded');
$('html').removeClass('noscroll noscroll-long');
}, 1100);
});
};
/* get blog data for first time */
$scope._getBlogArray($routeParams);
/* Click To Load More */
$scope.loadMore = function() {
// $scope.fetchTimes = $scope.fetchTimes + 1;
$scope._getBlogArray($routeParams);
};
/* Reset Data */
$scope._resetData = function() {
$scope._blogArray = [];
$scope._blogArrayDone = false;
};
/* Get Recent Post */
$scope.recentPostArray = [];
$scope.getRecentPost = function() {
var d = {
'cur_page': 1,
'per_page': 20,
'txt_sortby': 'post_update_time_DESC',
};
GAEAPI.get("post/lists", d, $scope).then(function(e) {
$scope.recentPostArray = (e.ok == 1) ? e.data.dataList : [];
});
};
/* Get relate post on each item */
$scope.recentPostArray = [];
$scope.getRelatePostEach = function() {
angular.forEach($scope._blogArray, function(item) {
if (item.post_tags != "" && typeof item.post_ralate_array === 'undefined') {
var d = {
'cur_page': 1,
'per_page': 3,
'txt_sortby': 'post_update_time_DESC',
'txt_filter_json': JSON.stringify({
'tags': item.post_tags,
'badge_id_array': [18],
'blog_id_array': [item.blog[0].blog_id]
})
};
GAEAPI.get("post/lists", d, $scope).then(function(e) {
/*console.log("getRelatePostEach",d,e);*/
if (e.ok == 1 && e.data.dataList.length) {
item.post_ralate_array = e.data.dataList;
}
});
}
});
};
/* Get Feature Post */
$scope.featuredPostArray = [];
$scope.featuredPostDone = false;
$scope.getFeaturedPost = function(per_page) {
var d = {
'cur_page': 1,
'per_page': per_page,
'txt_sortby': 'post_update_time_DESC',
};
GAEAPI.get("post/lists", d, $scope).then(function(e) {
$scope.featuredPostArray = (e.ok == 1) ? e.data.dataList : [];
$scope.featuredPostDone = true;
console.log("blog_feature : ", $scope.featuredPostArray);
});
};
/* show if not in featured */
$scope.notInFeatured = function(postIdStr) {
var r = true;
/*angular.forEach($scope.featuredPostArray,function(item){
if(item.post_id == postIdStr){
r = false;
break;
}
});*/
return r;
};
/* Watch Event */
$scope.$watch('type', function(newValue, oldValue) {
if (!newValue) return;
/* Other Query */
switch (newValue) {
case 'blog-boxed-standard':
case 'blog-boxed-sidebar':
if ($scope.recentPostArray.length <= 0) {
$scope.getRecentPost();
}
break;
case 'kpopmap':
if ($scope.recentPostArray.length <= 0) {
$scope.getRecentPost();
}
$scope.getFeaturedPost(3);
break;
case 'blog-boxed-grid-3-carousel-blog-id':
$scope.getPostArray_inblog2();
break;
case 'blog-boxed-grid-4-carousel-blog-id':
$scope.getPostArray_inblog2();
break;
case 'kpopmap2':
if ($scope.recentPostArray.length <= 0) {
$scope.getRecentPost();
}
$scope.getvideofirst();
$scope.getvideo();
$scope.getFeaturedPost(5);
$scope.getdiscussions_post();
$scope.getpopular_post();
break;
case 'featured-with-lists':
case 'featured-with-bloglists':
case 'featured-with-lists-small':
$scope.getFeaturedPost(4);
break;
default:
break;
}
});
/* when route success event */
/* $rootScope.$on('$routeChangeSuccess', function(event, current, prev) {
if (current.$$route.page === 'blog' && typeof $routeParams !== 'undefined') {
$scope._getBlogArray($routeParams);
}
}); */
/* Get parameter tag */
$scope.currentTag = function() {
var str = "";
if (typeof $routeParams.tags !== 'undefined') {
str = $routeParams.tags;
}
return str;
};
/* Get parameter blog id */
$scope.currentBlogId = function() {
var r = $routeParams.id || false;
return r;
};
/* Build date string */
$scope._makeDate = function(dateStr) {
return (dateStr != "") ? moment(parseInt(dateStr) * 1000).format('LL') : "";
};
/* Click view detail */
$scope._viewDetail = function(endPathString) {
if ($scope.checkSeo()) return window.location.href = endPathString;
else return GURL.location.href = endPathString;
};
$scope.postLifeTime = function(postLifetime) {
var now = moment().unix();
var start = false;
console.log("postLifeTime : postLifetime.lifetime_start_time : ", postLifetime.lifetime_start_time, " <= ", now, " : ", postLifetime.lifetime_start_time <= now);
console.log("postLifeTime : postLifetime.lifetime_end_time : ", postLifetime.lifetime_end_time, " == ", -1, " : ", postLifetime.lifetime_end_time == -1);
console.log("postLifeTime : now : ", now, " <= ", postLifetime.lifetime_end_time, " : ", now <= postLifetime.lifetime_end_time);
console.log("postLifeTime : postLifetime.lifetime_start_time <= now && (postLifetime.lifetime_end_time == -1 || now <= postLifetime.lifetime_end_time) : ", (postLifetime.lifetime_start_time <= now && (postLifetime.lifetime_end_time == -1 || now <= postLifetime.lifetime_end_time)));
if (postLifetime.lifetime_start_time <= now && (postLifetime.lifetime_end_time == -1 || now <= postLifetime.lifetime_end_time)) {
start = true;
}
return start;
};
/* Show On web */
$scope._showWeb = function(objArray) {
var r = false;
for (var i = 0; i < objArray.length; i++) {
if (objArray[i].badge_id == 18) {
r = true;
break;
}
}
return r;
};
/* Show On Mobile */
$scope._showApp = function(objArray) {
var r = false;
for (var i = 0; i < objArray.length; i++) {
if (objArray[i].badge_id == 19) {
r = true;
break;
}
}
return r;
};
/* Check if seo website */
$scope.viewRouteParams = function() {
return $routeParams;
};
/* Check if seo website */
$scope.checkSeo = function() {
return (GURL.isHtml5Mode()) ? true : false;
};
/* Build String title url */
$scope.buildTitleUrl = function(str) {
if (str == undefined) {
return;
}
var s = str.replace(/[^a-zA-Zก-๙0-9 ]/g, "").split(" ").join("-").replace("--", "-");
return s;
};
/* Check if config color exist -> use new button */
$scope.checkColor = function() {
return ($('config-color').length > 0) ? true : false;
};
$scope.getGridItemWidth = function() {
return (angular.element('.col-item').eq(0).width() - 150) / 2;
};
/* Pagination */
$scope.pagination_data_custom = {};
$scope.buildPaginationParameterCustom = function(data) {
if (data === false) {
$scope.pagination_data_custom = {};
return;
}
console.log("$scope.routeParams", $scope.routeParams, $location.search());
var generateRangeArray = function(total_items, per_page, cur_page) {
console.log("generateRangeArray", total_items, per_page, cur_page);
var returnPageArray = [];
var size = 5;
var totalPage = Math.ceil(total_items / per_page);
var start = cur_page;
if (totalPage <= size) {
for (var i = 0; i < totalPage; i++) {
returnPageArray.push(i + 1);
}
} else {
if (start <= size) {
for (var i = 0; i < size; i++) {
returnPageArray.push(i + 1);
}
} else {
if (start >= 1) {
var maxPage = (start - 1) + size;
} else {
var maxPage = start + size;
}
if (maxPage >= totalPage) {
maxPage = totalPage;
start = (maxPage - size) + 1;
}
for (var i = start - 1; i < maxPage; i++) {
returnPageArray.push(i + 1);
}
}
}
return returnPageArray;
};
$scope.pagination_data_custom.cur_page = parseInt(data.current_page);
$scope.pagination_data_custom.per_page = parseInt(data.per_page);
$scope.pagination_data_custom.result_rows = parseInt(data.data_lists.length);
$scope.pagination_data_custom.total_rows = parseInt(data.total_items);
$scope.pagination_data_custom.max_page = Math.ceil($scope.pagination_data_custom.total_rows / $scope.pagination_data_custom.per_page);
$scope.pagination_data_custom.prev_page = parseInt($scope.pagination_data_custom.cur_page - 1);
$scope.pagination_data_custom.next_page = parseInt($scope.pagination_data_custom.cur_page + 1);
$scope.pagination_data_custom.page_array = generateRangeArray($scope.pagination_data_custom.total_rows, $scope.pagination_data_custom.per_page, $scope.pagination_data_custom.cur_page);
/*console.log('$scope.pagination_data_custom', $scope.pagination_data_custom);*/
};
/* Broadcase event -> do something */
$rootScope.$on('repeatend', function() {
if ($('[data-id="' + $scope._key() + '"]').not('.slick-initialized')) {
$timeout(function() {
var optionSlider = {
main: 3,
a: 3,
b: 2,
c: 2,
d: 1,
};
if ($scope.type == 'blog-boxed-grid-carousel') {
optionSlider = {
main: 3,
a: 3,
b: 2,
c: 2,
d: 1,
};
$scope.slideInit(optionSlider)
} else if ($scope.type == 'blog-boxed-grid-4-carousel') {
optionSlider = {
main: 4,
a: 4,
b: 3,
c: 2,
d: 1,
};
$scope.slideInit(optionSlider);
} else if ($scope.type == 'blog-boxed-grid-4-carousel-blog-id') {
optionSlider = {
main: 4,
a: 4,
b: 3,
c: 2,
d: 1,
};
$scope.slideInit(optionSlider);
} else {
$scope.slideInit(optionSlider);
}
/*console.log('optionSlider',optionSlider);*/
}, 500);
}
/*console.log("repeatend");*/
});
/* Carousel */
$scope.prev_win_size = $(window).width();
$scope.slideInit = function(optionSlider) {
function responsiveOpt(a, b, c, d) {
var deFaultOptionResponsive = [{
breakpoint: 1200,
settings: {
slidesToShow: a || 3,
slidesToScroll: a || 3,
variableWidth: false,
centerMode: false
}
}, {
breakpoint: 769,
settings: {
slidesToShow: b || 2,
slidesToScroll: b || 2,
variableWidth: false,
centerMode: false
}
}, {
breakpoint: 601,
settings: {
slidesToShow: c || 2,
slidesToScroll: c || 2,
variableWidth: false,
centerMode: false,
}
}, {
breakpoint: 481,
settings: {
slidesToShow: d || 1,
slidesToScroll: d || 1,
variableWidth: false,
centerMode: false,
dots: false,
arrows: false,
}
}];
return deFaultOptionResponsive;
};
var elementName = '[data-id="' + $scope._key() + '"]';
var optionsParmas = {
autoplay: false,
slidesToShow: optionSlider.main || 3,
slidesToScroll: optionSlider.main || 3,
dots: true,
arrows: false,
centerMode: false,
infinite: false,
variableWidth: false
};
optionsParmas.responsive = responsiveOpt(optionSlider.a, optionSlider.b, optionSlider.c, optionSlider.d);
var extraOptions = {
animate: false,
slideFromRight: true,
};
sliderProvider(elementName, optionsParmas, "", $scope._key(), extraOptions);
/*console.log("repeatend: Option", optionsParmas);*/
angular.element($window).bind('resize', function() {
if ($scope.prev_win_size != $(window).width()) {
if ($(elementName).hasClass('slick-initialized') || $(elementName).hasClass('slick-slider')) {
$(elementName).slick('unslick');
}
setTimeout(function() {
if ($(elementName).hasClass('slick-initialized') || $(elementName).hasClass('slick-slider')) {
$(elementName).slick('unslick');
}
sliderProvider(elementName, optionsParmas, $scope.type, $scope._key(), extraOptions);
}, 3000);
}
});
};
/* Form & Input */
$scope.search_txt = $scope.viewRouteParams().search || '';
$scope.onSearchSubmit = function() {
if ($scope.search_txt == "") {
return;
}
$timeout(function() {
$('form#form-search-submit').submit();
}, 100);
};
/* Optimize image size by device pixel
* @params {size} (integer) prefer size
* @params {image_url} (string) original image source link
* @params {image_width} (string) original image width
* @return string
*/
$scope.viewOptimizeImage = function(size, image_url, image_width) {
if (window.devicePixelRatio >= 2 || parseInt(image_width) <= size) {
return image_url;
}
var a = image_url.split("/"),
b = a[a.length - 1];
a[a.length - 1] = 't' + size + '_' + b;
return a.join("/");
};
$scope.resultArray = [];
$scope.getvideo = function() {
var dataSend = {
'cur_page': 1,
'per_page': 20,
'badge_id_array': [18],
};
GAEAPI.get('video/lists', dataSend, $scope).then(function(res) {
if (res.ok != 1) {
return;
}
if (res.data.dataList.length) {
$scope.resultArray = res.data.dataList;
} else {
return;
}
});
};
$scope.resultArray_first = [];
$scope.getvideofirst = function() {
var dataSend = {
'cur_page': 1,
'per_page': 1,
'badge_id_array': [18],
};
GAEAPI.get('video/lists', dataSend, $scope).then(function(res) {
if (res.ok != 1) {
return;
}
if (res.data.dataList.length) {
$scope.resultArray_first = res.data.dataList;
$scope.getvideoid($scope.resultArray_first[0].video_id);
} else {
return;
}
});
};
$scope.resultArray_id = false;
$scope.getvideoid = function(id) {
console.log("text_id : ", id);
var dataSend = {
'txt_video_id': id,
};
GAEAPI.get('video/id', dataSend, $scope).then(function(res) {
if (res.ok != 1) {
return;
}
$scope.resultArray_id = res.data;
});
};
$scope.discussions_post = [];
$scope.getdiscussions_post = function() {
var filter_json = {
'tags': "trending discussions",
};
var dataSend = {
'cur_page': 1,
'per_page': 20,
'txt_filter_json': JSON.stringify(filter_json),
};
GAEAPI.get('post/lists', dataSend, $scope).then(function(res) {
if (res.ok != 1) {
return;
}
$scope.discussions_post = res.data.dataList;
console.log("testoioiiooioi : ", $scope.discussions_post);
});
};
$scope.popular_post = [];
$scope.getpopular_post = function() {
var filter_json = {
'tags': "popular",
};
var dataSend = {
'cur_page': 1,
'per_page': 20,
'txt_filter_json': JSON.stringify(filter_json),
};
GAEAPI.get('post/lists', dataSend, $scope).then(function(res) {
if (res.ok != 1) {
return;
}
$scope.popular_post = res.data.dataList;
console.log("testoioiiooioi : ", $scope.popular_post);
});
};
$scope.hideVideoDesc = function() {
$scope.playDRVideo = 1;
}
$scope.componentPleaseWait = function(idStr) {
var start = false;
if (CUR_THEME.shop_id() == "647") {
start = true;
}
return start;
};
$scope.showShop = function() {
var start = false;
if (CUR_THEME.shop_id() == "726") {
start = true;
}
if (CUR_THEME.shop_id() == "758") {
start = true;
}
return start;
};
$scope.showShopColumnImg = function() {
var start = "ALL";
if (CUR_THEME.shop_id() == "495") {
start = "ทั้งหมด";
}
return start;
};
$scope.pages = function() {
var getFunction = {
checkSeo: function(callback) {
var page_blog = ($scope.checkSeo()) ? 'blog' : '#/blog';
callback(page_blog);
},
buildTitleUrl: function(str, callback) {
var res_str = "";
if (str != undefined) {
res_str = str.replace(/[^a-zA-Zก-๙0-9 ]/g, "").split(" ").join("-").replace("--", "-");
}
callback(res_str);
},
pageBlog: function() {
var _self = this;
var page = "";
_self.checkSeo(function(page_blog) {
page = page_blog;
_self.windowOpne(page);
});
},
pageBlogId: function(blog_id, blog_name) {
var _self = this;
var page = "";
_self.checkSeo(function(page_blog) {
page = page_blog;
_self.buildTitleUrl(blog_name, function(res_str) {
page += "/" + blog_id + "-" + res_str + "?id=" + blog_id;
_self.windowOpne(page);
});
});
},
windowOpne: function(url) {
var _self = this;
if (url != '') {
window.location.href = url;
}
},
windowOpneBlank: function(url) {
var _self = this;
if (url != '') {
window.open(url, '_blank');
}
},
locationUrlReplace: function(page) {
var _self = this;
$location.url(page).replace();
},
main: function() {
var _self = this;
}
}
return getFunction;
};
/* get api */
$scope._component = {
name: "blogListProplugin",
show: (window.location.hostname == "localhost") ? true : false
};
$scope.getData = function() {
var getFunction = {
consoleLog: function(function_name, data_name, data) {
if ($scope._component.show) {
console.log($scope._component.name, ' : ', function_name, ' : ', data_name, ' : ', data);
}
},
getRouteParams: function(callback) {
var _self = this;
var params = $routeParams;
var state = _self.stateData(true, false);
_self.consoleLog("getRouteParams", "params", params);
callback(_self, params, state);
},
formatDataSend: function(data, callback) {
var _self = this;
_self.consoleLog("formatDataSend", "data", data);
callback(data);
},
stateData: function(load, done) {
var _self = this;
var state = {
load: load,
done: done
};
_self.consoleLog("stateData", "state", state);
return state;
},
dataSend: function(api, dataSend, callback) {
var _self = this;
_self.consoleLog("dataSend", "api", api);
_self.consoleLog("dataSend", "dataSend", dataSend);
callback(api, dataSend);
},
checkGetApi: function(resApi, callback) {
var _self = this;
var ok = false;
if (resApi.ok == 1) {
ok = true;
}
_self.consoleLog("checkGetApi", "ok", ok);
callback(ok);
},
getApi: function(api, dataSend, callback) {
var _self = this;
var state = _self.stateData(true, false);
GAEAPI.get(api, dataSend, $scope).then(function(res_api) {
_self.consoleLog("getApi", "res_api", res_api);
_self.checkGetApi(res_api, function(res_ok) {
_self.consoleLog("getApi", "res_ok", res_ok);
state = _self.stateData(false, true);
_self.consoleLog("checkGetApi", "state", state);
callback(res_ok, res_api, state);
})
});
},
getNameUrl: function(name, callback) {
var _self = this;
name = name.replace(/[^a-zA-Zก-๙0-9 ]/g, "").split(" ").join("-").replace("--", "-");
_self.consoleLog("getNameUrl", "name", name);
callback(name);
},
main: function() {
var _self = this;
}
}
return getFunction;
};
$scope.getPages = function() {
var getFunction = {
consoleLog: function(function_name, data_name, data) {
if ($scope._component.show) {
console.log($scope._component.name, ' : ', function_name, ' : ', data_name, ' : ', data);
}
},
locationUrlReplace: function(page) {
var _self = this;
$location.url(page).replace();
},
pageUrl: function(page_name, id, name_url) {
var _self = this;
var page = page_name + "/" + id + "-" + name_url;
_self.locationUrlReplace(page);
}
}
return getFunction;
};
/* get api */
$scope.data_api = {
load_more: {
load: false,
cur_page: 1,
per_page: 9,
total_rows: 0
},
collection: {
data_send: {},
api: "collection/lists",
ok: false,
data_array: [],
data_array_state: {
load: false,
done: false
}
}
};
$scope.loadMoreCollection = function() {
if (!$scope.data_api.load_more.load) {
$scope.data_api.load_more.cur_page++;
$scope.data_api.load_more.load = true;
$scope.getData().getRouteParams(function(_self, params, state) {
_self.formatDataSend($scope.data_api.collection, function(res_data) {
var filter_json = {};
var dataSend = {
'cur_page': $scope.data_api.load_more.cur_page,
'per_page': $scope.data_api.load_more.per_page,
'txt_sortby': 'collection_create_time_DESC',
'txt_filter_json': JSON.stringify(filter_json)
};
res_data.data_send = dataSend;
_self.dataSend(res_data.api, res_data.data_send, function(res_api, res_data_send) {
_self.getApi(res_api, res_data_send, function(res_ok, res_api, res_state) {
res_data.ok = res_ok;
if (res_data.data_array.length < res_api.data.total_rows) {
var oldData = res_data.data_array;
res_data.data_array = oldData.concat(res_api.data.dataList);
angular.forEach(res_data.data_array, function(item, index) {
_self.getNameUrl(res_data.data_array[index].collection_name, function(res_title) {
res_data.data_array[index].collection_name_url = res_title;
});
});
$scope.data_api.load_more.total_rows = res_api.data.total_rows;
} else {
$scope.data_api.load_more.cur_page--;
}
$scope.data_api.load_more.load = false;
});
});
});
});
}
}
$scope.getData().getRouteParams(function(_self, params, state) {
if (params.id == 'collections' || params.id == 'Collections')
$scope.data_api.collection.data_array_state = state;
_self.formatDataSend($scope.data_api.collection, function(res_data) {
var filter_json = {};
var dataSend = {
'cur_page': $scope.data_api.load_more.cur_page,
'per_page': $scope.data_api.load_more.per_page,
'txt_sortby': 'collection_create_time_DESC',
'txt_filter_json': JSON.stringify(filter_json)
};
res_data.data_send = dataSend;
_self.dataSend(res_data.api, res_data.data_send, function(res_api, res_data_send) {
_self.getApi(res_api, res_data_send, function(res_ok, res_api, res_state) {
res_data.ok = res_ok;
res_data.data_array = res_api.data.dataList;
angular.forEach(res_data.data_array, function(item, index) {
_self.getNameUrl(res_data.data_array[index].collection_name, function(res_title) {
res_data.data_array[index].collection_name_url = res_title;
});
});
res_data.data_array_state = res_state;
_self.consoleLog("getApiData", "res_data", res_data);
$scope.data_api.load_more.total_rows = res_api.data.total_rows;
});
});
});
});
/* get api */
};
return promise;
});
/* // JS READER : END */
/* // JS READER : START */
_ui_pvt_m.directive('carouselMaker', function ($rootScope, sliderProvider) {
var templateName = 'carouselMaker';
var templatePathUrl = _ui_host + templateName + '/' + templateName + '.html';
var promise = {};
promise.restrict = 'AE';
promise.scope = {
name: '@name',
type: '@type',
imgpath: '@imgpath',
lists: '=lists',
options: '=options',
arrows: '@arrows'
};
promise.templateUrl = templatePathUrl;
promise.transclude = true;
promise.link = function (scope, element, attr) {};
promise.controller = function ($scope, $timeout, $interval, $q, $window) {
$scope.forbidden = false;
$scope._config = [];
$scope._dataBanner = [];
$scope._host = _ui_host + templateName + '/';
/* UNIQUE KEY */
$scope._uniqueKey = '';
$scope._key = function () {
if ($scope._uniqueKey === '') {
$scope._uniqueKey = Math.floor((Math.random() * 9999) + 1000);
return $scope._uniqueKey;
} else {
return $scope._uniqueKey;
}
};
var optionsParmas = {
autoplay: (window.location.host !== 'localhost') ? true : false,
slidesToShow: 4,
slidesToScroll: 1,
dots: false,
arrows: false,
centerMode: false,
infinite: true,
variableWidth: false,
touchMove:false,
responsive: [
{
breakpoint: 1200,
settings: {
slidesToShow: 4,
slidesToScroll: 1
}
}, {
breakpoint: 769,
settings: {
slidesToShow: 3,
slidesToScroll: 1
}
}, {
breakpoint: 601,
settings: {
slidesToShow: 2,
slidesToScroll: 1
}
}, {
breakpoint: 481,
settings: {
slidesToShow: 2,
slidesToScroll: 1
}
},{
breakpoint: 401,
settings: {
slidesToShow: 1,
slidesToScroll: 1
}
}
]
};
var t = $interval(function(){
if(angular.element('.image_lazy_loaded').length > 0 && $scope.lists.length){
$interval.cancel(t);
var elementName = '._carousel_mk_container[data-key="' + $scope._key() + '"]';
if(typeof $scope.options !== 'undefined' && angular.isDefined($scope.options) && $scope.options != ""){
optionsParmas = $scope.options;
}
sliderProvider(elementName, optionsParmas, $scope.type, $scope._key());
} else {
angular.element('.image_lazy_loaded').hide()
}
}, 500);
$scope._viewLink = function(id){
switch($scope.name){
case 'tirebids':
if($scope.type === 'referral'){
return window.location.href='product-list?brand='+id;
}
break;
default:
return false;
break;
}
};
$scope._slickMkGoLeft = function(e){
var elementName = '._carousel_mk_container[data-key="' + $scope._key() + '"]';
setTimeout(function () {
$(elementName).slick('slickPrev');
}, 100);
};
$scope._slickMkGoRight = function(e){
var elementName = '._carousel_mk_container[data-key="' + $scope._key() + '"]';
setTimeout(function () {
$(elementName).slick('slickNext');
}, 100);
};
};
return promise;
});
/* // JS READER : END */
/* // JS READER : START */
/* UI: */
_ui_pvt_m.directive('categoryList', function ($rootScope, $routeParams) {
var templateName = 'categoryList';
var templatePathUrl = _ui_host + templateName + '/' + templateName + '.html';
var promise = {};
promise.restrict = 'AE';
promise.scope = {
name: '@name',
imgpath: '@imgpath',
type: '@type'
};
promise.templateUrl = templatePathUrl;
promise.transclude = true;
promise.link = function (scope, element, attr) {};
promise.controller = function ($scope, $timeout, $interval, $q, $window) {
$scope.forbidden = false;
$scope._config = [];
$scope._host = _ui_host + templateName + '/';
$scope._params = $routeParams;
/* UNIQUE KEY */
$scope._uniqueKey = '';
$scope._key = function () {
if ($scope._uniqueKey === '') {
$scope._uniqueKey = Math.floor((Math.random() * 9999) + 1000);
return $scope._uniqueKey;
} else {
return $scope._uniqueKey;
}
};
$scope.$watch('_params', function (newValue, oldValue) {
if (!newValue)
return;
if(typeof newValue.root_id !== 'undefined' && newValue.root_id !== ''){
}
});
$rootScope.$on('$routeChangeSuccess', function (event, current, prev) {
// do something
});
$scope._current_root_id = '';
$scope._current_root_name = '';
$scope._root_category_array = [];
$scope._root_product_array = [];
GAEAPI.get('referral/map',{'txt_referral_type_id':11}).then(function(e){
$scope._root_category_array = e.data;
angular.forEach($scope._root_category_array, function(i,k){
if(!i.referral_sub_array.length){
i.referral_product_array = [];
i.referral_product_array_wait = true;
i.referral_product_array_done = false;
var txt_json = {'badge_id_array':[18],'referral_id_array': [i.referral_id]};
var dataSend = {
'cur_page':1,
'per_page':100,
'txt_sortby':'product_lastest_create',
'txt_filter_json': JSON.stringify(txt_json)
};
GAEAPI.get('product/lists',dataSend).then(function(res){
i.referral_product_array = res.data.dataList;
i.referral_product_array_wait = false;
i.referral_product_array_done = true;
});
}
});
});
$scope.viewCategory=function(categoryObject, rootCategoryObject){
var st = '#/category-lists';
var target_referral_id = "?referral_id="+categoryObject.referral_id;
var target_referral_name = "&referral_name="+categoryObject.referral_name;
var root_id = "&root_id="+rootCategoryObject.referral_id;
var root_name = "&root_name="+rootCategoryObject.referral_name;
var target_sub_array = '';
if(categoryObject.referral_sub_array.length){
target_sub_array = '&sub_referral_id=true';
}
return GURL.location.href= st+target_referral_id+target_referral_name+root_id+root_name+target_sub_array;
};
$scope.viewProduct=function(pid){
return GURL.location.href="#/product-detail/"+pid;
};
$scope.viewCateogyOnProductVisible = function(subReferralArray, isProductLoad, productArray, rootObjectArray){
if(subReferralArray.length <= 0 && isProductLoad && productArray.length > 0){
var st = '#/category-lists';
var target_referral_id = "?referral_id="+rootObjectArray.referral_id;
var target_referral_name = "&referral_name="+rootObjectArray.referral_name;
var root_id = "&root_id="+rootObjectArray.referral_id;
var root_name = "&root_name="+rootObjectArray.referral_name;
return GURL.location.href= st+target_referral_id+target_referral_name+root_id+root_name;
}
};
};
return promise;
});
/* // JS READER : END */
/* // JS READER : START */
_ui_pvt_m.directive('collectionsDetailProplugin', function($rootScope, $routeParams, metaRender, sliderProvider, $location) {
var templateComponent = 'collectionsDetailProplugin';
var templateUrl = _ui_host + templateComponent + '/' + templateComponent + '.html';
var promise = {};
promise.restrict = 'AE';
promise.scope = {
name: '@name',
type: '@type',
margin: '@margin',
language: '@language',
};
promise.templateUrl = templateUrl;
promise.transclude = true;
promise.link = function(scope, element, attr) {};
promise.controller = function($scope, $timeout, $interval, $q, $window, $location) {
$scope._component = {
name: "collectionsDetailProplugin",
show: (window.location.hostname == "localhost") ? true : false
};
$scope._imgPath = CUR_THEME.file_url() + "images/";
$scope._icnPath = CUR_THEME.file_url() + "../../assets/";
$scope._componentType = _ui_host + $scope._component.name + "/type/";
$scope._module = _ui_host + $scope._component.name + "/module/";
$scope._class = ($scope.type != undefined && $scope.type != "") ? $scope.type : "default";
/* scope */
$scope._name = ($scope.name != undefined && $scope.name != "") ? $scope.name : "default";
$scope._type = $scope._componentType + $scope._class + ".html";
$scope._margin = ($scope.margin != undefined && $scope.margin != "") ? {
margin: $scope.margin
} : {
margin: 0
};
$scope._language = ($scope.language != undefined && $scope.language != "") ? $scope.language : "en";
/* scope */
$scope.getData = function() {
var getFunction = {
consoleLog: function(function_name, data_name, data) {
if ($scope._component.show) {
console.log($scope._component.name, ' : ', function_name, ' : ', data_name, ' : ', data);
}
},
getRouteParams: function(callback) {
var _self = this;
var params = $routeParams;
var state = _self.stateData(true, false);
_self.consoleLog("getRouteParams", "params", params);
callback(_self, params, state);
},
getCollectionId: function(params, callback) {
var _self = this;
var collection_id = (params.collection_id != undefined) ? params.collection_id.split("-", 1).join("") : false;
_self.consoleLog("getCollectionId", "collection_id", collection_id);
callback(collection_id);
},
formatDataSend: function(data, callback) {
var _self = this;
_self.consoleLog("formatDataSend", "data", data);
callback(data);
},
stateData: function(load, done) {
var _self = this;
var state = {
load: load,
done: done
};
_self.consoleLog("stateData", "state", state);
return state;
},
dataSend: function(api, dataSend, callback) {
var _self = this;
_self.consoleLog("dataSend", "api", api);
_self.consoleLog("dataSend", "dataSend", dataSend);
callback(api, dataSend);
},
checkGetApi: function(resApi, callback) {
var _self = this;
var ok = false;
if (resApi.ok == 1) {
ok = true;
}
_self.consoleLog("checkGetApi", "ok", ok);
callback(ok);
},
getApi: function(api, dataSend, callback) {
var _self = this;
var state = _self.stateData(true, false);
GAEAPI.get(api, dataSend, $scope).then(function(res_api) {
_self.consoleLog("getApi", "res_api", res_api);
_self.checkGetApi(res_api, function(res_ok) {
_self.consoleLog("getApi", "res_ok", res_ok);
state = _self.stateData(false, true);
_self.consoleLog("checkGetApi", "state", state);
callback(res_ok, res_api, state);
})
});
},
getDate: function(locale, format, lifetime, callback) {
var _self = this;
locale = (locale == '') ? 'en' : locale;
format = (format == '') ? 'LL' : format;
lifetime = (lifetime != "-1" && lifetime != "") ? lifetime : "";
if (lifetime != "") {
moment.locale(locale);
lifetime = moment.unix(parseInt(lifetime)).format(format);
}
_self.consoleLog("getDate", "lifetime", lifetime);
callback(lifetime);
},
getNameUrl: function(name, callback) {
var _self = this;
name = name.replace(/[^a-zA-Zก-๙0-9 ]/g, "").split(" ").join("-").replace("--", "-");
_self.consoleLog("getNameUrl", "name", name);
callback(name);
},
main: function() {
var _self = this;
}
}
return getFunction;
};
$scope.getPages = function() {
var getFunction = {
consoleLog: function(function_name, data_name, data) {
if ($scope._component.show) {
console.log($scope._component.name, ' : ', function_name, ' : ', data_name, ' : ', data);
}
},
locationUrlReplace: function(page) {
var _self = this;
$location.url(page).replace();
},
pageUrl: function(page_name, id, name_url) {
var _self = this;
var page = page_name + "/" + id + "-" + name_url;
_self.locationUrlReplace(page);
}
}
return getFunction;
};
$scope.countDown = function() {
var getFunction = {
consoleLog: function(function_name, data_name, data) {
if ($scope._component.show) {
console.log($scope._component.name, ' : ', function_name, ' : ', data_name, ' : ', data);
}
},
getLocation: function(callback) {
var _self = this;
var res_location = $location;
_self.consoleLog("getLocation", "res_location", res_location);
callback(res_location);
},
getRouteParams: function(callback) {
var _self = this;
var params = $routeParams;
_self.consoleLog("getRouteParams", "params", params);
callback(params);
},
getUnix: function(callback) {
var _self = this;
var now = moment().unix();
_self.consoleLog("getUnix", "now", now);
callback(now);
},
getCountDown: function(now, lifetime, callback) {
var _self = this;
var countdown_unix = parseInt(lifetime.lifetime_end_time) - now;
var milliseconds = moment.duration(countdown_unix * 1000, "milliseconds");
var res_countdown = ((milliseconds.days() <= 9) ? '0' + milliseconds.days() : milliseconds.days());
res_countdown = res_countdown + ' : ' + ((milliseconds.hours() <= 9) ? '0' + milliseconds.hours() : milliseconds.hours());
res_countdown = res_countdown + ' : ' + ((milliseconds.minutes() <= 9) ? '0' + milliseconds.minutes() : milliseconds.minutes());
res_countdown = res_countdown + ' : ' + ((milliseconds.seconds() <= 9) ? '0' + milliseconds.seconds() : milliseconds.seconds());
_self.consoleLog("getCountDown", "res_countdown", res_countdown);
callback(res_countdown, countdown_unix);
},
getNameUrl: function(name, callback) {
var _self = this;
name = name.replace(/[^a-zA-Zก-๙0-9 ]/g, "").split(" ").join("-").replace("--", "-");
_self.consoleLog("getNameUrl", "name", name);
callback(name);
},
locationUrlReplace: function(page) {
var _self = this;
$location.url(page).replace();
},
pageUrl: function(page_name) {
var _self = this;
var page = page_name;
_self.locationUrlReplace(page);
}
}
return getFunction;
};
$scope.pages = function() {
var getFunction = {
consoleLog: function(function_name, data_name, data) {
if ($scope._console) {
console.log($scope._component, ' : ', function_name, ' : ', data_name, ' : ', data);
}
},
locationUrlReplace: function(page) {
var _self = this;
$location.url(page).replace();
},
pageName: function(page_name) {
var _self = this;
var page = page_name;
_self.locationUrlReplace(page_name);
},
pageUrl: function(page_name, id, name_url) {
var _self = this;
var page = page_name + "/" + id + "-" + name_url;
_self.locationUrlReplace(page);
}
}
return getFunction;
};
/* get api */
$scope.data_api = {
load_more: {
load: false,
cur_page: 1,
per_page: 8,
total_rows: 0
},
collection_id: {
data_send: {},
api: "collection/short_id",
ok: false,
data_array: [],
data_array_state: {
load: false,
done: false
}
}
};
$scope.loadMore = function() {
if (!$scope.data_api.load_more.load) {
$scope.data_api.load_more.cur_page++;
$scope.data_api.load_more.load = true;
$scope.getData().getRouteParams(function(_self, params, state) {
_self.getCollectionId(params, function(res_collection_id) {
_self.formatDataSend($scope.data_api.collection_id, function(res_data) {
var filter_json = {};
var dataSend = {
'txt_collection_id': (res_collection_id != false) ? res_collection_id : "0",
'cur_page': $scope.data_api.load_more.cur_page,
'per_page': $scope.data_api.load_more.per_page,
'txt_badge_id': 18,
'txt_sortby': 'collection_create_time_DESC',
'txt_filter_json': JSON.stringify(filter_json)
};
res_data.data_send = dataSend;
_self.dataSend(res_data.api, res_data.data_send, function(res_api, res_data_send) {
_self.getApi(res_api, res_data_send, function(res_ok, res_api, res_state) {
res_data.ok = res_ok;
if (res_data.data_array.collection_product_array.length < res_api.data.collection_product_pagination.total_rows) {
var oldData = res_data.data_array.collection_product_array;
res_data.data_array.collection_product_array = oldData.concat(res_api.data.collection_product_array);
$scope.data_api.load_more.total_rows = res_api.data.collection_product_pagination.total_rows;
} else {
$scope.data_api.load_more.cur_page--;
}
$scope.data_api.load_more.load = false;
});
});
});
});
});
}
}
$scope.getData().getRouteParams(function(_self, params, state) {
$scope.data_api.collection_id.data_array_state = state;
_self.getCollectionId(params, function(res_collection_id) {
_self.formatDataSend($scope.data_api.collection_id, function(res_data) {
var dataSend = {};
var filter_json = {};
var dataSend = {
'txt_collection_id': (res_collection_id != false) ? res_collection_id : "0",
'cur_page': $scope.data_api.load_more.cur_page,
'per_page': $scope.data_api.load_more.per_page,
'txt_badge_id': 18,
'txt_sortby': 'collection_create_time_DESC',
'txt_filter_json': JSON.stringify(filter_json)
};
res_data.data_send = dataSend;
_self.dataSend(res_data.api, res_data.data_send, function(res_api, res_data_send) {
_self.getApi(res_api, res_data_send, function(res_ok, res_api, res_state) {
$scope.countDown().getUnix(function(now) {
res_data.ok = res_ok;
res_data.data_array = res_api.data;
if (res_api.data.collection_lifetime.length != 0) {
var lifetime_start_time = parseInt(res_api.data.collection_lifetime.lifetime_start_time);
var lifetime_end_time = parseInt(res_api.data.collection_lifetime.lifetime_end_time);
if (lifetime_start_time < now && (now < lifetime_end_time || lifetime_end_time == -1)) {
_self.consoleLog("getApiData", "display", "show");
}
else {
$scope.pages().pageName("blog/collections?id=collections");
}
}
_self.getDate('en', 'LL', res_data.data_array.collection_create_time, function(res_lifetime) {
res_data.data_array.collection_create_time_en = res_lifetime;
});
_self.getDate('en', 'LL', res_data.data_array.collection_update_time, function(res_lifetime) {
res_data.data_array.collection_update_time_en = res_lifetime;
});
angular.forEach(res_data.data_array.collection_product_array, function(item, index) {
_self.getNameUrl(res_data.data_array.collection_product_array[index].product_title, function(res_title) {
res_data.data_array.collection_product_array[index].product_title_url = res_title;
});
});
res_data.data_array_state = res_state;
_self.consoleLog("getApiData", "res_data", res_data);
$scope.data_api.load_more.total_rows = res_api.data.collection_product_pagination.total_rows;
});
});
});
});
});
});
/* get api */
};
return promise;
});
/* // JS READER : END */
/* // JS READER : START */
_ui_pvt_m.directive('componentBarFixedPosition', function($rootScope, $routeParams, $location) {
var templateName = 'componentBarFixedPosition';
var templatePathUrl = _ui_host + templateName + '/' + templateName + '.html';
var promise = {};
promise.restrict = 'AE';
promise.scope = {
width: '@width',
};
promise.templateUrl = templatePathUrl;
promise.transclude = {
'show_bar': '?showBar',
};
promise.link = function(scope, element, attr) {};
promise.controller = function($scope, $timeout, $interval, $q, $window) {};
return promise;
});
/* // JS READER : END */
/* // JS READER : START */
_ui_pvt_m.directive('componentSearchAutocomplete', function($rootScope, $routeParams, $location, sliderProvider) {
var templateName = 'componentSearchAutocomplete';
var templatePathUrl = _ui_host + templateName + '/' + templateName + '.html';
var promise = {};
promise.restrict = 'AE';
promise.scope = {
name: '@name',
type: '@type',
id: '@id',
text: '@text',
placeholder: '@placeholder',
refdata: '=referral'
};
promise.templateUrl = templatePathUrl;
promise.transclude = true;
promise.link = function(scope, element, attr) {};
promise.controller = function($scope, $timeout, $interval, $q, $window) {
$scope._text = (typeof $scope.text !== 'undefined' && $scope.text !== '') ? $scope.text : 'All';
$scope._placeholder = (typeof $scope.placeholder !== 'undefined' && $scope.placeholder !== '') ? $scope.placeholder : '';
/* Declare variables */
$scope._host = _ui_host + templateName + '/';
$scope._params = $routeParams;
$scope.assetsPath = 'extensions/themes/assets/';
$scope.viewType = $scope.type;
$scope.typerTxt = "";
$scope.timerTyper = 0;
$scope.ajaxObjTigger = new XMLHttpRequest();
$scope.countEnter = 0;
/* declare result for each type */
$scope.searchModel = {
categoryLists: [],
resultLists: [],
resultLoad: false,
resultComplete: false,
resultActiveIndex: -1,
resultActiveShow: false,
referral_id: 0,
referral_name: '',
referral_array: []
};
$scope._uniqueKey = '';
$scope._key = function() {
if ($scope._uniqueKey === '') {
$scope._uniqueKey = Math.floor((Math.random() * 9999) + 1000);
return $scope._uniqueKey;
} else {
return $scope._uniqueKey;
}
};
function requestName() {
var shopInt = parseInt(CUR_THEME.shop_id());
switch (shopInt) {
case 541:
return "zoomcamera";
break;
case 635:
return "lightmax";
break;
case 699:
return "worldcamera";
break;
case 718:
return "seselect";
break;
case 676:
return "flashmall";
break;
case 646:
return "myhappyphone";
break;
case 723:
return "eindhoven";
break;
case 738:
return "misamisa";
break;
case 717:
return "hongmin";
break;
case 747:
return "uandv";
break;
case 743:
return "smarthome";
break;
case 495:
return "proplugin";
break;
case 737:
return "gosowell";
break;
case 783:
return "maeju";
break;
case 765:
return "supercheap";
break;
}
};
$scope.requestName = requestName();
/* when user type something */
$scope.typerTxtTrigger = function(txtInput) {
if (txtInput.length < 2) {
return;
}
clearTimeout($scope.timerTyper);
$scope.timerTyper = setTimeout(function() {
return $scope.typerRequestActive(txtInput);
}, 350);
};
$scope.activeKeyCode = 0;
$scope.activeSearch = false;
/* bind document keydown for arrow keys (up, down) */
angular.element(document).bind('keydown', function(e) {
$scope.activeKeyCode = e.keyCode;
// return;
console.log("document: keydown", $scope.activeKeyCode);
console.log("searchModel.resultActiveIndex", $scope.searchModel.resultActiveIndex);
if ($scope.activeKeyCode == 38 || $scope.activeKeyCode == 40) {
$scope.triggerResultDown();
}
/* else if($scope.activeKeyCode == 13){
$scope.triggerEnter();
} else {
} */
});
/* bind body on click and check if target is search result */
angular.element('body').bind('click', function(e) {
var clickTarget = e.target.className;
console.log("you click :", clickTarget, clickTarget.indexOf('typerClickableClass'));
console.log("click all elelment : ", $('.inputCategoryPick').width());
if (CUR_THEME.shop_id() == 718 || CUR_THEME.shop_id() == 738 || CUR_THEME.shop_id() == 717 || CUR_THEME.shop_id() == 746 || CUR_THEME.shop_id() == 699 || CUR_THEME.shop_id() == 495 || CUR_THEME.shop_id() == 747 || CUR_THEME.shop_id() == 676 || CUR_THEME.shop_id() == 737 || CUR_THEME.shop_id() == 635 || CUR_THEME.shop_id() == 765) {
$('html body component-search-autocomplete .autoContainer .inputTyperContainer[data-id="' + $scope._key() + '"] input.padLeft').css("padding-left", ($('.inputCategoryPick[data-id="' + $scope._key() + '"]').width() + 15));
}
/* not click on search result */
if (clickTarget.indexOf('typerClickableClass') === -1) {
$scope.clearResult().renderList();
}
});
/* get data category */
$scope.searchCategoryLists = $scope.refdata || [];
$scope.getCategory = function() {
var dataSend = {
txt_referral_type_id: 11
};
if ($scope.searchCategoryLists.length <= 0) {
GAEAPI.get('referral/map', dataSend).then(function(e) {
$scope.searchCategoryLists = e.data;
});
}
};
$scope.getCategory();
var text_search = "";
/* press search by btn */
$scope.pressSearch = function() {
$scope.typerRequestActive($('.inputTyperContainer[data-id="' + $scope._uniqueKey + '"] #typerTxtFirst').val(), true);
text_search = $scope.typerTxt;
// $scope.clearResult().renderList();
// alert($('.inputTyperContainer[data-id='+$scope._uniqueKey+'] #typerTxtFirst').val());
return $scope.triggerEnter();
// return window.location.href = "search-result?search=" + text_search;
};
/* get data from api */
$scope.typerRequestActive = function(txtInput, bypass) {
/* case : enter */
/* if(txtInput.length >= 2 && $scope.activeKeyCode == 13){
return window.location.href = "search-result?search=" + txtInput;
} */
/* case auto search */
console.log("$scope.activeKeyCode", $scope.activeKeyCode, txtInput);
var allowSearch = ($scope.activeKeyCode >= 37 && $scope.activeKeyCode <= 40) ? false : true;
if (bypass) {
allowSearch = true;
$scope.activeKeyCode = 0;
}
/* if value and key is not up/down/enter */
if (txtInput.length >= 2 && allowSearch && $scope.activeKeyCode != 13) {
if (allowSearch) {
/* clear old data */
$scope.searchModel.resultLists = [];
$scope.searchModel.resultLoad = true;
$scope.searchModel.resultComplete = false;
$('.inputResultAutoCompleteContainer').removeClass('hide');
var filter_json = {
'search': txtInput,
'badge_id_array': [18]
};
if ($scope.searchModel.referral_array.length > 0) {
filter_json.referral_id_array = [$scope.searchModel.referral_id];
}
if ($scope.searchModel.referral_array.length > 0) {
filter_json.referral_id_array_or = $scope.searchModel.referral_array;
}
var dataSend = {
'cur_page': 1,
'per_page': 10,
'txt_filter_json': JSON.stringify(filter_json)
};
console.log("typerRequestActive: dataSend", allowSearch, dataSend);
/* trigger native ajax request */
$scope.ajaxTrigger($scope.ajaxObjTigger, 'product/lists', dataSend).then(function(e) {
console.log("typerRequestActive: result", e);
/* if valid result */
if (e.ok === 1) {
/* new data assign */
$scope.searchModel.resultLists = e.data.dataList;
/* hide loading */
$scope.searchModel.resultLoad = false;
$scope.searchModel.resultComplete = true;
/* reset active index */
$scope.searchModel.resultActiveShow = false;
$scope.searchModel.resultActiveIndex = -1;
/* mark that searach exists */
if ($scope.searchModel.resultLists.length > 0) {
$scope.activeSearch = true;
} else {
$scope.activeSearch = false;
}
}
});
}
} else {
if ($scope.activeKeyCode == 13) {
/* press left/right? */
$scope.triggerEnter();
} else {
/* press other than arrows key and enter? */
/* $scope.clearResult().renderList(); */
}
}
};
/* when user press up/down => change active index */
$scope.triggerResultDown = function(isCallback) {
if ($scope.searchModel.resultLists.length > 0) {
$scope.searchModel.resultActiveShow = true;
if ($scope.activeKeyCode == 38) {
if ($scope.searchModel.resultActiveIndex <= 0) {
return;
}
$scope.searchModel.resultActiveIndex = $scope.searchModel.resultActiveIndex - 1;
} else {
if ($scope.searchModel.resultActiveIndex <= $scope.searchModel.resultLists.length) {
$scope.searchModel.resultActiveIndex = $scope.searchModel.resultActiveIndex + 1;
}
}
console.log("searchModel.resultActiveIndex", $scope.searchModel.resultActiveIndex);
}
};
$scope.changePage = function(id, title) {
$scope.clearResult().renderList();
window.location.href = "product-detail/" + id + "-" + $scope.titleUrl(title);
};
$scope.triggerEnter = function() {
console.log("triger : 0 :", "start");
if ($scope.searchModel.resultLists.length > 0 && $scope.searchModel.resultActiveIndex != -1) {
var idx = $scope.searchModel.resultActiveIndex;
var oldObj = $scope.searchModel.resultLists[idx];
console.log("triger : 00 :", text_search);
$scope.clearResult().renderList();
return window.location.href = "product-detail/" + oldObj.product_id + "-" + $scope.titleUrl(oldObj.product_title);
} else {
var text_search = $scope.typerTxt;
// $scope.clearResult().renderList();
if (text_search != '') {
console.log("triger : 1 :", text_search, $scope.searchModel.referral_id);
if ($scope.searchModel.referral_id != 0 && !$scope.searchModel.referral_array.length) {
var page = "search-result?search=" + text_search + "&referral_array=" + $scope.searchModel.referral_id;
$location.url(page).replace();
// return window.location.href = "search-result?search=" + text_search + "&referral_array=" + $scope.searchModel.referral_id;
} else if ($scope.searchModel.referral_array.length && $scope.searchModel.referral_id == 0) {
var page = "search-result?search=" + text_search + "&referral_array=" + $scope.searchModel.referral_array.join();
$location.url(page).replace();
// return window.location.href = "search-result?search=" + text_search + "&referral_array=" + $scope.searchModel.referral_array.join();
} else {
var page = "search-result?search=" + text_search;
$location.url(page).replace();
// return window.location.href = "search-result?search=" + text_search;
}
}
}
};
$scope.ajaxTrigger = function(objxhr, apiCallName, dataArray, lastSearchTxt) {
return {
url: function() {
var s = '';
var c = 0;
for (var idx in dataArray) {
if (c <= 0) s += "?" + idx + "=" + dataArray[idx];
else s += "&" + idx + "=" + dataArray[idx];
c++;
}
return "https://" + $scope.requestName + ".getappeasy.com/store/api/v1/" + apiCallName + s;
},
then: function(isCallback) {
//var xhr = $scope.ajaxObjTigger;
objxhr.abort();
objxhr.onerror = function() {
var d = {
ok: 0,
data: false
};
$scope.$apply(function() {
isCallback(d);
});
};
objxhr.onload = function(r) {
if (objxhr.readyState === 4 && objxhr.status === 200) {
$scope.$apply(function() {
isCallback(JSON.parse(objxhr.responseText));
});
} else {
objxhr.onerror();
}
};
objxhr.open("GET", this.url(), true);
objxhr.send(null);
}
}
};
$scope.clearResult = function() {
return {
renderList: function() {
$scope.typerTxt = "";
$('#typerTxtFirst').val("");
$('.inputResultAutoCompleteContainer').addClass('hide');
/* clear old data */
$scope.searchModel.resultLists = [];
$scope.searchModel.resultLoad = false;
$scope.searchModel.resultComplete = false;
/* reset active index */
$scope.searchModel.resultActiveShow = false;
$scope.searchModel.resultActiveIndex = -1;
$scope.chooseCategoryForSeachDefault();
return true;
}
}
};
$scope.titleUrl = function(str) {
var s = str.replace(/[^a-zA-Zก-๙0-9 ]/g, "").split(" ").join("-").replace("--", "-");
return s.toLowerCase();
};
$scope.findHighlight = function(txt) {
var searchTxt = $('#typerTxtFirst').val().toLowerCase();
var reg = new RegExp(searchTxt, 'i');
var str = txt.toLowerCase();
var re = str.replace(reg, '$&');
return re;
};
$scope.componentWidth = function() {
return $('component-search-autocomplete[id="' + $scope.id + '"]').width();
};
$scope.showCategoryForSeach = function() {
$('component-search-autocomplete[id="' + $scope.id + '"]').find('.inputCategoryPickArea').toggleClass('active');
};
$scope.chooseCategoryForSeach = function(catObj) {
console.log("chooseCategoryForSeach", catObj);
$scope.searchModel.referral_name = catObj.referral_name;
var r = [];
if (catObj.referral_sub_array.length > 0) {
r.push(parseInt(catObj.referral_id));
for (var i = 0; i < catObj.referral_sub_array.length; i++) {
r.push(parseInt(catObj.referral_sub_array[i].referral_id));
if (catObj.referral_sub_array[i].referral_sub_array.length > 0) {
for (var ii = 0; ii < catObj.referral_sub_array[i].referral_sub_array.length; ii++) {
r.push(parseInt(catObj.referral_sub_array[i].referral_sub_array[ii].referral_id));
}
}
}
$scope.searchModel.referral_array = r;
$scope.searchModel.referral_id = 0;
} else {
$scope.searchModel.referral_array = [];
$scope.searchModel.referral_id = parseInt(catObj.referral_id);
}
$('component-search-autocomplete[id="' + $scope.id + '"]').find('.inputCategoryPickArea').removeClass('active');
};
$scope.chooseCategoryForSeachDefault = function() {
$scope.searchModel.referral_id = 0;
$scope.searchModel.referral_array = [];
$scope.searchModel.referral_name = '';
$('component-search-autocomplete[id="' + $scope.id + '"]').find('.inputCategoryPickArea').removeClass('active');
};
$scope.typerFocus = function() {
$('component-search-autocomplete[id="' + $scope.id + '"]').find('.inputCategoryPickArea').removeClass('active');
};
};
return promise;
});
/* // JS READER : END */
/* // JS READER : START */
_ui_pvt_m.directive('componentSearchAutocompleteA', function($rootScope, $routeParams, $location, sliderProvider) {
var templateName = 'componentSearchAutocompleteA';
var templatePathUrl = _ui_host + templateName + '/' + templateName + '.html';
var promise = {};
promise.restrict = 'AE';
promise.scope = {
name: '@name',
coloricon: '@coloricon',
placeholder: '@placeholder',
};
promise.templateUrl = templatePathUrl;
promise.transclude = true;
promise.link = function(scope, element, attr) {};
promise.controller = function($scope, $timeout, $interval, $q, $window) {
$scope._component = {
name: "componentSearchAutocompleteA",
show: (window.location.hostname == "localhost") ? true : false
};
$scope._imgPath = CUR_THEME.file_url() + "images/";
$scope._icnPath = CUR_THEME.file_url() + "../../assets/";
$scope._componentType = _ui_trump_share_host + $scope._component + "/type/";
$scope._coloricon = ($scope.coloricon != "" && $scope.coloricon != undefined) ? $scope.coloricon : "dark";
$scope._placeholder = ($scope.placeholder != "" && $scope.placeholder != undefined) ? $scope.placeholder : "ค้นหาสินค้า";
/* function */
/* get api */
$scope.getData = function() {
var getFunction = {
consoleLog: function(function_name, data_name, data) {
if ($scope._component.show) {
console.log($scope._component.name, ' : ', function_name, ' : ', data_name, ' : ', data);
}
},
getRouteParams: function(callback) {
var _self = this;
var params = $routeParams;
var state = _self.stateData(true, false);
_self.consoleLog("getRouteParams", "params", params);
callback(_self, params, state);
},
formatDataSend: function(data, callback) {
var _self = this;
_self.consoleLog("formatDataSend", "data", data);
callback(data);
},
stateData: function(load, done) {
var _self = this;
var state = {
load: load,
done: done
};
_self.consoleLog("stateData", "state", state);
return state;
},
dataSend: function(api, dataSend, callback) {
var _self = this;
_self.consoleLog("dataSend", "api", api);
_self.consoleLog("dataSend", "dataSend", dataSend);
callback(api, dataSend);
},
checkGetApi: function(resApi, callback) {
var _self = this;
var ok = false;
if (resApi.ok == 1) {
ok = true;
}
_self.consoleLog("checkGetApi", "ok", ok);
callback(ok);
},
getApi: function(api, dataSend, callback) {
var _self = this;
var state = _self.stateData(true, false);
GAEAPI.get(api, dataSend, $scope).then(function(res_api) {
_self.consoleLog("getApi", "res_api", res_api);
_self.checkGetApi(res_api, function(res_ok) {
_self.consoleLog("getApi", "res_ok", res_ok);
state = _self.stateData(false, true);
_self.consoleLog("checkGetApi", "state", state);
callback(res_ok, res_api, state);
})
});
},
main: function() {
var _self = this;
}
}
return getFunction;
};
/* get api */
/* control */
$scope.controlFunction = function() {
var getFunction = {
consoleLog: function(function_name, data_name, data) {
var _self = this;
if ($scope._component.show) {
console.log($scope._component.name, ' : ', function_name, ' : ', data_name, ' : ', data);
}
},
controlState: function() {
var _self = this;
if (!$scope.control.state) {
$scope.control.state = true;
$scope.control.text_input = "";
} else {
$scope.control.state = false;
$scope.control.text_input = "";
}
},
checkInput: function() {
var _self = this;
_self.consoleLog("checkInput", "control.input", $scope.control.text_input);
/* if ($scope.control.text_input.length > 2) {
$scope.getData().getRouteParams(function(_self_api, params, state) {
$scope.data_api.product.data_array_state = state;
_self_api.formatDataSend($scope.data_api.product, function(res_data) {
var filter_json = {
'search': $scope.control.text_input,
'badge_id_array': [18]
};
var dataSend = {
'cur_page': 1,
'per_page': 10,
'txt_filter_json': JSON.stringify(filter_json)
};
res_data.data_send = dataSend;
_self_api.dataSend(res_data.api, res_data.data_send, function(res_api, res_data_send) {
_self_api.getApi(res_api, res_data_send, function(res_ok, res_api, res_state) {
res_data.ok = res_ok;
res_data.data_array = res_api.data.dataList;
res_data.data_array_state = res_state;
_self_api.consoleLog("getApiData", "res_data", res_data);
});
});
});
});
} */
}
}
return getFunction;
};
/* control */
/* function */
$scope.control = {
state: false,
text_input: "",
};
$scope.data_api = {
show: false,
product: {
data_send: {},
api: "product/lists",
ok: false,
data_array: [],
data_array_state: {
load: false,
done: false
}
}
};
angular.element(document).bind('keydown', function(res_keydown) {
$scope.getData().getRouteParams(function(_self_api, params, state) {
_self_api.consoleLog("keydown", "res_keydown", res_keydown);
if (res_keydown.keyCode == 13 && $scope.control.text_input.length > 0) {
_self_api.consoleLog("keydown", "res_keydown.keyCode", res_keydown.keyCode);
var pages_data = "search-result?search=" + $scope.control.text_input;
$location.url(pages_data).replace();
}
});
});
};
return promise;
});
/* // JS READER : END */
/* // JS READER : START */
/* UI: */
_ui_pvt_m.directive('displayCode', function ($rootScope) {
var templateName = 'displayCode';
var templatePathUrl = _ui_host + templateName + '/' + templateName + '.html';
var promise = {};
promise.restrict = 'AE';
promise.scope = {
'tag':'@tag',
'transclude':'@transclude'
};
promise.templateUrl = templatePathUrl;
promise.transclude = true;
promise.link= function(scope, element, attrs, ctrl, transclude) {
};
promise.controller = function ($scope) {
};
return promise;
});
/* // JS READER : END */
/* // JS READER : START */
_ui_pvt_m.directive('displayHtml', function ($rootScope) {
var templateName = 'displayHtml';
var templatePathUrl = _ui_host + templateName + '/' + templateName + '.html';
var promise = {};
promise.restrict = 'AE';
promise.scope = {
'tag':'@tag',
'transclude':'@transclude'
};
promise.templateUrl = templatePathUrl;
promise.transclude = true;
promise.link= function(scope, element, attrs, ctrl, transclude) {
};
promise.controller = function ($scope) {
};
return promise;
});
/* // JS READER : END */
/* // JS READER : START */
/* UI: */
_ui_pvt_m.directive('headerDesktop', function($rootScope, menuCustomProvider, $location) {
var templateName = 'headerDesktop';
var templatePathUrl = _ui_host + templateName + '/' + templateName + '.html';
var promise = {};
promise.restrict = 'AE';
promise.scope = {
login: "=login",
logout: "=logout",
modal: "=modal",
btnstyle: "@btnstyle",
colorstyle: "@colorstyle",
imgpath: "@imgpath",
imgpathlogo: "@imgpathlogo",
pagename: "@datapagename",
};
promise.templateUrl = templatePathUrl;
promise.transclude = true;
promise.link = function(scope, element, attr) {
angular.forEach(attr, function(value, attributeName) {
if (attributeName.indexOf("config") !== -1) {
scope._config[attributeName] = value;
}
});
};
promise.controller = function($scope, $timeout, $interval, $q, $window, $sce, $routeParams) {
$scope.icnPath = CUR_THEME.file_url() + '../../assets/';
$scope.forbidden = false;
$scope._config = [];
$scope._dataBanner = [];
$scope._host = _ui_host + templateName + '/';
$scope.customerData = false;
$scope.routeParams = $routeParams;
$scope.assetsPath = 'extensions/themes/assets/';
if (!$scope.customerData) {
UiCustomerBox.listen.me(function(customerData) {
if (customerData == null) {} else {
if (!$scope.customerData) {
$scope.customerData = customerData;
}
}
});
}
if (typeof GAEAPI === 'undefined' || GAEAPI == undefined) {
_componentLog('headerDesktop', false);
$scope.forbidden = true;
} else {
_componentLog('headerDesktop', true);
}
$scope.newLoginregister = function(name) {
window.location.href = GURL.base_url() + name;
//window.location.href='login';
};
$scope.data_logo = false;
$scope.getShopCurrent = function() {
GAEAPI.get('shop/current', [], $scope).then(function(e) {
if (e.ok === 1) {
$scope.data_logo = e.data;
console.log("FootershopLogo", $scope.data_logo);
angular.forEach(e.data.shop_logo, function(i, key) {
console.log("FootershopLogo : key : ", key);
$scope.ItemObject(key, i);
});
}
});
};
$scope.getShopCurrent();
$scope.datalogo = false;
$scope.ItemObject = function(iconName, iconValue) {
var nameSplit = iconName.split("_");
// console.log("FootershopLogo", " iconName : ", iconName, " iconValue : ", iconValue);
if ($scope.imglogo_ == nameSplit[1]) {
// console.log("FootershopLogo : $scope.imglogo_ : ", $scope.imglogo_, iconValue[0].image_url);
$scope.datalogo = iconValue[0].image_url;
}
};
// $scope._getSearch = function () {
// // $scope.unViewMobile();
// return UiSearchBox.delegate.modal.open();
// };
/* Customer Element Style */
$scope._loadCustomerElementStyle = function() {
var a = $scope._host + 'elementstyle/' + $scope.colorstyle + '.html';
return a.toString();
};
$scope._shopDefaultLogo = "";
$scope._displayLogo = function(fileName) {
$scope._shopDefaultLogo = $scope.imgpath + fileName;
};
/* Mobile */
$scope._onMobileActive = function() {
var oma = setTimeout(function() {
angular.element('body').addClass('_bodyNoscroll');
angular.element('section.mobileOnActive').addClass('active');
angular.element('.hamburger_close').addClass('show');
clearTimeout(oma);
}, 100);
};
$scope._onMobileUnactive = function() {
var omua = setTimeout(function() {
angular.element('body').removeClass('_bodyNoscroll');
angular.element('section.mobileOnActive').removeClass('active');
angular.element('.hamburger_close').removeClass('show');
clearTimeout(omua);
}, 100);
};
$scope._menuMobileNaviageTo = function(toWhere) {
$scope._onMobileUnactive();
var check = (toWhere.indexOf('?') === -1 && toWhere.indexOf("&") === -1) ? true : false;
switch (check) {
case true:
$location.path(toWhere).search({});
break;
default:
window.location.href = toWhere;
break;
}
};
/* for missmonribs */
$scope._pathMMR = function(toWhere, root_id) {
$scope._onMobileUnactive();
$location.path(toWhere).search({
root_id: root_id,
referral_type: 'category'
});
};
// $scope._modalOpen = function (elementType, enableGuess, skipToCheckout) {
/*UiCustomerBox.get.isLogin()==false && UiCustomerBox.modal.openLoginForm(); UiCustomerBox.get.isLogin()==true && UiCustomerBox.modal.open();*/
/*if (typeof UiCustomerBox === 'undefined' || UiCustomerBox == undefined) {
return;
}*/
// var delayTrigger = 100;
// if (elementType === 'mobile') {
// $scope._onMobileUnactive();
// delayTrigger = 600;
// }
// var modalOpenTimer = setTimeout(function () {
// clearTimeout(modalOpenTimer);
/*if (!UiCustomerBox.delegate.get.isLogin()) {
return UiCustomerBox.delegate.modal.openLoginForm();
} else if (UiCustomerBox.delegate.get.isLogin()) {
return UiCart.delegate.modal.open();
}*/
// UiCart.delegate.modal.open();
// }, delayTrigger);
// };
$scope._modalOpen = function(elementType, enableGuess, skipToCheckout) {
UiCart.delegate.modal.open();
// if (typeof UiCustomerBox === 'undefined' || UiCustomerBox == undefined) {
// return;
// }
// var delayTrigger = 100;
// $scope.unViewMobile();
// var modalOpenTimer = setTimeout(function () {
// return UiCart.delegate.modal.open();
// clearTimeout(modalOpenTimer);
// if (!UiCustomerBox.delegate.get.isLogin()) {
// return UiCustomerBox.delegate.modal.openLoginForm();
// } else if (UiCustomerBox.delegate.get.isLogin()) {
// return UiCart.delegate.modal.open();
// }
// }, delayTrigger);
};
/* Customer Status */
$scope._getMe = {};
$scope._isLogin = function() {
if (UiCustomerBox.delegate.get.isLogin()) {
$scope._getMe = UiCustomerBox.delegate.get.me();
}
return UiCustomerBox.delegate.get.isLogin();
};
$scope._getLogin = function() {
$scope._onMobileUnactive();
return UiCustomerBox.delegate.modal.openLoginForm();
};
$scope.newLoginregister = function(name) {
window.location.href = GURL.base_url() + name;
};
$scope._getSearch = function() {
$scope._onMobileUnactive();
return UiSearchBox.delegate.modal.open();
};
$scope._getInfo = function() {
$scope._onMobileUnactive();
return UiCustomerBox.delegate.modal.open();
};
$scope._getLogout = function() {
$scope._onMobileUnactive();
return UiCustomerBox.delegate.doLogOut();
};
$scope._cartTotal = function() {
return UiCart.delegate.get.totalAmount();
};
/* JQ: onResize */
angular.element($window).bind('resize', function() {
if ($(document).scrollTop() > 240 && $(window).width() >= 931) {
$scope._makeHiddenActive();
} else {
$scope._makeHiddenUnActive();
}
});
/* JQ: onScroll */
$scope._makeHiddenActive = function() {
angular.element('._hidden_menu').addClass('onScroll');
};
$scope._makeHiddenUnActive = function() {
angular.element('._hidden_menu').removeClass('onScroll');
};
$scope.bindLoadEL = function() {
$timeout(function() {
if ($(document).scrollTop() > 240 && $(window).width() >= 931) {
$scope._makeHiddenActive();
} else {
$scope._makeHiddenUnActive();
}
angular.element($window).bind('scroll', function() {
if ($(document).scrollTop() > 240) {
$scope._makeHiddenActive();
} else {
$scope._makeHiddenUnActive();
}
});
}, 1000);
};
$scope.bindLoadEL();
/* API: Get Blogs & Page */
$scope._blogLists = [];
$scope._getBlogLists = function() {
$scope._BlogsData = [];
GAEAPI.get('post/lists', {
cur_page: 1,
per_page: 30,
txt_sortby: 'post_create_time_DESC'
}).then(function(res) {
if (res.ok === 1) {
$scope._BlogsData = res.data.dataList;
$scope._blogLists = res.data.dataList;
console.log("getGlogLists", res.data.dataList);
}
});
};
$scope._pageLists = [];
$scope._getPageLists = function() {
$scope._pageLists = [];
GAEAPI.get('page/lists', {
cur_page: 1,
per_page: 30,
txt_sortby: 'page_lastest_create'
}).then(function(res) {
if (res.ok === 1) {
$scope._pageLists = res.data.dataList;
angular.forEach($scope._pageLists, function(item, key) {
if (item.page_search_url == "") {
item.page_search_url = item.page_id;
}
});
}
});
};
/*$scope._getBlogLists();*/
$scope._getPageLists();
/* Menu Manual */
$scope.custommenu = menuCustomProvider.get('unity');
$scope.currentViewMenu = "";
$scope.setCurrentViewMenu = function(n) {
if ($scope.currentViewMenu != n) {
$scope.currentViewMenu = n;
} else {
$scope.currentViewMenu = "";
}
};
$scope._showWeb = function(objArray) {
var r = false;
for (var i = 0; i < objArray.length; i++) {
if (objArray[i].badge_id == 18) {
r = true;
break;
}
}
return r;
};
$scope._showApp = function(objArray) {
var r = false;
for (var i = 0; i < objArray.length; i++) {
if (objArray[i].badge_id == 19) {
r = true;
break;
}
}
return r;
};
/*
* Type custom
* get referral list by id
* @params none
* @return array
*/
$scope._referralList_product = [];
$scope._referralList_tour = [];
$scope._referralList_Brand = [];
$scope._getReferral_TourProductBrand = function() {
var dataSendA = {
txt_referral_type_id: 11,
txt_parent_id: 4716
};
var dataSendB = {
txt_referral_type_id: 11,
txt_parent_id: 4717
};
var dataSendC = {
txt_referral_type_id: 12,
txt_parent_id: 0
};
GAEAPI.get('referral/map', dataSendA, $scope).then(function(e) {
if (e.ok === 1) {
$scope._referralList_product = e.data;
}
});
GAEAPI.get('referral/map', dataSendB, $scope).then(function(e) {
if (e.ok === 1) {
$scope._referralList_tour = e.data;
}
});
GAEAPI.get('referral/map', dataSendC, $scope).then(function(e) {
if (e.ok === 1) {
$scope._referralList_Brand = e.data;
}
});
};
$scope._getReferral_TourProductBrand();
$scope._data_referral_list_display = [];
$scope._get_referral_list_display = function() {
var dataSend = {
'txt_referral_type_id': 11,
'txt_sortby': 'referral_sort_index_asc_name_asc'
};
var dataEndPoint = 'referral/map';
GAEAPI.get(dataEndPoint, dataSend).then(function(res) {
if (res.ok === 1) {
$scope._data_referral_list_display = res.data;
}
});
};
$scope._get_referral_list_display();
/**
* View Menu function
* @params path (string)
* @return eventObject
*/
$scope.setViewFromMenu = function(path) {
$scope.currentViewMenu = '';
$timeout(function() {
GURL.location.href = path;
}, 300);
};
$scope.checkDropMobileLogoHeight = function() {
var promise = {
margin: $('div#logo-id-drop-menu').height() + 'px',
height: 'calc(100vh - ' + $('div#logo-id-drop-menu').height() + 'px)'
};
return promise;
};
$scope.titleUrl = function(str) {
var s = str.replace(/[^a-zA-Zก-๙0-9 ]/g, "").split(" ").join("-").replace("--", "-");
return s;
};
};
return promise;
});
/* // JS READER : END */
/* // JS READER : START */
/* UI: */
_ui_pvt_m.directive('layoutHeroTransparent', function ($rootScope, sliderProvider, $window, outerElement) {
var templateName = 'layoutHeroTransparent';
var templatePathUrl = _ui_host + templateName + '/' + templateName + '.html';
var promise = {};
promise.restrict = 'AE';
promise.scope = {
name: '@name',
type: '@type',
dataimg: '@dataimg',
dataimgsub: '@dataimgsub',
datatxtone: '@datatxtone',
datatxttwo: '@datatxttwo',
datatxtthree: '@datatxtthree',
datalink: '@datalink',
responsive: '@responsive',
key: '@key',
height: '@height',
noheight: '@noheight',
lockheight: '@lockheight',
fitwidth: '@fitwidth',
imgpath: '@imgpath',
enableanimate: '@enableanimate'
};
promise.templateUrl = templatePathUrl;
promise.transclude = true;
promise.link = function (scope, element, attr) {
//console.debug('attr', attr);
angular.forEach(attr, function (value, attributeName) {
if (attributeName == "config" && typeof value !== 'undefined') {
if (typeof value !== 'undefined' && value !== undefined)
scope._config[attributeName] = value;
else
scope._config[attributeName] = "";
}
if (attributeName == "height" && typeof value !== 'undefined') {
if (typeof value !== 'undefined' && value !== undefined)
scope._config[attributeName] = value;
else
scope._config[attributeName] = "";
}
if (attributeName == "responsive" && typeof value !== 'undefined') {
if (typeof value !== 'undefined' && value !== undefined)
scope._config[attributeName] = value;
else
scope._config[attributeName] = "";
}
if (attributeName == "noheight" && typeof value !== 'undefined') {
if (typeof value !== 'undefined' && value !== undefined)
scope._config[attributeName] = value;
else
scope._config[attributeName] = "";
}
if (attributeName == "lockheight" && typeof value !== 'undefined') {
if (typeof value !== 'undefined' && value !== undefined)
scope._config[attributeName] = value;
else
scope._config[attributeName] = "";
}
if (attributeName == "fitwidth" && typeof value !== 'undefined') {
if (typeof value !== 'undefined' && value !== undefined)
scope._config[attributeName] = value;
else
scope._config[attributeName] = "";
}
});
};
promise.controller = function ($scope, $timeout, $interval, $q, $window, $sce) {
$scope.forbidden = false;
$scope._config = [];
$scope._dataBanner = [];
$scope._host = _ui_host + templateName + '/';
if (typeof GAEAPI === 'undefined' || GAEAPI == undefined) {
_componentLog('layoutHeroTransparent', false);
$scope.forbidden = true;
} else {
_componentLog('layoutHeroTransparent', true);
}
$scope._includeByType = function (t) {
var r = '';
if (t === 'top') {
r = 'elementstyle/.html';
}
};
$scope._trust = function (str) {
return $sce.trustAsUrl(str);
};
/* Customer Element Style */
$scope.loadTemplateElement = function () {
var a = $scope._host + 'elementstyle/';
return a.toString();
};
$scope.isMobileSize = ($(window).width() <= 991) ? true : false;
/* BANNER */
$scope.getBanner = function () {
var dataSend = {};
GAEAPI.get('web/home', dataSend, $scope).then(function (res) {
$scope._dataBanner = res.data;
var t = $interval(function () {
if ($scope._uniqueKey !== "") {
$interval.cancel(t);
var tt = $timeout(function () {
$timeout.cancel(tt);
if($scope.type !== 'bannerhighlight'){
$scope._heroMakeCarousel();
}
}, 500);
}
}, 500);
});
};
$scope.getBanner();
/* UNIQUE KEY */
$scope._uniqueKey = '';
$scope._key = function () {
if ($scope._uniqueKey === '') {
$scope._uniqueKey = Math.floor((Math.random() * 9999) + 1000);
return $scope._uniqueKey;
} else {
return $scope._uniqueKey;
}
};
/* WINDOWS EVENT */
$scope.windowsSize = {
width: $(window).width() || 0,
height: $(window).height() || 0,
heightHero: {
main: parseInt($(window).height() * 0.7),
margin: parseInt($(window).height() * 0.15)
}
};
$scope.windowOriginal = $(window).width();
$scope._winWidth = function () {
return $(window).width();
};
$scope._winHeight = function () {
return $(window).height();
};
$scope.getWindowsSize = function () {
$scope.windowOriginal = $(window).width();
$scope.windowsSize.width = $(window).width();
$scope.windowsSize.height = $(window).height();
$scope.windowsSize.heightHero.main = parseInt($(window).height() * 0.7);
$scope.windowsSize.heightHero.margin = parseInt($(window).height() * 0.15);
};
$scope.getWindowsSize();
var timerResize = null;
angular.element($window).bind('resize', function () {
var doWhenStop = function () {
$scope.isMobileSize = ($scope._winWidth() <= 991) ? true : false;
//if (!$scope.isMobileSize) {
// console.debug("Resized Window");
$scope.windowsSize.width = $scope._winWidth();
$scope.windowsSize.height = $scope._winHeight();
$scope.windowsSize.heightHero.main = parseInt($scope._winHeight() * 0.7);
$scope.windowsSize.heightHero.margin = parseInt($scope._winHeight() * 0.15);
$scope._fitHeight = $('.layoutHeroTransparent[data-key="' + $scope._uniqueKey + '"]').find('.background').height();
//if($(window).width() != $scope.windowsSize.width) {
//$scope._heroDestroyCarousel();
//}
//}
};
clearTimeout(timerResize);
timerResize = setTimeout(doWhenStop, 500);
});
/* Size */
$scope._mobileAdjustmentPad = function () {
if ($scope._winWidth <= 991) {
return 64;
}
return 0;
};
$scope.getClosest = function (arr, closestTo) {
var closest = Math.max.apply(null, arr);
for (var i = 0; i < arr.length; i++) {
if (arr[i] >= closestTo && arr[i] < closest)
closest = arr[i];
}
return closest;
};
$scope.sizeSet = [100, 200, 300, 400, 800, 1000];
$scope.viewImage_ = function (imageSrc, image_id) {
if (window.devicePixelRatio >= 2) {
return imageSrc;
}
var w = (image_id !== 0) ? $('#display-' + image_id).width() : window.innerWidth;
var p = $scope.getClosest($scope.sizeSet, w);
var t = imageSrc.split("://");
var r = t[1].split('/');
r[r.length - 1] = "t" + p + "_" + r[r.length - 1];
var ret = "";
for (var i = 0; i < r.length; i++) {
if (i == 0)
ret += r[i];
else
ret += "/" + r[i];
}
return t[0] + '://' + ret;
};
/* Badge */
$scope._showWeb = function (itemData) {
/* Skip if carousel */
if($scope.type == 'default' || $scope.type==='top_carousel' || $scope.type === 'secondary_carousel' ){
return true;
}
var item = itemData.banner_badge;
var r = false;
if (item.length <= 0) {
return false;
} else {
for (var i = 0; i < item.length; i++) {
if (item[i].badge_id == 18) {
r = true;
break;
}
}
}
return r;
};
$scope._showApp = function (itemData) {
/* Skip if carousel */
if($scope.type == 'default' || $scope.type==='top_carousel' || $scope.type === 'secondary_carousel'){
return true;
}
var item = itemData.banner_badge;
var r = false;
if (item.length <= 0) {
return false;
} else {
for (var i = 0; i < item.length; i++) {
if (item[i].badge_id == 19) {
r = true;
break;
}
}
}
return r;
};
/* SLIDER EVENT (REQUIRE SLICK) */
$scope._hideNoData = function () {
console.debug("Slide None", $scope.type);
$('.layouytHeroOverlayLazy[data-key="' + $scope._uniqueKey + '"]').addClass('_active');
$('.layouytHeroOverlayLazy[data-key="' + $scope._uniqueKey + '"]').addClass('_hide');
$('layout-hero-transparent .layouytHeroOverlayLazy[data-key="' + $scope._uniqueKey + '"]').hide();
$('layout-hero-transparent .layoutHeroTransparent[data-key="' + $scope._uniqueKey + '"]').hide();
};
$scope._heroDestroyCarousel = function () {
var elementName = '.slickSider[data-key="' + $scope._uniqueKey + '"]';
if ($('.slickSider[data-key="' + $scope._uniqueKey + '"]').find('.column').length) {
//$('.slickSider[data-key="' + $scope._uniqueKey + '"]').slick('unslick');
$timeout(function () {
$scope._heroMakeCarousel();
}, 1000);
} else {
$scope._hideNoData();
}
};
$scope._heroMakeCarousel = function () {
var elementName = '.slickSider[data-key="' + $scope._uniqueKey + '"]';
if ($('.slickSider[data-key="' + $scope._uniqueKey + '"]').find('.column').length) {
var optionsParmas = {
autoplay: (window.location.host !== 'localhost') ? true : false,
slidesToShow: ($scope.type === 'minibanner') ? 3 : 1,
slidesToScroll: 1,
dots: ($scope.type === 'top' || $scope.type === 'bottom' || $scope.type === 'minibanner') ? false : true,
arrows: ($scope.type === 'top' || $scope.type === 'bottom' || $scope.type === 'minibanner') ? false : true,
centerMode: false,
infinite: true,
variableWidth: false
};
/* Re-apply options*/
if ($scope.type === 'minibanner') {
optionsParmas.responsive = [
{
breakpoint: 1200,
settings: {
slidesToShow: 3,
slidesToScroll: 3,
variableWidth: false,
centerMode: false
}
}, {
breakpoint: 769,
settings: {
slidesToShow: 2,
slidesToScroll: 2,
variableWidth: false,
centerMode: false
}
}, {
breakpoint: 601,
settings: {
slidesToShow: 2,
slidesToScroll: 2,
variableWidth: false,
centerMode: false,
}
}, {
breakpoint: 481,
settings: {
slidesToShow: 1,
slidesToScroll: 1,
variableWidth: false,
centerMode: false,
dots: false,
arrows: false,
}
}
];
}if ($scope.type === 'mainbanner') {
optionsParmas.responsive = [
{
breakpoint: 481,
settings: {
slidesToShow: 1,
slidesToScroll: 1,
variableWidth: false,
centerMode: false,
dots: false,
arrows: false,
}
}
];
}
if($scope.name == 'tkgroup'){
optionsParmas.autoplay = true;
optionsParmas.autoplaySpeed = 10000;
}
var extraOptions = {
animate: (typeof $scope.enableanimate !== 'undefined' && $scope.enableanimate == 1) ? true : false
};
if ($('.slickSider[data-key="' + $scope._uniqueKey + '"]').find('.column').length > 1) {
/*console.log("Apply Option", optionsParmas);*/
sliderProvider(elementName, optionsParmas, $scope.type, $scope._uniqueKey, extraOptions);
} else if ($('.slickSider[data-key="' + $scope._uniqueKey + '"]').find('.column').length == 1) {
$('.layouytHeroOverlayLazy[data-key="' + $scope._uniqueKey + '"]').addClass('_active');
$('.layouytHeroOverlayLazy[data-key="' + $scope._uniqueKey + '"]').addClass('_hide');
$('.layoutHeroTransparent[data-key="' + $scope._uniqueKey + '"]').addClass('_active');
/*$('._nav[data-key="' + $scope._uniqueKey + '"]').addClass('_open');*/
} else {
$('layout-hero-transparent .layouytHeroOverlayLazy[data-key="' + $scope._uniqueKey + '"]').hide();
}
} else {
/* $interval.cancel(carouselTimer);*/
/* 0 ? */
$scope._hideNoData();
outerElement.remove($scope.name);
}
};
$scope._int = function (s) {
return parseInt(s);
}
/* Broad Case Function */
$scope._broadCarousel = function (elementName, elementOption) {
var t, l = $scope.$watch(function () {
clearTimeout(t);
t = setTimeout(function () {
l();
$rootScope.$broadcast("makeCarouselBroadcast", {
element_name: elementName,
element_option: elementOption
});
}, 300);
});
};
/* Calculate Height uppon user */
$scope._autoHeight = 0;
$scope._lockPadding = 0;
$scope._fitHeight = 0;
$scope._responseHeight = function () {
//console.log('_config', $scope._config);
if ($scope._config['noheight'] !== "") {
$scope._autoHeight = "height:auto;";
}
if ($scope._config['lockheight'] !== "") {
$scope._lockPadding = 1;
}
};
$scope._responseHeight();
var chkHeight = $interval(function () {
if ($scope._uniqueKey != "") {
$scope._fitHeight = $('.layoutHeroTransparent[data-key="' + $scope._uniqueKey + '"]').find('.background').height();
if ($scope._fitHeight > 0) {
$interval.cancel(chkHeight);
}
}
}, 500);
/* Slick Events */
$scope._slickGoLeft = function () {
setTimeout(function () {
$('.slickSider[data-key="' + $scope._uniqueKey + '"]').slick('slickPrev');
}, 100);
};
$scope._slickGoRight = function () {
setTimeout(function () {
$('.slickSider[data-key="' + $scope._uniqueKey + '"]').slick('slickNext');
}, 100);
};
$scope._NavArrowPad = function () {
var h = $('.layoutHeroTransparent[data-key="' + $scope._uniqueKey + '"]').find('.background').height();
var r = "top:calc(" + h + "px / 2 - 20px);";
return r;
};
$scope._highlightClick = function (i) {
var link = $scope._dataBanner.main_banner_master.banner_array[i].banner_link_url || '';
if(link != ''){
return $window.location.href = link;
}
return;
};
};
return promise;
});
/* // JS READER : END */
/* // JS READER : START */
var $noNgForm = $noNgForm || {};
$noNgForm.call = function(elementName) {
/* */
};
$noNgForm.go = function(valueStringToBeArray){
console.log("$noNgForm.select: go",valueStringToBeArray);
var valStr = valueStringToBeArray.split('@')[1];
var valArray = valStr.split('|');
var strHref = "category-lists?"+valArray[0];
if(valArray[1]!=""){
strHref += "&"+valArray[1];
}
if(valArray[2]!=""){
strHref += "&"+valArray[2];
}
window.location.href = strHref;
};
$noNgForm.getReferralIdFromSelect = function(str){
var a = str.split('@');
var bArr = a[1].split('|');
return bArr[1];
};
$noNgForm.typeTimer = null;
$noNgForm.select = function(elementName, typeSelect) {
console.log('getReferralMap: number', typeSelect);
var tt = parseInt(typeSelect);
var v = $(elementName).val();
switch(tt){
case 1: // zoomcamera
clearTimeout($noNgForm.typeTimer);
$noNgForm.typeTimer = setTimeout(function(){
if($('input[data-id="'+elementName+'"]').val().length >= 3 && $('input'+elementName).val().indexOf('referral_id') !== -1 && $('select'+elementName).val() !== 'เลือกกลุ่มสินค้า'){
var selectVal = $('select'+elementName).val();
var txtVal = $('input[data-id="'+elementName+'"]').val();
var a = (selectVal.indexOf('@') !== -1) ? selectVal.split('@')[0] : selectVal;
var hrefString = "search-result?page=1&perpage=10&query="+txtVal+"&"+$noNgForm.getReferralIdFromSelect(selectVal);
$('[data-id="'+elementName+'"]').find('.value').text(a);
setTimeout(function(){
window.location.href=hrefString;
}, 500);
}
},1000);
break;
case 2: // myhappyphone
var a = (v.indexOf('@') !== -1) ? v.split('@')[0] : v;
$('[data-id="'+elementName+'"]').find('.value').text(a);
console.log("$noNgForm.select : value (2)", a, v);
setTimeout(function(){
$noNgForm.go(v);
}, 300);
break;
case 3: // missmonribs
var a = (v.indexOf('@') !== -1) ? v.split('@')[0] : v;
$('[data-id="'+elementName+'"]').find('.value').text(a);
console.log("$noNgForm.select : value (2)", a, v);
setTimeout(function(){
$noNgForm.go(v);
}, 300);
break;
default:
$('[data-id="'+elementName+'"]').find('.value').text(v);
console.log("$noNgForm.select : value", v);
break;
}
};
$noNgForm.tabShow = function(elementParentPrefix,tabIndex, event){
var elementName = elementParentPrefix+event.getAttribute('data-index');
$(elementName).find('[data-content!='+tabIndex+']').removeClass('show').removeClass('active');
$(elementName).find('[data-target!='+tabIndex+']').removeClass('active');
var e = $(elementName).find('[data-content='+tabIndex+']');
var p = $(elementName).find('[data-target='+tabIndex+']');
e.addClass('active');
p.addClass('active');
var tabTimer = setTimeout(function(){
e.addClass('show');
window.clearTimeout(tabTimer);
}, 100);
};
$noNgForm.active = function(element, idElement){
/*var a = element.classList.value.toString();
if(a.indexOf('active')==-1){
element.classList.add('active');
} else {
element.classList.remove('active');
} */
if($(window).width() <= 991){
$('.item_choice[data-id="'+idElement+'"]').toggleClass('active');
} else {
$('.item_choice[data-id="'+idElement+'"]').removeClass('active');
}
};
$noNgForm.inputChange = function(e,elementCall){
console.log("inputChange",e.value);
if(e.value.length >= 3){
UiSearchBox.delegate.modal.open();
}
};
/* // JS READER : END */
/* // JS READER : START */
/* UI: */
_ui_pvt_m.directive('pageDetail', function($rootScope, $routeParams, metaRender) {
var templateName = 'pageDetail';
var templatePathUrl = _ui_host + templateName + '/' + templateName + '.html';
var promise = {};
promise.restrict = 'AE';
promise.scope = {
name: '@name',
imgpath: '@imgpath',
type: '@type',
callback: '@callback',
pageslug: '=pageslug',
};
promise.templateUrl = templatePathUrl;
promise.transclude = true;
promise.link = function(scope, element, attr) {};
promise.controller = function($scope, $timeout, $interval, $q, $window, $location) {
$scope.forbidden = false;
$scope._config = [];
$scope._host = _ui_host + templateName + '/';
$scope.assetsPath = 'extensions/themes/assets/';
$scope.is_callback = (typeof $scope.callback !== 'undefined' && $scope.callback !== '') ? true : false;
/* UNIQUE KEY */
$scope._uniqueKey = '';
$scope._key = function() {
if ($scope._uniqueKey === '') {
$scope._uniqueKey = Math.floor((Math.random() * 9999) + 1000);
return $scope._uniqueKey;
} else {
return $scope._uniqueKey;
}
};
$scope._pageDetail = false;
$scope._pageDetailDone = false;
$scope._postOn = "";
$scope._getBlogArray = function() {
$('.load-effect').addClass('is-active');
console.log("pageDetail: Get By Slug : Start");
var id_or_slug = '';
if (parseInt($scope.pageslug) > 0) {
id_or_slug = $scope.pageslug;
$scope.getDataByID($scope.pageslug);
return;
} else if (typeof $routeParams.page_slug !== 'undefined' && $routeParams.page_slug !== '') {
id_or_slug = $routeParams.page_slug;
}
$scope._resetData();
var dataSend = {
'txt_slug': id_or_slug || ''
};
GAEAPI.get('page/get_slug', dataSend , $scope).then(function(res) {
$scope._pageDetailDone = true;
/*console.log("pageDetail: Get By Slug : $routeParams", $routeParams);
console.log("pageDetail: Get By Slug : End", res);*/
if (res.ok === 1) {
$scope._pageDetail = res.data;
console.log("page_detaik_log : ", $scope._pageDetail);
$timeout(function() {
$('.load-effect').addClass('de-active');
}, 0);
$timeout(function() {
$('.load-effect').addClass('loaded');
$('.load-effect').removeClass('is-active de-active');
$('.load-effect').removeClass('loaded');
$('html').removeClass('noscroll noscroll-long');
}, 500);
/* Date */
$scope._postOn = moment(parseInt($scope._pageDetail.page_create_time) * 1000).format('LL');
/* Badge */
/*var _showWeb = false;
for(var i=0;i<$scope._pageDetail.page_badge.length;i++){
if($scope._pageDetail.page_badge[i].badge_id==18){
_showWeb=true;
break;
}
}
if(!_showWeb){
$scope._resetData();
window.location.href = "#/home";
}*/
if (typeof $scope._pageDetail.page_id == 'undefined' && $scope.is_callback) {
$scope._getBlogDummy();
}
} else {
if ($scope.is_callback) {
$scope._getBlogDummy();
} else {
location.path('/home').search({});
}
}
});
};
$scope._getBlogDummy = function() {
var d = new Date();
var n = d.getTime() / 1000;
$scope._pageDetail = {
'page_id': 999999,
'page_name': 'This is post title of your content',
'page_title': 'This is post title of your content',
'page_share_image': [{
'image_url': 'extensions/themes/gae_default301/staticfiles/images/default/490x490.gif'
}],
'page_image': [{
'image_url': 'extensions/themes/gae_default301/staticfiles/images/default/490x490.gif'
}],
'page_image': [{
'image_url': 'extensions/themes/gae_default301/staticfiles/images/default/490x490.gif'
}],
'blog': [{
'blog_name': 'Smartphone',
'blog_id': 999999
}],
'page_author_name': 'Admin',
'page_excerpt': 'มีท่อนต่างๆ ของ Lorem Ipsum ให้หยิบมาใช้งานได้มากมาย แต่ส่วนใหญ่แล้วจะถูกนำไปปรับให้เป็นรูปแบบอื่นๆ',
'page_create_time': n,
'page_content': 'Lorem Ipsum คืออะไร? Lorem Ipsum คือ เนื้อหาจำลองแบบเรียบๆ ที่ใช้กันในธุรกิจงานพิมพ์หรืองานเรียงพิมพ์ มันได้กลายมาเป็นเนื้อหาจำลองมาตรฐานของธุรกิจดังกล่าวมาตั้งแต่ศตวรรษที่ 16 เมื่อเครื่องพิมพ์โนเนมเครื่องหนึ่งนำรางตัวพิมพ์มาสลับสับตำแหน่งตัวอักษรเพื่อทำหนังสือตัวอย่าง Lorem Ipsum อยู่ยงคงกระพันมาไม่ใช่แค่เพียงห้าศตวรรษ แต่อยู่มาจนถึงยุคที่พลิกโฉมเข้าสู่งานเรียงพิมพ์ด้วยวิธีทางอิเล็กทรอนิกส์ และยังคงสภาพเดิมไว้อย่างไม่มีการเปลี่ยนแปลง มันได้รับความนิยมมากขึ้นในยุค ค.ศ. 1960 เมื่อแผ่น Letraset วางจำหน่ายโดยมีข้อความบนนั้นเป็น Lorem Ipsum และล่าสุดกว่านั้น คือเมื่อซอฟท์แวร์การทำสื่อสิ่งพิมพ์ (Desktop Publishing) อย่าง Aldus PageMaker ได้รวมเอา Lorem Ipsum เวอร์ชั่นต่างๆ เข้าไว้ในซอฟท์แวร์ด้วย',
};
$scope._postOn = moment(n).format("LL");
$scope._tagArray = ['Tag Example A', 'Tag Example B'];
$scope._pageDetailDone = true;
};
$scope.getDataByID = function(pageId) {
console.log("pageDetail: Get By Id : Start");
$('.load-effect').addClass('is-active');
var d = {
'txt_page_id': pageId
};
GAEAPI.get('page/id', d, $scope).then(function(e) {
$scope._pageDetailDone = true;
$timeout(function() {
$('.load-effect').addClass('de-active');
}, 0);
$timeout(function() {
$('.load-effect').addClass('loaded');
$('.load-effect').removeClass('is-active de-active');
$('.load-effect').removeClass('loaded');
$('html').removeClass('noscroll noscroll-long');
}, 500);
if (e.ok == 1) {
$scope._pageDetail = e.data;
if (typeof $scope._pageDetail.page_id == 'undefined' && $scope.is_callback) {
$scope._getBlogDummy();
}
} else {
if ($scope.is_callback) {
$scope._getBlogDummy();
} else {
location.path('/home').search({});
}
}
console.log("pageDetail: Get By Id : End", e);
});
};
$scope._resetData = function() {
$scope._pageDetail = false;
$scope._pageDetailDone = false;
$scope._postOn = "";
};
$scope.$watch('pageslug', function(newValue, oldValue) {
$scope._getBlogArray();
});
/*$scope._makeBlogHeadActive = function () {
if (!angular.element('._b_d_header').hasClass('_active')) {
angular.element('._b_d_header').addClass('_active');
}
};*/
$scope._makeBlogHeadUnActive = function() {
angular.element('._b_d_header').removeClass('_active');
};
angular.element($window).bind('scroll', function() {
if ($(document).scrollTop() > 500) {
/*$scope._makeBlogHeadActive();*/
} else {
$scope._makeBlogHeadUnActive();
}
});
$scope._shareThisUrl = function() {
var a = ($window.location.href).toString();
a.replace("#/", "?t=b&i=" + $routeParams.blog_id + "#/");
return a;
};
$scope._viewMeta = function(name, pageType, uniqueId) {
return metaRender.get(name, pageType, uniqueId);
};
$scope._fill = function(image) {
if ($scope.name === 'gaoyang') {
return 'background-position: center;background-repeat: no-repeat;background-image: url(' + $scope.imgpath + image + ');background-attachment: fixed;';
}
return '';
};
};
return promise;
});
/* // JS READER : END */
/* // JS READER : START */
/* UI: */
_ui_pvt_m.directive('pageVideo', function($rootScope) {
var templateName = 'pageVideo';
var templatePathUrl = _ui_host + templateName + '/' + templateName + '.html';
var promise = {};
promise.restrict = 'AE';
promise.scope = {
name: '@name',
preload: '@preload',
imgpath: '@imgpath',
imgcover: '@imgcover',
imgsrc: '@imgsrc',
videowidth: '@videowidth',
videoheight: '@videoheight',
margin: '@margin',
callback: '@callback',
type: '@type'
};
promise.templateUrl = templatePathUrl;
promise.transclude = true;
promise.link = function(scope, element, attr) {
angular.forEach(attr, function(value, attributeName) {
if (attributeName.indexOf("config") !== -1) {
scope._config[attributeName] = value;
}
});
};
promise.controller = function($scope, $timeout, $interval, $q, $window) {
$scope.forbidden = false;
$scope._config = [];
$scope._host = _ui_host + templateName + '/';
$scope.assetsPath = 'extensions/themes/assets/';
/**
* get shop setting data -> video inside shop setting
* @params none
* return objectArray
*/
$scope._videoData = [];
$scope._finishLoading = false;
$scope._getVideoByShopSettings = function() {
$scope._videoData = [];
GAEAPI.get('shop/current', {}).then(function(res) {
if (res.ok == 1) {
var v = {
video_link: res.data.shop_video_link,
video_embed_code: res.data.shop_video_embed_code,
video_title: res.data.shop_video_title,
video_description: res.data.shop_video_description
};
$scope._videoData.push(v);
}
if ($scope._videoData.length && $scope._videoData[0].video_embed_code == '') {
$('page-video[name="' + $scope.name + '"]').hide();
$('.cover-vdo').hide();
}
if ($scope._videoData[0].video_embed_code == '' && typeof $scope.callback !== 'undefined' && $scope.callback !== '') {
$scope._videoData[0].video_embed_code = '';
$scope._videoData[0].video_title = 'Your highlight video title';
$scope._videoData[0].video_description = 'Some description about the video';
$('page-video').show();
$('.cover-vdo').show();
}
console.log('_getVideoByShopSettings: callback', $scope.callback);
console.log('_getVideoByShopSettings: _videoData', $scope._videoData);
$timeout(function() {
$('._videoLazyItem').hide();
}, 1500);
});
};
$scope._getVideoByShopSettings();
};
return promise;
});
/* // JS READER : END */
/* // JS READER : START */
_ui_pvt_m.directive('pleaseWait', function ($rootScope) {
var templateName = 'pleaseWait';
var templatePathUrl = _ui_host + templateName + '/' + templateName + '.html';
var promise = {};
promise.restrict = 'AE';
promise.scope = {
margin: '@margin',
};
promise.templateUrl = templatePathUrl;
promise.transclude = true;
promise.link = function (scope, element, attr) {};
promise.controller = function ($scope) {
$scope.icnPath = CUR_THEME.file_url() + '../../assets/';
};
return promise;
});
/* // JS READER : END */
/* // JS READER : START */
/* UI: */
_ui_pvt_m.directive('powerByGetAppEasy', function ($rootScope) {
var templateName = 'powerByGetAppEasy';
var templatePathUrl = _ui_host + templateName + '/' + templateName + '.html';
var promise = {};
promise.restrict = 'AE';
promise.scope = {
bg: '@bg',
color: '@color',
fill: '@fill',
};
promise.templateUrl = templatePathUrl;
promise.transclude = true;
promise.link = function (scope, element, attr) {
angular.forEach(attr, function (value, attributeName) {
if (attributeName.indexOf("config") !== -1) {
scope._config[attributeName] = value;
}
if(typeof attributeName !== 'undefined' && attributeName === 'fill' && value !== ""){
scope.fillcolor = value;
if(scope.fillcolor == '' || scope.fillcolor == undefined){
scope.fillcolor = '#CCCCCC'
}
}
});
};
promise.controller = function ($scope, $timeout, $interval, $q, $window) {
$scope.forbidden = false;
$scope._config = [];
$scope._dataBanner = [];
$scope._host = _ui_host + templateName + '/';
$scope.fillcolor = '#CCCCCC';
if (typeof GAEAPI === 'undefined' || GAEAPI == undefined) {
_componentLog('powerByGetAppEasy', false);
$scope.forbidden = true;
} else {
_componentLog('powerByGetAppEasy', true);
}
};
return promise;
});
/* // JS READER : END */
/* // JS READER : START */
/* UI: */
_ui_pvt_m.directive('productBuyButton', function ($rootScope) {
var templateName = 'productBuyButton';
var templatePathUrl = _ui_host + templateName + '/' + templateName + '.html';
var promise = {};
promise.restrict = 'AE';
promise.scope = {
product: '=product',
text: '@text',
type: '@type',
forcedetail: '@forcedetail',
qty: '=qty',
};
promise.templateUrl = templatePathUrl;
promise.transclude = true;
promise.link = function (scope, element, attr) {
angular.forEach(attr, function (value, attributeName) {
if (attributeName.indexOf("config") !== -1) {
scope._config[attributeName] = value;
}
});
};
promise.controller = function ($scope, $timeout, $interval, $q, $window) {
$scope.forbidden = false;
$scope._config = [];
$scope._host = _ui_host + templateName + '/';
$scope._virtualCart = false;
$scope.assetsPath = CUR_THEME.extensions_url() + '../../assets/';
if (CUR_THEME.shop_id() == 395) {
$scope._virtualCart = true;
}
if (typeof GAEAPI === 'undefined' || GAEAPI == undefined) {
_componentLog('productBuyButton', false);
$scope.forbidden = true;
} else {
_componentLog('productBuyButton', true);
}
/* Process */
$scope._cartStatus = function (product_id) {
var a = '_noCartStatus';
if (UiCart.delegate.product.isProgress(product_id)) {
a = '_inProcess';
if (UiCart.delegate.product.isSelected(product_id)) {
a = '_inCart';
}
} else {
if (UiCart.delegate.product.isSelected(product_id)) {
a = '_inCart';
}
}
return a;
};
/* Press Buy */
$scope._qtn = 1;
$scope._buy = function (product_id, product_qtn) {
var f = $scope.forcedetail;
var q = (typeof $scope.qty !== 'undefined' && $scope.qty > 0) ? $scope.qty : $scope._qtn;
if (f != "" && f !== undefined && typeof f !== 'undefined' && f.length > 0) {
if ($scope.name === 'missmonribs') {
return GURL.location.href = "#/product-detail/" + product_id;
}
if ($scope.name === 'hannah') {
return GURL.location.href = "#/product-detail/" + product_id;
}
if ($scope.name === 'bombbike') {
return GURL.location.href = "#/product-detail/" + product_id;
}
if (GURL.isHtml5Mode()) {
return GURL.location.href = "#/product-detail/" + product_id;
}
return $window.location.href = "#/product-detail/" + product_id;
}
if (!UiCustomerBox.delegate.get.isLogin()) {
//return UiCustomerBox.delegate.modal.openLoginForm();
}
/* If Product Is Not In Cart && This Product Currenly Loading */
if (!UiCart.delegate.product.isSelected(product_id)) {
/* If Not Loading or Processing */
if (!UiCart.delegate.product.isProgress(product_id)) {
UiCart.delegate.product.add(product_id, q);
console.log("Product Add:", product_id, q);
/* Pixel */
$pixelScript.event('AddToCart');
} else {
return UiCart.delegate.modal.open();
}
} else {
/* Open cart when already added */
return UiCart.delegate.modal.open();
}
};
/* Virtual Cart*/
$scope.virtualCartState = false;
$scope.checkVirtualStatus = function () {
return $scope.virtualCartState;
};
$scope.openVirtualCart = function () {
if (!$scope.virtualCartState) {
$scope.virtualCartState = true;
return;
}
$scope.virtualCartState = false;
return;
};
$scope.virtualItemArray = [];
$scope.virtualItemArrayTemp = [];
$scope.addVirtualCartItem = function (productObject) {
if (!$scope.virtualCartState) {
$scope.virtualCartState = true;
}
var t = $scope.virtualItemArrayTemp;
if (t.indexOf(productObject.product_id) == -1) {
var q = (typeof $scope.qty !== 'undefined' && $scope.qty > 0) ? $scope.qty : $scope._qtn;
var buildItem = function (data, q) {
return {
product_id: productObject.product_id,
product_compare_price: productObject.product_compare_price || 0,
product_price: productObject.product_price || 0,
product_qtn: q || 1,
product_title: productObject.product_title,
product_image: productObject.product_image[0].image_url || '',
};
};
$scope.virtualItemArray.push(buildItem(productObject, q));
$scope.virtualItemArrayTemp.push(productObject.product_id);
}
console.log("current vir iutel",$scope.virtualItemArray,$scope.virtualItemArrayTemp);
};
$scope.virItemQUp = function (idx) {
$scope.virtualItemArray[idx].product_qtn++;
return;
};
$scope.virItemQdown = function (idx) {
var i = $scope.virtualItemArray[idx].product_qtn;
var a = i - 1;
if (a >= 1) {
var q = a;
} else {
var q = 1;
}
$scope.virtualItemArray[idx].product_qtn = q;
return;
};
$scope.virItemKill = function (product_id) {
var currentArray = $scope.virtualItemArray;
var pos = 0;
for (var i = 0; i < currentArray.length; i++) {
if (currentArray[i].product_id == product_id) {
pos = i;
break;
}
}
currentArray.splice(pos, 1);
$scope.virtualItemArray = currentArray;
var currentArrayTemp = $scope.virtualItemArrayTemp;
var posFind = currentArrayTemp.indexOf(product_id);
if(posFind != -1){
currentArrayTemp.splice(posFind,1);
$scope.virtualItemArrayTemp = currentArrayTemp;
}
console.log("current vir iutel",$scope.virtualItemArray,$scope.virtualItemArrayTemp);
};
/* Check if config color exist -> use new button */
$scope.checkColor = function(){
return ($('config-color').length > 0) ? true : false;
};
$scope.checkHide = function(){
if(CUR_THEME.shop_id()==536){
return true;
}
return false;
};
};
return promise;
});
/* // JS READER : END */
/* // JS READER : START */
_ui_pvt_m.directive('productCategoryBadge', function($rootScope, $routeParams, sliderProvider) {
var templateName = 'productCategoryBadge';
var templatePathUrl = _ui_host + templateName + '/' + templateName + '.html';
var promise = {};
promise.restrict = 'AE';
promise.scope = {
name: '@name',
imgpath: '@imgpath',
badgeid: '@badgeid',
badgename: '@badgename',
};
promise.templateUrl = templatePathUrl;
promise.transclude = true;
promise.link = function(scope, element, attr) {};
promise.controller = function($scope, $timeout, $interval, $q, $window, $location) {
$scope.forbidden = false;
$scope._config = [];
$scope._host = _ui_host + templateName + '/';
/* UNIQUE KEY */
$scope._uniqueKey = '';
$scope._key = function() {
if ($scope._uniqueKey === '') {
$scope._uniqueKey = Math.floor((Math.random() * 9999) + 1000);
return $scope._uniqueKey;
} else {
return $scope._uniqueKey;
}
};
$scope._featureList = [];
$scope._featureListDone = false;
$scope._featureNav = false;
$scope._getFeatureList = function() {
if ($scope.referralid == '0' || $scope.referralid == '') {
var dataSend = {
'txt_referral_type_id': 11,
'cur_page': 1,
'per_page': 100,
'txt_sortby': 'referral_sort_index_asc_name_asc',
'txt_filter_json': JSON.stringify([{
'badge_id_array': [16]
}])
};
var endPoint = 'referral/lists';
} else {
var dataSend = {
'txt_referral_id': $scope.referralid
};
var endPoint = 'referral/id';
}
GAEAPI.get(endPoint, dataSend).then(function(e) {
if (e.ok === 1) {
if ($scope.referralid == '0' || $scope.referralid == '') {
$scope._featureList = e.data.dataList;
$scope._getProductByReferralId(e.data.dataList);
} else {
$scope._featureList = [e.data];
var arrData = [e.data];
$scope._getProductByReferralId(arrData);
}
}
$scope._featureListDone = true;
});
};
$scope._getProductByReferralId = function(objectReferralArray) {
var ref = [];
$scope._productFeatureList = [];
if (objectReferralArray.length) {
angular.forEach(objectReferralArray, function(item, key) {
ref.push(parseInt(item.referral_id));
});
if (ref.length) {
var jsonFilter = {
'referral_id_array': ref,
'badge_id_array': ($scope.category !== 'brand') ? [18] : [16, 18]
};
var dataSend = {
'cur_page': 1,
'per_page': 20,
'txt_sortby': 'product_lastest_create',
'txt_filter_json': JSON.stringify(jsonFilter)
};
GAEAPI.get('product/lists', dataSend).then(function(e) {
console.log("_getProductByReferralId : e.ok : ", e.ok);
if (e.ok == 1) {
$scope._productFeatureList = e.data.dataList;
} else {
$scope._productFeatureList = [];
}
$scope._featureNav = ($scope._productFeatureList.length > 3) ? true : false;
if ($scope._productFeatureList.length > 0) {
$scope._makeProductToCarousel();
}
$scope._makeProductHide(ref);
});
}
}
};
$scope._getProductByBadgeId = function(badgeIdRequest) {
var badgeInt = parseInt(badgeIdRequest);
var jsonFilter = {
'badge_id_array': [16, badgeInt]
};
var dataSend = {
'cur_page': 1,
'per_page': 20,
'txt_sortby': 'product_lastest_create',
'txt_filter_json': JSON.stringify(jsonFilter)
};
GAEAPI.get('product/lists', dataSend).then(function(e) {
if (e.ok == 1) {
$scope._productFeatureList = e.data.dataList;
} else {
$scope._productFeatureList = [];
}
$scope._featureNav = ($scope._productFeatureList.length > 3) ? true : false;
if ($scope._productFeatureList.length > 0) {
$scope._makeProductToCarousel();
}
$scope._makeProductHide(badgeInt);
});
};
$scope._getProductByBadgeId($scope.badgeid);
$scope._makeProductToCarousel = function() {
var elementName = '.proList[data-key="' + $scope._uniqueKey + '"]';
var optionsParmas = {
autoplay: (window.location.host !== 'localhost') ? true : false,
slidesToShow: 3,
slidesToScroll: 1,
dots: false,
arrows: false,
centerMode: false,
infinite: true,
variableWidth: false,
responsive: [{
breakpoint: 1200,
settings: {
slidesToShow: 3,
slidesToScroll: 3,
variableWidth: false,
centerMode: false
}
}, {
breakpoint: 769,
settings: {
slidesToShow: 2,
slidesToScroll: 2,
variableWidth: false,
centerMode: false
}
}, {
breakpoint: 601,
settings: {
slidesToShow: 2,
slidesToScroll: 2,
variableWidth: false,
centerMode: false
}
}, {
breakpoint: 481,
settings: {
slidesToShow: 1,
slidesToScroll: 1,
variableWidth: false,
centerMode: false,
dots: false
}
}]
};
return sliderProvider(elementName, optionsParmas, $scope.type, $scope._uniqueKey);
};
$scope._makeProductHide = function(i) {
$timeout(function() {
if (angular.element('[data-id="item-of-' + i + '"]').length <= 0) {
angular.element('[data-referral-container="' + i + '"]').hide();
}
}, 500);
};
$scope._resetData = function() {
$scope._featureList = [];
$scope._featureListDone = false;
};
$scope._slickGoLeft = function() {
setTimeout(function() {
$('.proList[data-key="' + $scope._uniqueKey + '"]').slick('slickPrev');
}, 100);
};
$scope._slickGoRight = function() {
setTimeout(function() {
$('.proList[data-key="' + $scope._uniqueKey + '"]').slick('slickNext');
}, 100);
};
$scope._productFeatureListNavHide = function(r) {
return ($('[data-id="item-of-' + r + '""]').length > 3) ? false : true;
};
$scope._productDetailGo = function(p, t) {
if ($scope.checkSeo()) {
return window.location.href = "product-detail/" + p + ((typeof t !== 'undefined') ? '-' + $scope.buildTitleUrl(t) : '');
} else {
return window.location.href = "#/product-detail/" + p + ((typeof t !== 'undefined') ? '-' + $scope.buildTitleUrl(t) : '');
}
};
/* Process */
$scope._cartStatus = function(product_id) {
var a = '_noCartStatus';
if (UiCart.delegate.product.isProgress(product_id)) {
a = '_inProcess';
if (UiCart.delegate.product.isSelected(product_id)) {
a = '_inCart';
}
} else {
if (UiCart.delegate.product.isSelected(product_id)) {
a = '_inCart';
}
}
return a;
};
$scope._buy = function(product_id, q) {
if (!UiCustomerBox.delegate.get.isLogin()) {
return UiCustomerBox.delegate.modal.openLoginForm();
}
/* If Product Is Not In Cart && This Product Currenly Loading */
if (!UiCart.delegate.product.isSelected(product_id)) {
/* If Not Loading or Processing */
if (!UiCart.delegate.product.isProgress(product_id)) {
UiCart.delegate.product.add(product_id, q);
console.log("Product Add:", product_id, q);
} else {
return UiCart.modal.open();
}
} else {
/* Open cart when already added */
return UiCart.modal.open();
}
};
$scope._viewDetail = function(endPathString) {
return (GURL.isHtml5Mode()) ? GURL.location.href = endPathString : window.location.href = endPathString;
};
$scope.checkSeo = function() {
return (GURL.isHtml5Mode()) ? true : false;
};
$scope.buildTitleUrl = function(str) {
var s = str.replace(/[^a-zA-Zก-๙0-9 ]/g, "").split(" ").join("-").replace("--", "-");
return s;
};
};
return promise;
});
/* // JS READER : END */
/* // JS READER : START */
/* UI: */
_ui_pvt_m.directive('productCategoryFeature', function ($rootScope, $routeParams, sliderProvider) {
var templateName = 'productCategoryFeature';
var templatePathUrl = _ui_host + templateName + '/' + templateName + '.html';
var promise = {};
promise.restrict = 'AE';
promise.scope = {
name: '@name',
imgpath: '@imgpath',
referralid: '@referralid',
rootid: '@rootid',
type: '@type',
pageslug: '@limit',
odd: '@odd',
idx: '@idx',
category: '@category',
};
promise.templateUrl = templatePathUrl;
promise.transclude = true;
promise.link = function (scope, element, attr) {};
promise.controller = function ($scope, $timeout, $interval, $q, $window, $location) {
$scope.forbidden = false;
$scope._config = [];
$scope._host = _ui_host + templateName + '/';
/* UNIQUE KEY */
$scope._uniqueKey = '';
$scope._key = function () {
if ($scope._uniqueKey === '') {
$scope._uniqueKey = Math.floor((Math.random() * 9999) + 1000);
return $scope._uniqueKey;
} else {
return $scope._uniqueKey;
}
};
$scope._featureList = [];
$scope._featureListDone = false;
$scope._featureNav = false;
$scope._getFeatureList = function () {
//$scope._resetData();
if ($scope.referralid == '0' || $scope.referralid == '') {
var dataSend = {
'txt_referral_type_id': 11,
'cur_page': 1,
'per_page': 100,
'txt_sortby': 'referral_sort_index_asc_name_asc',
'txt_filter_json': JSON.stringify([{'badge_id_array': [16]}])
};
var endPoint = 'referral/lists';
} else {
var dataSend = {
'txt_referral_id': $scope.referralid
};
var endPoint = 'referral/id';
}
/*console.log("_getFeatureList", dataSend);*/
GAEAPI.get(endPoint, dataSend).then(function (e) {
if (e.ok === 1) {
if ($scope.referralid == '0' || $scope.referralid == '') {
$scope._featureList = e.data.dataList;
$scope._getProductByReferralId(e.data.dataList);
} else {
$scope._featureList = [e.data];
var arrData = [e.data];
$scope._getProductByReferralId(arrData);
}
}
$scope._featureListDone = true;
});
};
$scope._getFeatureList();
$scope._getProductByReferralId = function (objectReferralArray) {
var ref = [];
$scope._productFeatureList = [];
if (objectReferralArray.length) {
angular.forEach(objectReferralArray, function (item, key) {
ref.push(parseInt(item.referral_id));
});
if (ref.length) {
var jsonFilter = {
'referral_id_array': ref,
'badge_id_array': ($scope.category !== 'brand') ? [18] : [16,18]
};
var dataSend = {
'cur_page': 1,
'per_page': 20,
'txt_sortby': 'product_lastest_create',
'txt_filter_json': JSON.stringify(jsonFilter)
};
GAEAPI.get('product/lists', dataSend).then(function (e) {
if(e.ok == 1){
$scope._productFeatureList = e.data.dataList;
} else {
$scope._productFeatureList = [];
}
$scope._featureNav = ($scope._productFeatureList.length > 3) ? true : false;
if ($scope._productFeatureList.length > 0) {
$scope.$apply(function() {
$scope._makeProductToCarousel();
});
}
$scope._makeProductHide(ref);
});
}
}
};
$scope._makeProductToCarousel = function () {
var elementName = '.proList[data-key="' + $scope._uniqueKey + '"]';
var optionsParmas = {
autoplay: (window.location.host !== 'localhost') ? true : false,
slidesToShow: 3,
slidesToScroll: 1,
dots: false,
arrows: false,
centerMode: false,
infinite: true,
variableWidth: false,
responsive: [
{
breakpoint: 1200,
settings: {
slidesToShow: 3,
slidesToScroll: 3,
variableWidth: false,
centerMode: false
}
}, {
breakpoint: 769,
settings: {
slidesToShow: 2,
slidesToScroll: 2,
variableWidth: false,
centerMode: false
}
}, {
breakpoint: 601,
settings: {
slidesToShow: 2,
slidesToScroll: 2,
variableWidth: false,
centerMode: false
}
}, {
breakpoint: 481,
settings: {
slidesToShow: 1,
slidesToScroll: 1,
variableWidth: false,
centerMode: false,
dots: false
}
}
]
};
return sliderProvider(elementName, optionsParmas, $scope.type, $scope._uniqueKey);
};
$scope._makeProductHide = function (referralObjectArray) {
console.log('referralObjectArray>', referralObjectArray);
$timeout(function () {
angular.forEach(referralObjectArray, function (i, k) {
console.log('item-of-', i);
if(angular.element('[data-id="item-of-'+i+'"]').length <= 0){
angular.element('[data-referral-container="'+i+'"]').hide();
}
});
}, 4000);
};
$scope._resetData = function () {
$scope._featureList = [];
$scope._featureListDone = false;
};
$scope._slickGoLeft = function () {
setTimeout(function () {
$('.proList[data-key="' + $scope._uniqueKey + '"]').slick('slickPrev');
}, 100);
};
$scope._slickGoRight = function () {
setTimeout(function () {
$('.proList[data-key="' + $scope._uniqueKey + '"]').slick('slickNext');
}, 100);
};
$scope._productFeatureListNavHide = function (r) {
return ($('[data-id="item-of-' + r + '""]').length > 3) ? false : true;
};
$scope._productDetailGo = function (p) {
//return $window.location.href="#/product-detail/"+p;
return (GURL.isHtml5Mode()) ? GURL.location.href = 'product-detail/'+p : window.location.href = '#/product-detail/'+p;
};
/* Process */
$scope._cartStatus = function (product_id) {
var a = '_noCartStatus';
if (UiCart.delegate.product.isProgress(product_id)) {
a = '_inProcess';
if (UiCart.delegate.product.isSelected(product_id)) {
a = '_inCart';
}
} else {
if (UiCart.delegate.product.isSelected(product_id)) {
a = '_inCart';
}
}
return a;
};
$scope._buy = function (product_id, q) {
if (!UiCustomerBox.delegate.get.isLogin()) {
return UiCustomerBox.delegate.modal.openLoginForm();
}
/* If Product Is Not In Cart && This Product Currenly Loading */
if (!UiCart.delegate.product.isSelected(product_id)) {
/* If Not Loading or Processing */
if (!UiCart.delegate.product.isProgress(product_id)) {
UiCart.delegate.product.add(product_id, q);
console.log("Product Add:", product_id, q);
} else {
return UiCart.modal.open();
}
} else {
/* Open cart when already added */
return UiCart.modal.open();
}
};
$scope._viewDetail = function(endPathString){
return (GURL.isHtml5Mode()) ? GURL.location.href = endPathString : window.location.href = endPathString;
};
};
return promise;
});
/* // JS READER : END */
/* // JS READER : START */
/* UI: */
_ui_pvt_m.directive('productDetailView', function($rootScope, $routeParams, metaRender, $location) {
var templateName = 'productDetailView';
var templatePathUrl = _ui_host + templateName + '/' + templateName + '.html';
var promise = {};
promise.restrict = 'AE';
promise.scope = {
name: '@name',
type: '@type',
id: '@id',
imgpath: '@imgpath',
promotelink: '@promotelink',
imgcart: '@imgcart',
refidid: '@refidid'
};
promise.templateUrl = templatePathUrl;
promise.transclude = true;
promise.link = function(scope, element, attr) {
angular.forEach(attr, function(value, attributeName) {
if (attributeName.indexOf("config") !== -1) {
scope._config[attributeName] = value;
}
});
};
promise.controller = function($scope, $timeout, $interval, $window, $http) {
$scope.forbidden = false;
$scope._config = [];
$scope._host = _ui_host + templateName + '/';
$scope._params = $routeParams;
$scope._viewTab = 1;
$scope.assetsPath = 'extensions/themes/assets/';
$scope._getMe = {};
$scope._isLogin = function() {
if (UiCustomerBox.delegate.get.isLogin()) {
$scope._getMe = UiCustomerBox.delegate.get.me();
}
return UiCustomerBox.delegate.get.isLogin();
};
$scope.$watch('refidid', function(newValue, oldValue) {
if (newValue) {
console.log("product_id_____1 : ", newValue);
$scope._get_product_id($scope._getPostIdFromURL());
} else {
return;
}
});
$scope._viewRouteParams = function() {
return $routeParams || false;
};
$scope.test_view = function(index) {
$scope._viewTab = index;
console.log("view_tab", $scope._viewTab);
}
$scope._getPostIdFromURL = function() {
var test = $scope.id;
var a = $scope.id;
if (typeof $routeParams.product_id !== 'undefined') {
test = parseInt($routeParams.product_id);
a = $routeParams.product_id;
}
if (typeof test === 'number' && test > 0) {
return test;
} else {
var b = a.split("-");
return b[0];
}
};
$scope.redirectCheckout = function(p, q) {
window.location.href = GURL.base_url() + "checkout?pdata=" + p + '-' + q;
};
if (typeof GAEAPI === 'undefined' || GAEAPI == undefined) {
_componentLog('productDetailView', false);
$scope.forbidden = true;
} else {
_componentLog('productDetailView', true);
}
/* Product Id */
$scope._data_qty_model = 1;
$scope._data_qty_selected = 1;
$scope._data_product_id_load = false;
$scope._data_product_id = false;
$scope._data_the_id = 0;
$scope._focus_image = "";
$scope._reset_product_id = function() {
$scope._data_product_id_load = false;
$scope._data_product_id = false;
$scope._data_the_id = 0;
$scope._focus_image = "";
$scope._data_product_relate = false;
$scope.selectedOptionTextJson = '';
$scope.productOptionLevelArray = [];
$scope.optionToCalculateNext = false;
};
$scope._get_product_sample = function() {
var product_desc = 'Lorem Ipsum คือ เนื้อหาจำลองแบบเรียบๆ ที่ใช้กันในธุรกิจงานพิมพ์หรืองานเรียงพิมพ์ มันได้กลายมาเป็นเนื้อหาจำลองมาตรฐานของธุรกิจดังกล่าวมาตั้งแต่ศตวรรษที่ 16 เมื่อเครื่องพิมพ์โนเนมเครื่องหนึ่งนำรางตัวพิมพ์มาสลับสับตำแหน่งตัวอักษรเพื่อทำหนังสือตัวอย่าง Lorem Ipsum อยู่ยงคงกระพันมาไม่ใช่แค่เพียงห้าศตวรรษ แต่อยู่มาจนถึงยุคที่พลิกโฉมเข้าสู่งานเรียงพิมพ์ด้วยวิธีทางอิเล็กทรอนิกส์ และยังคงสภาพเดิมไว้อย่างไม่มีการเปลี่ยนแปลง มันได้รับความนิยมมากขึ้นในยุค ค.ศ. 1960 เมื่อแผ่น Letraset วางจำหน่ายโดยมีข้อความบนนั้นเป็น Lorem Ipsum และล่าสุดกว่านั้น คือเมื่อซอฟท์แวร์การทำสื่อสิ่งพิมพ์ (Desktop Publishing) อย่าง Aldus PageMaker ได้รวมเอา Lorem Ipsum เวอร์ชั่นต่างๆ เข้าไว้ในซอฟท์แวร์ด้วย';
var prodcut_id = "999999";
var product_title = "Samsung Galaxy S8";
var product_image = [{
image_url: 'extensions/themes/gae_default301/staticfiles/images/default/490x490.gif',
image_id: 1,
image_title: 'Samsung'
}, {
image_url: 'extensions/themes/gae_default301/staticfiles/images/default/490x490.gif',
image_id: 2,
image_title: 'Samsung'
}, {
image_url: 'extensions/themes/gae_default301/staticfiles/images/default/490x490.gif',
image_id: 3,
image_title: 'Samsung'
}, ];
var productObject = {
'product_id': prodcut_id,
'product_referral_display': {
'category': [{
'referral_name': 'Smartphone Samsung'
}]
},
'product_title': product_title,
'product_sku': 'SMK-S8-9774956747-7417A-31',
'product_badge': [{
'badge_id': 72
}],
'product_description': product_desc,
'product_compare_price': 55500,
'product_price': 45000,
'product_image': product_image,
};
return productObject;
};
/* get other data */
$scope._getSupportDataCategory = function(type, data) {
var dataSend = {
'txt_referral_id': data.product_referral_display.category[0].referral_id
};
GAEAPI.get('referral/relation', dataSend, $scope).then(function(e) {
console.log("_getSupportDataCategory", dataSend, e);
if (e.ok == 1) {
$scope.support_data.category = e.data;
}
});
};
$scope.data_video_id = false;
/* get product data*/
$scope.dataOption = [];
$scope.dataVariants = [];
$scope.buildVariantOption = function(data) {
console.log("buildVariantOption : ", data);
if (data.product_total_variant <= 0) {
return;
}
$scope.dataOption = data.product_attribute.option_data.pclass_array;
$scope.dataVariants = data.product_attribute.option_data.variant_array;
console.log("buildVariantOption : dataOption : ", $scope.dataOption);
console.log("buildVariantOption : dataVariants : ", $scope.dataOption);
$scope.makeVariantsClick();
}
$scope.makeVariantsClick = function() {
var optionAuto = [];
console.log("makeVariantsClick : dataOption : ", $scope.dataOption.length);
for (var i = 0; $scope.dataOption.length > i; i++) {
console.log("makeVariantsClick : for : ", i);
optionAuto.push($scope.dataOption[i]);
}
console.log("makeVariantsClick : optionAuto : ", optionAuto);
var s = $timeout(function() {
console.log("makeVariantsClick");
for (var i = 0; optionAuto.length > i; i++) {
if (optionAuto[i].pclass_option_array.length > 0) {
$scope._chageProductByOptionId({}, i, optionAuto[i].pclass_option_array[0].option_id)
}
}
}, 2000);
};
$scope.qtyProduct = 1;
$scope.result_price = 0;
$scope.checkQty = function(qtyProduct) {
var productQuantityBreak = GAEAPI.getValueForKey($scope._data_product_id, "product_quantity_break", []);
var quantityBreak = GAEAPI.getValueForKey(productQuantityBreak, "quantity_break", []);
var product_price = GAEAPI.getValueForKey($scope._data_product_id, "product_price", 0);
console.log("quantityBreak : ", quantityBreak);
console.log("quantityBreak : qtyProduct : ", qtyProduct);
for (var index in quantityBreak) {
var rowData = quantityBreak[index];
var amount_end = parseInt(GAEAPI.getValueForKey(rowData, "amount_end", 0));
var unit_price = parseInt(GAEAPI.getValueForKey(rowData, "unit_price", 0));
if (qtyProduct >= amount_end) {
$scope.result_price = unit_price;
}
}
};
$scope.getQuantityBreak = function(dataSend, api, callback) {
console.log("getQuantityBreak : dataSend : ", dataSend, " api : ", api);
var quantity = [];
var quantity_break = [];
GAEAPI.get(api, dataSend).then(function(output) {
console.log("getQuantityBreak : output : ", output);
if (output.ok == 1) {
quantity = output.data;
quantity_break = output.data.quantity_break;
callback(quantity, quantity_break);
}
callback(quantity, quantity_break);
});
callback(quantity, quantity_break);
};
$scope.checkLogin = function(urlApi, product_id, status_login, callback) {
var dataSend = {};
var productId = parseInt(product_id);
var statusLogin = status_login;
var api = urlApi;
var customerId = 0;
if (api == 'product/id') {
dataSend = {
'txt_product_id': productId,
}
console.log("checkLogin : statusLogin : ", statusLogin, " customerId : ", customerId, " dataSend : ", dataSend, " api : ", api);
callback(statusLogin, customerId, dataSend, api);
} else if (api == 'product/quantity_break') {
if (statusLogin) {
customerId = parseInt(UiCustomerBox.delegate.get.me().customer_id);
dataSend = {
'txt_product_id': productId,
'txt_customer_id': customerId,
}
console.log("checkLogin : statusLogin : ", statusLogin, " customerId : ", customerId, " dataSend : ", dataSend, " api : ", api);
callback(statusLogin, customerId, dataSend, api);
} else {
console.log("checkLogin : statusLogin : ", statusLogin, " customerId : ", customerId, " dataSend : ", dataSend, " api : ", api);
callback(statusLogin, customerId, dataSend, api);
}
}
};
$scope.quantity_break_row = [];
$scope._get_product_id = function(id) {
// alert(id);
$scope._reset_product_id();
$scope._data_product_id_load = true;
$scope._data_product_id = false;
$scope._data_the_id = id;
var dataSend = {
'txt_product_id': id
};
if (CUR_THEME.shop_id() == 500) {
$scope.support_data = {
category: [],
};
$http.get('https://missmonribs.getappeasy.com/store/api/v1/product/id?txt_product_id=' + id).then(function(response) {
var e = response.data;
if (e.ok == 1) {
$scope._data_product_id_load = false;
$scope._data_product_id = e.data;
$scope.productOptionLevelArray = [];
$scope.optionToCalculateNext = false;
$scope._getSupportDataCategory('category', e.data);
/* Copy Price */
$scope._data_product_id.product_original_price = e.data.product_price;
$scope._get_product_relate(e.data.product_tags);
$scope._get_referral_relate_(e.data.product_referral_display.category);
if (e.data.product_image.length) {
$scope._focus_image = $scope._data_product_id.product_image[0].image_url;
}
var vm = {
productDetail: e.data
};
if (typeof $scope._data_product_id.product_attribute.option_data !== 'undefined' && $scope._data_product_id.product_total_variant > 0) {
if (typeof $scope._data_product_id.product_attribute.option_data.pclass_array !== 'undefined' && $scope._data_product_id.product_attribute.option_data.pclass_array.length) {
$scope.buildMultipleQuantity(e.data);
for (var op = 0; op < $scope._data_product_id.product_attribute.option_data.pclass_array.length; op++) {
$scope.productOptionLevelArray.push({
level_index: op,
level_id: $scope._data_product_id.product_attribute.option_data.pclass_array[op].pclass_id,
level_label: $scope._data_product_id.product_attribute.option_data.pclass_array[op].pclass_name,
level_data: 0
});
}
if (!$scope._data_product_id.product_attribute.option_data.variant_array.length) {
$scope.optionToCalculateNext = true;
}
} else {
$scope.optionToCalculateNext = true;
}
} else {
$scope.optionToCalculateNext = true;
}
var productCheckTimeLoading_b = $timeout(function() {
$timeout.cancel(productCheckTimeLoading_b);
angular.element('.load-effect').addClass('de-active');
}, 600);
var productCheckTimeLoading_c = setInterval(function() {
clearInterval(productCheckTimeLoading_c);
angular.element('.load-effect').addClass('loaded');
angular.element('.load-effect').removeClass('is-active de-active');
angular.element('.load-effect').removeClass('loaded');
}, 1600);
} else {
$scope._data_product_id_load = false;
$scope._data_product_id = false;
return $window.location.href = "#/home";
}
});
} else {
GAEAPI.get('product/id', dataSend, $scope).then(function(e) {
console.log('_get_product_id', e);
if (e.ok == 1) {
console.log("testwesttest", e);
console.log("param_test", $scope._params);
$scope._data_product_id_load = false;
$scope._data_product_id = e.data;
// console.log("qty_braek_ : ",$scope._data_product_id);
/* product_quantity_break */
$scope.checkLogin('product/quantity_break', dataSend.txt_product_id, UiCustomerBox.delegate.get.isLogin(), function(statusLogin, customerId, dataSend, api) {
console.log("getProductId checkLogin callback : statusLogin : ", statusLogin, " customerId : ", customerId, " dataSend : ", dataSend, " api : ", api);
if (statusLogin) {
console.log("getProductId checkLogin : IF");
$scope.getQuantityBreak(dataSend, api, function(quantity, quantity_break) {
console.log("getProductId checkLogin callback getQuantityBreak : quantity : ", quantity);
console.log("getProductId checkLogin callback getQuantityBreak : quantity_break : ", quantity_break);
$scope.quantity_break_row = quantity.quantity_break_row;
$scope._data_product_id.product_quantity_break.quantity_break = quantity_break;
if (quantity_break.length) {
$scope.result_price = quantity_break[0].unit_price;
}
});
} else {
console.log("getProductId checkLogin : ELSE")
}
});
$scope.data_video_id = e.data.product_id;
console.log("_data_product_id", $scope._data_product_id);
$scope.productOptionLevelArray = [];
$scope.optionToCalculateNext = false;
if (CUR_THEME.shop_id() == 647) {
$scope.buildVariantOption(e.data);
}
$scope._get_product_relate(e.data.product_tags);
$scope._get_referral_relate_(e.data.product_referral_display.category);
if (e.data.product_image.length) {
$scope._focus_image = $scope._data_product_id.product_image[0].image_url;
}
var vm = {
productDetail: e.data
};
if (typeof $scope._data_product_id.product_attribute.option_data !== 'undefined' && $scope._data_product_id.product_total_variant > 0) {
if (typeof $scope._data_product_id.product_attribute.option_data.pclass_array !== 'undefined' && $scope._data_product_id.product_attribute.option_data.pclass_array.length) {
$scope.buildMultipleQuantity(e.data);
for (var op = 0; op < $scope._data_product_id.product_attribute.option_data.pclass_array.length; op++) {
$scope.productOptionLevelArray.push({
level_index: op,
level_id: $scope._data_product_id.product_attribute.option_data.pclass_array[op].pclass_id,
level_label: $scope._data_product_id.product_attribute.option_data.pclass_array[op].pclass_name,
level_data: 0
});
}
if (!$scope._data_product_id.product_attribute.option_data.variant_array.length) {
$scope.optionToCalculateNext = true;
}
var set_varia0 = e.data.product_attribute.option_data.variant_array[0].price;
for (var i = 0; i < e.data.product_attribute.option_data.variant_array.length; i++) {
if (parseInt(set_varia0) >= parseInt(e.data.product_attribute.option_data.variant_array[i].price)) {
set_varia0 = e.data.product_attribute.option_data.variant_array[i].price;
$scope.data_min = e.data.product_attribute.option_data.variant_array[i];
}
}
if ($scope.data_min.length == 0) {
$scope.data_min = e.data.product_attribute.option_data.variant_array[0];
}
$scope._data_product_id.product_price = $scope.data_min.price;
$scope._data_product_id.product_compare_price = $scope.data_min.compare_price;
} else {
$scope.optionToCalculateNext = true;
}
} else {
$scope.optionToCalculateNext = true;
}
var productCheckTimeLoading_b = $timeout(function() {
$timeout.cancel(productCheckTimeLoading_b);
angular.element('.load-effect').addClass('de-active');
}, 600);
var productCheckTimeLoading_c = setInterval(function() {
clearInterval(productCheckTimeLoading_c);
angular.element('.load-effect').addClass('loaded');
angular.element('.load-effect').removeClass('is-active de-active');
angular.element('.load-effect').removeClass('loaded');
}, 1600);
} else {
if (dataSend.txt_product_id == 999999) {
$scope._data_product_id_load = false;
$scope._data_product_id = $scope._get_product_sample();
} else {
$scope._data_product_id_load = false;
$scope._data_product_id = false;
$location.path("/home");
}
}
});
}
};
$scope._data_product_relate = false;
$scope._get_product_relate = function(tagsString) {
if (tagsString === '' || typeof tagsString === 'undefined') {
return;
}
var dataSend = {
'cur_page': '1',
'per_page': '10',
'txt_filter_json': JSON.stringify({
'tags': tagsString
})
};
GAEAPI.get('product/lists', dataSend, $scope).then(function(e) {
console.debug("related products", e);
console.log("testwesttest", e);
if (e.ok === 1) {
$scope._data_product_relate = e.data.dataList;
}
});
};
$scope._data_referral_relate_ = [];
$scope._get_referral_relate_ = function(catArray) {
if (catArray !== undefined && catArray !== '') {
var dataSend = {
'txt_referral_id': catArray[0].referral_id
};
GAEAPI.get('referral/relation', dataSend, $scope).then(function(e) {
if (e.ok === 1) {
$scope._data_referral_relate_ = e.data;
}
});
}
};
$scope._get_referral_relate = function(catArray) {
$scope._data_referral_relate = [];
if (catArray !== undefined && catArray !== '') {
var dataSend = {
'txt_referral_id': catArray[0].referral_id,
'txt_is_lookup': 0
};
GAEAPI.get('referral/relation', dataSend, $scope).then(function(e) {
if (e.data[0].referral_id !== catArray[0].referral_id) {
var dataSendTwo = {
'txt_referral_id': e.data[0].referral_id
};
GAEAPI.get('referral/id_map', dataSendTwo, $scope).then(function(ee) {
$scope._data_referral_relate.push(ee.data);
console.log("ref_test_array :", $scope._data_referral_relate);
});
}
});
}
};
$scope._get_product_id($scope._getPostIdFromURL());
// $rootScope.$on('$routeChangeStart', function(event, current, prev) {
// if (!$scope._data_product_id) {
// $timeout(function() {
// }, 100);
// }
// });
// $rootScope.$on('$routeChangeSuccess', function(event, current, prev) {
// if (!$scope._data_product_id) {
// $timeout(function() {
// $scope._get_product_id($scope._getPostIdFromURL());
// }, 100);
// }
// });
/* Varaint */
$scope.selectedOptionTextJson = '';
$scope.productOptionLevelArray = [];
$scope.optionToCalculateNext = false;
$scope.optionNotFound = 0;
$scope.check_alloption = false;
$scope.buy_button = false;
$scope._chageProductByOptionId = function($event, masterIndex, optionId) {
console.log("event :", $event, " masterIndex :", masterIndex, " optionId : ", optionId);
function compareArray(array_a, array) {
if (!array) return false;
if (array_a.length != array.length) return false;
for (var i = 0, l = array_a.length; i < l; i++) {
if (array_a[i] instanceof Array && array[i] instanceof Array) {
if (!compareArray(array_a[i], array[i])) return false;
} else if (array_a[i] != array[i]) {
return false;
}
}
return true;
}
$scope.productOptionLevelArray[masterIndex].level_data = optionId;
console.log('$scope.productOptionLevelArray: clicked!', $scope.productOptionLevelArray);
var optionSelectedArray = [];
for (var i = 0; i < $scope.productOptionLevelArray.length; i++) {
if ($scope.productOptionLevelArray[i].level_data != 0) {
optionSelectedArray.push($scope.productOptionLevelArray[i].level_data);
}
}
if (optionSelectedArray.length === $scope._data_product_id.product_attribute.option_data.pclass_array.length) {
$scope.optionToCalculateNext = true;
}
if (!$scope.optionToCalculateNext) {
console.log("_chageProductByOptionId : Failed", $scope.optionToCalculateNext);
console.log("_chageProductByOptionId : Failed Data Length", optionSelectedArray.length, $scope._data_product_id.product_attribute.option_data.pclass_array.length);
console.log("_chageProductByOptionId : Failed Data Length", optionSelectedArray, $scope._data_product_id.product_attribute.option_data.pclass_array);
return;
}
$scope.optionNotFound = 0;
for (var i = 0; i < $scope._data_product_id.product_attribute.option_data.variant_array.length; i++) {
var _self = $scope._data_product_id.product_attribute.option_data.variant_array[i];
var _self_option = angular.fromJson(_self.option_id_json);
if (compareArray(optionSelectedArray, _self_option)) {
$scope._data_product_id.product_id = _self.product_id;
$scope._data_product_id.product_price = _self.price;
$scope._data_product_id.product_sku = _self.sku;
// $scope._data_product_id.product_compare_price = _self.compare_price;
$scope._data_product_id.product_variant_compare_price = _self.compare_price;
$scope._data_product_id.product_total_stock = _self.total_stock;
console.log("selectedOptionTextJson: option", _self);
$scope.check_alloption = true;
$scope.buy_button = true;
$scope.selectedOptionTextJson = _self.option_id_json;
console.log('selectedOptionTextJson: Key', '-' + optionSelectedArray.join('-') + '-');
/* Switch Quantity Input */
$scope.switchQuantityByKey('-' + optionSelectedArray.join('-') + '-');
/* Find Image Variant */
if (_self.variant_image.length) {
var rightImagePosition = 0;
for (var im = 0; im < $scope._data_product_id.product_image.length; im++) {
if ($scope._data_product_id.product_image[im].image_id == _self.variant_image[0].image_id) {
rightImagePosition = im;
break;
}
}
$timeout(function() {
console.log("Found Varaint Image", _self.variant_image[0].image_id);
console.log("Found Varaint Image", _self.variant_image);
console.log("Found Varaint Image rightImagePosition ", rightImagePosition);
console.log("_self.variant_image.length", _self.variant_image.length);
if (_self.variant_image.length > 0) { /* pop */
if ($(window).width <= 991) {
$scope._slickGoto('sliderDetailView', rightImagePosition);
} else {
angular.element('.d_gallery .item[data-image-id="' + _self.variant_image[0].image_id + '"]').click();
}
}
}, 300);
}
$scope.optionNotFound = 0;
break;
} else {
$scope.optionNotFound++;
$scope.check_alloption = false;
$scope.buy_button = false;
}
}
console.log("_chageProductByOptionId : optionNotFound", $scope.optionNotFound, $scope._data_product_id.product_attribute.option_data.pclass_array.length);
};
/* Image Focus */
$scope._focus = function(srcTxt) {
$scope._focus_image = srcTxt;
};
/* Make Variant Click */
$scope.variantFirstClick = function(m) {
$timeout(function() {
$('.list_option[data-master="' + m + '"]:not(.disable)').eq(0).click();
}, 1000);
};
/* SLIDER EVENT (REQUIRE SLICK) */
$scope._makeCarousel = function(el) {
var elementToMake = '.' + el + '';
/*console.log('_makeCarousel: trigger', elementToMake);*/
if ($(elementToMake).hasClass('slick-initialized')) {
/*console.debug($(elementToMake)," already initialized: destroy now");*/
$(elementToMake).slick('unslick');
}
if ($(elementToMake).find('.i').length > 1) {
/*console.debug($(elementToMake)," is now ready to build slider");*/
setTimeout(function() {
$(elementToMake).not('.slick-initialized').slick({
arrows: false,
dots: false,
autoplay: false,
autoplaySpeed: 3000,
infinite: true,
speed: 450,
fade: true,
centerMode: true,
cssEase: 'linear',
lazyLoad: 'progressive',
responsive: [{
breakpoint: 768,
settings: {
arrows: false,
centerMode: true,
adaptiveHeight: true,
}
}, {
breakpoint: 480,
settings: {
arrows: false,
centerMode: true,
adaptiveHeight: true,
}
}]
});
}, 500);
} else {
console.log("fail to make slider", $(elementToMake));
}
$scope._makeCarouselMobile('mobile_gallery');
};
/* SLIDER EVENT (REQUIRE SLICK) */
$scope._makeCarouselMobile = function(el) {
var elementToMake = '.' + el + '';
if ($(elementToMake).hasClass('slick-initialized')) {
$(elementToMake).slick('unslick');
}
if ($(elementToMake).find('.i').length > 1) {
setTimeout(function() {
$('.mobile_gallery').not('.slick-initialized').slick({
arrows: false,
dots: false,
autoplay: true,
autoplaySpeed: 3000,
speed: 450,
slideToShow: 1,
slideToScroll: 1
});
}, 500);
} else {
console.log("fail to make slider", $(elementToMake));
}
};
/* Click SLick Item */
$scope._slickGoto = function(el, idx) {
console.log(el, idx);
setTimeout(function() {
$('.' + el).slick('slickGoTo', idx);
}, 500);
};
/* toNext Product */
$scope._next_product = function(id) {
angular.element('.load-effect').addClass('is-active');
$scope._get_product_id($scope._getPostIdFromURL());
if ($scope.name === 'bombbike') {
return GURL.location.href = "#/product-detail/" + id;
}
window.location.href = "#/product-detail/" + id;
};
$scope.currentYTshow = false;
$scope.viewPopupShow = function() {
$scope.currentYTshow = true;
};
$scope.viewPopupHide = function() {
$scope.currentYTshow = false;
};
$scope.viewPopupIframe = function(linkShare, autoPlay) {
function buildIframeHTML(sourceString) {
var htmlString = '';
htmlString += '';
htmlString += '
';
htmlString += '';
htmlString += '
';
htmlString += '';
return htmlString;
}
function getId(linkShare, autoPlay) {
var a = linkShare.split("/");
var last = a[a.length - 1];
if (last.indexOf('=') !== -1) {
a = last.split("=");
last = a[1];
if (last.indexOf("&") !== -1) {
a = last.split("&");
last = a[0];
}
}
var autoPlayString = (autoPlay) ? "&autoplay=1" : "";
return "https://www.youtube.com/embed/" + last + "?ecver=2" + autoPlayString;
}
var embedString = getId(linkShare, autoPlay);
var s = buildIframeHTML(embedString);
return s;
};
$scope.decreseQty = function(variant_key) {
var e = angular.element('input[name="detail_qty"]');
if (typeof variant_key !== 'undefined') {
e = angular.element('input[name="detail_qty"][variant-key="' + variant_key + '"]');
}
var i = parseInt(e.val());
if (i > 1) {
e.val(i - 1);
$scope._data_qty_selected = (i - 1);
}
return $scope._data_qty_selected;
};
$scope.increseQty = function(variant_key) {
var e = angular.element('input[name="detail_qty"]');
if (typeof variant_key !== 'undefined') {
e = angular.element('input[name="detail_qty"][variant-key="' + variant_key + '"]');
}
var i = parseInt(e.val());
console.log("increseQty : isNaN :", isNaN(i));
console.log("increseQty : i :", i);
if (i < 0) {
i = 0;
}
if (isNaN(i)) {
i = 0;
}
if (i < 20) {
e.val(i + 1);
$scope._data_qty_selected = (i + 1);
}
return $scope._data_qty_selected;
};
$scope.watchQty = function(variant_key) {
var e = angular.element('input[name="detail_qty"]');
if (typeof variant_key !== 'undefined') {
e = angular.element('input[name="detail_qty"][variant-key="' + variant_key + '"]');
}
var i = parseInt(e.val());
if (i <= 0 || typeof i == 'undefined' || isNaN(i)) {
var t = $timeout(function() {
$timeout.cancel(t);
$scope._data_qty_selected = 1;
e.val(1);
}, 600);
}
};
$scope.currentOptionQtyPick = function(variant_key) {
var e = angular.element('input[name="detail_qty"]');
if (typeof variant_key !== 'undefined') {
e = angular.element('input[name="detail_qty"][variant-key="' + variant_key + '"]');
}
return e.val();
};
$scope.ifOptionUnSelect = function() {
return ($('.d_qty_price.active.inin').length > 0) ? true : false;
};
$scope.getDiscountOfVaraint = function() {};
$scope.addProduct = function(id, qty) {
// UiCart.delegate.product.add(id,qty);
UiCart.delegate.product.eventCheckout(id, qty);
};
/* Finish buy button */
$rootScope.$on('buyFinished', function() {
$scope._data_qty_selected = 1;
angular.element("input[name='detail_qty']").val(1);
});
/* Register Qtn Array for Each option */
$scope.optionArrayQty = [];
$scope.buildRootIdParams = function(categoryObject) {
if (typeof categoryObject === 'undefined') {
return;
}
var r = '';
if (categoryObject.referral_parent_id != 0) {
r += '&root_id=' + categoryObject.referral_parent_id;
} else {
r += '&root_id=' + categoryObject.referral_id;
}
r += "&referral_name=" + categoryObject.referral_name;
return r;
};
$scope._viewMeta = function(name, pageType, uniqueId) {
return metaRender.get(name, pageType, uniqueId);
};
$scope.checkColorConfig = function() {
return ($('config-color').length) ? true : false;
};
/* Build Multiple Option */
$scope.productQuantityMultiArray = [];
$scope.lastCheckedVariantKey = '';
$scope.buildMultipleQuantity = function(productObj) {
$scope.productQuantityMultiArray = [];
var r = [],
p = productObj.product_attribute.option_data.variant_array;
for (var i = 0; i < p.length; i++) {
if (p[i].status == 1 && p[i].status == 1) {
$scope.productQuantityMultiArray.push({
v_key: p[i].variant_key,
v_name: p[i].option_name_array[0],
v_qty: 1,
v_active: 0
});
}
}
};
/* Switch Quantity Input forEach Option */
$scope.switchQuantityByKey = function(variant_key) {
$scope.lastCheckedVariantKey = variant_key;
$('.d_qty').removeClass('active').removeClass('inin');
$('.d_qty_price[variant-key!="' + variant_key + '"]').removeClass('active').removeClass('inin');
$('.d_qty[variant-key="' + variant_key + '"]').addClass('active');
$('.d_qty_price[variant-key="' + variant_key + '"]').addClass('active');
$timeout(function() {
$('.d_qty[variant-key="' + variant_key + '"]').addClass('inin');
$('.d_qty_price[variant-key="' + variant_key + '"]').addClass('inin');
}, 300);
};
$scope.buildTitleUrl = function(str) {
if (str == undefined || str == "") {
return '';
}
var s = str.replace(/[^a-zA-Zก-๙0-9 ]/g, "").split(" ").join("-").replace("--", "-");
return s;
};
/* Render Quantity */
$scope.viewQuantity = function() {
return $(".d_qty.active.inin").find('input').val() || 1;
};
$scope.warning = 0;
$scope.getWarn = function() {
$scope.warning = 1;
};
$scope.getPriceFromPClass = function(option_name) {
var variantArr = $scope._data_product_id.product_attribute.option_data.variant_array;
var price = 0;
for (var i = 0; i < variantArr.length; i++) {
var j = angular.fromJson(variantArr[i].option_name_array);
}
};
$scope.slickGoLeft = function(elementName) {
setTimeout(function() {
$(elementName).slick('slickPrev');
}, 100);
};
$scope.slickGoRight = function(elementName) {
setTimeout(function() {
$(elementName).slick('slickNext');
}, 100);
};
$scope.calSlide = function(elementName, calcHeight) {
var top = angular.element(elementName).width();
if (calcHeight) {
return (top / 2) - 20;
}
return top;
};
/* Optimize image size by device pixel
* @params {size} (integer) prefer size
* @params {image_url} (string) original image source link
* @params {image_width} (string) original image width
* @return string
*/
$scope.viewOptimizeImage = function(size, image_url, image_width) {
if (window.devicePixelRatio >= 2 || parseInt(image_width) <= size) {
return image_url;
}
var a = image_url.split("/"),
b = a[a.length - 1];
a[a.length - 1] = 't' + size + '_' + b;
return a.join("/");
};
/* generate link for category-lists */
$scope.buildSubCatLink = function(obj) {
var a = 'category-lists?';
a += 'root_id=' + obj.product_referral_display.category[0].referral_parent_id;
a += '&referral_id=' + obj.product_referral_display.category[0].referral_id;
a += '&referral_name=' + encodeURIComponent(obj.product_referral_display.category[0].referral_name);
a += '&referral_type=category';
return a;
};
$scope.getBadgeArray = function(inputArray) {
var array = inputArray;
var output = "";
for (var i = 0; i < array.length; i++) {
console.log("Array :", array[i]);
if (array[i].badge_id == 72) {
output = "New Arrival";
} else if (array[i].badge_id == 74) {
output = "Recommend";
} else if (array[i].badge_id == 75) {
output = "Best Seller";
}
}
return output;
};
$scope.getClass = function(inputArray) {
var array = inputArray;
var output = "";
for (var i = 0; i < array.length; i++) {
console.log("Array :", array[i]);
if (array[i].badge_id == 72) {
output = "-new-arrival";
} else if (array[i].badge_id == 74) {
output = "-reccommend";
} else if (array[i].badge_id == 75) {
output = "-best-seller";
}
}
return output;
};
$scope._saleState = {
discount: 0
};
$scope.sale = function(price, compare_price, discount_id, discount_price, discount_percent) {
var sale = 0;
if (discount_id != undefined) {
if (discount_price != 0 && discount_percent == 0) {
sale = discount_price;
$scope._saleState.discount = 'price';
} else if (discount_percent != 0 && discount_price == 0) {
sale = discount_percent;
$scope._saleState.discount = 'percent';
}
}
return (sale > 0) ? sale : 0;
}
$scope._pricefullState = {
pricefull: 0
};
$scope.pricefull = function(price, compare_price, discount_id, discount_price, discount_percent) {
var pricefull = 0;
if (discount_id != undefined) {
pricefull = price;
} else {
if (compare_price != 0) {
pricefull = compare_price;
$scope._pricefullState.pricefull = 'not zero';
} else {
$scope._pricefullState.pricefull = 'zero';
}
}
return pricefull;
}
$scope.calculate = function(price, compare_price, discount_id, discount_price, discount_percent) {
var calculate = 0;
if (discount_id != undefined) {
if (discount_price != 0 && discount_percent == 0) {
calculate = price - discount_price;
} else if (discount_percent != 0 && discount_price == 0) {
calculate = price - ((discount_percent / 100) * price);
}
} else {
calculate = price
}
return (calculate > 0) ? calculate : 0;
};
};
return promise;
});
/* // JS READER : END */
/* // JS READER : START */
/* UI: */
_ui_pvt_m.directive('productGridDark', function ($rootScope, outerElement, $routeParams) {
var templateName = 'productGridDark';
var templatePathUrl = _ui_host + templateName + '/' + templateName + '.html';
var promise = {};
promise.restrict = 'AE';
promise.scope = {
name: '@name',
type: '@type',
header: '@header',
subheader: '@subheader',
imgpath: '@imgpath',
layoutcenter: '@layoutcenter',
referral: '@referral',
badge: '@badge',
orderby: '@orderby',
forcedetail: '@forcedetail',
searchtxt: '@searchtxt',
subreferral: '@subreferral',
keynumber:'=keynumber'
};
promise.templateUrl = templatePathUrl;
promise.transclude = true;
promise.link = function (scope, element, attr) {
angular.forEach(attr, function (value, attributeName) {
if (attributeName.indexOf("config") !== -1) {
scope._config[attributeName] = value;
}
if (attributeName == 'referral' && typeof value !== 'undefined') {
if (value.length || value !== '') {
var str = value.split(','), r = [];
for (var i = 0; i < str.length; i++) {
r.push(parseInt(str[i]));
}
scope._option_product_request.referral_id_array = r;
}
}
scope.referral = $routeParams.referral_id;
if (attributeName == 'badge' && typeof value !== 'undefined') {
if (value.length || value !== '') {
var str = value.split(','), r = [];
for (var i = 0; i < str.length; i++) {
r.push(parseInt(str[i]));
}
scope._option_product_request.badge_id_array = r;
}
}
if (attributeName == 'searchtxt' && typeof value !== 'undefined') {
scope._option_product_request.searchtxt = value;
}
});
};
promise.controller = function ($scope, $timeout, $interval, $q, $window) {
$scope.forbidden = false;
$scope._config = [];
$scope._host = _ui_host + templateName + '/';
if (typeof GAEAPI === 'undefined' || GAEAPI == undefined) {
_componentLog('productGridDark', false);
$scope.forbidden = true;
} else {
_componentLog('productGridDark', true);
}
/* Product View Fit */
$scope._imgFit = function (src) {
var retina = (window.devicePixelRatio > 1) ? true : false;
var attributeSize = (retina) ? 800 : 400;
var current_image = src.toString(),
current_image_array = current_image.split('/'),
current_image_last = current_image_array.length - 1,
new_image = "",
expect_size = (attributeSize > 0) ? "t" + attributeSize + "_" : "";
for (var i = 0; i < current_image_array.length; i++) {
if (i < current_image_last) {
new_image += current_image_array[i] + "/";
} else {
new_image += expect_size + current_image_array[i];
}
}
return new_image || src;
};
/* Product Request */
$scope._option_product_request = {};
$scope._data_type = 0;
/* Product */
$scope._data_product_Lists = [];
$scope._data_product_load = false;
$scope._data_product_fail = false;
$scope._data_product_cur_page = 1;
$scope._data_product_per_page = 8;
$scope._data_product_total_rows = 0;
$scope._data_product_result_rows = 0;
$scope._get_data_product_Lists = function (cur_page, per_page, option) {
/*console.log("product q",$scope.keynumber, option);*/
$scope._data_product_load = true;
$scope._data_product_Lists = [];
var buildJson = function (option) {
if (typeof option !== 'undefined') {
var txt = {};
var f = 0;
if (typeof option.search !== 'undefined' && option.search !== undefined) {
txt.search = option.search;
f++;
}
if ($scope.name !== 'superstarlady') {
if (typeof option.referral_id_array !== 'undefined' && option.referral_id_array !== undefined) {
txt.referral_id_array = option.referral_id_array;
f++;
}
} else {
if (typeof $routeParams.referral_id !== 'undefined' && $routeParams.referral_id != '') {
txt.referral_id_array = [$routeParams.referral_id];
f++;
}
}
if (typeof option.badge_id_array !== 'undefined' && option.badge_id_array !== undefined) {
txt.badge_id_array = option.badge_id_array;
f++;
}
if (typeof option.product_type_id_array !== 'undefined' && option.product_type_id_array !== undefined) {
txt.product_type_id_array = option.product_type_id_array;
f++;
}
if (typeof option.is_promotion_array !== 'undefined' && option.is_promotion_array !== undefined) {
txt.is_promotion_array = option.is_promotion_array;
f++;
}
if (typeof option.tags !== 'undefined' && option.tags !== undefined) {
txt.tags = option.tags;
f++;
}
if (typeof option.searchtxt !== 'undefined' && option.searchtxt !== undefined) {
txt.search = option.searchtxt;
f++;
}
return (f > 0) ? JSON.stringify(txt) : '';
} else {
return '';
}
};
$scope.optionR = option;
/*console.debug('Option Request', $scope.referral, option);*/
/*console.debug('RouteParams Request', $routeParams);*/
per_page = $scope._rebuild_per_page(per_page);
if (typeof $routeParams.sub_referral_id === 'undefined' || $routeParams.sub_referral_id == '') {
$scope._data_type = 0;
var sendOption = JSON.stringify(option);
if ($scope.name === 'superstarlady') {
sendOption = buildJson(option);
}
var dataSend = {
'cur_page': cur_page,
'per_page': per_page,
'txt_sortby': $scope.orderby || 'product_lastest_create',
'txt_filter_json': JSON.stringify(option)
};
GAEAPI.get('product/lists', dataSend).then(function (e) {
console.debug("Component: Product List", dataSend, e);
if (e.ok === 1 && e.data.dataList.length) {
$scope._data_product_fail = false;
$scope._data_product_load = false;
$scope._data_product_cur_page = e.data.cur_page;
$scope._data_product_per_page = e.data.per_page;
$scope._data_product_total_rows = e.data.total_rows;
$scope._data_product_result_rows = e.data.result_rows;
if ($scope._data_product_cur_page == 1) {
$scope._data_product_Lists = e.data.dataList;
if (!$scope._data_product_Lists.length) {
$scope._data_product_fail = true;
}
} else if ($scope._data_product_cur_page != 1) {
$scope._data_product_Lists.concat(e.data.dataList);
}
$scope._broadHideLoading();
} else if (e.ok !== 1) {
$scope._data_product_fail = true;
$scope._data_product_load = false;
$scope._data_product_Lists = [];
$scope._broadHideLoading();
} else {
/* OK =1, Data = no */
$scope._data_product_fail = true;
$scope._data_product_load = false;
$scope._data_product_Lists = [];
$scope._broadHideLoading();
if($scope.name==='scl'){
$timeout(function(){
outerElement.remove($scope.name);
}, 2000);
}
}
if ($scope._data_product_fail) {
if ($scope.name === 'magic') {
if (window.location.hash === '#/' || window.location.hash === '#/home') {
$('product-grid-dark[badge="' + $scope.badge + '"]').hide();
outerElement.remove($scope.name);
}
}
if ($scope.name === 'superstarlady') {
if (window.location.hash === '#/' || window.location.hash === '#/home') {
outerElement.remove($scope.name);
}
}
if ($scope.name === 'gaoyang') {
if (window.location.hash === '#/' || window.location.hash === '#/home') {
outerElement.remove($scope.name);
}
}
/* Auto hide if key assign and no product */
if(typeof $scope.keynumber !== 'undefined' && $scope.keynumber != ''){
angular.element('[data-key="'+$scope.keynumber+'"]').hide();
}
}
});
} else {
$scope._fetchCategorySub();
}
};
/* Fetch When Open */
var timerLoadProductList = setTimeout(function () {
clearTimeout(timerLoadProductList);
$scope._get_data_product_Lists(
$scope._data_product_cur_page,
$scope._data_product_per_page,
$scope._option_product_request
);
}, 100);
/* Load More Items */
$scope._get_data_product_Lists_load_more = function (next_page, per_page) {
$scope._data_product_cur_page = next_page;
$scope._data_product_per_page = per_page;
var timerLoadProductListMore = $timeout(function () {
$scope._get_data_product_Lists(
$scope._data_product_cur_page,
$scope._data_product_per_page,
$scope._option_product_request
);
$timeout.cancel(timerLoadProductListMore);
}, 500);
};
$scope._broadHideLoading = function () {
/*var t, l = $scope.$watch(function () {
clearTimeout(t);
t = setTimeout(function () {
l();
$rootScope.$broadcast("hideLoading", {});
}, 300);
});*/
var clearLoading1 = setTimeout(function () {
$('.load-effect').addClass('de-active');
clearTimeout(clearLoading1);
}, 1000);
var clearLoading2 = setTimeout(function () {
$('.load-effect').addClass('loaded').removeClass('is-active de-active').removeClass('loaded');
clearTimeout(clearLoading2);
}, 2000);
};
/* Watch Search Params */
$scope.$watch('searchtxt', function (newValue, oldValue) {
if (!newValue || newValue == "") {
return;
}
$scope._option_product_request.searchtxt = newValue;
$scope._get_data_product_Lists($scope._data_product_cur_page, $scope._data_product_per_page, $scope._option_product_request);
});
/* Watch Search Params */
$scope.$watch('referral', function (newValue, oldValue) {
if (!newValue || newValue == "") {
return;
}
console.log("watch: referral", $routeParams.referral_id);
if (typeof $routeParams.referral_id != "undefined" && $routeParams.referral_id != "") {
if($routeParams.referral_id == $scope.referral){
$scope._option_product_request.referral_id_array = [$routeParams.referral_id];
} else {
$scope._option_product_request.referral_id_array = [$scope.referral];
}
}
$scope._get_data_product_Lists($scope._data_product_cur_page, $scope._data_product_per_page, $scope._option_product_request);
});
/* Get Current Params */
$scope.current_params = {};
/* Load Sub Category */
$scope._fetchCategorySub = function () {
$scope._data_type = 1;
var dataSend = {
'txt_referral_type_id': 11,
'txt_parent_id': $routeParams.referral_id
};
GAEAPI.get('referral/map', dataSend).then(function (e) {
console.log('_fetchCategorySub', e);
if (e.ok === 1 && e.data.length) {
$scope._data_product_fail = false;
$scope._data_product_load = false;
$scope._data_product_cur_page = 1;
$scope._data_product_per_page = 8;
$scope._data_product_total_rows = e.data.length;
$scope._data_product_result_rows = e.data.length;
if ($scope._data_product_cur_page == 1) {
$scope._data_product_Lists = e.data;
if (!e.data.length) {
$scope._data_product_fail = true;
}
} else if ($scope._data_product_cur_page != 1) {
$scope._data_product_Lists.concat(e.data.dataList);
}
$scope._broadHideLoading();
} else if (e.ok !== 1) {
$scope._data_product_fail = true;
$scope._data_product_load = false;
$scope._data_product_Lists = [];
$scope._broadHideLoading();
} else {
/* OK =1, Data = no */
$scope._data_product_fail = true;
$scope._data_product_load = false;
$scope._data_product_Lists = [];
$scope._broadHideLoading();
}
if (!$scope._data_product_Lists.length) {
if ($scope.name === 'magic') {
if (window.location.hash === '#/' || window.location.hash === '#/home') {
$('product-grid-dark[badge="' + $scope.badge + '"]').hide();
outerElement.remove($scope.name);
}
}
if ($scope.name === 'superstarlady') {
if (window.location.href.indexOf('home')) {
$('product-grid-dark[badge="' + $scope.badge + '"]').hide();
outerElement.remove($scope.name);
}
}
}
});
};
/* view Current Params */
$scope._current = function (n) {
if (n == 'referral_id') {
return $scope.referral || 0;
}
};
/* change perpage for each customer */
$scope._rebuild_per_page = function (currentperPage) {
if ($scope.name === 'unity') {
return 100;
} else if ($scope.name === 'superstarlady') {
return 100;
} else if ($scope.name === 'missmonribs') {
return 30;
} else if ($scope.name === 'gaoyang') {
return 100;
}
return currentperPage;
};
/* check if string more than 20 character */
$scope._lessString = function (str, n) {
return (str.length <= n) ? true : false;
};
/* GEt current Params*/
$scope._current_root_id = function () {
return $routeParams;
};
/* Maunal Put Class */
$scope._genClassAnimate = function () {
if ($scope.name === 'jemappelle') {
return "animate-in";
}
return "";
};
$scope._clickProduct = function (productId,productTitle) {
if(GURL.isHtml5Mode()){
return window.location.href = "product-detail/" + productId + ((typeof productTitle !== 'undefined') ? '-'+$scope.buildTitleUrl(productTitle) : '');
}
return window.location.href = "#/product-detail/" + productId + ((typeof productTitle !== 'undefined') ? '-'+$scope.buildTitleUrl(productTitle) : '');
};
$scope.base_url = function () {
if (window.location.host !== 'localhost') {
return window.location.origin + "/";
} else {
return window.location.origin + "/gae/store/";
}
};
$scope.sendBuyText = function(){
if($scope.name === 'superstarlady'){
return "Shop Now"
} else if($scope.name === "magic"){
return "Shop Now"
} else if($scope.name === "gaoyang"){
return "ซื้อเลย"
} else {
return "Shop Now";
}
};
$scope.checkSeo = function(){
return (GURL.isHtml5Mode()) ? true : false;
};
$scope.buildTitleUrl = function(str){
var s = str.replace(/[^a-zA-Zก-๙0-9 ]/g, "").split(" ").join("-").replace("--","-");
return s;
};
};
return promise;
});
/* // JS READER : END */
/* // JS READER : START */
/* UI: */
_ui_pvt_m.directive('productListFeature', function ($rootScope) {
var templateName = 'productListFeature';
var templatePathUrl = _ui_host + templateName + '/' + templateName + '.html';
var promise = {};
promise.restrict = 'AE';
promise.scope = {
name: '@name',
type: '@type',
imgpath: '@imgpath',
forcedetail: '@forcedetail',
};
promise.templateUrl = templatePathUrl;
promise.transclude = true;
promise.link = function (scope, element, attr) {};
promise.controller = function ($scope, $timeout, $interval, $q, $window) {
$scope.forbidden = false;
$scope._config = [];
$scope._host = _ui_host + templateName + '/';
if (typeof GAEAPI === 'undefined' || GAEAPI == undefined) {
_componentLog('productListFeature', false);
$scope.forbidden = true;
} else {
_componentLog('productListFeature', true);
}
/* Product Request */
$scope._option_product_request = {
badge_id_array: [16],
badge_id_query: "((18 AND 16) OR (18 AND 72) OR (18 AND 74) OR (18 AND 75))"
};
/* Product */
$scope._data_product_Lists = [];
$scope._data_product_load = false;
$scope._data_product_fail = false;
$scope._data_product_cur_page = 1;
$scope._data_product_per_page = 4;
$scope._data_product_total_rows = 0;
$scope._data_product_result_rows = 0;
$scope._get_data_product_Lists = function (cur_page, per_page, option) {
$scope._data_product_load = true;
var buildJson = function (option) {
if (typeof option !== 'undefined') {
var txt = {};
var f = 0;
if (typeof option.search !== 'undefined' && option.search !== undefined) {
txt.search = option.search;
f++;
}
if (typeof option.referral_id_array !== 'undefined' && option.referral_id_array !== undefined) {
txt.referral_id_array = option.referral_id_array;
f++;
}
if (typeof option.badge_id_array !== 'undefined' && option.badge_id_array !== undefined) {
txt.badge_id_array = option.badge_id_array;
f++;
}
if (typeof option.badge_id_query !== 'undefined' && option.badge_id_query !== undefined) {
if($scope.type === 'scl'){
txt.badge_id_query = option.badge_id_query;
delete txt['badge_id_array'];
f++;
}
}
if (typeof option.product_type_id_array !== 'undefined' && option.product_type_id_array !== undefined) {
txt.product_type_id_array = option.product_type_id_array;
f++;
}
if (typeof option.is_promotion_array !== 'undefined' && option.is_promotion_array !== undefined) {
txt.is_promotion_array = option.is_promotion_array;
f++;
}
if (typeof option.tags !== 'undefined' && option.tags !== undefined) {
txt.tags = option.tags;
f++;
}
if (typeof option.searchtxt !== 'undefined' && option.searchtxt !== undefined) {
txt.search = option.searchtxt;
f++;
}
return (f > 0) ? JSON.stringify(txt) : '';
} else {
return '';
}
};
if($scope.name === 'missmonribs'){
per_page = 100;
}
var dataSend = {
'cur_page': cur_page,
'per_page': per_page,
'txt_sortby':'product_lastest_create',
'txt_filter_json': buildJson(option)
};
GAEAPI.get('product/lists', dataSend).then(function (e) {
console.debug("Component: Product List Feature", dataSend, e);
if (e.ok === 1 && e.data.dataList.length) {
$scope._data_product_fail = false;
$scope._data_product_load = false;
$scope._data_product_cur_page = e.data.cur_page;
$scope._data_product_per_page = e.data.per_page;
$scope._data_product_total_rows = e.data.total_rows;
$scope._data_product_result_rows = e.data.result_rows;
if ($scope._data_product_cur_page == 1) {
$scope._data_product_Lists = e.data.dataList;
if (!e.data.dataList.length) {
$scope._data_product_fail = true;
}
} else if ($scope._data_product_cur_page != 1) {
$scope._data_product_Lists.concat(e.data.dataList);
}
$scope._broadHideLoading();
} else if (e.ok !== 1) {
$scope._data_product_fail = true;
$scope._data_product_load = false;
$scope._data_product_Lists = [];
$scope._broadHideLoading();
} else {
/* OK =1, Data = no */
$scope._data_product_fail = true;
$scope._data_product_load = false;
$scope._data_product_Lists = [];
$scope._broadHideLoading();
}
});
};
/* Fetch When Open */
var timerLoadProductList = $timeout(function () {
$timeout.cancel(timerLoadProductList);
$scope._get_data_product_Lists($scope._data_product_cur_page,$scope._data_product_per_page,$scope._option_product_request);
}, 100);
/* Load More Items */
$scope._get_data_product_Lists_load_more = function (next_page, per_page) {
$scope._data_product_cur_page = next_page;
$scope._data_product_per_page = per_page;
var timerLoadProductListMore = $timeout(function () {
$scope._get_data_product_Lists(
$scope._data_product_cur_page,
$scope._data_product_per_page,
$scope._option_product_request
);
$timeout.cancel(timerLoadProductListMore);
}, 500);
};
$scope._broadHideLoading = function () {
var clearLoading1 = setTimeout(function () {
$('.load-effect').addClass('de-active');
clearTimeout(clearLoading1);
}, 1000);
var clearLoading2 = setTimeout(function () {
$('.load-effect').addClass('loaded').removeClass('is-active de-active').removeClass('loaded');
clearTimeout(clearLoading2);
}, 2000);
};
/* Watch Search Params */
/*$scope.$watch('searchtxt',function(newValue, oldValue){
if(!newValue||newValue==""){
return;
}
$scope._get_data_product_Lists($scope._data_product_cur_page,$scope._data_product_per_page,$scope._option_product_request);
});*/
/* Get Current Params */
$scope.current_params = {};
/**
* check badge if badge array exist by custom title
* @params badge name (string)
* @return true | false *
*/
$scope.viewBadge=function(badgeString, objArray){
var badgeId = 0;
if(badgeString==='feature'){
badgeId = 16;
}
if(badgeString==='recommend'){
badgeId = 74;
}
if(badgeString==='newarrival'){
badgeId = 72;
}
if(badgeString==='bestseller'){
badgeId = 75;
}
var r = false;
for(var i = 0; i < objArray.length; i++){
if(objArray[i].badge_id==badgeId){
r = true;
break;
}
}
return r;
};
/**
* check if show on web
* @params objectArray
* @return true | false
*/
$scope._showWeb = function(objArray){
var r = false;
for(var i = 0; i < objArray.length; i++){
if(objArray[i].badge_id==18){
r = true;
break;
}
}
return r;
};
$scope.checkSeo=function(){
return (GURL.isHtml5Mode()) ? true : false;
};
$scope.titleUrl = function(str){
var s = str.replace(/[^a-zA-Zก-๙0-9 ]/g, "").split(" ").join("-").replace("--","-");
return s;
};
$scope._clickProduct = function(p, t){
if($scope.checkSeo()){
return window.location.href = 'product-detail/'+p + ((typeof t !== 'undefined') ? '-'+$scope.titleUrl() : '');
}
return window.location.href = '#/product-detail/'+p + ((typeof t !== 'undefined') ? '-'+$scope.titleUrl() : '');
/*return window.location.href = 'product-detail/'+p + ((typeof t !== 'undefined') ? '-'+$scope.titleUrl() : '');*/
};
};
return promise;
});
/* // JS READER : END */
/* // JS READER : START */
/* UI: */
_ui_pvt_m.directive('productListTest', function ($rootScope) {
var templateName = 'productListTest';
var templatePathUrl = _ui_host + templateName + '/' + templateName + '.html';
var promise = {};
promise.restrict = 'AE';
promise.scope = {
data_1: '=one'
};
promise.templateUrl = templatePathUrl;
promise.transclude = true;
promise.link = function (scope, element, attr) {
angular.forEach(attr, function (value, attributeName) {
if (attributeName.indexOf("config") !== -1) {
scope._config[attributeName] = value;
}
});
};
promise.controller = function ($scope, $timeout, $interval, $q, $window) {
$scope.forbidden = false;
$scope._config = [];
$scope._dataBanner = [];
$scope._host = _ui_host + templateName + '/';
if (typeof GAEAPI === 'undefined' || GAEAPI == undefined) {
_componentLog('productListTest', false);
$scope.forbidden = true;
} else {
_componentLog('productListTest', true);
}
$scope.getBanner = function () {
var dataSend = {};
GAEAPI.get('web/home', dataSend, $scope).then(function (res) {
$scope._dataBanner = res.data;
console.log('getBanner', $scope._dataBanner);
});
};
$scope.getBanner();
};
return promise;
});
/* // JS READER : END */
/* // JS READER : styleLoader/styleLoader.js : FAILED */
/* // JS READER : thirdPartyComponent/thirdPartyComponent.js : FAILED */
/* // JS READER : START */
/* UI: */
_ui_pvt_m.directive('toTop', function ($rootScope) {
var templateName = 'toTop';
var templatePathUrl = _ui_host + templateName + '/' + templateName + '.html';
var promise = {};
promise.restrict = 'AE';
promise.scope = {
name: '@name',
imgpath: '@imgpath',
chat:'@chat'
};
promise.templateUrl = templatePathUrl;
promise.transclude = true;
promise.link = function (scope, element, attr) {};
promise.controller = function ($scope, $timeout, $interval, $q, $window) {
$scope.icnPath = CUR_THEME.file_url() + '../../assets/';
$scope.forbidden = false;
$scope._config = [];
$scope._dataBanner = [];
$scope._host = _ui_host + templateName + '/';
angular.element($window).bind('scroll', function(){
// if($(window).scrollTop() >= ($(window).height() * 1.5)){
if($(window).scrollTop() > 0){
$('to-top ._to_top_container').addClass('active').addClass('shown')
} else {
$('to-top ._to_top_container').removeClass('shown').removeClass('active');
}
});
$scope.toTop = function(){
$timeout(function(){
$('html,body').animate({scrollTop: 0}, 'slow');
}, 100);
};
};
return promise;
});
/* // JS READER : END */
/* // JS READER : START */
var $streamLigtboxPage = ['catalog', 'product-detail', 'blog-detail', 'gallery', 'pen-detail', 'en/pen-detail', 'fr/pen-detail', 'en/product-detail', 'fr/product-detail', 'market-infomation', 'set-product-detail'];
var $streamLigtboxReject = false;
var $streamLigtboxInstall = true;
if (CUR_THEME.shop_id() == 474) {
$streamLigtboxInstall = false;
}
if (CUR_THEME.shop_id() == 643) {
$streamLigtboxInstall = false;
}
/*else if(CUR_THEME.shop_id() == 509){
$streamLigtboxInstall = false;
} */
var $sb_ = {
_image: "",
assets: function(imgFile) {
var str = '
';
if (CUR_THEME.shop_id() == 535) {
/*return str.replace("_light@2x","_dark@2x");*/
}
return str;
},
_buildSocial: function() {
var download = '' + this.assets('icnt_fill_downloadbig01_light@2x.png') + '';
/* var facebook = '' + this.assets('icnt_fill_facebook01_color@2x.png') + '';
var twitter = '' + this.assets('icnt_fill_twitter01_color@2x.png') + '';
var googleplus = '' + this.assets('icnt_fill_google01_color@2x.png') + ''; */
return download ;
},
_buildRight: function() {
var _close = '' + this.assets('icnt_fill_closebig01_light@2x.png') + '
';
var _expand = '' + this.assets('icnt_outline_actualsizebig01_light@2x.png') + '
';
var _social = '' + this._buildSocial() + '
';
return _close + _expand;
},
_useDark: function() {
$('#root-stream-lightbox').find('.vi-ground').addClass('is-dark');
},
install: function() {
var a, b, c, d = false;
a = $('div#root-stream-lightbox').append('');
if (a) {
$('div#root-stream-lightbox .vi-ground').append('');
$('div#root-stream-lightbox .vi-ground').append('');
$('div#root-stream-lightbox .vi-ground').append('' + this._buildRight() + '
');
}
/* use dark theme ? */
if (CUR_THEME.shop_id() == 535) {
/*this._useDark();*/
}
},
open: function(imgSrc, imgAlt) {
this._image = imgSrc;
if (!$('div#root-stream-lightbox').hasClass('active')) {
$('div#root-stream-lightbox').addClass('active');
}
$('div#root-stream-lightbox').find('.vi-bar-top').html(imgAlt);
$('div#root-stream-lightbox').find('.vi-cell').html('');
$('div#root-stream-lightbox .vi-ground').find('.vi-bar-right').remove('.socia');
$('div#root-stream-lightbox .vi-ground').find('.vi-bar-right').append('' + this._buildSocial() + '
');
},
close: function() {
if ($('div#root-stream-lightbox').hasClass('active')) {
$('div#root-stream-lightbox').removeClass('active');
}
$('div#root-stream-lightbox').find('.vi-bar-top').html('');
$('div#root-stream-lightbox').find('.vi-cell').html('');
$('div#root-stream-lightbox').find('.social').html('');
this._image = '';
$('div#root-stream-lightbox .vi-ground').find('.vi-bar-right').remove('.socia');
},
expand: function() {
return window.location.href = this._image;
},
reinit: function() {
$('.icon-action-container').remove();
$('img').each(function() {
var element = $(this);
if ($streamLigtboxReject) {
var wid = element.width();
var top = element.height();
if (wid > 200 && top > 200) {
if (element.hasClass('no-vi')) {
return;
}
element.addClass('image_lazy_loaded');
var marginLeft = $('img.image_lazy_loaded[src="' + attrs.src + '"]').offset().left - $('img.image_lazy_loaded[src="' + attrs.src + '"]').parent().offset().left || 0;
if (marginLeft < 0) {
marginLeft = 0;
}
/* render overlay lightbox */
element.after('' + assets('icnt_fill_viewsizebig01_light@2x.png') + '
');
/* check if no root-id div */
$streamLightboxInit();
}
}
});
},
};
/* install lightbox */
var $streamLightboxInit = function() {
/* check if no root-id div */
if (!$('body').find('div#root-stream-lightbox').length && $streamLigtboxInstall) {
$('body').append('');
$sb_.install();
}
};
/* when click on overlay lightbox */
var $streamLightbox = function(imgSrc, imgAlt) {
/* var altStr = imgAlt.split(".");
$sb_.open(imgSrc, altStr[0]);
*/
/* BACKUP by pop */
var altStr = imgAlt;
$sb_.open(imgSrc, altStr);
};
_ui_pvt_m.directive("img", function($route) {
return {
restrict: "E",
link: function(scope, element, attrs) {
var assets = function(imgFile) {
var str = '
';
if (CUR_THEME.shop_id() == 535) {
/*return str.replace("_light@2x","_dark@2x");*/
}
return str;
};
element.bind('load', function() {
var wid = element.width();
var top = element.height();
if (wid > 200 && top > 200 && typeof $route.current.$$route.page !== 'undefined' && !element.hasClass('_imageBanner') && $streamLigtboxInstall) {
if ($streamLigtboxPage.indexOf($route.current.$$route.page) == -1 || element.hasClass('no-vi')) {
/* Dont render image lightbox within random page or img contain class .no-vi */
$streamLigtboxReject = true;
return;
} else {
$streamLigtboxReject = false;
}
element.addClass('image_lazy_loaded');
var marginLeft = $('img.image_lazy_loaded[src="' + attrs.src + '"]').offset().left - $('img.image_lazy_loaded[src="' + attrs.src + '"]').parent().offset().left || 0;
if (marginLeft < 0) {
marginLeft = 0;
}
/* render overlay lightbox */
element.after('' + assets('icnt_fill_viewsizebig01_light@2x.png') + '
');
/* check if no root-id div */
$streamLightboxInit();
} else {
/* This shop dont allow to use lightbox */
}
});
}
};
});
/* // JS READER : END */