;(function (AmpUtils, undefined) {
/**
* ajax请求公共方法-promise方式调用
*/
AmpUtils.doJsonpAjax = function (url, params) {
var deferred = $.Deferred();
$.ajax({
type: 'GET',
url: url,
traditional: true,
data: params,
dataType: 'jsonp',
jsonp: AMPConstant.jsonp,
success: function (resp) {
if (!resp.hasLogin) {
AmpUtils.goLoginPage();
}
deferred.resolve(resp);
},
error: function (resp) {
deferred.reject(resp);
}
});
return deferred.promise();
};
//读取widget的json数据
AmpUtils.loadWidgetJson = function (params) {
var deferred = $.Deferred();
$.ajax({
type: 'GET',
url: AMPConstant.requestPath + 'resources/widget/' + params.widgetId + '/widget.json',
dataType: 'json',
//不要使用同步加载,当widget过多时会导致页面加载非常慢,同时也会阻塞页面的其他操作,导致显示不正确
//async:false,
success: function (resp) {
deferred.resolve(resp, params);
},
error: function (resp) {
deferred.reject(resp, params);
}
});
return deferred.promise();
};
AmpUtils.checkLogin = function () {
$.ajax({
type: 'GET',
url: AMPConstant.jsonpRequestPath + AMPConstant.APIList.checkLogin,
traditional: true,
dataType: 'jsonp',
jsonp: AMPConstant.jsonp,
success: function (resp) {
if (!resp) {
}
},
error: function () {
}
});
};
AmpUtils.goLoginPage = function () {
if ($("#user").find("img").attr("data-tooltip-title")) {
window.location.href = AMPConstant.requestPath + "login?service=" + window.location.href;
return;
}
};
/**
* 绘制服务中心的左侧字母导航
*/
AmpUtils.drawLetter = function (selector) {
var letter = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"],
letterLen = letter.length,
letterHtml = "";
for (var i = 0; i < letterLen; i++) {
letterHtml += '
' + letter[i] + '
';
}
selector.html(letterHtml); //wengqi20151029
};
AmpUtils.getLetterTopData = function ($letterAppList) {
var letterTopData = [];
$letterAppList.children().each(function () {
var $letter = $(this);
var letterH = $letter.offset().top - 40;
var letter = $.trim($letter.children(".letter").text());
letterTopData.push({
letter: letter,
height: letterH
});
});
return letterTopData;
};
/**
* 页面滚动时设置字母高亮
* startSetNavTop 开始设置字母高亮的滚动高度
* letterList 字母列表
* letterTopData app字母对应的top值
* win 要高亮的窗口
* @param data
*/
AmpUtils.resetLetterNavHighlight = function (data) {
var startSetNavTop = data.startSetNavTop;
var $letterList = data.letterList;
var letterTopData = data.letterTopData;
var $scrollObj = data.win;
var scrollH = $scrollObj.scrollTop();
//当滚动高度大于导航距顶部的高度时,将导航div固定在页面上显示
if (scrollH >= startSetNavTop) {
$letterList.css({"position": "fixed", "top": "8px"});
} else if (scrollH < startSetNavTop) {
$letterList.removeAttr("style");
}
var letterLen = letterTopData.length;
$(letterTopData).each(function (i) {
if (i != letterLen - 1) {//若不是数组的最后一个
if (scrollH + 100 >= this.height && scrollH + 100 < letterTopData[i + 1].height) {//如果当前滚轮的高度大于等于当前数组节点的高度并小于下一节点的高度,100为后加的视觉偏移量
setLetterNavHighlight($letterList, letterTopData[i].letter);
return;
}
} else {
if (scrollH >= this.height) {//若是数组的最后一个
setLetterNavHighlight($letterList, letterTopData[i].letter);
return;
}
}
});
};
function setLetterNavHighlight($letterList, letter) {
$letterList.children().each(function () {//如果当前滚轮的高度大于等于最后一个数组节点的高度
var $item = $(this);
var itemText = $.trim($item.text());
if (itemText === letter) {//遍历左侧字母导航,找出对应的字母并标识高亮
$letterList.children(".active").removeClass("active");
$item.addClass("active");
return;
}
});
}
AmpUtils.bodyListen = function () {
var $body = $("body");
$body.on("click", function (e) {
var $targetObj = $(e.target || e.srcElement);
//关闭右上角的退出弹框
if ($targetObj.closest("#homeMenuDropdown").length === 0 && !$targetObj.hasClass("icon-home-menu-wrap") && $targetObj.closest(".icon-home-menu-wrap").length === 0) {
$("#homeMenuDropdown").removeClass("active");
$("#homeMenu").removeClass("active");
}
// 关闭顶部栏搜索框的提示框 和 搜索历史框
if ($targetObj.closest(".amp-header-search-box").length === 0) {
$("#searchBlock").hide();
$("#historyBlock").hide();
}
// 关闭服务中心搜索框历史记录框
if ($targetObj.closest(".fwzx-search-box").length === 0) {
$("#historyBlock02").hide();
}
//打开应用的情况下,点击页面的其他地方关闭右侧栏
if ($("body").hasClass("open-app")) {
if ($targetObj.closest("#rightSide").length === 0 && !$targetObj.hasClass("icon-right-side")) {
$("#rightSideIcon").removeClass("active");
$("#rightSide").removeClass("active");
var $rightSideCover = $("#rightSideCover");
if ($rightSideCover.length > 0) {
$rightSideCover.animate({"opacity": "0"}, 500, function () {
$rightSideCover.remove();
});
}
}
}
//搜索框的隐藏
if ($("body").hasClass("head-search-open")) {
if ($targetObj.closest(".amp-header-search-container").length === 0) {
var $iframe = $('#indexIframe');
var iframeUrl = $iframe.attr("data-url");
if ($iframe.length > 0 && iframeUrl && (iframeUrl.indexOf('ehall.html') > 0 || iframeUrl.indexOf('serviceCenter.html') > 0)) {
$("body").removeClass("head-search-open");
}
}
}
// 关闭意见反馈按钮 的下拉菜单
if ($targetObj.closest("#feedbackDropdown").length == 0 && $targetObj.closest("#appTools").length == 0) {
$("#feedbackDropdown").removeClass("active");
}
// 关闭选择站点的下拉菜单
if ($targetObj.closest("#siteSwitch").length == 0) {
$("#headerBarRoleBox").removeClass("bh-active");
}
// 关闭头像的下拉菜单
if ($targetObj.closest("#user").length == 0 && $targetObj.closest("#headerBarUserInfoBox").length == 0) {
$("#headerBarUserInfoBox").removeClass("bh-active");
}
// 关闭主题的下拉菜单
if ($targetObj.closest(".theme-box").length == 0 && $targetObj.closest(".current-theme").length == 0) {
$(".theme-box").removeClass("bh-active");
}
//记录评价是否要刷新
if ($targetObj.closest(".feedback-submit").length > 0) {
AMP.myFeedbackRefreshFlag = true;
}
});
//设置办事大厅滚动联动
$(window).on('mousewheel', function (e) {
var $iframe = $('#indexIframe');
var iframeSrc = $iframe.attr('src');
if (iframeSrc && iframeSrc.indexOf('ehall.html') > 1) {
var scrollHeight = -e.originalEvent.wheelDelta;
var $iframeContainer = $iframe[0].contentWindow.$('body');
$iframeContainer.scrollTop($iframeContainer.scrollTop() + scrollHeight);
}
});
};
/**
* 显示和隐藏弹出层
* @param $iconObj 被点击按钮
* @param $asideObj 需处理的弹出层
*/
AmpUtils.showOrHideAside = function ($iconObj, $asideObj) {
if ($iconObj.hasClass("active")) {
$iconObj.removeClass("active");
$asideObj.removeClass("active");
} else {
$iconObj.addClass("active");
$asideObj.addClass("active");
}
};
/**
* 滚动条美化
* @param _selector 被美化对象的选择器或jquery对象
*/
AmpUtils.niceScrollInit = function (_selector) {
var niceObj;
if (typeof(_selector) === "string") {
niceObj = $(_selector);
} else {
niceObj = _selector;
}
niceObj.niceScroll({zindex: 99999});
};
AmpUtils.openApp = function (appId) {
AmpOpenApp.getOrOpenAppById(appId, AmpOpenApp.openOneApp, "widget", null);
};
AmpUtils.openAppByUrl = function (appId, widgetId, path) {
var appDeployPrefixUrl = AmpUtils.getAppDeployPath(widgetId);
var openPath = appDeployPrefixUrl + path;
AmpOpenApp.getOrOpenAppById(appId, AmpOpenApp.openOneApp, "widget", openPath);
};
AmpUtils.getAppDeployPath = function (widgetId) {
if (AMP.allWidgetData && AMP.allWidgetData.length > 0) {
for (var i = 0; i < AMP.allWidgetData.length; ++i) {
if (widgetId == AMP.allWidgetData[i].widgetId) {
return AMP.allWidgetData[i].appDeployPrefixUrl;
}
}
return "";
} else {
return "";
}
};
AmpUtils.getUserInfo = function () {
return AMP.userInfo;
};
/**
* 获取评价星级html
* @param _score 评分
* @returns {string}
*/
AmpUtils.getScoreHtml = function (_score) {
var starHtml = "";
var scoreList = _score.toString().split(".");
var halfFlag = false;
if (scoreList.length > 1) {
if (scoreList[1] !== 0) {
halfFlag = true;
_score = scoreList[0];
}
}
for (var i = 0; i < 5; i++) {
if (i < _score) {
starHtml += '';
} else {
if (halfFlag) {
halfFlag = false;
starHtml += '';
} else {
starHtml += '';
}
}
}
return starHtml;
};
/**
* 文本截断,一个汉字当两个字节处理
* @param sSource 文本
* @param iLen 截取长度
* @param moreHtml 更多按钮的html
* @returns {*}
*/
AmpUtils.getInterceptedStr = function (sSource, iLen, moreHtml) {
if (sSource.replace(/[^\x00-\xff]/g, "xx").length <= iLen) {
return sSource;
}
var str = "";
var l = 0;
var schar;
for (var i = 0; schar = sSource.charAt(i); i++) {
str += schar;
l += (schar.match(/[^\x00-\xff]/) != null ? 2 : 1);
if (l >= iLen) {
break;
}
}
str += "...";
if (moreHtml) {
str += moreHtml;
}
return str;
};
/**
* 弹出提示信息
* 当右侧栏打开时,则弹出信息在右侧栏的左侧,否则在内容的右边缘弹出
* @param flag
* @param text 自定义的提示文字
*/
AmpUtils.showPrompt = function (flag, text, isHiddenIcon, otherIconName, id) {
var promptText;
switch (flag) {
case "collection":
promptText = "服务收藏成功";
break;
case "needlogin":
promptText = "请您先登录";
break;
case "needauth":
promptText = "您没有权限使用该应用";
break;
case "assessContent":
promptText = "您的评论存在非法字符,请重新输入";
break;
case "notOpen":
promptText = "该应用尚未开放";
break;
case "maintaining":
promptText = "该应用正在维护中...";
break;
default:
promptText = "服务收藏已取消";
break;
}
if (text) {
promptText = text;
}
var active = flag === "collection" ? "active" : "";
var isHidden = isHiddenIcon ? "hidden-icon" : "";
otherIconName = otherIconName ? 'iconfont ' + otherIconName : 'icon app-collection ';
var promptHtml = '' +
'
' +
'
' +
'
' +
'
' + promptText + '
' +
'
' +
'
';
if (flag === "needlogin" || flag === "needauth" || flag === "assessContent") {
promptHtml = '' +
'
' +
'
' +
'
' +
'
' + promptText + '
' +
'
' +
'
';
}
if (flag === "message") {
promptHtml = '' +
'
' +
'
' +
'
' +
'
' + promptText + '
' +
'
' +
'
';
}
var $prompt = $(promptHtml);
$('#collectionPromptDiv').append($prompt);
setTimeout(function () {
closePrompt($prompt);
}, 10);
};
/**
* 关闭提示信息
* @param promptTop
* @param promptLeft
* @constructor
*/
function closePrompt($prompt) {
setTimeout(function () {
$prompt.animate({
opacity: "0.5",
right: "-290px"
}, 1000);
setTimeout(function () {
$prompt.remove();
}, 1000);
}, 3000);
}
//在右侧栏显示或隐藏状态下,重设内容显示区域的宽度
AmpUtils.setContainer = function () {
var $body = $("body");
//未打开应用的情况
if (!$body.hasClass("open-app")) {
var $currentIframe = $('#indexIframe');
var iframeSrc = $currentIframe.attr('src');
var $rightSide = $("#rightSide"),
$footer = $('footer'),
bodyWidth = $body[0].clientWidth > 1200 ? $body[0].clientWidth : 1200,
rightSideWidth = AMP.rightSideIsShow ? $rightSide[0].clientWidth : 0,
contentWidth = AMP.rightSideIsShow ? bodyWidth - rightSideWidth : 1152;
var $iframeList = $('#iframeList');
if (AMP.rightSideIsShow) {
$iframeList.css({"width": contentWidth + 'px'});
$footer.css({"width": contentWidth + 'px'});
if (iframeSrc && iframeSrc.indexOf('ehall.html') > 1) {
$currentIframe.css({"width": "100%", "left": '0'});
}
} else {
$iframeList.css({"width": '100%'});
$footer.css({"width": '100%'});
if (iframeSrc && iframeSrc.indexOf('ehall.html') > 1) {
var iframeLeft = parseInt(($body[0].clientWidth - 1152) / 2, 10);
$currentIframe.css({"width": "1152px", "left": iframeLeft + 'px'});
}
}
AmpUtils.setBodyContainerMinHeight();
}
};
//设置内容展示区的最小高度,避免内容过少时,footer上移到页面中间
AmpUtils.setBodyContainerMinHeight = function () {
var windowHeight = window.innerHeight,
footerHeight = $("footer").outerHeight(true),
containerMinHeight = windowHeight - footerHeight;
$("#iframeList").css({"min-height": containerMinHeight + "px"});
};
//隐藏头部tab和右侧栏
AmpUtils.hideIndexBlock = function (flag) {
if (flag === 'siteApp') {
return;
}
//右侧栏
$("#rightSide").removeClass("active");
$("#rightSideIcon").removeClass("active");
var $iframeList = $("#iframeList");
$iframeList.children("iframe").hide();
$iframeList.children("div").hide();
$iframeList.show().css("opacity", 1);
};
/**
* 获取body或屏幕的宽高
* @param flag
* @returns {*}
*/
AmpUtils.getScreenWidthHeight = function (flag) {
if (flag === "body") {
return {"screenH": window.innerHeight, "screenW": document.body.clientWidth};
} else if (flag === "screen") {
return {"screenH": window.screen.availHeight, "screenW": window.screen.availWidth};
}
};
/**
* 获取浏览器的滚动条宽度
* @returns {number}
*/
AmpUtils.getScrollWidth = function () {
var noScroll, scroll, oDiv = document.createElement("DIV");
oDiv.style.cssText = "position:absolute; top:-1000px; width:100px; height:100px; overflow:hidden;";
noScroll = document.body.appendChild(oDiv).clientWidth;
oDiv.style.overflowY = "scroll";
scroll = oDiv.clientWidth;
document.body.removeChild(oDiv);
return noScroll - scroll;
};
/**
* 针对IE9使用的placeholder插件,失去焦点时使placeholder能显示
* @param searchText
* @param $input
*/
AmpUtils.showPlaceholderInIe9 = function (searchText, $input) {
if (document.documentMode === 9) {
if (searchText === "") {
$input.next("span").show();
}
}
};
//tooltip事件初始化绑定
AmpUtils.tooltipInit = function () {
var $body = $("body");
//hover时显示tooltip
$body.on("mouseover", ".tooltipFlag", function (e) {
showTooltip(e);
});
//鼠标移除时删除tooltip
$body.on("mouseout", ".tooltipFlag", function (e) {
removeTooltip(e);
});
};
/**
* 显示提示信息
* @param e
*/
function showTooltip(e) {
var $targetObj = $(e.target || e.srcElement);
if (!$targetObj.hasClass("tooltipFlag")) {
return;
}
var targetWidth = $targetObj[0].offsetWidth,
targetHeight = $targetObj[0].offsetHeight,
targetOffset = $targetObj.offset(),
isShowInLeftAlign = $targetObj.hasClass("tooltipLeftFlag"),
title = $targetObj.attr("data-tooltip-title");
if (title) {
var guid = AmpUtils.NewGuid(),
$tooltip = createTooltipHtml(title, guid),
tooltipWidth = $tooltip.outerWidth(true),
tooltipHeight = $tooltip.outerHeight(true),
targetMiddleLeft = isShowInLeftAlign ? 0 : parseInt(targetOffset.left + targetWidth / 2),
tooltipLeft = isShowInLeftAlign ? targetOffset.left : targetMiddleLeft - parseInt(tooltipWidth / 2),
tooltipTop = targetOffset.top + targetHeight + 4,
_style = {"left": tooltipLeft + "px", "top": tooltipTop + "px", "height": 0};
if (tooltipLeft + tooltipWidth > $("body").width()) {
_style = {"right": "0", "top": tooltipTop + "px", "height": 0};
}
$tooltip.css(_style).show().animate({"height": tooltipHeight + "px"}, 300);
$targetObj.attr("data-tooltip-guid", guid);
}
}
//移除提示信息
function removeTooltip(e) {
var $targetObj = $(e.target || e.srcElement),
guid = $targetObj.attr("data-tooltip-guid"),
$tooltip = $("body").find("#tooltip_" + guid);
$tooltip.animate({"height": 0}, 300).promise().done(function () {
$tooltip.remove();
});
}
//创建一个guid如:fe493a2e-d9b9-337f-1678-85bb9e88733a
AmpUtils.NewGuid = function () {
return (s4() + s4() + "-" + s4() + "-" + s4() + "-" + s4() + "-" + s4() + s4() + s4());
};
function s4() {
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
}
//获取提示div的html
function createTooltipHtml(title, guid) {
$("body").append('' + title + '
');
return $("#tooltip_" + guid);
}
AmpUtils.setLocalStorageData = function (_key, value) {
var storage = window.localStorage;
storage.setItem(_key, value);
};
AmpUtils.getLocalStorageData = function (_key) {
var storage = window.localStorage;
return storage.getItem(_key);
};
AmpUtils.setSessionStorageData = function (_key, value) {
sessionStorage.setItem(_key, value);
};
AmpUtils.getSessionStorageData = function (_key) {
return sessionStorage.getItem(_key);
};
AmpUtils.deleteSessionStorageData = function (_key) {
sessionStorage.removeItem(_key);
};
/**
* 返回首页的相关操作
* @param clickFlag
*/
AmpUtils.goBackIndex = function (clickFlag) {
//头部
var $body = $("body");
$body.removeClass("open-app").addClass(sessionStorage.getItem("headTab"));
//右侧栏
if (AMP.rightSideIsShow) {
$("#rightSide").addClass("active");
$("#rightSideIcon").addClass("active");
} else {
$("#rightSide").removeClass("active");
$("#rightSideIcon").removeClass("active");
}
AmpUtils.setContainer();
//从头部搜索避免两次添加
if (!clickFlag) {
Wisedu.userActionDataSend();
}
};
/**
* 数据加载完成后定位第一个块的首字母
* @param $letterListParent 字母导航块
* @param $letterAppList 内容块
*/
AmpUtils.afterLoadLetterDataToInit = function ($letterListParent, $letterAppList) {
var $letterList = $letterListParent.children("div");//wengqi20151029
$letterList.removeClass("active");
var $firstLetter = $letterAppList.children("div.app-letter").first();//wengqi20151029
if ($firstLetter.length > 0) {
var letter = $firstLetter.children(".letter").text();
$letterList.each(function () {
var $item = $(this);
if ($item.text() === letter) {
$item.addClass("active");
return;
}
});
}
};
// 刷新应用
AmpUtils.appRefresh = function () {
var currentIframe = $("#indexIframe");
currentIframe.attr("src", currentIframe.attr("src"));
};
AmpUtils.windowResize = function () {
if ($("#iframeList").css("display") === "block") {
//重设iframe的高度
AmpOpenApp.setIframeWidthHeight();
} else {
//重设app列表的宽度
AmpUtils.setContainer();
}
};
//获取用户历史搜索记录数据
AmpUtils.getUserSearchHistory = function (selector) {
AmpServices.userSearchHistory().done(function (data) {
if (data.data && data.data.length > 0) {
var listHtml = '';
if (data.data.length == 0) {
return;
}
$(data.data).each(function () {
listHtml += '' + this.searchKey + '';
});
selector.html(listHtml).show();
}
});
};
AmpUtils.getLetterAppItemHtml = function (item, flag) {
var appListHtml = "";
var appId = item.appId,
title = item.appName,
categoryList = item.categoryList,
classify = "",
image = item.middleIcon,
// favoriteCount = item.assessCount,
favoriteCount = item.favoriteCount,
aScore = item.assessAvgScore,
isCuration = item.type === 1 ? true : false;
if (categoryList && categoryList.length > 0) {
var categoryNameList = [];
for (var k = 0, categoryLen = categoryList.length; k < categoryLen; k++) {
categoryNameList.push(categoryList[k].categoryName);
classify = categoryNameList.join(" / ");
}
} else {
classify = AMP.unknowClassifyName;
}
var removeIconHtml = '';
if (flag === "myFavorite") {
removeIconHtml = '';
}
if (!isCuration) {
//给应用加权限下标
var appPermissionClass = '';
if (flag === 'service') {
appPermissionClass = item.hasPermission == 1 ? 'has-permission' : 'no-permission';
}
appListHtml += '' +
'' +
'
' +
'
' +
'
' +
'
' + classify + '
' +
'
' + AmpUtils.getScoreHtml(aScore) + '
' +
'
' + favoriteCount + '人收藏
' +
'
' +
'
' +
'
';
} else {
var appList = item.appList;
if (!appList) {
appList = AMP.curation[appId];
}
var appCount = appList.length;
var appImgList = "";
for (var i = 0; i < appCount && i < 6; i++) {
appImgList += '';
}
appListHtml += '' +
'' +
'
' +
'
' + classify + '
' +
'
' + appImgList + '
' +
'
' +
'
';
AMP.curation[appId] = item;
}
return appListHtml;
};
/**
* 返回widget所在的列是跨几列的或是否是在侧边栏的
* @param widget
* @returns {string} side是在侧边栏,1是跨一列,2是跨两列,3是跨三列
*/
AmpUtils.getWidgetColNumberOrAtSide = function (widget) {
var $widget = $(widget);
var $rightSide = $widget.closest("#rightWidgetBlock");
var type;
if ($rightSide.length > 0) {
type = "side";
} else {
var $curCol = $widget.closest(".my-site-column");
if ($curCol.length > 0) {
if ($curCol.hasClass("col-two")) {
type = "2";
} else {
type = "1";
}
} else {
type = "3";
}
}
return type;
};
/**
* 拼接app属性字符串
* @param appData
* @returns {string}
*/
AmpUtils.getAppAttr = function (appData) {
var appId = appData.appId;
var appKey = appData.appKey;
var showFullScreen;
var url = "appShow?appId=" + appId;
var title = appData.appName;
var image = appData.middleIcon;
var favorite = appData.favoriteApp ? "active" : "0";
var appPc = appData.appPc;
var hasDescription;
var descriptionAuth;
var hasPermission = appData.hasPermission;
if (appPc) {
hasDescription = appPc.isEnableDescription;
descriptionAuth = appPc.descriptionAuth;
showFullScreen = appPc.isOpenInNewTab;
} else {
hasDescription = appData.isEnableDescription;
descriptionAuth = appData.descriptionAuth;
showFullScreen = appData.isOpenInNewTab;
}
var unviewableDescription = appData.unviewableDescription;
var type = appData.type;
var opening = appData.opening;
var maintaining = appData.maintaining;
var attrStr = '';
attrStr += ' data-appid=' + appId;
attrStr += ' data-appkey=' + appKey;
attrStr += ' data-full-screen=' + showFullScreen;
attrStr += ' data-url=' + url;
attrStr += ' data-title=' + title;
attrStr += ' data-img=' + image;
attrStr += ' data-favorite=' + favorite;
attrStr += ' data-haspermission=' + hasPermission;
attrStr += ' data-hasdescription=' + hasDescription;
attrStr += ' data-descriptionauth=' + descriptionAuth;
attrStr += ' data-unviewabledescription=' + unviewableDescription;
attrStr += ' data-type=' + type;
attrStr += ' data-opening=' + opening;
attrStr += ' data-maintaining=' + maintaining;
return attrStr;
};
/**
* 点击左侧栏字母导航字母的处理
* @param $clickItem 被点击的字母节点
* @param type fwzx是点击的服务中心,favorite是点击的文件夹
*/
AmpUtils.handleClickLetterNav = function ($clickItem, letterTopData, $body) {
var letterLen = letterTopData.length;
if (letterLen === 0) {
return;
}
var clickLetter = $.trim($clickItem.text());
var letterData;
for (var i = 0; i < letterLen; i++) {
var letterItem = letterTopData[i];
if (letterItem.letter === clickLetter) {
letterData = letterItem;
break;
}
}
if (letterData) {
$body.animate({scrollTop: (letterData.height - 30)}, '250');
}
};
/**
* html转义
* @param value 需要转义的字符串
*/
AmpUtils.encode = function (value) {
return $('').text(value).html();
};
AmpUtils.decode = function (value) {
return $('').html(value).text();
};
AmpUtils.openFixedPage = function(data) {
data.headerTab = $("#headTab");
var isExistFlag = intoHeaderExistFixedTabPage(data);
if (!isExistFlag) {
data.headerTab = $("#moreTabsContainer");
isExistFlag = intoHeaderExistFixedTabPage(data);
}
if (!isExistFlag) {
AmpUtils.goBackIndex("headSearch");
if (data.flag === 'serviceCenter') {
AMP.searchKey = data.searchData ? data.searchData.key : "";
AmpOpenApp.openOneApp({
"title": '服务中心',
"appId": 'personalCenter',
"url": 'portal/html/serviceCenter.html',
"flag": 'noOpenEvaluate'
}, 'noOpenEvaluate');
} else if (data.flag === 'favorite') {
AMP.rightSideIsShow = false;
AmpOpenApp.openOneApp({
"title": '我的收藏',
"appId": 'favorite',
"url": 'portal/html/favorite.html',
"flag": 'noOpenEvaluate'
}, 'noOpenEvaluate');
}
} else {
if (data.flag === 'favorite') {
AMP.rightSideIsShow = false;
}
}
};
function intoHeaderExistFixedTabPage(data) {
var isExistFlag = null;
var url = '';
switch (data.flag) {
case 'serviceCenter':
url = 'serviceCenter.html';
break;
case 'favorite':
url = 'favorite.html';
break;
default:
break;
}
data.headerTab.find('div').each(function () {
var $item = $(this);
var itemUrl = $item.attr('data-url');
if (itemUrl && itemUrl.indexOf(url) > 0) {
isExistFlag = true;
if (data.flag === 'serviceCenter') {
setGlobalSearchData(data.searchData);
data.item = $item;
//searchToReloadServiceCenter(data);
}
$item.click();
return;
}
});
return isExistFlag;
}
function setGlobalSearchData(data) {
if (data) {
AMP.searchKey = data.key;
AMP.searchFlag = data.flag;
AMP.searchLabels = data.labels;
} else {
AMP.searchKey = '';
AMP.searchFlag = '';
AMP.searchLabels = '';
}
}
//当服务中心已经打开时,通知服务中心重新查询
function searchToReloadServiceCenter(data) {
var appId = data.item.attr('data-menu-id') || data.item.attr('data-appid');
var $iframe = $('#iframeList').find('iframe[data-appid=' + appId + ']');
if ($iframe.length > 0) {
if (data.searchData && data.searchData.flag === 'classify') {
$iframe[0].contentWindow.AmpServiceCenter.drawFwzx(data.searchData.flag, data.searchData.labels, '');
} else {
$iframe[0].contentWindow.AmpServiceCenter.drawFwzx("", "", AMP.searchKey);
}
}
}
AmpUtils.checkImageLoadComplete = function ($dom) {
var dfd = $.Deferred();
$dom.bind('load', function () {
dfd.resolve();
}).bind('error', function () {
//图片加载错误,加入错误处理
dfd.reject();
});
return dfd.promise();
};
//刷新我的反馈iframe的数据
AmpUtils.refreshFeedbackIframe = function () {
var $feedbackFrame = $('#iframeList').find('iframe[data-appid=myfeedback]');
if ($feedbackFrame.length > 0) {
$feedbackFrame[0].contentWindow.postMessage(JSON.stringify({'feedbackReload': true}), '*');
}
};
//获取公共应用路径
AmpUtils.getPublicAppPath = function () {
return AMPConstant.publicRequestPath;
};
/**
* 同步app属性
* @param appId
* @param attrs 数组[{key: "id", value: "abc"}]
*/
AmpUtils.synchronousAppAttr = function (appId, attrs) {
var $iframeList = $("#iframeList");
//将办事大厅,服务中心,收藏夹的app和已经打开的app进行同步
var attrLen = attrs.length;
$iframeList.find('iframe').each(function () {
var $iframe = $(this);
var iframeSrc = $iframe.attr('src');
if (iframeSrc.indexOf('ehall.html') > 0 || iframeSrc.indexOf('serviceCenter.html') > 0 || iframeSrc.indexOf('favorite.html') > 0 || iframeSrc.indexOf('personalCenter.html') > 0) {
var iframeWindow = this.contentWindow;
var $existApp = $(iframeWindow.document).find("div[data-appid=" + appId + "]");
$existApp.each(function (appIndex, appItem) {
for (var i = 0; i < attrLen; i++) {
var attrItem = attrs[i];
var key = attrItem.key;
var value = attrItem.value;
$(appItem).attr(key, value);
if (key.indexOf('data-') === 0) {
$(appItem).data(key.replace('data-', ''), value);
}
}
});
}
});
};
/**
* 评价时同步页面上的应用数据
* @param appId
*/
AmpUtils.synchronousAppAssess = function (appId) {
var $iframeList = $("#iframeList");
$iframeList.find('iframe').each(function () {
var $iframe = $(this);
var iframeSrc = $iframe.attr('src');
if (iframeSrc.indexOf('ehall.html') > 0 || iframeSrc.indexOf('serviceCenter.html') > 0 || iframeSrc.indexOf('favorite.html') > 0 || iframeSrc.indexOf('personalCenter.html') > 0) {
var iframeWindow = this.contentWindow;
var $container = iframeWindow.$('body');
var $existApp = $container.find("div[data-appid=" + appId + "]");
if ($existApp.length > 0) {
if (iframeSrc.indexOf('serviceCenter.html') > 0) {
//直接点击查询按钮
iframeWindow.fwzxSearchBtn.click();
} else if (iframeSrc.indexOf('ehall.html') > 0) {
//点击当前active的tab,并将所有的tab的road属性去掉
iframeWindow.$("#homeTabList").children().each(function () {
var $tabItem = $(this);
$tabItem.removeAttr('data-flag');
if ($tabItem.hasClass('active')) {
$tabItem.click();
}
});
} else if (iframeSrc.indexOf('personalCenter.html') > 0) {
//重新加载含有该app的widget
$existApp.each(function () {
var $widgetBlock = $(this).closest('.my-site-widget');
var widgetTag = $widgetBlock.attr('data-widget-id');
$widgetBlock.find(widgetTag).after('<' + widgetTag + '>' + widgetTag + '>').remove();
});
} else if (iframeSrc.indexOf('favorite.html') > 0) {
//点击查询的按钮
iframeWindow.favSearchBtn.click();
}
}
}
});
};
})(window.AmpUtils = window.AmpUtils || {});