Skip to content

Commit

Permalink
modify
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaran113 committed Jan 22, 2016
1 parent 9024cc2 commit 5e29e04
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 11 deletions.
1 change: 1 addition & 0 deletions Gruntfile.js
Expand Up @@ -68,6 +68,7 @@ module.exports = function(grunt) {
'js/searchbar.js',
'js/panels.js',
'js/router.js',
'js/last-position.js',
'js/init.js',
'js/scroll-fix.js'
],
Expand Down
99 changes: 98 additions & 1 deletion dist/js/sm.js
Expand Up @@ -7489,6 +7489,92 @@ Device/OS Detection
* @property {*|HTMLElement} $content $doc 里的 routerConfig.innerViewClass 元素
*/

/*======================================================
************ Modals ************
======================================================*/
/*jshint unused: false*/
/* global Zepto:true */
+function ($) {
"use strict";
$.lastPosition =function(options) {
if (!location || !sessionStorage) {
return;
}
// 需要记忆模块的className
var needMemoryClass = options.needMemoryClass || [];


var url = location.href;
//var positionName = location.pathname + '?' + (url.split('?')[1] || '');
var positionName = JSON.parse(sessionStorage.getItem("sm.router.currentState")).pageId + '?' + (url.split('?')[1] || '');

var currentScrollTop;
try {
currentScrollTop = parseInt(sessionStorage.getItem(positionName));
} catch (e) {
currentScrollTop = 0;
}

var timer;

// 设置需要记忆模块的高度
needMemoryClass.forEach(function(item, index) {
var memoryNodes = $(item);

if (memoryNodes.length === 0) {
return;
}

var memoryHeight;
// 遍历对应节点设置存储的高度
memoryNodes.each(function (i, node) {
try {
memoryHeight = sessionStorage.getItem(positionName + '_' + item + '_' + i);
} catch (e) {
memoryHeight = 'auto';
}
$(node).scrollTop(parseInt(memoryHeight));
});
$(window).off('beforePageSwitch').on("beforePageSwitch",function(event,id){
// if (timer) clearTimeout(timer);
// timer = setTimeout(updateMemory, 100);

updateMemory(id);
});
// memoryNodes.off('scroll').on('scroll', function() {
// if (timer) clearTimeout(timer);
// timer = setTimeout(updateMemory, 100);
// });
});


function updateMemory(id) {

//positionName = location.pathname + '?' + (url.split('?')[1] || '');
var positionName = id + '?' + (url.split('?')[1] || '');
// 存储需要记忆模块的高度
needMemoryClass.forEach(function(item, index) {
var memoryNodes = $(item);

if (memoryNodes.length === 0) {
return;
}

// 遍历对应节点设置存储的高度
memoryNodes.each(function (i, node) {
try {
sessionStorage.setItem(
positionName + '_' + item + '_' + i,
$(node).scrollTop()
);
} catch (e) {
}
});
});
}
};
}(Zepto);

/* global Zepto:true */
/*jshint unused: false*/
+function($) {
Expand Down Expand Up @@ -7545,8 +7631,19 @@ Device/OS Detection
// 这里暂且处理一下
$('body').removeClass('panel-closing');
$.allowPanelOpen = true;
});



});

$(window).on('pageInit', function() {
$.hideIndicator();
$.lastPosition({
needMemoryClass: [
'.content'
]
});
});
// safari 在后退的时候会使用缓存技术,但实现上似乎存在些问题,
// 导致路由中绑定的点击事件不会正常如期的运行(log 和 debugger 都没法调试),
// 从而后续的跳转等完全乱了套。
Expand Down
13 changes: 12 additions & 1 deletion js/init.js
Expand Up @@ -54,8 +54,19 @@
// 这里暂且处理一下
$('body').removeClass('panel-closing');
$.allowPanelOpen = true;
});



});

$(window).on('pageInit', function() {
$.hideIndicator();
$.lastPosition({
needMemoryClass: [
'.content'
]
});
});
// safari 在后退的时候会使用缓存技术,但实现上似乎存在些问题,
// 导致路由中绑定的点击事件不会正常如期的运行(log 和 debugger 都没法调试),
// 从而后续的跳转等完全乱了套。
Expand Down
24 changes: 15 additions & 9 deletions js/last-position.js
Expand Up @@ -14,7 +14,8 @@


var url = location.href;
var positionName = location.pathname + '?' + (url.split('?')[1] || '');
//var positionName = location.pathname + '?' + (url.split('?')[1] || '');
var positionName = JSON.parse(sessionStorage.getItem("sm.router.currentState")).pageId + '?' + (url.split('?')[1] || '');

var currentScrollTop;
try {
Expand Down Expand Up @@ -43,18 +44,23 @@
}
$(node).scrollTop(parseInt(memoryHeight));
});

memoryNodes.off('scroll').on('scroll', function() {
if (timer) clearTimeout(timer);
timer = setTimeout(updateMemory, 100);
});
$(window).off('beforePageSwitch').on("beforePageSwitch",function(event,id){
// if (timer) clearTimeout(timer);
// timer = setTimeout(updateMemory, 100);

updateMemory(id);
});
// memoryNodes.off('scroll').on('scroll', function() {
// if (timer) clearTimeout(timer);
// timer = setTimeout(updateMemory, 100);
// });
});


function updateMemory() {

positionName = location.pathname + '?' + (url.split('?')[1] || '');
function updateMemory(id) {

//positionName = location.pathname + '?' + (url.split('?')[1] || '');
var positionName = id + '?' + (url.split('?')[1] || '');
// 存储需要记忆模块的高度
needMemoryClass.forEach(function(item, index) {
var memoryNodes = $(item);
Expand Down

0 comments on commit 5e29e04

Please sign in to comment.