Subversion Repositories php-qbpwcf

Rev

Rev 399 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 399 Rev 401
Line 11762... Line 11762...
11762
 
11762
 
11763
			}//function end
11763
			}//function end
11764
 
11764
 
11765
		";
11765
		";
11766
 
11766
 
-
 
11767
		#js function
-
 
11768
		$conf["javaScript::toScript"]["jsFunciton"][]=
-
 
11769
		"
-
 
11770
 
-
 
11771
		/*
-
 
11772
		說明:
-
 
11773
		偵測 html input type=\"text\" 的 dom,當內容過長無法於 input 區塊完整顯現,必須滾動才能看到前後內容時,提供滾動協助的按鈕.
-
 
11774
 
-
 
11775
		範例:
-
 
11776
 
-
 
11777
		//初始化參數
-
 
11778
		var params={};
-
 
11779
 
-
 
11780
		//顯示往右滾動的icon dom,不指定就不要指定該參數.
-
 
11781
		//params.iconScrollToRight='';
-
 
11782
		
-
 
11783
		//顯示往左滾動的icon  dom,不指定就不要指定該參數.
-
 
11784
		//params.iconScrollToLeft='';
-
 
11785
		
-
 
11786
		//初始化、 設置參數
-
 
11787
		var inputTextScrollHelper=window.qbpwcf.inputTextScrollHelper.init(params);
-
 
11788
		
-
 
11789
		//執行
-
 
11790
		inputTextScrollHelper.run(event);
-
 
11791
		*/
-
 
11792
 
-
 
11793
		//該方法的物件
-
 
11794
		window.qbpwcf.inputTextScrollHelper={};
-
 
11795
		
-
 
11796
		//初始化、設定
-
 
11797
		window.qbpwcf.inputTextScrollHelper.init=function(params){
-
 
11798
		
-
 
11799
			//預設的往右滾動的div
-
 
11800
			var toRightIcon=document.createElement('div');
-
 
11801
			
-
 
11802
			//預設向右滾動的圖示會出現,且可以抓到顯示有內容的寬度.
-
 
11803
			toRightIcon.style.display='inline-block';
-
 
11804
			
-
 
11805
			//跟上個元素同位置
-
 
11806
			toRightIcon.style.position='relative';
-
 
11807
			
-
 
11808
			//設置方文字
-
 
11809
			toRightIcon.innerText='>>>';
-
 
11810
			
-
 
11811
			//設置cursor為pointer
-
 
11812
			toRightIcon.style.cursor='pointer';
-
 
11813
			
-
 
11814
			//預設的往作左滾動div
-
 
11815
			var toLeftIcon=document.createElement('div');
-
 
11816
			
-
 
11817
			//一開始不顯示
-
 
11818
			toLeftIcon.style.display='inline-block';
-
 
11819
			
-
 
11820
			//跟上個元素同位置
-
 
11821
			toLeftIcon.style.position='relative';
-
 
11822
			
-
 
11823
			//設置文字
-
 
11824
			toLeftIcon.innerText='<<<';
-
 
11825
			
-
 
11826
			//設置cursor為pointer
-
 
11827
			toLeftIcon.style.cursor='pointer';
-
 
11828
			
-
 
11829
			//如果有設置 iconScrollToRight
-
 
11830
			if(params.iconScrollToRight!=undefined){
-
 
11831
			
-
 
11832
				//設置指定的圖示
-
 
11833
				toRightIcon=params.iconScrollToRight;
-
 
11834
				
-
 
11835
				//預設向右滾動的圖示會出現,且可以抓到顯示有內容的寬度.
-
 
11836
				toRightIcon.style.display='inline-block';
-
 
11837
				
-
 
11838
				//跟上個元素同位置
-
 
11839
				toRightIcon.style.position='relative';
-
 
11840
				
-
 
11841
				//設置方文字
-
 
11842
				toRightIcon.innerText='>>>';
-
 
11843
				
-
 
11844
				//設置cursor為pointer
-
 
11845
				toRightIcon.style.cursor='pointer';
-
 
11846
			
-
 
11847
				}//if end
-
 
11848
				
-
 
11849
			//如果有設置 iconScrollToLeft
-
 
11850
			if(params.iconScrollToLeft!=undefined){
-
 
11851
			
-
 
11852
				//設置指定的圖示
-
 
11853
				toLeftIcon=params.iconScrollToLeft;
-
 
11854
				
-
 
11855
				//預設向左滾動的圖示會出現,且可以抓到顯示有內容的寬度.
-
 
11856
				toLeftIcon.style.display='inline-block';
-
 
11857
				
-
 
11858
				//跟上個元素同位置
-
 
11859
				toLeftIcon.style.position='relative';
-
 
11860
				
-
 
11861
				//設置文字
-
 
11862
				toLeftIcon.innerText='<<<';
-
 
11863
				
-
 
11864
				//設置cursor為pointer
-
 
11865
				toLeftIcon.style.cursor='pointer';
-
 
11866
			
-
 
11867
				}//if end
-
 
11868
			
-
 
11869
			//設置要回傳的結果
-
 
11870
			var result={
-
 
11871
				
-
 
11872
				//放置向右滾動的icon
-
 
11873
				'toRightIcon':toRightIcon,
-
 
11874
				
-
 
11875
				//放置向左滾動的icon
-
 
11876
				'toLeftIcon':toLeftIcon,
-
 
11877
				
-
 
11878
				//放置運行該功能的function
-
 
11879
				'run':function(event){
-
 
11880
				
-
 
11881
					//取得 input dom
-
 
11882
					var ele=event.target;
-
 
11883
				
-
 
11884
					//如果不是 input dom
-
 
11885
					if(ele.tagName!='INPUT'){
-
 
11886
					
-
 
11887
						//不做事
-
 
11888
						return false;
-
 
11889
					
-
 
11890
						}//if end
-
 
11891
						
-
 
11892
					//如果 type 不是 text
-
 
11893
					else if(ele.type!='text'){
-
 
11894
					
-
 
11895
						//不做事
-
 
11896
						return false;
-
 
11897
					
-
 
11898
						}//if end
-
 
11899
				
-
 
11900
					//如果是 mobile client
-
 
11901
					if(navigator.userAgent.includes('Mobile')){
-
 
11902
					
-
 
11903
						//不做事
-
 
11904
						return false;
-
 
11905
					
-
 
11906
						}//if end
-
 
11907
				
-
 
11908
					//取得最大的滾動寬度
-
 
11909
					var maxScrollPx=ele.scrollLeftMax;
-
 
11910
					
-
 
11911
					//如果沒有內容無法呈現
-
 
11912
					if( maxScrollPx == ele.clientWidth ){
-
 
11913
					
-
 
11914
						//不做事
-
 
11915
						return false;
-
 
11916
					
-
 
11917
						}//if end
-
 
11918
						
-
 
11919
					//如果沒有需要滾軸
-
 
11920
					if(ele.scrollLeftMax==0){
-
 
11921
					
-
 
11922
						//不做事
-
 
11923
						return false;
-
 
11924
					
-
 
11925
						}//if end
-
 
11926
				
-
 
11927
					//取得目前滾軸的位置
-
 
11928
					var scrollX=ele.scrollLeft;
-
 
11929
					
-
 
11930
					//取得一次要滾動多少px
-
 
11931
					var scrollPxPerTime=ele.clientWidth;
-
 
11932
					
-
 
11933
					//顯示向左滾動的 icon
-
 
11934
					ele.parentElement.append(result.toLeftIcon);
-
 
11935
				
-
 
11936
					//取得向左滾動的圖示其 bottom 樣式的數值
-
 
11937
					var toLeftIcon_bottomPosition=parseInt(window.getComputedStyle(ele.parentElement.children[1]).height)+parseInt(window.getComputedStyle(ele).height)/2-parseInt(window.getComputedStyle(ele.parentElement.children[1]).height)/2;
-
 
11938
				
-
 
11939
					//如果為負數
-
 
11940
					if(toLeftIcon_bottomPosition<0){
-
 
11941
					
-
 
11942
						//轉正數
-
 
11943
						toLeftIcon_bottomPosition=toLeftIcon_bottomPosition-toLeftIcon_bottomPosition*2;
-
 
11944
					
-
 
11945
						}//if end
-
 
11946
				
-
 
11947
					//位置在可視區域的最左端,且上下置中
-
 
11948
					ele.parentElement.children[1].style.bottom=toLeftIcon_bottomPosition+'px';
-
 
11949
					
-
 
11950
					//不能占用空間
-
 
11951
					ele.parentElement.children[1].style.height='0px';
-
 
11952
					
-
 
11953
					//先隱藏該按鈕
-
 
11954
					ele.parentElement.children[1].style.display='none';
-
 
11955
					
-
 
11956
					//當點擊向左滾動的icon
-
 
11957
					result.toLeftIcon.addEventListener('click',function(e){
-
 
11958
					
-
 
11959
						//取得 input dom
-
 
11960
						var inputEle=e.target.previousElementSibling;
-
 
11961
					
-
 
11962
						//滾動到新位置
-
 
11963
						inputEle.scroll(scrollX-scrollPxPerTime,0);
-
 
11964
						
-
 
11965
						//更新目前滾軸的位置
-
 
11966
						scrollX=inputEle.scrollLeft;
-
 
11967
						
-
 
11968
						//如果已經在最左邊
-
 
11969
						if(scrollX==0){
-
 
11970
					
-
 
11971
							//隱藏該按鈕
-
 
11972
							inputEle.parentElement.children[1].style.display='none';
-
 
11973
					
-
 
11974
							}//if end
-
 
11975
							
-
 
11976
						//如果還可以往右邊滾動
-
 
11977
						if(scrollX<maxScrollPx){
-
 
11978
						
-
 
11979
							//顯示向右滾動的按鈕
-
 
11980
							inputEle.parentElement.children[2].style.display='inline-block';
-
 
11981
						
-
 
11982
							}//if end
-
 
11983
					
-
 
11984
						});
-
 
11985
					
-
 
11986
					//顯示向右滾動的 icon
-
 
11987
					ele.parentElement.append(result.toRightIcon);
-
 
11988
					
-
 
11989
					//取得向右滾動的圖示其 left 樣式的數值
-
 
11990
					var toRightIcon_leftPosition=parseInt(window.getComputedStyle(ele).width)-parseInt(window.getComputedStyle(ele.parentElement.children[2]).width);
-
 
11991
					
-
 
11992
					//取得向右滾動的圖示其 bottom 樣式的數值
-
 
11993
					var toRightIcon_bottomPosition=parseInt(window.getComputedStyle(ele.parentElement.children[2]).height)+parseInt(window.getComputedStyle(ele).height)/2-parseInt(window.getComputedStyle(ele.parentElement.children[2]).height)/2;
-
 
11994
				
-
 
11995
					//如果為負數
-
 
11996
					if(toRightIcon_bottomPosition<0){
-
 
11997
					
-
 
11998
						//轉正數
-
 
11999
						toRightIcon_bottomPosition=toRightIcon_bottomPosition-toRightIcon_bottomPosition*2;
-
 
12000
					
-
 
12001
						}//if end
-
 
12002
				
-
 
12003
					//位置在可視區域的最右端
-
 
12004
					ele.parentElement.children[2].style.left=toRightIcon_leftPosition+'px';
-
 
12005
				
-
 
12006
					//且上下置中
-
 
12007
					ele.parentElement.children[2].style.bottom=toRightIcon_bottomPosition+'px';
-
 
12008
					
-
 
12009
					//且不能占用空間
-
 
12010
					ele.parentElement.children[2].style.height='0px';
-
 
12011
				
-
 
12012
					//當點擊了向右滾動的 icon
-
 
12013
					result.toRightIcon.addEventListener('click',function(e){
-
 
12014
					
-
 
12015
						//取得 input dom
-
 
12016
						var inputEle=e.target.previousElementSibling.previousElementSibling;
-
 
12017
					
-
 
12018
						//取得剩下多少可以滾動
-
 
12019
						var leftScrollPx=maxScrollPx-scrollX;
-
 
12020
						
-
 
12021
						//滾動到新位置
-
 
12022
						inputEle.scroll(scrollX+scrollPxPerTime,0);
-
 
12023
						
-
 
12024
						//更新目前滾軸的位置
-
 
12025
						scrollX=inputEle.scrollLeft;
-
 
12026
						
-
 
12027
						//如果已經在最右邊
-
 
12028
						if(scrollX>=maxScrollPx){
-
 
12029
					
-
 
12030
							//隱藏該按鈕
-
 
12031
							inputEle.parentElement.children[2].style.display='none';
-
 
12032
					
-
 
12033
							}//if end
-
 
12034
							
-
 
12035
						//如果不是在最左邊
-
 
12036
						if(scrollX!=0){
-
 
12037
					
-
 
12038
							//顯示向左滾動的按鈕
-
 
12039
							inputEle.parentElement.children[1].style.display='inline-block';
-
 
12040
					
-
 
12041
							}//if end
-
 
12042
					
-
 
12043
						});
-
 
12044
				
-
 
12045
					}//function end
-
 
12046
				};
-
 
12047
				
-
 
12048
			//回傳結果
-
 
12049
			return result;
-
 
12050
		
-
 
12051
			};//function end
-
 
12052
		";
-
 
12053
 
11767
		#$conf["noScriptTag"],字串,是否不要輸出<script></script>,預設為"false",代表要輸出;反之為"true",代表不要輸出.
12054
		#$conf["noScriptTag"],字串,是否不要輸出<script></script>,預設為"false",代表要輸出;反之為"true",代表不要輸出.
11768
		$conf["javaScript::toScript"]["noScriptTag"]=$conf["noScriptTag"];
12055
		$conf["javaScript::toScript"]["noScriptTag"]=$conf["noScriptTag"];
11769
 
12056
 
11770
		#參考資料:
12057
		#參考資料:
11771
		#http://stackoverflow.com/questions/9899372/pure-javascript-equivalent-to-jquerys-ready-how-to-call-a-function-when-the
12058
		#http://stackoverflow.com/questions/9899372/pure-javascript-equivalent-to-jquerys-ready-how-to-call-a-function-when-the
Line 17058... Line 17345...
17058
document.getElementById('bottom').scrollHeight;
17345
document.getElementById('bottom').scrollHeight;
17059
 
17346
 
17060
#視窗的高度(含滾軸)
17347
#視窗的高度(含滾軸)
17061
document.scrollingElement.scrollHeight
17348
document.scrollingElement.scrollHeight
17062
 
17349
 
-
 
17350
#dom的滾軸目前x軸距離起點多少 px
-
 
17351
dom.scrollLeft;
-
 
17352
 
-
 
17353
#dom的滾軸的最大可滾動寬度(x)by scroll(x,y)
-
 
17354
dom.scrollLeftMax;
-
 
17355
 
17063
#視窗的高度拉到頂
17356
#視窗的高度拉到頂
17064
document.scrollingElement.scrollTop=0;
17357
document.scrollingElement.scrollTop=0;
17065
 
17358
 
17066
#取得id為"ID"的元素位置與寬高
17359
#取得id為"ID"的元素位置與寬高
17067
var element = document.getElementById('ID');
17360
var element = document.getElementById('ID');
Line 17972... Line 18265...
17972
//參考資料 https://developer.mozilla.org/en-US/docs/Web/API/NavigatorID/userAgent
18265
//參考資料 https://developer.mozilla.org/en-US/docs/Web/API/NavigatorID/userAgent
17973
 
18266
 
17974
//判斷 user agent 是不是 windows
18267
//判斷 user agent 是不是 windows
17975
navigator.userAgent.includes('Windows');
18268
navigator.userAgent.includes('Windows');
17976
 
18269
 
-
 
18270
//判斷 user agent 是不是 mobile
-
 
18271
navigator.userAgent.includes('Mobile');
-
 
18272
 
17977
//參考資料 https://www.w3schools.com/jsref/jsref_includes.asp
18273
//參考資料 https://www.w3schools.com/jsref/jsref_includes.asp
17978
 
18274
 
17979
//取得目前瀏覽的 hostname
18275
//取得目前瀏覽的 hostname
17980
window.location.hostname
18276
window.location.hostname
17981
 
18277
 
Line 18052... Line 18348...
18052
//https://developer.mozilla.org/en-US/docs/Web/API/Document/replaceChildren
18348
//https://developer.mozilla.org/en-US/docs/Web/API/Document/replaceChildren
18053
 
18349
 
18054
//將元素dom的直向滾動到結尾
18350
//將元素dom的直向滾動到結尾
18055
dom.scrollIntoView({'behavior':'smooth','block':'end'});
18351
dom.scrollIntoView({'behavior':'smooth','block':'end'});
18056
 
18352
 
18057
//將元素dom的橫向滾動到結尾
18353
//將元素dom的橫向滾動到結尾,目前測試還是直向滾動.
18058
dom.scrollIntoView({'behavior':'smooth','inline':'end'});
18354
dom.scrollIntoView({'behavior':'smooth','inline':'end'});
18059
 
18355
 
18060
*/
18356
*/
18061
 
18357
 
18062
?>
18358
?>