| 3 |
liveuser |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
|
|
|
5 |
QBPWCF, Quick Build PHP website Component base on Fedora Linux.
|
| 226 |
liveuser |
6 |
Copyright (C) 2014~2025 MIN ZHI, CHEN
|
| 3 |
liveuser |
7 |
|
|
|
8 |
This file is part of QBPWCF.
|
|
|
9 |
|
|
|
10 |
QBPWCF is free software: you can redistribute it and/or modify
|
|
|
11 |
it under the terms of the GNU General Public License as published by
|
|
|
12 |
the Free Software Foundation, either version 3 of the License, or
|
|
|
13 |
(at your option) any later version.
|
|
|
14 |
|
|
|
15 |
QBPWCF is distributed in the hope that it will be useful,
|
|
|
16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
18 |
GNU General Public License for more details.
|
|
|
19 |
|
|
|
20 |
You should have received a copy of the GNU General Public License
|
|
|
21 |
along with QBPWCF. If not, see <http://www.gnu.org/licenses/>.
|
|
|
22 |
|
|
|
23 |
*/
|
|
|
24 |
namespace qbpwcf;
|
|
|
25 |
|
|
|
26 |
/*
|
|
|
27 |
類別說明:
|
|
|
28 |
javaScript應用的類別.
|
|
|
29 |
備註:
|
|
|
30 |
無.
|
|
|
31 |
*/
|
|
|
32 |
class javaScript{
|
|
|
33 |
|
|
|
34 |
/*
|
|
|
35 |
#函式說明:
|
|
|
36 |
#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
|
|
|
37 |
#回傳結果:
|
|
|
38 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
39 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
40 |
#$result["function"],當前執行的函式名稱.
|
|
|
41 |
#必填參數:
|
|
|
42 |
#$method,物件,為物件實體或類別名稱,會自動置入該參數.
|
|
|
43 |
#$arguments,陣列,為呼叫方法時所用的參數.
|
|
|
44 |
#參考資料:
|
|
|
45 |
#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
|
|
|
46 |
*/
|
|
|
47 |
public function __call($method,$arguments){
|
|
|
48 |
|
|
|
49 |
#取得當前執行的函式
|
|
|
50 |
$result["function"]=__FUNCTION__;
|
|
|
51 |
|
|
|
52 |
#設置執行不正常
|
|
|
53 |
$result["status"]="false";
|
|
|
54 |
|
|
|
55 |
#設置執行錯誤
|
|
|
56 |
$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
|
|
|
57 |
|
|
|
58 |
#設置所丟入的參數
|
|
|
59 |
$result["error"][]=$arguments;
|
|
|
60 |
|
|
|
61 |
#回傳結果
|
|
|
62 |
return $result;
|
|
|
63 |
|
|
|
64 |
}#function __call end
|
|
|
65 |
|
|
|
66 |
/*
|
|
|
67 |
#函式說明:
|
|
|
68 |
#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
|
|
|
69 |
#回傳結果:
|
|
|
70 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
71 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
72 |
#$result["function"],當前執行的函式名稱.
|
|
|
73 |
#必填參數:
|
|
|
74 |
#$method,物件,為物件實體或類別名稱,會自動置入該參數.
|
|
|
75 |
#$arguments,陣列,為呼叫方法時所用的參數.
|
|
|
76 |
#參考資料:
|
|
|
77 |
#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
|
|
|
78 |
*/
|
|
|
79 |
public static function __callStatic($method,$arguments){
|
|
|
80 |
|
|
|
81 |
#取得當前執行的函式
|
|
|
82 |
$result["function"]=__FUNCTION__;
|
|
|
83 |
|
|
|
84 |
#設置執行不正常
|
|
|
85 |
$result["status"]="false";
|
|
|
86 |
|
|
|
87 |
#設置執行錯誤
|
|
|
88 |
$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
|
|
|
89 |
|
|
|
90 |
#設置所丟入的參數
|
|
|
91 |
$result["error"][]=$arguments;
|
|
|
92 |
|
|
|
93 |
#回傳結果
|
|
|
94 |
return $result;
|
|
|
95 |
|
|
|
96 |
}#function __callStatic end
|
|
|
97 |
|
|
|
98 |
/*
|
|
|
99 |
#函式說明:
|
|
|
100 |
#script 語法開始
|
|
|
101 |
#回傳結果:
|
|
|
102 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
103 |
#$result["error"],錯誤訊息陣列.
|
|
|
104 |
#$result["warning"],警告訊息陣列.
|
|
|
105 |
#$result["founded"],識別是否有找到要匯入的js檔案,若有指定jsPosition參數才會回傳該結果.
|
|
|
106 |
#$result["function"],當前執行的函數名稱.
|
|
|
107 |
#$result["content"],javaScript語法.
|
|
|
108 |
#$result["argv"], 使用的參數.
|
|
|
109 |
#必填參數:
|
|
|
110 |
#$conf["include"],字串,是否要匯入外部js庫,"true"爲要匯入;"false"爲沒有要匯入。
|
|
|
111 |
$conf["include"]="true";
|
|
|
112 |
#可省略參數:
|
|
|
113 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑,請與參數"jsPosition"一起設置,預設為當前檔案的位置.
|
|
|
114 |
#$conf["fileArgu"]=__FILE__;
|
|
|
115 |
#$conf["jsPosition"],字串,要匯入的js檔案位置,請與參數"fileArgu"一起設置,用了該參數後,該<script src="jsFileAddr"></script>裡面放的程式將不會運作.
|
|
|
116 |
#$conf["jsPosition"]="";
|
|
|
117 |
#$conf["web"],字串,true代表是網頁系統的位置,"false"代表是檔案系統的位置,預設為"true".
|
|
|
118 |
#$conf["web"]="true";
|
|
|
119 |
#$conf["allowNotExist"],字串,預設為"true",代表允許js檔案於server端檢查後不存在的結果;反之為"false".
|
|
|
120 |
#$conf["allowNotExist"]="true";
|
|
|
121 |
#$conf["importWhenExist"],字串,預設為"true",代表有存在才輸出匯入的語法;反之為"false".
|
|
|
122 |
#$conf["importWhenExist"]="true";
|
|
|
123 |
#參考資料:
|
|
|
124 |
#無.
|
|
|
125 |
#備註:
|
|
|
126 |
#無.
|
|
|
127 |
*/
|
|
|
128 |
public static function start(&$conf){
|
|
|
129 |
|
|
|
130 |
#初始化要回傳的變數
|
|
|
131 |
$result=array();
|
|
|
132 |
|
|
|
133 |
#記錄當前執行的函數名稱
|
|
|
134 |
$result["function"]=__FUNCTION__;
|
|
|
135 |
|
|
|
136 |
#如果 $conf 不為陣列
|
|
|
137 |
if(gettype($conf)!="array"){
|
|
|
138 |
|
|
|
139 |
#設置執行失敗
|
|
|
140 |
$result["status"]="false";
|
|
|
141 |
|
|
|
142 |
#設置執行錯誤訊息
|
|
|
143 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
144 |
|
|
|
145 |
#如果傳入的參數為 null
|
|
|
146 |
if($conf==null){
|
|
|
147 |
|
|
|
148 |
#設置執行錯誤訊息
|
|
|
149 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
150 |
|
|
|
151 |
}#if end
|
|
|
152 |
|
|
|
153 |
#回傳結果
|
|
|
154 |
return $result;
|
|
|
155 |
|
|
|
156 |
}#if end
|
|
|
157 |
|
|
|
158 |
#記錄當前執行的函數名稱
|
|
|
159 |
$result["argv"]=$conf;
|
|
|
160 |
|
|
|
161 |
#檢查參數
|
|
|
162 |
#函式說明:
|
|
|
163 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
164 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
165 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
166 |
#$result["function"],當前執行的函式名稱.
|
|
|
167 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
168 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
169 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
170 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
171 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
172 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
173 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
174 |
#必填參數:
|
|
|
175 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
176 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
177 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
178 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("include");
|
|
|
179 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
|
|
180 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
181 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
182 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
183 |
#可以省略的參數:
|
|
|
184 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
185 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
186 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
187 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("jsPosition","web","fileArgu","allowNotExist","importWhenExist");
|
|
|
188 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
189 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string");
|
|
|
190 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
191 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"true",__FILE__,"true","true");
|
|
|
192 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
193 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
|
|
|
194 |
#參考資料來源:
|
|
|
195 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
196 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
197 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
198 |
|
|
|
199 |
#如果檢查失敗
|
|
|
200 |
if($checkResult["status"]==="false"){
|
|
|
201 |
|
|
|
202 |
#設置錯誤狀態
|
|
|
203 |
$result["status"]="false";
|
|
|
204 |
|
|
|
205 |
#設置錯誤提示
|
|
|
206 |
$result["error"]=$checkResult;
|
|
|
207 |
|
|
|
208 |
#回傳結果
|
|
|
209 |
return $result;
|
|
|
210 |
|
|
|
211 |
}#if end
|
|
|
212 |
|
|
|
213 |
#如果檢查不通過
|
|
|
214 |
if($checkResult["passed"]==="false"){
|
|
|
215 |
|
|
|
216 |
#設置錯誤狀態
|
|
|
217 |
$result["status"]="false";
|
|
|
218 |
|
|
|
219 |
#設置錯誤提示
|
|
|
220 |
$result["error"]=$checkResult;
|
|
|
221 |
|
|
|
222 |
#回傳結果
|
|
|
223 |
return $result;
|
|
|
224 |
|
|
|
225 |
}#if end
|
|
|
226 |
|
|
|
227 |
#如果 $conf["include"] 其值爲 "true"
|
|
|
228 |
if($conf["include"]==="true"){
|
|
|
229 |
|
|
|
230 |
#如果 $conf["jsPosition"] 有設定
|
|
|
231 |
if(isset($conf["jsPosition"])){
|
|
|
232 |
|
|
|
233 |
#var_dump($conf["jsPosition"]);
|
|
|
234 |
|
|
|
235 |
#轉換成檔案系統路徑
|
|
|
236 |
#函式說明:
|
|
|
237 |
#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
|
|
|
238 |
#回傳結果:
|
|
|
239 |
#$result["status"],"true"爲建立成功,"false"爲建立失敗.
|
|
|
240 |
#$result["error"],錯誤訊息陣列.
|
| 226 |
liveuser |
241 |
#$result["function"],函數名稱.
|
| 3 |
liveuser |
242 |
#$result["argu"],使用的參數.
|
|
|
243 |
#$result["content"],網址,若是在命令列執行,則為"null".
|
|
|
244 |
#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
|
|
|
245 |
#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
|
|
|
246 |
#必填參數:
|
|
|
247 |
#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
|
|
|
248 |
$conf["fileAccess::getInternetAddressV2"]["address"]=$conf["jsPosition"];
|
|
|
249 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
|
|
|
250 |
$conf["fileAccess::getInternetAddressV2"]["fileArgu"]=$conf["fileArgu"];
|
|
|
251 |
#可省略參數:
|
|
|
252 |
#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
|
|
|
253 |
$conf["fileAccess::getInternetAddressV2"]["web"]=$conf["web"];
|
|
|
254 |
#備註:
|
|
|
255 |
#建構中,fileSystemRelativePosition尚未實作,檢查參數尚未實作.
|
|
|
256 |
$getInternetAddressV2=fileAccess::getInternetAddressV2($conf["fileAccess::getInternetAddressV2"]);
|
|
|
257 |
unset($conf["fileAccess::getInternetAddressV2"]);
|
|
|
258 |
|
|
|
259 |
#var_dump($getInternetAddressV2);
|
|
|
260 |
|
|
|
261 |
#如果檢查不通過
|
|
|
262 |
if($getInternetAddressV2["status"]=="false"){
|
|
|
263 |
|
|
|
264 |
#設置錯誤狀態
|
|
|
265 |
$result["status"]="false";
|
|
|
266 |
|
|
|
267 |
#設置錯誤提示
|
|
|
268 |
$result["error"]=$getInternetAddressV2;
|
|
|
269 |
|
|
|
270 |
#回傳結果
|
|
|
271 |
return $result;
|
|
|
272 |
|
|
|
273 |
}#if end
|
| 226 |
liveuser |
274 |
|
| 3 |
liveuser |
275 |
#用成網路位置
|
|
|
276 |
$conf["jsPosition"]=$getInternetAddressV2["content"];
|
| 226 |
liveuser |
277 |
|
| 3 |
liveuser |
278 |
#檢查要匯入的js檔案是否存在
|
|
|
279 |
#函式說明:檢查多個檔案與資料夾是否存在.
|
|
|
280 |
#回傳結果:
|
|
|
281 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
|
|
282 |
#$result["error"],錯誤訊息陣列.
|
|
|
283 |
#$resutl["function"],當前執行的涵式名稱.
|
|
|
284 |
#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
|
|
|
285 |
#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
|
|
|
286 |
#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
|
|
|
287 |
#必填參數:
|
|
|
288 |
$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["jsPosition"]);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
|
|
|
289 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
|
|
|
290 |
$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
|
|
|
291 |
#可省略參數
|
|
|
292 |
#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
|
|
|
293 |
$conf["fileAccess::checkMultiFileExist"]["disableWebSearch"]="false";
|
|
|
294 |
#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,於設為"true".
|
|
|
295 |
$conf["fileAccess::checkMultiFileExist"]["web"]="true";
|
|
|
296 |
#參考資料來源:
|
|
|
297 |
#http://php.net/manual/en/function.file-exists.php
|
|
|
298 |
#http://php.net/manual/en/control-structures.foreach.php
|
|
|
299 |
$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
|
|
|
300 |
unset($conf["fileAccess::checkMultiFileExist"]);
|
| 226 |
liveuser |
301 |
|
| 3 |
liveuser |
302 |
#debug
|
|
|
303 |
#var_dump($checkMultiFileExist);
|
| 226 |
liveuser |
304 |
|
| 3 |
liveuser |
305 |
#如果檢查要匯入的js檔案失敗
|
|
|
306 |
if($checkMultiFileExist["status"]=="false"){
|
|
|
307 |
|
|
|
308 |
#設置錯誤狀態
|
|
|
309 |
$result["status"]="false";
|
|
|
310 |
|
|
|
311 |
#設置錯誤提示
|
|
|
312 |
$result["error"]=$checkMultiFileExist;
|
|
|
313 |
|
|
|
314 |
#回傳結果
|
|
|
315 |
return $result;
|
|
|
316 |
|
|
|
317 |
}#if end
|
|
|
318 |
|
|
|
319 |
#如果檢查要匯入的js檔案不存在
|
|
|
320 |
if($checkMultiFileExist["varExist"][0]=="false"){
|
|
|
321 |
|
|
|
322 |
#設置沒有找到 js 檔案
|
|
|
323 |
$result["founded"]="false";
|
|
|
324 |
|
|
|
325 |
#如果不允許 server 端找不到 js 檔案
|
|
|
326 |
if($conf["allowNotExist"]==="false"){
|
| 226 |
liveuser |
327 |
|
| 3 |
liveuser |
328 |
#設置錯誤狀態
|
|
|
329 |
$result["status"]="false";
|
|
|
330 |
|
|
|
331 |
#設置錯誤提示
|
|
|
332 |
$result["error"][]="要匯入的js檔案「".$checkMultiFileExist["varName"][0]."」不存在";
|
|
|
333 |
|
|
|
334 |
#取得原生的錯誤訊息
|
|
|
335 |
$result["error"][]=$checkMultiFileExist;
|
|
|
336 |
|
|
|
337 |
#回傳結果
|
|
|
338 |
return $result;
|
|
|
339 |
|
|
|
340 |
}#if end
|
|
|
341 |
|
|
|
342 |
#執行到這邊代表允許 server 端找不到 js 檔案
|
|
|
343 |
|
|
|
344 |
#設置警告提示
|
|
|
345 |
$result["warning"][]="要匯入的js檔案「".$checkMultiFileExist["varName"][0]."」不存在";
|
|
|
346 |
|
|
|
347 |
}#if end
|
|
|
348 |
|
|
|
349 |
#反之
|
|
|
350 |
else{
|
|
|
351 |
|
|
|
352 |
#設置有找到 js 檔案
|
|
|
353 |
$result["founded"]="true";
|
|
|
354 |
|
|
|
355 |
}#else end
|
|
|
356 |
|
|
|
357 |
#設定要匯入的js函式庫
|
|
|
358 |
$conf["jsPosition"]=" src=\"".$checkMultiFileExist["varNameWebPath"][0]."\" ";
|
|
|
359 |
|
|
|
360 |
}#if end
|
|
|
361 |
|
|
|
362 |
#反之
|
|
|
363 |
else{
|
|
|
364 |
|
|
|
365 |
#將$conf["jsPosition"]設爲空字串
|
|
|
366 |
$conf["jsPosition"]="";
|
|
|
367 |
|
|
|
368 |
}#else end
|
|
|
369 |
|
|
|
370 |
}#if end
|
|
|
371 |
|
|
|
372 |
#反之
|
|
|
373 |
else{
|
|
|
374 |
|
|
|
375 |
#將$conf["jsPosition"]設爲空字串
|
|
|
376 |
$conf["jsPosition"]="";
|
|
|
377 |
|
|
|
378 |
}#else end
|
|
|
379 |
|
|
|
380 |
#debug
|
|
|
381 |
#var_dump($result);
|
|
|
382 |
|
|
|
383 |
#如果有是找到js檔案的識別
|
|
|
384 |
if(isset($result["founded"])){
|
| 226 |
liveuser |
385 |
|
| 3 |
liveuser |
386 |
#如果找不到js檔案,且沒有要求也要輸出匯入js的標籤
|
|
|
387 |
if( $result["founded"]==="false" && $conf["importWhenExist"]==="true" ){
|
| 226 |
liveuser |
388 |
|
| 3 |
liveuser |
389 |
#清空匯入js的標籤
|
|
|
390 |
$conf["jsPosition"]="";
|
| 226 |
liveuser |
391 |
|
| 3 |
liveuser |
392 |
}#if end
|
| 226 |
liveuser |
393 |
|
| 3 |
liveuser |
394 |
}#if end
|
|
|
395 |
|
|
|
396 |
#設置要回傳javascript語法
|
|
|
397 |
$result["content"]="<script type=\"text/javascript\" ".$conf["jsPosition"]." >";
|
|
|
398 |
|
|
|
399 |
#設置執行正常
|
|
|
400 |
$result["status"]="true";
|
|
|
401 |
|
|
|
402 |
#回傳結果
|
|
|
403 |
return $result;
|
|
|
404 |
|
|
|
405 |
}#function start end
|
|
|
406 |
|
|
|
407 |
/*
|
|
|
408 |
#函式說明:
|
|
|
409 |
#script 語法結束
|
|
|
410 |
#script 語法開始
|
|
|
411 |
#回傳結果:
|
|
|
412 |
#javaScript語法
|
|
|
413 |
#必填參數:
|
|
|
414 |
#無.
|
|
|
415 |
#可省略參數:
|
|
|
416 |
#無.
|
|
|
417 |
#參考資料:
|
|
|
418 |
#無.
|
|
|
419 |
#備註:
|
|
|
420 |
#無.
|
|
|
421 |
*/
|
|
|
422 |
public static function end(){
|
|
|
423 |
|
|
|
424 |
return "</script>";
|
|
|
425 |
|
|
|
426 |
}#function end
|
|
|
427 |
|
|
|
428 |
/*
|
|
|
429 |
#函式說明:
|
|
|
430 |
#彈出視窗
|
|
|
431 |
#回傳結果:
|
|
|
432 |
#$result["status"],執行正確與否,"true"為執行正確,"false"為執行失敗.
|
|
|
433 |
#$result["error"],錯誤訊息陣列.
|
|
|
434 |
#$result["content"],JavaScript語法.
|
|
|
435 |
#$result["function"],當前執行的函數名稱
|
|
|
436 |
#必填參數:
|
|
|
437 |
#$conf["alertSentence"],字串,爲要彈出式視窗的內容,"\\n"代表換行.
|
|
|
438 |
$conf["alertSentence"]="";
|
|
|
439 |
#可省略參數:
|
| 226 |
liveuser |
440 |
#無.
|
| 3 |
liveuser |
441 |
#參考資料:
|
|
|
442 |
#無.
|
|
|
443 |
#備註:
|
|
|
444 |
#無.
|
|
|
445 |
*/
|
|
|
446 |
public static function alertWindow(&$conf){
|
|
|
447 |
|
|
|
448 |
#初始化要回傳的內容
|
|
|
449 |
$result=array();
|
|
|
450 |
|
|
|
451 |
#當前執行的函數名稱
|
|
|
452 |
$result["function"]=__FUNCTION__;
|
|
|
453 |
|
|
|
454 |
#初始化要回傳的語法
|
|
|
455 |
$result["content"]="";
|
|
|
456 |
|
|
|
457 |
#如果 $conf 不為陣列
|
|
|
458 |
if(gettype($conf)!="array"){
|
|
|
459 |
|
|
|
460 |
#設置執行失敗
|
|
|
461 |
$result["status"]="false";
|
|
|
462 |
|
|
|
463 |
#設置執行錯誤訊息
|
|
|
464 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
465 |
|
|
|
466 |
#如果傳入的參數為 null
|
|
|
467 |
if($conf==null){
|
|
|
468 |
|
|
|
469 |
#設置執行錯誤訊息
|
|
|
470 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
471 |
|
|
|
472 |
}#if end
|
|
|
473 |
|
|
|
474 |
#回傳結果
|
|
|
475 |
return $result;
|
|
|
476 |
|
|
|
477 |
}#if end
|
|
|
478 |
|
|
|
479 |
#檢查參數
|
|
|
480 |
#函式說明:
|
|
|
481 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
482 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
483 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
484 |
#$result["function"],當前執行的函式名稱.
|
|
|
485 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
486 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
487 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
488 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
489 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
490 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
491 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
492 |
#必填參數:
|
|
|
493 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
494 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
495 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
496 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("alertSentence");
|
|
|
497 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
|
|
498 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
499 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
500 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
501 |
#可以省略的參數:
|
|
|
502 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
503 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
504 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
505 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("closeWindow");
|
|
|
506 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
507 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
508 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
509 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
|
|
|
510 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
511 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
|
|
|
512 |
#參考資料來源:
|
|
|
513 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
514 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
515 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
516 |
|
|
|
517 |
#debug
|
|
|
518 |
#var_dump($checkResult);
|
|
|
519 |
#exit;
|
|
|
520 |
|
|
|
521 |
#如果檢查失敗
|
|
|
522 |
if($checkResult["status"]=="false"){
|
|
|
523 |
|
|
|
524 |
#設置錯誤狀態
|
|
|
525 |
$result["status"]="false";
|
|
|
526 |
|
|
|
527 |
#設置錯誤提示
|
|
|
528 |
$result["error"]=$checkResult;
|
|
|
529 |
|
|
|
530 |
#回傳結果
|
|
|
531 |
return $result;
|
|
|
532 |
|
|
|
533 |
}#if end
|
|
|
534 |
|
|
|
535 |
#如果檢查不通過
|
|
|
536 |
if($checkResult["passed"]=="false"){
|
|
|
537 |
|
|
|
538 |
#設置錯誤狀態
|
|
|
539 |
$result["status"]="false";
|
|
|
540 |
|
|
|
541 |
#設置錯誤提示
|
|
|
542 |
$result["error"]=$checkResult;
|
|
|
543 |
|
|
|
544 |
#回傳結果
|
|
|
545 |
return $result;
|
|
|
546 |
|
|
|
547 |
}#if end
|
|
|
548 |
|
|
|
549 |
#如果 $conf["alertSentence"] 不存在的話"
|
|
|
550 |
if(!isset($conf["alertSentence"])){
|
|
|
551 |
|
|
|
552 |
#設置錯誤識別
|
|
|
553 |
$result["status"]="false";
|
|
|
554 |
|
|
|
555 |
#設置錯誤訊息
|
|
|
556 |
$result["error"][]="\$conf[\"alertSentence\"]參數未設定";
|
|
|
557 |
|
|
|
558 |
#回傳結果
|
|
|
559 |
return $result;
|
|
|
560 |
|
|
|
561 |
}#if end
|
|
|
562 |
|
|
|
563 |
#初始化要回傳的語法
|
|
|
564 |
$result["content"]="";
|
|
|
565 |
|
|
|
566 |
#函式說明:
|
|
|
567 |
#script 語法開始
|
|
|
568 |
#回傳結果:
|
|
|
569 |
#javaScript語法
|
|
|
570 |
#必填參數:
|
|
|
571 |
$conf["javaScript"]["start"]["include"]="false";#是否要匯入外部js庫。"true"爲要匯入;"false"爲沒有要匯入。
|
|
|
572 |
#可省略參數:
|
|
|
573 |
#$conf["jsPosition"]="";#要匯入的js檔案位置。
|
|
|
574 |
$javaScriptStart=javaScript::start($conf["javaScript"]["start"]);
|
|
|
575 |
unset($conf["javaScript"]["start"]);
|
|
|
576 |
|
|
|
577 |
#如果 js 語法開始失敗
|
|
|
578 |
if($javaScriptStart["status"]=="false"){
|
|
|
579 |
|
|
|
580 |
#設置錯誤識別
|
|
|
581 |
$result["status"]="false";
|
|
|
582 |
|
|
|
583 |
#設置錯誤訊息
|
|
|
584 |
$result["error"]=$javaScriptStart;
|
|
|
585 |
|
|
|
586 |
#回傳結果
|
|
|
587 |
return $result;
|
|
|
588 |
|
|
|
589 |
}#if end
|
|
|
590 |
|
|
|
591 |
#串接js開始的語法
|
|
|
592 |
$result["content"]=$result["content"].$javaScriptStart["content"];
|
|
|
593 |
|
|
|
594 |
#增加出現警示視窗的語法
|
|
|
595 |
$result["content"]=$result["content"]."alert('".$conf["alertSentence"]."');";
|
|
|
596 |
|
|
|
597 |
#javaScript結束
|
|
|
598 |
$result["content"]=$result["content"].javaScript::end();
|
|
|
599 |
|
|
|
600 |
#執行到這邊代表執行成功
|
|
|
601 |
|
|
|
602 |
#設置執行正常
|
|
|
603 |
$result["status"]="true";
|
|
|
604 |
|
|
|
605 |
#回傳結果
|
|
|
606 |
return $result;
|
|
|
607 |
|
|
|
608 |
}#function alertWindos end
|
|
|
609 |
|
|
|
610 |
/*
|
|
|
611 |
#函式說明:
|
|
|
612 |
#若存在sessions變數則將其內容用彈出式視窗呈現,並移除session的內容.
|
|
|
613 |
#回傳結果:
|
|
|
614 |
#$result["status"],執行正確與否,"true"為執行正確,"false"為執行失敗.
|
|
|
615 |
#$result["error"],錯誤訊息陣列.
|
|
|
616 |
#$result["content"],彈出視窗的語法.
|
|
|
617 |
#$result["function"],函式名稱.
|
|
|
618 |
#必填參數:
|
|
|
619 |
#$conf["sessionName"],字串,session變數的key名稱.
|
|
|
620 |
$conf["sessionName"]="";
|
|
|
621 |
#可省略參數:
|
|
|
622 |
#無.
|
|
|
623 |
#參考資料:
|
|
|
624 |
#無.
|
|
|
625 |
#備註:
|
|
|
626 |
#無.
|
|
|
627 |
*/
|
|
|
628 |
public static function alertWindowFromSession($conf){
|
|
|
629 |
|
|
|
630 |
#初始化要回傳的內容
|
|
|
631 |
$result=array();
|
|
|
632 |
|
|
|
633 |
#當前執行的函數名稱
|
|
|
634 |
$result["function"]=__FUNCTION__;
|
|
|
635 |
|
|
|
636 |
#初始化要回傳的語法
|
|
|
637 |
$result["content"]="";
|
|
|
638 |
|
|
|
639 |
#如果 $conf 不為陣列
|
|
|
640 |
if(gettype($conf)!="array"){
|
|
|
641 |
|
|
|
642 |
#設置執行失敗
|
|
|
643 |
$result["status"]="false";
|
|
|
644 |
|
|
|
645 |
#設置執行錯誤訊息
|
|
|
646 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
647 |
|
|
|
648 |
#如果傳入的參數為 null
|
|
|
649 |
if($conf==null){
|
|
|
650 |
|
|
|
651 |
#設置執行錯誤訊息
|
|
|
652 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
653 |
|
|
|
654 |
}#if end
|
|
|
655 |
|
|
|
656 |
#回傳結果
|
|
|
657 |
return $result;
|
|
|
658 |
|
|
|
659 |
}#if end
|
|
|
660 |
|
|
|
661 |
#檢查參數
|
|
|
662 |
#函式說明:
|
|
|
663 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
664 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
665 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
666 |
#$result["function"],當前執行的函式名稱.
|
|
|
667 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
668 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
669 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
670 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
671 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
672 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
673 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
674 |
#必填參數:
|
|
|
675 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
676 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
677 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
678 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("sessionName");
|
|
|
679 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
|
|
680 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
681 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
682 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
683 |
#可以省略的參數:
|
|
|
684 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
685 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
686 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
687 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("closeWindow");
|
|
|
688 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
689 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
690 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
691 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
|
|
|
692 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
693 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
|
|
|
694 |
#參考資料來源:
|
|
|
695 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
696 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
697 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
698 |
|
|
|
699 |
#debug
|
|
|
700 |
#var_dump($checkResult);
|
|
|
701 |
#exit;
|
|
|
702 |
|
|
|
703 |
#如果檢查失敗
|
|
|
704 |
if($checkResult["status"]=="false"){
|
|
|
705 |
|
|
|
706 |
#設置錯誤狀態
|
|
|
707 |
$result["status"]="false";
|
|
|
708 |
|
|
|
709 |
#設置錯誤提示
|
|
|
710 |
$result["error"]=$checkResult;
|
|
|
711 |
|
|
|
712 |
#回傳結果
|
|
|
713 |
return $result;
|
|
|
714 |
|
|
|
715 |
}#if end
|
|
|
716 |
|
|
|
717 |
#如果檢查不通過
|
|
|
718 |
if($checkResult["passed"]=="false"){
|
|
|
719 |
|
|
|
720 |
#設置錯誤狀態
|
|
|
721 |
$result["status"]="false";
|
|
|
722 |
|
|
|
723 |
#設置錯誤提示
|
|
|
724 |
$result["error"]=$checkResult;
|
|
|
725 |
|
|
|
726 |
#回傳結果
|
|
|
727 |
return $result;
|
|
|
728 |
|
|
|
729 |
}#if end
|
|
|
730 |
|
|
|
731 |
#函式說明:
|
|
|
732 |
#取得session變數裡面的數值,然後卸除該session變數
|
|
|
733 |
#回傳結果:
|
|
|
734 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表有誤.
|
|
|
735 |
#$result["error"],錯誤訊息
|
|
|
736 |
#$result["warning"],警告訊息
|
|
|
737 |
#$result["founded"],是否找到session變數,"true"代表找到,"false"代表沒找到.
|
|
|
738 |
#$result["content"],取得的變數內容
|
|
|
739 |
#必填參數:
|
|
|
740 |
$conf["session"]["getSessionValue"]["sessionVarName"]=$conf["sessionName"];#要取得內容的session變數
|
|
|
741 |
#可省略參數:
|
|
|
742 |
$conf["session"]["getSessionValue"]["unsetSessionVar"]="true";#"true"代表要卸除session變數
|
|
|
743 |
#參考資料:
|
|
|
744 |
#http://stackoverflow.com/questions/8971261/php-5-4-call-time-pass-by-reference-easy-fix-available
|
|
|
745 |
#可變變數->http://emn178.pixnet.net/blog/post/80119035-php%E6%95%99%E5%AD%B8---%E8%AE%8A%E6%95%B8%28variables%29
|
|
|
746 |
#卸除參考的原始變數->http://stackoverflow.com/questions/6654538/php-function-to-unset-variables-passed-by-reference
|
|
|
747 |
$getSessionValue=session::getSessionValue($conf["session"]["getSessionValue"]);
|
|
|
748 |
unset($conf["session"]["getSessionValue"]);
|
|
|
749 |
|
|
|
750 |
#如果 $getSessionValue["status"] 等於 "false"
|
|
|
751 |
if($getSessionValue["status"]=="false"){
|
|
|
752 |
|
|
|
753 |
#設置錯誤識別
|
|
|
754 |
$result["status"]="false";
|
|
|
755 |
|
|
|
756 |
#設置錯誤訊息
|
|
|
757 |
$result["error"]=$getSessionValue;
|
|
|
758 |
|
|
|
759 |
#回傳結果
|
|
|
760 |
return $result;
|
|
|
761 |
|
|
|
762 |
}#if end
|
|
|
763 |
|
|
|
764 |
#如果找不到session變數
|
|
|
765 |
if($getSessionValue["founded"]=="false"){
|
|
|
766 |
|
|
|
767 |
#設置語法為空
|
|
|
768 |
$result["content"]="";
|
|
|
769 |
|
|
|
770 |
#設置警告訊息
|
|
|
771 |
$result["warning"][]="名為「".$conf["sessionName"]."」的session變數不存在";
|
|
|
772 |
|
|
|
773 |
#設置執行正常
|
|
|
774 |
$result["status"]="true";
|
|
|
775 |
|
|
|
776 |
#回傳結果
|
|
|
777 |
return $result;
|
|
|
778 |
|
|
|
779 |
}#if end
|
|
|
780 |
|
|
|
781 |
#取得session變數的內容
|
|
|
782 |
$msg=$getSessionValue["content"];
|
|
|
783 |
|
|
|
784 |
#函式說明:
|
|
|
785 |
#彈出視窗
|
|
|
786 |
#回傳結果:
|
|
|
787 |
#$result["status"],執行正確與否,"true"為執行正確,"false"為執行失敗.
|
|
|
788 |
#$result["error"],錯誤訊息陣列.
|
|
|
789 |
#$result["content"],avaScript語法.
|
|
|
790 |
#必填的參數
|
|
|
791 |
$conf["javaScript"]["alertWindow"]["alertSentence"]=$msg;#爲要彈出式視窗的內容。
|
|
|
792 |
$js=javaScript::alertWindow($conf["javaScript"]["alertWindow"]);
|
|
|
793 |
unset($conf["javaScript"]["alertWindow"]);
|
|
|
794 |
|
|
|
795 |
#如果 $js["status"] 等於 "false"
|
|
|
796 |
if($js["status"]=="false"){
|
|
|
797 |
|
|
|
798 |
#設置錯誤識別
|
|
|
799 |
$result["status"]="false";
|
|
|
800 |
|
|
|
801 |
#設置錯誤訊息
|
|
|
802 |
$result["error"]=$js;
|
|
|
803 |
|
|
|
804 |
#回傳結果
|
|
|
805 |
return $result;
|
|
|
806 |
|
|
|
807 |
}#if end
|
|
|
808 |
|
|
|
809 |
#取得彈出視窗的語法
|
|
|
810 |
$result["content"]=$js["content"];
|
|
|
811 |
|
|
|
812 |
#設置錯誤識別
|
|
|
813 |
$result["status"]="true";
|
|
|
814 |
|
|
|
815 |
#回傳結果
|
|
|
816 |
return $result;
|
|
|
817 |
|
|
|
818 |
}#function alertWindowFromSession end
|
|
|
819 |
|
|
|
820 |
/*
|
|
|
821 |
#函式說明:
|
|
|
822 |
#根據sesssion變數的內容來彈出視窗來進行提示
|
|
|
823 |
#回傳內容:
|
|
|
824 |
#$result["status"],執行是否正常,"true"代表執行正常,"false"代表執行失敗.
|
|
|
825 |
#$result["error"],錯誤訊息陣列.
|
|
|
826 |
#$result["content"],javaScript語法,當session變數無法取得時,將會回傳"".
|
|
|
827 |
#$result["function"],當前執行的函數名稱
|
|
|
828 |
#必填參數:
|
|
|
829 |
$conf["sessionName"]="";#要取得的session變數名稱.
|
|
|
830 |
#可省略參數:
|
|
|
831 |
#$conf["altMethod"]="true";#爲當彈出式視窗無法使用時,可以改用的臨時處理辦法。若爲"true",則代表要採用臨時的應變措施,預設為"false".
|
|
|
832 |
#參考資料:
|
|
|
833 |
#無.
|
|
|
834 |
#備註:
|
|
|
835 |
#功能需要確認
|
|
|
836 |
*/
|
|
|
837 |
public static function alertSessionVarWindows(&$conf){
|
|
|
838 |
|
|
|
839 |
#初始化要回傳的內容
|
|
|
840 |
$result=array();
|
|
|
841 |
|
|
|
842 |
#當前執行的函數名稱
|
|
|
843 |
$result["function"]=__FUNCTION__;
|
|
|
844 |
|
|
|
845 |
#初始化要回傳的語法
|
|
|
846 |
$result["content"]="";
|
|
|
847 |
|
|
|
848 |
#如果 $conf 不為陣列
|
|
|
849 |
if(gettype($conf)!="array"){
|
|
|
850 |
|
|
|
851 |
#設置執行失敗
|
|
|
852 |
$result["status"]="false";
|
|
|
853 |
|
|
|
854 |
#設置執行錯誤訊息
|
|
|
855 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
856 |
|
|
|
857 |
#如果傳入的參數為 null
|
|
|
858 |
if($conf==null){
|
|
|
859 |
|
|
|
860 |
#設置執行錯誤訊息
|
|
|
861 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
862 |
|
|
|
863 |
}#if end
|
|
|
864 |
|
|
|
865 |
#回傳結果
|
|
|
866 |
return $result;
|
|
|
867 |
|
|
|
868 |
}#if end
|
|
|
869 |
|
|
|
870 |
#檢查參數
|
|
|
871 |
#函式說明:
|
|
|
872 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
873 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
874 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
875 |
#$result["function"],當前執行的函式名稱.
|
|
|
876 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
877 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
878 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
879 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
880 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
881 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
882 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
883 |
#必填參數:
|
|
|
884 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
885 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
886 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
887 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("sessionName");
|
|
|
888 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
|
|
889 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
890 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
891 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
892 |
#可以省略的參數:
|
|
|
893 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
894 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
895 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
896 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("altMethod");
|
|
|
897 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
898 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
899 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
900 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
|
|
|
901 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
902 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
|
|
|
903 |
#參考資料來源:
|
|
|
904 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
905 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
906 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
907 |
|
|
|
908 |
#如果檢查失敗
|
|
|
909 |
if($checkResult["status"]=="false"){
|
|
|
910 |
|
|
|
911 |
#設置錯誤狀態
|
|
|
912 |
$result["status"]="false";
|
|
|
913 |
|
|
|
914 |
#設置錯誤提示
|
|
|
915 |
$result["error"]=$checkResult;
|
|
|
916 |
|
|
|
917 |
#回傳結果
|
|
|
918 |
return $result;
|
|
|
919 |
|
|
|
920 |
}#if end
|
|
|
921 |
|
|
|
922 |
#如果檢查不通過
|
|
|
923 |
if($checkResult["passed"]=="false"){
|
|
|
924 |
|
|
|
925 |
#設置錯誤狀態
|
|
|
926 |
$result["status"]="false";
|
|
|
927 |
|
|
|
928 |
#設置錯誤提示
|
|
|
929 |
$result["error"]=$checkResult;
|
|
|
930 |
|
|
|
931 |
#回傳結果
|
|
|
932 |
return $result;
|
|
|
933 |
|
|
|
934 |
}#if end
|
|
|
935 |
|
|
|
936 |
#函式說明:
|
|
|
937 |
#取得session變數裡面的數值,然後卸除該session變數
|
|
|
938 |
#回傳結果:
|
|
|
939 |
#$result,取得的變數內容
|
|
|
940 |
#必填參數:
|
|
|
941 |
$conf["session"]["getSessionValue"]["sessionVarName"]=$conf["sessionName"];#要取得內容的session變數
|
|
|
942 |
#可省略參數:
|
|
|
943 |
$conf["session"]["getSessionValue"]["unsetSessionVar"]="true";#"true"代表要卸除session變數
|
|
|
944 |
#參考資料:
|
|
|
945 |
#http://stackoverflow.com/questions/8971261/php-5-4-call-time-pass-by-reference-easy-fix-available
|
|
|
946 |
#可變變數->http://emn178.pixnet.net/blog/post/80119035-php%E6%95%99%E5%AD%B8---%E8%AE%8A%E6%95%B8%28variables%29
|
|
|
947 |
#卸除參考的原始變數->http://stackoverflow.com/questions/6654538/php-function-to-unset-variables-passed-by-reference
|
|
|
948 |
$assignSessionValueToVar=session::getSessionValue($conf["session"]["getSessionValue"]);
|
|
|
949 |
unset($conf["session"]["getSessionValue"]);
|
|
|
950 |
|
|
|
951 |
#如果 $assignSessionValueToVar["status"] 等於 "false"
|
|
|
952 |
if($assignSessionValueToVar["status"]=="false"){
|
|
|
953 |
|
|
|
954 |
#設置執行錯誤識別
|
|
|
955 |
$result["status"]="false";
|
|
|
956 |
|
|
|
957 |
#設置錯誤訊息
|
|
|
958 |
$result["error"]=$assignSessionValueToVar;
|
|
|
959 |
|
|
|
960 |
#回傳結果
|
|
|
961 |
return $result;
|
|
|
962 |
|
|
|
963 |
}#if end
|
|
|
964 |
|
|
|
965 |
#如果 $assignSessionValueToVar["founded"] 等於 "false"
|
|
|
966 |
if($assignSessionValueToVar["founded"]=="false"){
|
|
|
967 |
|
|
|
968 |
#設置語法內容
|
|
|
969 |
$result["content"]="";
|
|
|
970 |
|
|
|
971 |
#執行到這邊代表執行成功,設置執行成功識別
|
|
|
972 |
$result["status"]="true";
|
|
|
973 |
|
|
|
974 |
#回傳結果
|
|
|
975 |
return $result;
|
|
|
976 |
|
|
|
977 |
}#if end
|
|
|
978 |
|
|
|
979 |
#若 $conf["altMethod"] 爲 "true"
|
|
|
980 |
if($conf["altMethod"]=="true"){
|
|
|
981 |
|
|
|
982 |
#用應變措施來印出提示文字。
|
|
|
983 |
$result["content"]="<center><p><font color=red><strong><b>".$assignSessionValueToVar["content"]."</strong></b></font><p></center>";
|
|
|
984 |
|
|
|
985 |
#設置執行成功
|
|
|
986 |
$result["status"]="true";
|
|
|
987 |
|
|
|
988 |
#回傳結果
|
|
|
989 |
return $result;
|
|
|
990 |
|
|
|
991 |
}#if end
|
|
|
992 |
|
|
|
993 |
#函式說明:
|
|
|
994 |
#彈出視窗
|
|
|
995 |
#回傳結果:
|
|
|
996 |
#$result["status"],執行正確與否,"true"為執行正確,"false"為執行失敗.
|
|
|
997 |
#$result["error"],錯誤訊息陣列.
|
|
|
998 |
#$result["content"],avaScript語法.
|
|
|
999 |
#必填的參數
|
|
|
1000 |
$conf["javaScript"]["alertWindow"]["alertSentence"]=$assignSessionValueToVar["content"];#爲要彈出式視窗的內容。
|
|
|
1001 |
$javaScript["alertWindow"]=javaScript::alertWindow($conf["javaScript"]["alertWindow"]);
|
|
|
1002 |
unset($conf["javaScript"]["alertWindow"]);
|
|
|
1003 |
|
|
|
1004 |
#如果 $javaScript["alertWindow"]["status"] 等於 "false"
|
|
|
1005 |
if($javaScript["alertWindow"]["status"]=="false"){
|
|
|
1006 |
|
|
|
1007 |
#設置執行錯誤識別
|
|
|
1008 |
$result["status"]="false";
|
|
|
1009 |
|
|
|
1010 |
#設置錯誤訊息
|
|
|
1011 |
$result["error"]=$javaScript["alertWindow"];
|
|
|
1012 |
|
|
|
1013 |
#回傳結果
|
|
|
1014 |
return $result;
|
|
|
1015 |
|
|
|
1016 |
}#if end
|
|
|
1017 |
|
|
|
1018 |
#設置語法內容
|
|
|
1019 |
$result["content"]=$javaScript["alertWindow"]["content"];
|
|
|
1020 |
|
|
|
1021 |
#執行到這邊代表執行成功,設置執行成功識別
|
|
|
1022 |
$result["status"]="true";
|
|
|
1023 |
|
|
|
1024 |
#回傳結果
|
|
|
1025 |
return $result;
|
|
|
1026 |
|
|
|
1027 |
}#alertSessionVarWindows end
|
|
|
1028 |
|
|
|
1029 |
/*
|
|
|
1030 |
#函式說明:
|
|
|
1031 |
#改變背景顏色
|
|
|
1032 |
#回傳結果:
|
|
|
1033 |
#$result["status"],執行正確與否,"true"為執行正確,"false"為執行失敗.
|
|
|
1034 |
#$result["error"],錯誤訊息陣列.
|
|
|
1035 |
#$result["content"],彈出視窗的語法.
|
|
|
1036 |
#$result["function"],函式名稱.
|
|
|
1037 |
#必填參數:
|
|
|
1038 |
#$conf["color"],字串,爲要改變成什麼顏色,ex 'pink' 'blue' 'green' 'white' 'black' 'red' 'orange'
|
|
|
1039 |
$conf["color"]="";
|
|
|
1040 |
#可省略參數:
|
|
|
1041 |
#無.
|
|
|
1042 |
#參考資料:
|
|
|
1043 |
#無.
|
|
|
1044 |
#備註:
|
|
|
1045 |
#無.
|
|
|
1046 |
*/
|
|
|
1047 |
public static function changeBackgroundColor($conf){
|
|
|
1048 |
|
|
|
1049 |
#初始化要回傳的內容
|
|
|
1050 |
$result=array();
|
|
|
1051 |
|
|
|
1052 |
#當前執行的函數名稱
|
|
|
1053 |
$result["function"]=__FUNCTION__;
|
|
|
1054 |
|
|
|
1055 |
#初始化要回傳的語法
|
|
|
1056 |
$result["content"]="";
|
|
|
1057 |
|
|
|
1058 |
#如果 $conf 不為陣列
|
|
|
1059 |
if(gettype($conf)!="array"){
|
|
|
1060 |
|
|
|
1061 |
#設置執行失敗
|
|
|
1062 |
$result["status"]="false";
|
|
|
1063 |
|
|
|
1064 |
#設置執行錯誤訊息
|
|
|
1065 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1066 |
|
|
|
1067 |
#如果傳入的參數為 null
|
|
|
1068 |
if($conf==null){
|
|
|
1069 |
|
|
|
1070 |
#設置執行錯誤訊息
|
|
|
1071 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
1072 |
|
|
|
1073 |
}#if end
|
|
|
1074 |
|
|
|
1075 |
#回傳結果
|
|
|
1076 |
return $result;
|
|
|
1077 |
|
|
|
1078 |
}#if end
|
|
|
1079 |
|
|
|
1080 |
#檢查參數
|
|
|
1081 |
#函式說明:
|
|
|
1082 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1083 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1084 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1085 |
#$result["function"],當前執行的函式名稱.
|
|
|
1086 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1087 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1088 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1089 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1090 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1091 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1092 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1093 |
#必填參數:
|
|
|
1094 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1095 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1096 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1097 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("color");
|
|
|
1098 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
|
|
1099 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
1100 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1101 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1102 |
#可以省略的參數:
|
|
|
1103 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
1104 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
1105 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1106 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("closeWindow");
|
|
|
1107 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
1108 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
1109 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1110 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
|
|
|
1111 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1112 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
|
|
|
1113 |
#參考資料來源:
|
|
|
1114 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1115 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1116 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
1117 |
|
|
|
1118 |
#如果檢查失敗
|
|
|
1119 |
if($checkResult["status"]=="false"){
|
|
|
1120 |
|
|
|
1121 |
#設置錯誤狀態
|
|
|
1122 |
$result["status"]="false";
|
|
|
1123 |
|
|
|
1124 |
#設置錯誤提示
|
|
|
1125 |
$result["error"]=$checkResult;
|
|
|
1126 |
|
|
|
1127 |
#回傳結果
|
|
|
1128 |
return $result;
|
|
|
1129 |
|
|
|
1130 |
}#if end
|
|
|
1131 |
|
|
|
1132 |
#如果檢查不通過
|
|
|
1133 |
if($checkResult["passed"]=="false"){
|
|
|
1134 |
|
|
|
1135 |
#設置錯誤狀態
|
|
|
1136 |
$result["status"]="false";
|
|
|
1137 |
|
|
|
1138 |
#設置錯誤提示
|
|
|
1139 |
$result["error"]=$checkResult;
|
|
|
1140 |
|
|
|
1141 |
#回傳結果
|
|
|
1142 |
return $result;
|
|
|
1143 |
|
|
|
1144 |
}#if end
|
|
|
1145 |
|
|
|
1146 |
#設定背景顏色
|
|
|
1147 |
$script="document.bgColor='".$conf["color"]."'";
|
|
|
1148 |
|
|
|
1149 |
#函式說明:
|
|
|
1150 |
#將要執行的script語法透過該函式執行(會在程式外層用<script></script>包起來).
|
|
|
1151 |
#回傳結果:
|
|
|
1152 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
1153 |
#$result["error"],錯誤訊息陣列
|
|
|
1154 |
#$result["function"],當前執行的函數名稱
|
|
|
1155 |
#$result["content"],要執行的javaScript語法
|
|
|
1156 |
#必填參數:
|
|
|
1157 |
#$conf["script"],字串,要執行的javaScript語法.
|
|
|
1158 |
$conf["javaScript::toScript"]["script"]=$script;
|
|
|
1159 |
#可省略參數:
|
|
|
1160 |
#$conf["onReady"],字串,是否要在網頁載入完再執行,"false"為不等載入完就先執行,預設為"true"要等載入完再執行.
|
|
|
1161 |
#$conf["onReady"]="true";
|
|
|
1162 |
#$conf["jsFunciton"],字串陣列,為要放入<script>標籤的js函數.
|
|
|
1163 |
#$conf["jsFunciton"]=array();
|
|
|
1164 |
#參考資料:
|
|
|
1165 |
#http://stackoverflow.com/questions/9899372/pure-javascript-equivalent-to-jquerys-ready-how-to-call-a-function-when-the
|
|
|
1166 |
$toScript=javaScript::toScript($conf["javaScript::toScript"]);
|
|
|
1167 |
unset($conf["javaScript::toScript"]);
|
|
|
1168 |
|
|
|
1169 |
#如果建立script語法失敗
|
|
|
1170 |
if($toScript["status"]==="false"){
|
|
|
1171 |
|
|
|
1172 |
#設置錯誤狀態
|
|
|
1173 |
$result["status"]="false";
|
|
|
1174 |
|
|
|
1175 |
#設置錯誤提示
|
|
|
1176 |
$result["error"]=$toScript;
|
|
|
1177 |
|
|
|
1178 |
#回傳結果
|
|
|
1179 |
return $result;
|
|
|
1180 |
|
|
|
1181 |
}#if end
|
|
|
1182 |
|
|
|
1183 |
#取得js語法
|
|
|
1184 |
$result["content"]=$toScript["content"];
|
|
|
1185 |
|
|
|
1186 |
#設置執行成功識別
|
|
|
1187 |
$result["status"]="true";
|
|
|
1188 |
|
|
|
1189 |
#回傳結果
|
|
|
1190 |
return $result;
|
|
|
1191 |
|
|
|
1192 |
}#function changeBackgroundColor end
|
|
|
1193 |
|
|
|
1194 |
/*
|
|
|
1195 |
#函式說明:
|
|
|
1196 |
#建立透過javaScript傳送post數值到特定頁面,並且取得頁面的回應,將之結果放置在特定的區塊裏面的js函式.
|
|
|
1197 |
#回傳結果:
|
|
|
1198 |
#$result["status"],執行正確與否,"true"代表執行正確,"false"代表執行失敗.
|
|
|
1199 |
#$result["error"],錯誤訊息陣列.
|
|
|
1200 |
#$result["content"],JavaScript的語法
|
|
|
1201 |
#$result["function"],當前執行的函數名稱
|
|
|
1202 |
#必填參數:
|
|
|
1203 |
#$conf["receivePage"],字串,要接收數值的頁面.
|
|
|
1204 |
$conf["receivePage"]="";
|
|
|
1205 |
#$conf["jsFunctionName"],字串,ajax裏面的js涵式名稱.
|
|
|
1206 |
$conf["jsFunctionName"]="";
|
|
|
1207 |
#可省略參數:
|
|
|
1208 |
#$conf["scriptTag"],是否要用<script></script>包住,預設為"false",不包住;"true"為包住.
|
|
|
1209 |
#$conf["scriptTag"]="false";
|
|
|
1210 |
#$conf["varNameArray"],字串陣列,要傳送的數值名稱,預設為array("is_ajax").
|
|
|
1211 |
#$conf["varNameArray"]=array("is_ajax");
|
|
|
1212 |
#$conf["varValueArray"],陣列,要傳送的數值內容,預設為array("true");
|
|
|
1213 |
#$conf["varValueArray"]=array("true");
|
|
|
1214 |
#$conf["jsVarNameArray"],字串陣列,要傳送的js數值名稱.
|
|
|
1215 |
$conf["jsVarNameArray"]=array("");
|
|
|
1216 |
#$conf["jsVarValueArray"],陣列,要傳送的js數值內容.
|
|
|
1217 |
$conf["jsVarValueArray"]=array("");
|
|
|
1218 |
#$conf["responsePalaceId"],字串,回傳的內容要呈現於哪個<span id = ? ></span>、<div id= ? ></div>區塊之間。
|
|
|
1219 |
#$conf["responsePalaceId"]="";
|
|
|
1220 |
#$conf["condition"],字串,立即執行ajax的條件.
|
|
|
1221 |
#$conf["condition"]="";
|
|
|
1222 |
#$conf["conditionComment"],字串,立即執行ajax的條件註解,預設為$conf["condition"].
|
|
|
1223 |
#$conf["conditionComment"]="";
|
|
|
1224 |
#$conf["sendNow"],字串,是否要在document.ready後馬上執行ajax,預設為"false",代表不要,"true"代表要.
|
|
|
1225 |
#$conf["sendNow"]="false";
|
|
|
1226 |
#$conf["redir_url"],字串,是否要在要求成功後進行轉址的動作,轉址到$conf["redir_url"],若存在$conf["successAction"],則以$conf["successAction"]為主.
|
|
|
1227 |
#$conf["redir_url"]="";
|
|
|
1228 |
#$conf["successAction"],字串,ajax要求成功後做的事情.
|
|
|
1229 |
#$conf["successAction"]="";
|
|
|
1230 |
#參考資料:
|
|
|
1231 |
#http://www.w3school.com.cn/php/php_ajax_suggest.asp
|
|
|
1232 |
#建議允許不傳送任何get參數.
|
|
|
1233 |
#備註:
|
|
|
1234 |
#無.
|
|
|
1235 |
*/
|
|
|
1236 |
public static function ajaxSendPostValue($conf){
|
|
|
1237 |
|
|
|
1238 |
#初始化要回傳的內容
|
|
|
1239 |
$result=array();
|
|
|
1240 |
|
|
|
1241 |
#當前執行的函數名稱
|
|
|
1242 |
$result["function"]=__FUNCTION__;
|
|
|
1243 |
|
|
|
1244 |
#初始化要回傳的語法
|
|
|
1245 |
$result["content"]="";
|
|
|
1246 |
|
|
|
1247 |
#如果 $conf 不為陣列
|
|
|
1248 |
if(gettype($conf)!="array"){
|
|
|
1249 |
|
|
|
1250 |
#設置執行失敗
|
|
|
1251 |
$result["status"]="false";
|
|
|
1252 |
|
|
|
1253 |
#設置執行錯誤訊息
|
|
|
1254 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1255 |
|
|
|
1256 |
#如果傳入的參數為 null
|
|
|
1257 |
if($conf==null){
|
|
|
1258 |
|
|
|
1259 |
#設置執行錯誤訊息
|
|
|
1260 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
1261 |
|
|
|
1262 |
}#if end
|
|
|
1263 |
|
|
|
1264 |
#回傳結果
|
|
|
1265 |
return $result;
|
|
|
1266 |
|
|
|
1267 |
}#if end
|
|
|
1268 |
|
|
|
1269 |
#檢查參數
|
|
|
1270 |
#函式說明:
|
|
|
1271 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1272 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1273 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1274 |
#$result["function"],當前執行的函式名稱.
|
|
|
1275 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1276 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1277 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1278 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1279 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1280 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1281 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1282 |
#必填參數:
|
|
|
1283 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1284 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1285 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1286 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("receivePage","jsFunctionName");
|
|
|
1287 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
|
|
1288 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
1289 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1290 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1291 |
#可以省略的參數:
|
|
|
1292 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
1293 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
1294 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1295 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("scriptTag","responsePalaceId","sendNow","varNameArray","varValueArray","jsVarNameArray","jsVarValueArray","redir_url","successAction","condition","conditionComment");
|
|
|
1296 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
1297 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","array","array","array","array","string","string","string","string");
|
|
|
1298 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1299 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false",null,"false",array("is_ajax"),array("true"),null,null,null,null,null,null);
|
|
|
1300 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1301 |
$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("varValueArray","jsFunctionName");
|
|
|
1302 |
$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("jsVarNameArray","jsVarValueArray");
|
|
|
1303 |
#參考資料來源:
|
|
|
1304 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1305 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1306 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
1307 |
|
|
|
1308 |
#如果檢查失敗
|
|
|
1309 |
if($checkResult["status"]=="false"){
|
|
|
1310 |
|
|
|
1311 |
#設置錯誤狀態
|
|
|
1312 |
$result["status"]="false";
|
|
|
1313 |
|
|
|
1314 |
#設置錯誤提示
|
|
|
1315 |
$result["error"]=$checkResult;
|
|
|
1316 |
|
|
|
1317 |
#回傳結果
|
|
|
1318 |
return $result;
|
|
|
1319 |
|
|
|
1320 |
}#if end
|
|
|
1321 |
|
|
|
1322 |
#如果檢查不通過
|
|
|
1323 |
if($checkResult["passed"]=="false"){
|
|
|
1324 |
|
|
|
1325 |
#設置錯誤狀態
|
|
|
1326 |
$result["status"]="false";
|
|
|
1327 |
|
|
|
1328 |
#設置錯誤提示
|
|
|
1329 |
$result["error"]=$checkResult;
|
|
|
1330 |
|
|
|
1331 |
#回傳結果
|
|
|
1332 |
return $result;
|
|
|
1333 |
|
|
|
1334 |
}#if end
|
|
|
1335 |
|
|
|
1336 |
#初始化儲存要傳送的post變數
|
|
|
1337 |
$sendStr=array();
|
|
|
1338 |
|
|
|
1339 |
#有幾個 $conf["varNameArray"] 就執行幾次
|
|
|
1340 |
for($i=0;$i<count($conf["varNameArray"]);$i++){
|
|
|
1341 |
|
|
|
1342 |
#設置post變數
|
|
|
1343 |
$sendStr[$conf["varNameArray"][$i]]=$conf["varValueArray"][$i];
|
|
|
1344 |
|
|
|
1345 |
}#for end
|
|
|
1346 |
|
|
|
1347 |
#轉成 url encode 格式
|
|
|
1348 |
$sendStr=http_build_query($sendStr);
|
|
|
1349 |
|
|
|
1350 |
#如果存在 $conf["jsVarNameArray"]
|
|
|
1351 |
if(isset($conf["jsVarNameArray"])){
|
|
|
1352 |
|
|
|
1353 |
#針對每個js變數
|
|
|
1354 |
for($i=0;$i<count($conf["jsVarNameArray"]);$i++){
|
|
|
1355 |
|
|
|
1356 |
#串接js變數
|
|
|
1357 |
$sendStr=$sendStr."'+'&".$conf["jsVarNameArray"][$i]."='+".$conf["jsVarValueArray"][$i];
|
|
|
1358 |
|
|
|
1359 |
#如果是最後一筆
|
|
|
1360 |
if($i===(count($conf["jsVarNameArray"])-1)){
|
|
|
1361 |
|
|
|
1362 |
#補上 "+'"
|
|
|
1363 |
$sendStr=$sendStr."+'";
|
|
|
1364 |
|
|
|
1365 |
}#if end
|
|
|
1366 |
|
|
|
1367 |
}#foreach end
|
|
|
1368 |
|
|
|
1369 |
}#if end
|
|
|
1370 |
|
|
|
1371 |
#初始化馬上執行ajax的js語法
|
|
|
1372 |
$sendNow="";
|
|
|
1373 |
|
|
|
1374 |
#如果 $conf["sendNow"] 為 "true"...
|
|
|
1375 |
if($conf["sendNow"]==="true"){
|
|
|
1376 |
|
|
|
1377 |
#設置馬上執行ajax
|
|
|
1378 |
$sendNow=$conf["jsFunctionName"]."();";
|
|
|
1379 |
|
|
|
1380 |
}#if end
|
|
|
1381 |
|
|
|
1382 |
#設置不對回應做處理
|
|
|
1383 |
$actionWhenGotResponse="";
|
|
|
1384 |
|
|
|
1385 |
#如果有設置 $conf["responsePalaceId"]
|
|
|
1386 |
if(isset($conf["responsePalaceId"])){
|
|
|
1387 |
|
|
|
1388 |
#設置收到ajax的回應後要把內容吐到特定id的標籤裡面
|
|
|
1389 |
$actionWhenGotResponse="document.getElementById('".$conf["responsePalaceId"]."').innerHTML=xmlhttp.responseText;";
|
|
|
1390 |
|
|
|
1391 |
}#if end
|
|
|
1392 |
|
|
|
1393 |
#如果有設置 $conf["redir_url"]
|
|
|
1394 |
if(isset($conf["redir_url"])){
|
|
|
1395 |
|
|
|
1396 |
#設置要轉址
|
|
|
1397 |
$actionWhenGotResponse="window.location.href='".$conf["redir_url"]."'";
|
|
|
1398 |
|
|
|
1399 |
}#if end
|
|
|
1400 |
|
|
|
1401 |
#如果有設置 $conf["successAction"]
|
|
|
1402 |
if(isset($conf["successAction"])){
|
|
|
1403 |
|
|
|
1404 |
#設置ajax成功要做的事情
|
|
|
1405 |
$actionWhenGotResponse=$conf["successAction"];
|
|
|
1406 |
|
|
|
1407 |
}#if end
|
|
|
1408 |
|
|
|
1409 |
//js函數的開頭
|
|
|
1410 |
$scriptHead=
|
|
|
1411 |
"
|
|
|
1412 |
//傳送post變數到指定頁面。
|
|
|
1413 |
function ".$conf["jsFunctionName"]."(){
|
|
|
1414 |
";
|
|
|
1415 |
|
|
|
1416 |
//js函數的結尾
|
|
|
1417 |
$scriptTail=
|
|
|
1418 |
"
|
|
|
1419 |
}//js function end
|
|
|
1420 |
";
|
|
|
1421 |
|
|
|
1422 |
#建立 XMLDoc,傳值
|
|
|
1423 |
$script=
|
|
|
1424 |
"
|
|
|
1425 |
//建立 XMLDoc
|
|
|
1426 |
if(window.XMLHttpRequest){
|
|
|
1427 |
|
|
|
1428 |
// code for IE7+, Firefox, Chrome, Opera, Safari
|
|
|
1429 |
xmlhttp=new XMLHttpRequest();
|
|
|
1430 |
|
|
|
1431 |
}//if end
|
|
|
1432 |
|
|
|
1433 |
else{
|
|
|
1434 |
|
|
|
1435 |
// code for IE6, IE5
|
|
|
1436 |
xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
|
|
|
1437 |
|
|
|
1438 |
}//else end
|
|
|
1439 |
|
|
|
1440 |
//如果服務端有回傳完稱的狀態
|
|
|
1441 |
xmlhttp.onreadystatechange=function(){
|
|
|
1442 |
|
|
|
1443 |
//如果狀態為4且response code為200
|
|
|
1444 |
if(xmlhttp.readyState==4 && xmlhttp.status==200){
|
|
|
1445 |
|
|
|
1446 |
//將回應進行處理
|
|
|
1447 |
".$actionWhenGotResponse."
|
|
|
1448 |
|
|
|
1449 |
}//if end
|
|
|
1450 |
|
|
|
1451 |
}//function end
|
|
|
1452 |
|
|
|
1453 |
//設定要求的屬性、目的、是否不要同步
|
|
|
1454 |
xmlhttp.open('POST','".$conf["receivePage"]."',true);
|
|
|
1455 |
|
|
|
1456 |
//設定 header
|
|
|
1457 |
xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
|
|
|
1458 |
|
|
|
1459 |
//設定 要求為ajax 的 header
|
|
|
1460 |
xmlhttp.setRequestHeader('X-Requested-With','XMLHttpRequest');
|
|
|
1461 |
|
|
|
1462 |
//要傳送的數值名稱與數值內容,ex:num1=100&num2=50
|
|
|
1463 |
xmlhttp.send('".$sendStr."');
|
|
|
1464 |
";
|
|
|
1465 |
|
|
|
1466 |
#如果有執行的條件
|
|
|
1467 |
if(isset($conf["condition"])){
|
|
|
1468 |
|
|
|
1469 |
#函式說明:
|
|
|
1470 |
#javascript的if...esle if...判斷式.
|
|
|
1471 |
#回傳結果:
|
|
|
1472 |
#$result["status"],執行正確與否,"true"代表執行正確,"false"代表執行失敗.
|
|
|
1473 |
#$result["error"],錯誤訊息陣列.
|
|
|
1474 |
#$result["content"],JavaScript的語法
|
|
|
1475 |
#$result["function"],當前執行的函數名稱
|
|
|
1476 |
#必填參數:
|
|
|
1477 |
#無:
|
|
|
1478 |
#可省略參數:
|
|
|
1479 |
#$conf["scriptTag"],是否要用<script></script>包住,預設為"false",不包住;"true"為包住.
|
|
|
1480 |
#$conf["scriptTag"]="false";
|
|
|
1481 |
#$conf["condition"],陣列,每個判斷式的條件,若有多個則會依序判斷下去.
|
|
|
1482 |
$conf["javascript::jsIf"]["condition"]=array($conf["condition"]);
|
|
|
1483 |
|
|
|
1484 |
#如果有設定條件註解
|
|
|
1485 |
if(isset($conf["conditionComment"])){
|
|
|
1486 |
|
|
|
1487 |
#$conf["conditionComment"],陣列,每個判斷式的註解,預設為$conf["condition"].
|
|
|
1488 |
$conf["javascript::jsIf"]["conditionComment"]=array($conf["conditionComment"]);
|
|
|
1489 |
|
|
|
1490 |
}#if end
|
|
|
1491 |
|
|
|
1492 |
#$conf["todo"],陣列,每個判斷式成立時要做的事情.
|
|
|
1493 |
$conf["javascript::jsIf"]["todo"]=array($script);
|
|
|
1494 |
#$conf["todoComment"],陣列,每件要做的事情之註解,預設為"do something...".
|
|
|
1495 |
$conf["javascript::jsIf"]["todoComment"]=array("start ajax...");
|
|
|
1496 |
$jsIf=javascript::jsIf($conf["javascript::jsIf"]);
|
|
|
1497 |
unset($conf["javascript::jsIf"]);
|
|
|
1498 |
|
|
|
1499 |
#如果設置條件失敗
|
|
|
1500 |
if($jsIf["status"]==="false"){
|
|
|
1501 |
|
|
|
1502 |
#設置錯誤狀態
|
|
|
1503 |
$result["status"]="false";
|
|
|
1504 |
|
|
|
1505 |
#設置錯誤提示
|
|
|
1506 |
$result["error"]=$jsIf;
|
|
|
1507 |
|
|
|
1508 |
#回傳結果
|
|
|
1509 |
return $result;
|
|
|
1510 |
|
|
|
1511 |
}#if end
|
|
|
1512 |
|
|
|
1513 |
#設置執行函式的條件
|
|
|
1514 |
$script=$jsIf["content"];
|
|
|
1515 |
|
|
|
1516 |
}#if end
|
|
|
1517 |
|
|
|
1518 |
#組合成完整的js函數
|
|
|
1519 |
$script=$scriptHead.$script.$scriptTail;
|
|
|
1520 |
|
|
|
1521 |
#如果要將script用<script></script>包住.
|
|
|
1522 |
if($conf["scriptTag"]==="true"){
|
|
|
1523 |
|
|
|
1524 |
#建立完整的<script>
|
|
|
1525 |
#函式說明:
|
|
|
1526 |
#將要執行的script語法透過該函式執行(會在程式外層用<script></script>包起來).
|
|
|
1527 |
#回傳結果:
|
|
|
1528 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
1529 |
#$result["error"],錯誤訊息陣列
|
|
|
1530 |
#$result["function"],當前執行的函數名稱
|
|
|
1531 |
#$result["content"],要執行的javaScript語法
|
|
|
1532 |
#必填參數:
|
|
|
1533 |
#$conf["script"],字串,要執行的javaScript語法,標籤「<script></script>」會自動補上.
|
|
|
1534 |
$conf["javaScript::toScript"]["script"]=$sendNow;
|
|
|
1535 |
#可省略參數:
|
|
|
1536 |
#$conf["onReady"],字串,是否要在網頁載入完再執行,"false"為不等載入完就先執行,預設為"true"要等載入完再執行.
|
|
|
1537 |
#$conf["onReady"]="true";
|
|
|
1538 |
#$conf["jsFunciton"],字串陣列,為要放入<script>標籤的js函數.
|
|
|
1539 |
$conf["javaScript::toScript"]["jsFunciton"]=array($script);
|
|
|
1540 |
#參考資料:
|
|
|
1541 |
#http://stackoverflow.com/questions/9899372/pure-javascript-equivalent-to-jquerys-ready-how-to-call-a-function-when-the
|
|
|
1542 |
$toScript=javaScript::toScript($conf["javaScript::toScript"]);
|
|
|
1543 |
unset($conf["javaScript::toScript"]);
|
|
|
1544 |
|
|
|
1545 |
#如果建立js語法失敗
|
|
|
1546 |
if($toScript["status"]==="false"){
|
|
|
1547 |
|
|
|
1548 |
#設置錯誤狀態
|
|
|
1549 |
$result["status"]="false";
|
|
|
1550 |
|
|
|
1551 |
#設置錯誤提示
|
|
|
1552 |
$result["error"]=$toScript;
|
|
|
1553 |
|
|
|
1554 |
#回傳結果
|
|
|
1555 |
return $result;
|
|
|
1556 |
|
|
|
1557 |
}#if end
|
|
|
1558 |
|
|
|
1559 |
#取得js語法
|
|
|
1560 |
$result["content"]=$toScript["content"];
|
|
|
1561 |
|
|
|
1562 |
}#if end
|
|
|
1563 |
|
|
|
1564 |
#反之
|
|
|
1565 |
else{
|
|
|
1566 |
|
|
|
1567 |
#取得js語法
|
|
|
1568 |
$result["content"]=$script;
|
|
|
1569 |
|
|
|
1570 |
}#else end
|
|
|
1571 |
|
|
|
1572 |
#執行到這代表執行成功
|
|
|
1573 |
$result["status"]="true";
|
|
|
1574 |
|
|
|
1575 |
#回傳javascript語法
|
|
|
1576 |
return $result;
|
|
|
1577 |
|
|
|
1578 |
}# function sendPostValue end
|
|
|
1579 |
|
|
|
1580 |
/*
|
|
|
1581 |
#函式說明:
|
|
|
1582 |
#透過javaScript傳送get數值到特定頁面,並且取得頁面的回應,將之結果放置在特定的區塊裏面。
|
|
|
1583 |
#回傳的內容:
|
|
|
1584 |
#$result["status"],執行正確與否,"true"代表執行正確,"false"代表執行失敗.
|
|
|
1585 |
#$result["error"],錯誤訊息陣列.
|
|
|
1586 |
#$result["content"],JavaScript的語法
|
|
|
1587 |
#$result["function"],當前執行的函數名稱
|
|
|
1588 |
#必填參數:
|
|
|
1589 |
#$conf["receivePage"],字串,要接收數值的頁面。
|
|
|
1590 |
$conf["receivePage"]="";
|
|
|
1591 |
#$conf["var"],陣列,要傳送的變數名稱與內容,$conf["var"]["name"]=$value,代表變數名為$name,值為$value.
|
|
|
1592 |
$conf["var"]=array();
|
|
|
1593 |
#$conf["jsFunctionName"],字串,ajax裏面的js涵式名稱,使用該function的範例 jsFunction(this.value) ,這樣就會把表單的數值傳進去
|
|
|
1594 |
$conf["jsFunctionName"]="";
|
|
|
1595 |
#可省略參數:
|
|
|
1596 |
#$conf["responsePalaceId"],字串,回傳的內容要呈現於哪個<span id = ? ></span>、<div id= ? ></div>區塊之間。
|
|
|
1597 |
#$conf["responsePalaceId"]="";
|
|
|
1598 |
#$conf["sendNow"],字串,是否要在document.ready後馬上執行ajax,預設為"false",代表不要,"true"代表要.
|
|
|
1599 |
#$conf["sendNow"]="false";
|
|
|
1600 |
#參考資料:
|
|
|
1601 |
#http://www.w3school.com.cn/php/php_ajax_suggest.asp
|
|
|
1602 |
#http://www.w3schools.com/php/php_ajax_php.asp
|
|
|
1603 |
#備註:
|
|
|
1604 |
#無.
|
|
|
1605 |
*/
|
|
|
1606 |
public static function ajaxSendGetValue($conf){
|
|
|
1607 |
|
|
|
1608 |
#初始化要回傳的內容
|
|
|
1609 |
$result=array();
|
|
|
1610 |
|
|
|
1611 |
#初始化要回傳的語法
|
|
|
1612 |
$result["content"]="";
|
|
|
1613 |
|
|
|
1614 |
#記錄當前執行的函數名稱
|
|
|
1615 |
$result["function"]=__FUNCTION__;
|
|
|
1616 |
|
|
|
1617 |
#如果 $conf 不為陣列
|
|
|
1618 |
if(gettype($conf)!="array"){
|
|
|
1619 |
|
|
|
1620 |
#設置執行失敗
|
|
|
1621 |
$result["status"]="false";
|
|
|
1622 |
|
|
|
1623 |
#設置執行錯誤訊息
|
|
|
1624 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1625 |
|
|
|
1626 |
#如果傳入的參數為 null
|
|
|
1627 |
if($conf==null){
|
|
|
1628 |
|
|
|
1629 |
#設置執行錯誤訊息
|
|
|
1630 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
1631 |
|
|
|
1632 |
}#if end
|
|
|
1633 |
|
|
|
1634 |
#回傳結果
|
|
|
1635 |
return $result;
|
|
|
1636 |
|
|
|
1637 |
}#if end
|
|
|
1638 |
|
|
|
1639 |
#檢查參數
|
|
|
1640 |
#函式說明:
|
|
|
1641 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1642 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1643 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1644 |
#$result["function"],當前執行的函式名稱.
|
|
|
1645 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1646 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1647 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1648 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1649 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1650 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1651 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1652 |
#必填參數:
|
|
|
1653 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1654 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1655 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1656 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("receivePage","var","jsFunctionName");
|
|
|
1657 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
|
|
1658 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","array","string");
|
|
|
1659 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1660 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1661 |
#可以省略的參數:
|
|
|
1662 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
1663 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
1664 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1665 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("responsePalaceId","sendNow");
|
|
|
1666 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
1667 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
|
|
|
1668 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1669 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"false");
|
|
|
1670 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1671 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
|
|
|
1672 |
#參考資料來源:
|
|
|
1673 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1674 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1675 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
1676 |
|
|
|
1677 |
#如果檢查失敗
|
|
|
1678 |
if($checkResult["status"]=="false"){
|
|
|
1679 |
|
|
|
1680 |
#設置錯誤狀態
|
|
|
1681 |
$result["status"]="false";
|
|
|
1682 |
|
|
|
1683 |
#設置錯誤提示
|
|
|
1684 |
$result["error"]=$checkResult;
|
|
|
1685 |
|
|
|
1686 |
#回傳結果
|
|
|
1687 |
return $result;
|
|
|
1688 |
|
|
|
1689 |
}#if end
|
|
|
1690 |
|
|
|
1691 |
#如果檢查不通過
|
|
|
1692 |
if($checkResult["passed"]=="false"){
|
|
|
1693 |
|
|
|
1694 |
#設置錯誤狀態
|
|
|
1695 |
$result["status"]="false";
|
|
|
1696 |
|
|
|
1697 |
#設置錯誤提示
|
|
|
1698 |
$result["error"]=$checkResult;
|
|
|
1699 |
|
|
|
1700 |
#回傳結果
|
|
|
1701 |
return $result;
|
|
|
1702 |
|
|
|
1703 |
}#if end
|
|
|
1704 |
|
|
|
1705 |
#初始化馬上執行ajax的js語法
|
|
|
1706 |
$sendNow="";
|
|
|
1707 |
|
|
|
1708 |
#如果 $conf["sendNow"] 為 "true"...
|
|
|
1709 |
if($conf["sendNow"]==="true"){
|
|
|
1710 |
|
|
|
1711 |
#設置馬上執行ajax
|
|
|
1712 |
$sendNow=$conf["jsFunctionName"]."();";
|
|
|
1713 |
|
|
|
1714 |
}#if end
|
|
|
1715 |
|
|
|
1716 |
#設置不對回應做處理
|
|
|
1717 |
$actionWhenGotResponse="";
|
|
|
1718 |
|
|
|
1719 |
#如果有設置 $conf["responsePalaceId"]
|
|
|
1720 |
if(isset($conf["responsePalaceId"])){
|
|
|
1721 |
|
|
|
1722 |
#設置收到ajax的回應後要把內容吐到特定id的標籤裡面
|
|
|
1723 |
$actionWhenGotResponse="document.getElementById('".$conf["responsePalaceId"]."').innerHTML=xmlhttp.responseText;";
|
|
|
1724 |
|
|
|
1725 |
}#if end
|
|
|
1726 |
|
|
|
1727 |
#url_encode get request
|
|
|
1728 |
$conf["var"]="?".http_build_query($conf["var"]);
|
|
|
1729 |
|
|
|
1730 |
#建立ajax的script
|
|
|
1731 |
|
|
|
1732 |
#傳送post變數到指定頁面的函式開始.
|
|
|
1733 |
$script="
|
|
|
1734 |
function ".$conf["jsFunctionName"]."(){
|
|
|
1735 |
|
|
|
1736 |
if(window.XMLHttpRequest){
|
|
|
1737 |
|
|
|
1738 |
// code for IE7+, Firefox, Chrome, Opera, Safari
|
|
|
1739 |
xmlhttp=new XMLHttpRequest();
|
|
|
1740 |
|
|
|
1741 |
}//if end
|
|
|
1742 |
|
|
|
1743 |
else{
|
|
|
1744 |
|
|
|
1745 |
// code for IE6, IE5
|
|
|
1746 |
xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
|
|
|
1747 |
|
|
|
1748 |
}// else end
|
|
|
1749 |
|
|
|
1750 |
//如果服務端有回傳完稱的狀態
|
|
|
1751 |
xmlhttp.onreadystatechange=function(){
|
|
|
1752 |
|
|
|
1753 |
//如果狀態為4且response code為200
|
|
|
1754 |
if(xmlhttp.readyState==4 && xmlhttp.status==200){
|
|
|
1755 |
|
|
|
1756 |
//將回應進行處理
|
|
|
1757 |
".$actionWhenGotResponse."
|
|
|
1758 |
|
|
|
1759 |
}//if end
|
|
|
1760 |
|
|
|
1761 |
}//function end
|
|
|
1762 |
|
|
|
1763 |
//設定要用get傳送的數值
|
|
|
1764 |
xmlhttp.open('GET','".$conf["receivePage"].$conf["var"]."',true);
|
|
|
1765 |
|
|
|
1766 |
//設定 header
|
|
|
1767 |
xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
|
|
|
1768 |
|
|
|
1769 |
//設定要求為ajax 的 header
|
|
|
1770 |
xmlhttp.setRequestHeader('X-Requested-With','XMLHttpRequest');
|
|
|
1771 |
|
|
|
1772 |
//傳送要求
|
|
|
1773 |
xmlhttp.send();
|
|
|
1774 |
|
|
|
1775 |
}//function end
|
|
|
1776 |
|
|
|
1777 |
";
|
|
|
1778 |
|
|
|
1779 |
#建立完整的<script>
|
|
|
1780 |
#函式說明:
|
|
|
1781 |
#將要執行的script語法透過該函式執行(會在程式外層用<script></script>包起來).
|
|
|
1782 |
#回傳結果:
|
|
|
1783 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
1784 |
#$result["error"],錯誤訊息陣列
|
|
|
1785 |
#$result["function"],當前執行的函數名稱
|
|
|
1786 |
#$result["content"],要執行的javaScript語法
|
|
|
1787 |
#必填參數:
|
|
|
1788 |
#$conf["script"],字串,要執行的javaScript語法,標籤「<script></script>」會自動補上.
|
|
|
1789 |
$conf["javaScript::toScript"]["script"]=$sendNow;
|
|
|
1790 |
#可省略參數:
|
|
|
1791 |
#$conf["onReady"],字串,是否要在網頁載入完再執行,"false"為不等載入完就先執行,預設為"true"要等載入完再執行.
|
|
|
1792 |
#$conf["onReady"]="true";
|
|
|
1793 |
#$conf["jsFunciton"],字串陣列,為要放入<script>標籤的js函數.
|
|
|
1794 |
$conf["javaScript::toScript"]["jsFunciton"]=array($script);
|
|
|
1795 |
#參考資料:
|
|
|
1796 |
#http://stackoverflow.com/questions/9899372/pure-javascript-equivalent-to-jquerys-ready-how-to-call-a-function-when-the
|
|
|
1797 |
$toScript=javaScript::toScript($conf["javaScript::toScript"]);
|
|
|
1798 |
unset($conf["javaScript::toScript"]);
|
|
|
1799 |
|
|
|
1800 |
#如果建立js語法失敗
|
|
|
1801 |
if($toScript["status"]==="false"){
|
|
|
1802 |
|
|
|
1803 |
#設置錯誤狀態
|
|
|
1804 |
$result["status"]="false";
|
|
|
1805 |
|
|
|
1806 |
#設置錯誤提示
|
|
|
1807 |
$result["error"]=$toScript;
|
|
|
1808 |
|
|
|
1809 |
#回傳結果
|
|
|
1810 |
return $result;
|
|
|
1811 |
|
|
|
1812 |
}#if end
|
|
|
1813 |
|
|
|
1814 |
#取得js語法
|
|
|
1815 |
$result["content"]=$toScript["content"];
|
|
|
1816 |
|
|
|
1817 |
#執行到這代表執行成功
|
|
|
1818 |
$result["status"]="true";
|
|
|
1819 |
|
|
|
1820 |
#回傳javascript語法
|
|
|
1821 |
return $result;
|
|
|
1822 |
|
|
|
1823 |
}# function sendGetValue end
|
|
|
1824 |
|
|
|
1825 |
/*
|
|
|
1826 |
#函式說明:
|
|
|
1827 |
#建立從當前iframe去增加其他iframe裏面元素的數值內容的js函數.
|
|
|
1828 |
#回傳結果:
|
|
|
1829 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
1830 |
#$result["error"],錯誤訊息陣列.
|
|
|
1831 |
#$result["function"],當前執行的函數名稱.
|
|
|
1832 |
#$result["content"],javaScript語法.
|
|
|
1833 |
#必填參數:
|
|
|
1834 |
$conf["idVarName"]="inputElementId";#目標iframe底下的javaScript變數名稱,其變數值應爲元素的id.
|
|
|
1835 |
$conf["jsFunctionName"]="sendKey";#該javaScript的涵式名稱.
|
|
|
1836 |
#可省略參數:
|
|
|
1837 |
#無.
|
|
|
1838 |
#參考資料:
|
|
|
1839 |
#無.
|
|
|
1840 |
#備註:
|
|
|
1841 |
#無.
|
|
|
1842 |
*/
|
|
|
1843 |
public static function addOtherIframeInterElementValueFromThisIframe($conf){
|
|
|
1844 |
|
|
|
1845 |
#初始化要回傳的變數
|
|
|
1846 |
$result=array();
|
|
|
1847 |
|
|
|
1848 |
#初始化javaScript語法
|
|
|
1849 |
$result["content"]="";
|
|
|
1850 |
|
|
|
1851 |
#記錄當前執行的函數名稱
|
|
|
1852 |
$result["function"]=__FUNCTION__;
|
|
|
1853 |
|
|
|
1854 |
#如果 $conf 不為陣列
|
|
|
1855 |
if(gettype($conf)!="array"){
|
|
|
1856 |
|
|
|
1857 |
#設置執行失敗
|
|
|
1858 |
$result["status"]="false";
|
|
|
1859 |
|
|
|
1860 |
#設置執行錯誤訊息
|
|
|
1861 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1862 |
|
|
|
1863 |
#如果傳入的參數為 null
|
|
|
1864 |
if($conf==null){
|
|
|
1865 |
|
|
|
1866 |
#設置執行錯誤訊息
|
|
|
1867 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
1868 |
|
|
|
1869 |
}#if end
|
|
|
1870 |
|
|
|
1871 |
#回傳結果
|
|
|
1872 |
return $result;
|
|
|
1873 |
|
|
|
1874 |
}#if end
|
|
|
1875 |
|
|
|
1876 |
#檢查參數
|
|
|
1877 |
#函式說明:
|
|
|
1878 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1879 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1880 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1881 |
#$result["function"],當前執行的函式名稱.
|
|
|
1882 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1883 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1884 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1885 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1886 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1887 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1888 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1889 |
#必填參數:
|
|
|
1890 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1891 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1892 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1893 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("idVarName","jsFunctionName");
|
|
|
1894 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
|
|
1895 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
1896 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1897 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1898 |
#可以省略的參數:
|
|
|
1899 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
1900 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
1901 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1902 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("jsPosition");
|
|
|
1903 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
1904 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
1905 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1906 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
|
|
|
1907 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1908 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
|
|
|
1909 |
#參考資料來源:
|
|
|
1910 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1911 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1912 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
1913 |
|
|
|
1914 |
#debug
|
|
|
1915 |
#var_dump($checkResult);
|
|
|
1916 |
#exit;
|
|
|
1917 |
|
|
|
1918 |
#如果檢查失敗
|
|
|
1919 |
if($checkResult["status"]=="false"){
|
|
|
1920 |
|
|
|
1921 |
#設置錯誤狀態
|
|
|
1922 |
$result["status"]="false";
|
|
|
1923 |
|
|
|
1924 |
#設置錯誤提示
|
|
|
1925 |
$result["error"]=$checkResult;
|
|
|
1926 |
|
|
|
1927 |
#回傳結果
|
|
|
1928 |
return $result;
|
|
|
1929 |
|
|
|
1930 |
}#if end
|
|
|
1931 |
|
|
|
1932 |
#如果檢查不通過
|
|
|
1933 |
if($checkResult["passed"]=="false"){
|
|
|
1934 |
|
|
|
1935 |
#設置錯誤狀態
|
|
|
1936 |
$result["status"]="false";
|
|
|
1937 |
|
|
|
1938 |
#設置錯誤提示
|
|
|
1939 |
$result["error"]=$checkResult;
|
|
|
1940 |
|
|
|
1941 |
#回傳結果
|
|
|
1942 |
return $result;
|
|
|
1943 |
|
|
|
1944 |
}#if end
|
|
|
1945 |
|
|
|
1946 |
#javaScript開始
|
|
|
1947 |
$conf["javaScript"]["start"]["include"]="false";#是否要匯入外部js庫。"true"爲要匯入;"false"爲沒有要匯入。
|
|
|
1948 |
$javaScriptStart=javaScript::start($conf["javaScript"]["start"]);
|
|
|
1949 |
unset($conf["javaScript"]["start"]);
|
|
|
1950 |
|
|
|
1951 |
#javaScript語法開始失敗
|
|
|
1952 |
if($javaScriptStart["status"]=="false"){
|
|
|
1953 |
|
|
|
1954 |
#設置錯誤狀態
|
|
|
1955 |
$result["status"]="false";
|
|
|
1956 |
|
|
|
1957 |
#設置錯誤提示
|
|
|
1958 |
$result["error"]=$javaScriptStart;
|
|
|
1959 |
|
|
|
1960 |
#回傳結果
|
|
|
1961 |
return $result;
|
|
|
1962 |
|
|
|
1963 |
}#if end
|
|
|
1964 |
|
|
|
1965 |
#串接javaScript開始的語法
|
|
|
1966 |
$result["content"]=$result["content"].$javaScriptStart["content"];
|
|
|
1967 |
|
|
|
1968 |
#從當前iframe去增加其他iframe裏面元素的數值內容的javaScript涵式
|
|
|
1969 |
$result["content"]=$result["content"]."
|
|
|
1970 |
|
|
|
1971 |
//將數值傳到別到iframe裡的元素
|
|
|
1972 |
//必填的參數:
|
|
|
1973 |
//frameId,要存取的目標iframe的id
|
|
|
1974 |
//key,要增加的數值內容
|
|
|
1975 |
//參考資料來源:
|
|
|
1976 |
//http://www.dotblogs.com.tw/puma/archive/2008/11/13/5982.aspx
|
|
|
1977 |
//http://stackoverflow.com/questions/13757943/access-a-variable-of-iframe-from-parent
|
|
|
1978 |
function ".$conf["jsFunctionName"]."(frameId,key){
|
|
|
1979 |
|
|
|
1980 |
//將目標iframe元素物件化,並取得其id
|
|
|
1981 |
var iframe = parent.document.getElementById(frameId);
|
|
|
1982 |
|
|
|
1983 |
//取得其iframe底下的變數
|
|
|
1984 |
var id=iframe.contentWindow.".$conf["idVarName"].";
|
|
|
1985 |
|
|
|
1986 |
//將目標iframe裏的元素物件化,並取得其id
|
|
|
1987 |
var inputField=iframe.contentDocument.getElementById(id);
|
|
|
1988 |
|
|
|
1989 |
//將要傳送的數值連在目標iframe裏元素的內容後面。
|
|
|
1990 |
inputField.value = inputField.value+key;
|
|
|
1991 |
|
|
|
1992 |
}//function sendKey end
|
|
|
1993 |
|
|
|
1994 |
";
|
|
|
1995 |
|
|
|
1996 |
#javaScript結束
|
|
|
1997 |
$result["content"]=$result["content"].javaScript::end();
|
|
|
1998 |
|
|
|
1999 |
#設置執行正常
|
|
|
2000 |
$result["status"]="true";
|
|
|
2001 |
|
|
|
2002 |
#回傳結果
|
|
|
2003 |
return $result;
|
|
|
2004 |
|
|
|
2005 |
}#function
|
|
|
2006 |
|
|
|
2007 |
/*
|
|
|
2008 |
#函式說明:
|
|
|
2009 |
#建立從當前iframe去刪除其他iframe裏面元素的數值內容的js函數
|
|
|
2010 |
#回傳結果:
|
|
|
2011 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
2012 |
#$result["error"],錯誤訊息陣列.
|
|
|
2013 |
#$result["function"],當前執行的函數名稱.
|
|
|
2014 |
#$result["content"],javaScript語法.
|
|
|
2015 |
#必填參數:
|
|
|
2016 |
$conf["idVarName"]="inputElementId";#目標iframe底下的javaScript變數名稱,其變數值應爲元素的id
|
|
|
2017 |
$conf["jsFunctionName"]="delOne";#該javaScript的涵式名稱
|
|
|
2018 |
#可省略參數:
|
|
|
2019 |
#無.
|
|
|
2020 |
#參考資料:
|
|
|
2021 |
#無.
|
|
|
2022 |
#備註:
|
|
|
2023 |
#無.
|
|
|
2024 |
*/
|
|
|
2025 |
public static function delOtherIframeInterElementValueFromThisIframe($conf){
|
|
|
2026 |
|
|
|
2027 |
#初始化要回傳的變數
|
|
|
2028 |
$result=array();
|
|
|
2029 |
|
|
|
2030 |
#初始化javaScript語法
|
|
|
2031 |
$result["content"]="";
|
|
|
2032 |
|
|
|
2033 |
#記錄當前執行的函數名稱
|
|
|
2034 |
$result["function"]=__FUNCTION__;
|
|
|
2035 |
|
|
|
2036 |
#如果 $conf 不為陣列
|
|
|
2037 |
if(gettype($conf)!="array"){
|
|
|
2038 |
|
|
|
2039 |
#設置執行失敗
|
|
|
2040 |
$result["status"]="false";
|
|
|
2041 |
|
|
|
2042 |
#設置執行錯誤訊息
|
|
|
2043 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
2044 |
|
|
|
2045 |
#如果傳入的參數為 null
|
|
|
2046 |
if($conf==null){
|
|
|
2047 |
|
|
|
2048 |
#設置執行錯誤訊息
|
|
|
2049 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
2050 |
|
|
|
2051 |
}#if end
|
|
|
2052 |
|
|
|
2053 |
#回傳結果
|
|
|
2054 |
return $result;
|
|
|
2055 |
|
|
|
2056 |
}#if end
|
|
|
2057 |
|
|
|
2058 |
#檢查參數
|
|
|
2059 |
#函式說明:
|
|
|
2060 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
2061 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2062 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2063 |
#$result["function"],當前執行的函式名稱.
|
|
|
2064 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
2065 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
2066 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
2067 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
2068 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
2069 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
2070 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
2071 |
#必填參數:
|
|
|
2072 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
2073 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
2074 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
2075 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("idVarName","jsFunctionName");
|
|
|
2076 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
|
|
2077 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
2078 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
2079 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
2080 |
#可以省略的參數:
|
|
|
2081 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
2082 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
2083 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
2084 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("jsPosition");
|
|
|
2085 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
2086 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
2087 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
2088 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
|
|
|
2089 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
2090 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
|
|
|
2091 |
#參考資料來源:
|
|
|
2092 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
2093 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
2094 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
2095 |
|
|
|
2096 |
#debug
|
|
|
2097 |
#var_dump($checkResult);
|
|
|
2098 |
#exit;
|
|
|
2099 |
|
|
|
2100 |
#如果檢查失敗
|
|
|
2101 |
if($checkResult["status"]=="false"){
|
|
|
2102 |
|
|
|
2103 |
#設置錯誤狀態
|
|
|
2104 |
$result["status"]="false";
|
|
|
2105 |
|
|
|
2106 |
#設置錯誤提示
|
|
|
2107 |
$result["error"]=$checkResult;
|
|
|
2108 |
|
|
|
2109 |
#回傳結果
|
|
|
2110 |
return $result;
|
|
|
2111 |
|
|
|
2112 |
}#if end
|
|
|
2113 |
|
|
|
2114 |
#如果檢查不通過
|
|
|
2115 |
if($checkResult["passed"]=="false"){
|
|
|
2116 |
|
|
|
2117 |
#設置錯誤狀態
|
|
|
2118 |
$result["status"]="false";
|
|
|
2119 |
|
|
|
2120 |
#設置錯誤提示
|
|
|
2121 |
$result["error"]=$checkResult;
|
|
|
2122 |
|
|
|
2123 |
#回傳結果
|
|
|
2124 |
return $result;
|
|
|
2125 |
|
|
|
2126 |
}#if end
|
|
|
2127 |
|
|
|
2128 |
#javaScript開始
|
|
|
2129 |
$conf["javaScript"]["start"]["include"]="false";#是否要匯入外部js庫。"true"爲要匯入;"false"爲沒有要匯入。
|
|
|
2130 |
$javaScriptStart=javaScript::start($conf["javaScript"]["start"]);
|
|
|
2131 |
unset($conf["javaScript"]["start"]);
|
|
|
2132 |
|
|
|
2133 |
#如果 javaScript 開始
|
|
|
2134 |
if($javaScriptStart["status"]=="false"){
|
|
|
2135 |
|
|
|
2136 |
#設置錯誤狀態
|
|
|
2137 |
$result["status"]="false";
|
|
|
2138 |
|
|
|
2139 |
#設置錯誤提示
|
|
|
2140 |
$result["error"]=$checkResult;
|
|
|
2141 |
|
|
|
2142 |
#回傳結果
|
|
|
2143 |
return $result;
|
|
|
2144 |
|
|
|
2145 |
}#if end
|
|
|
2146 |
|
|
|
2147 |
#串接javaScript開始的語法
|
|
|
2148 |
$result["content"]=$result["content"].$javaScriptStart["content"];
|
|
|
2149 |
|
|
|
2150 |
#從當前iframe去增加其他iframe裏面元素的數值內容的javaScript涵式
|
|
|
2151 |
$result["content"]=$result["content"]."
|
|
|
2152 |
|
|
|
2153 |
//將別的iframe裡的元素刪除一個字
|
|
|
2154 |
//必填的參數:
|
|
|
2155 |
//frameId,要存取的目標iframe的id
|
|
|
2156 |
//key,要增加的數值內容
|
|
|
2157 |
//參考資料來源:
|
|
|
2158 |
//http://www.dotblogs.com.tw/puma/archive/2008/11/13/5982.aspx
|
|
|
2159 |
//http://stackoverflow.com/questions/13757943/access-a-variable-of-iframe-from-parent
|
|
|
2160 |
//http://www.w3school.com.cn/js/jsref_split.asp
|
|
|
2161 |
//http://www.w3school.com.cn/js/jsref_join.asp
|
|
|
2162 |
function ".$conf["jsFunctionName"]."(frameId){
|
|
|
2163 |
|
|
|
2164 |
//將目標iframe元素物件化,並取得其id
|
|
|
2165 |
var iframe = parent.document.getElementById(frameId);
|
|
|
2166 |
|
|
|
2167 |
//取得其iframe底下的變數
|
|
|
2168 |
var id=iframe.contentWindow.".$conf["idVarName"].";
|
|
|
2169 |
|
|
|
2170 |
//將目標iframe裏的元素物件化,並取得其id
|
|
|
2171 |
var inputField=iframe.contentDocument.getElementById(id);
|
|
|
2172 |
|
|
|
2173 |
//取得原始的字串內容
|
|
|
2174 |
var strValue=inputField.value;
|
|
|
2175 |
|
|
|
2176 |
//將表單原始的字串內容,變成陣列
|
|
|
2177 |
var strArray=strValue.split('');
|
|
|
2178 |
|
|
|
2179 |
//取得陣列的長度
|
|
|
2180 |
var strArrayLength=strArray.length;
|
|
|
2181 |
|
|
|
2182 |
//將陣列的最後一個元素移除
|
|
|
2183 |
strArray[strArrayLength-1]='';
|
|
|
2184 |
|
|
|
2185 |
//將陣列合併爲字串
|
|
|
2186 |
var deledStr = strArray.join('');
|
|
|
2187 |
|
|
|
2188 |
//更改表單的字串內容爲移除了最後一個字的結果
|
|
|
2189 |
inputField.value = deledStr;
|
|
|
2190 |
|
|
|
2191 |
}//function sendKey end
|
|
|
2192 |
|
|
|
2193 |
";
|
|
|
2194 |
|
|
|
2195 |
#javaScript結束
|
|
|
2196 |
$result["content"]=$result["content"].javaScript::end();
|
|
|
2197 |
|
|
|
2198 |
#設置執行正常
|
|
|
2199 |
$result["status"]="true";
|
|
|
2200 |
|
|
|
2201 |
#回傳結果
|
|
|
2202 |
return $result;
|
|
|
2203 |
|
|
|
2204 |
}#function
|
|
|
2205 |
|
|
|
2206 |
/*
|
|
|
2207 |
#函式說明:
|
|
|
2208 |
#列印當前頁面
|
|
|
2209 |
#回傳結果:
|
|
|
2210 |
#列印的javaScript語法.
|
|
|
2211 |
#必填參數:
|
|
|
2212 |
#無.
|
|
|
2213 |
#可省略參數:
|
|
|
2214 |
#無.
|
|
|
2215 |
#參考資料:
|
|
|
2216 |
#無.
|
|
|
2217 |
#備註:
|
|
|
2218 |
#無.
|
|
|
2219 |
*/
|
|
|
2220 |
public static function printWebPage(){
|
|
|
2221 |
|
|
|
2222 |
#初始化要回傳的javaScript語法
|
|
|
2223 |
$result="<body onload=window.print()>";
|
|
|
2224 |
|
|
|
2225 |
#回傳語法
|
|
|
2226 |
return $result;
|
|
|
2227 |
|
|
|
2228 |
}#function printWebPage end
|
|
|
2229 |
|
|
|
2230 |
/*
|
|
|
2231 |
#函式說明:
|
|
|
2232 |
#確認視窗,回傳的javaScript結果可在要觸發的元素裡面搭配「onclink=本函數回傳的內容」,來使連結或按鈕確定觸發或不觸發.
|
|
|
2233 |
#回傳結果:
|
|
|
2234 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
2235 |
#$result["error"],錯誤訊息陣列.
|
|
|
2236 |
#$result["function"],當前執行的函數名稱.
|
|
|
2237 |
#$result["content"],javaScript語法,不含<script>標籤.
|
|
|
2238 |
#必填參數:
|
|
|
2239 |
#$conf["alertSentenceArray"],字串陣列彈出式視窗的內容,每個元素代表每一列的內容.
|
|
|
2240 |
$conf["alertSentenceArray"]=array();
|
|
|
2241 |
#可省略參數:
|
|
|
2242 |
#無.
|
|
|
2243 |
#參考資料:
|
|
|
2244 |
#無.
|
|
|
2245 |
#備註:
|
|
|
2246 |
#無.
|
|
|
2247 |
*/
|
|
|
2248 |
public static function confirmWindow(&$conf){
|
|
|
2249 |
|
|
|
2250 |
#初始化要回傳的變數
|
|
|
2251 |
$result=array();
|
|
|
2252 |
|
|
|
2253 |
#記錄當前執行的函數名稱
|
|
|
2254 |
$result["function"]=__FUNCTION__;
|
|
|
2255 |
|
|
|
2256 |
#如果 $conf 不為陣列
|
|
|
2257 |
if(gettype($conf)!="array"){
|
|
|
2258 |
|
|
|
2259 |
#設置執行失敗
|
|
|
2260 |
$result["status"]="false";
|
|
|
2261 |
|
|
|
2262 |
#設置執行錯誤訊息
|
|
|
2263 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
2264 |
|
|
|
2265 |
#如果傳入的參數為 null
|
|
|
2266 |
if($conf==null){
|
|
|
2267 |
|
|
|
2268 |
#設置執行錯誤訊息
|
|
|
2269 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
2270 |
|
|
|
2271 |
}#if end
|
|
|
2272 |
|
|
|
2273 |
#回傳結果
|
|
|
2274 |
return $result;
|
|
|
2275 |
|
|
|
2276 |
}#if end
|
|
|
2277 |
|
|
|
2278 |
#檢查參數
|
|
|
2279 |
#函式說明:
|
|
|
2280 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
2281 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2282 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2283 |
#$result["function"],當前執行的函式名稱.
|
|
|
2284 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
2285 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
2286 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
2287 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
2288 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
2289 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
2290 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
2291 |
#必填參數:
|
|
|
2292 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
2293 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
2294 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
2295 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("alertSentenceArray");
|
|
|
2296 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
|
|
2297 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array");
|
|
|
2298 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
2299 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
2300 |
#可以省略的參數:
|
|
|
2301 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
2302 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
2303 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
2304 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("alertSentenceArray");
|
|
|
2305 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
2306 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
2307 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
2308 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array();
|
|
|
2309 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
2310 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
|
|
|
2311 |
#參考資料來源:
|
|
|
2312 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
2313 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
2314 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
2315 |
|
|
|
2316 |
#如果檢查失敗
|
|
|
2317 |
if($checkResult["status"]=="false"){
|
|
|
2318 |
|
|
|
2319 |
#設置錯誤狀態
|
|
|
2320 |
$result["status"]="false";
|
|
|
2321 |
|
|
|
2322 |
#設置錯誤提示
|
|
|
2323 |
$result["error"]=$checkResult;
|
|
|
2324 |
|
|
|
2325 |
#回傳結果
|
|
|
2326 |
return $result;
|
|
|
2327 |
|
|
|
2328 |
}#if end
|
|
|
2329 |
|
|
|
2330 |
#如果檢查不通過
|
|
|
2331 |
if($checkResult["passed"]=="false"){
|
|
|
2332 |
|
|
|
2333 |
#設置錯誤狀態
|
|
|
2334 |
$result["status"]="false";
|
|
|
2335 |
|
|
|
2336 |
#設置錯誤提示
|
|
|
2337 |
$result["error"]=$checkResult;
|
|
|
2338 |
|
|
|
2339 |
#回傳結果
|
|
|
2340 |
return $result;
|
|
|
2341 |
|
|
|
2342 |
}#if end
|
|
|
2343 |
|
|
|
2344 |
#回傳結果的confirm視窗語法開始
|
|
|
2345 |
$result["content"]="return confirm('";
|
|
|
2346 |
|
|
|
2347 |
#針對每個 $conf["alertSentenceArray"]
|
|
|
2348 |
foreach($conf["alertSentenceArray"] as $sentence){
|
|
|
2349 |
|
|
|
2350 |
#接上每列內容
|
|
|
2351 |
$result["content"]=$result["content"].$sentence."\\n";
|
|
|
2352 |
|
|
|
2353 |
}#foreach end
|
|
|
2354 |
|
|
|
2355 |
#回傳結果的confirm視窗語法結束
|
|
|
2356 |
$result["content"]=$result["content"]."')";
|
|
|
2357 |
|
|
|
2358 |
#設置執行正常
|
|
|
2359 |
$result["status"]="true";
|
|
|
2360 |
|
|
|
2361 |
#回傳結果
|
|
|
2362 |
return $result;
|
|
|
2363 |
|
|
|
2364 |
}#function confirmWindow end
|
|
|
2365 |
|
|
|
2366 |
/*
|
|
|
2367 |
#函式說明:
|
|
|
2368 |
#依據需要加上<script></script>標籤,並且可以指定要匯入的js檔案.
|
|
|
2369 |
#回傳結果:
|
|
|
2370 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
2371 |
#$result["error"],錯誤訊息陣列
|
|
|
2372 |
#$result["function"],當前執行的函數名稱
|
|
|
2373 |
#$result["content"],javaScript語法
|
|
|
2374 |
#$result["importJS"],匯入js的語法,必定含有<script></script>標籤.
|
|
|
2375 |
#必填參數:
|
|
|
2376 |
#$conf["jsProgramSection"],陣列字串,不含<script></script>標籤的javsScript程式碼,可以放多個script程式.
|
|
|
2377 |
$conf["jsProgramSection"]=array("");
|
|
|
2378 |
#可省略參數:
|
|
|
2379 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑,請與參數"jsPosition"一起設置,預設為當前檔案的位置.
|
|
|
2380 |
#$conf["fileArgu"]=__FILE__;
|
|
|
2381 |
#$conf["jsPosition"],字串,要匯入的js檔案位置.
|
|
|
2382 |
#$conf["jsPosition"]="";
|
|
|
2383 |
#$conf["noScriptTag"],字串,是否不要用script tag包住回傳的內容($result["content"]),"true"代表不要用,"false"代表要用,預設為"false".
|
|
|
2384 |
#$conf["noScriptTag"]="false";
|
|
|
2385 |
#參考資料:
|
|
|
2386 |
#無.
|
|
|
2387 |
#備註:
|
|
|
2388 |
#無.
|
|
|
2389 |
*/
|
|
|
2390 |
public static function addScriptTag(&$conf){
|
|
|
2391 |
|
|
|
2392 |
#初始化要回傳的變數
|
|
|
2393 |
$result=array();
|
|
|
2394 |
|
|
|
2395 |
#記錄當前執行的函數名稱
|
|
|
2396 |
$result["function"]=__FUNCTION__;
|
|
|
2397 |
|
|
|
2398 |
#如果 $conf 不為陣列
|
|
|
2399 |
if(gettype($conf)!="array"){
|
|
|
2400 |
|
|
|
2401 |
#設置執行失敗
|
|
|
2402 |
$result["status"]="false";
|
|
|
2403 |
|
|
|
2404 |
#設置執行錯誤訊息
|
|
|
2405 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
2406 |
|
|
|
2407 |
#如果傳入的參數為 null
|
|
|
2408 |
if($conf==null){
|
|
|
2409 |
|
|
|
2410 |
#設置執行錯誤訊息
|
|
|
2411 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
2412 |
|
|
|
2413 |
}#if end
|
|
|
2414 |
|
|
|
2415 |
#回傳結果
|
|
|
2416 |
return $result;
|
|
|
2417 |
|
|
|
2418 |
}#if end
|
|
|
2419 |
|
|
|
2420 |
#初始化要回傳的變數
|
|
|
2421 |
$result["content"]="";
|
|
|
2422 |
|
|
|
2423 |
#檢查參數
|
|
|
2424 |
#函式說明:
|
|
|
2425 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
2426 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2427 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2428 |
#$result["function"],當前執行的函式名稱.
|
|
|
2429 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
2430 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
2431 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
2432 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
2433 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
2434 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
2435 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
2436 |
#必填參數:
|
|
|
2437 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
2438 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
2439 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
2440 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("jsProgramSection");
|
|
|
2441 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
|
|
2442 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array");
|
|
|
2443 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
2444 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
2445 |
#可以省略的參數:
|
|
|
2446 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
2447 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
2448 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
2449 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("jsPosition","fileArgu","noScriptTag");
|
|
|
2450 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
2451 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
|
|
|
2452 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
2453 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,__FILE__,"false");
|
|
|
2454 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
2455 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
|
|
|
2456 |
#參考資料來源:
|
|
|
2457 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
2458 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
2459 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
2460 |
|
|
|
2461 |
#如果檢查失敗
|
|
|
2462 |
if($checkResult["status"]=="false"){
|
|
|
2463 |
|
|
|
2464 |
#設置錯誤狀態
|
|
|
2465 |
$result["status"]="false";
|
|
|
2466 |
|
|
|
2467 |
#設置錯誤提示
|
|
|
2468 |
$result["error"]=$checkResult;
|
|
|
2469 |
|
|
|
2470 |
#回傳結果
|
|
|
2471 |
return $result;
|
|
|
2472 |
|
|
|
2473 |
}#if end
|
|
|
2474 |
|
|
|
2475 |
#如果檢查不通過
|
|
|
2476 |
if($checkResult["passed"]=="false"){
|
|
|
2477 |
|
|
|
2478 |
#設置錯誤狀態
|
|
|
2479 |
$result["status"]="false";
|
|
|
2480 |
|
|
|
2481 |
#設置錯誤提示
|
|
|
2482 |
$result["error"]=$checkResult;
|
|
|
2483 |
|
|
|
2484 |
#回傳結果
|
|
|
2485 |
return $result;
|
|
|
2486 |
|
|
|
2487 |
}#if end
|
|
|
2488 |
|
|
|
2489 |
#如果 $conf["jsPosition"] 存在
|
|
|
2490 |
if(isset($conf["jsPosition"])){
|
|
|
2491 |
|
|
|
2492 |
#函式說明:
|
|
|
2493 |
#script 語法開始
|
|
|
2494 |
#回傳結果:
|
|
|
2495 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
2496 |
#$result["error"],錯誤訊息陣列
|
|
|
2497 |
#$result["function"],當前執行的函數名稱
|
|
|
2498 |
#$result["content"],javaScript語法
|
|
|
2499 |
#必填參數:
|
|
|
2500 |
|
|
|
2501 |
#如果 $conf["jsPosition"] 存在
|
|
|
2502 |
if(isset($conf["jsPosition"])){
|
|
|
2503 |
|
|
|
2504 |
#$conf["include"],字串,是否要匯入外部js庫,"true"爲要匯入;"false"爲沒有要匯入。
|
|
|
2505 |
$conf["javaScript::start"]["include"]="true";
|
|
|
2506 |
|
|
|
2507 |
}#if end
|
|
|
2508 |
|
|
|
2509 |
#反之
|
|
|
2510 |
else{
|
|
|
2511 |
|
|
|
2512 |
#$conf["include"],字串,是否要匯入外部js庫,"true"爲要匯入;"false"爲沒有要匯入。
|
|
|
2513 |
$conf["javaScript::start"]["include"]="false";
|
|
|
2514 |
|
|
|
2515 |
}#else end
|
|
|
2516 |
|
|
|
2517 |
#可省略參數:
|
|
|
2518 |
|
|
|
2519 |
#如果有設置 $conf["fileArgu"]
|
|
|
2520 |
if(isset($conf["fileArgu"])){
|
|
|
2521 |
|
|
|
2522 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑,請與參數"jsPosition"一起設置,預設為當前檔案的位置.
|
|
|
2523 |
$conf["javaScript::start"]["fileArgu"]=$conf["fileArgu"];
|
|
|
2524 |
|
|
|
2525 |
}#if end
|
|
|
2526 |
|
|
|
2527 |
#如果 $conf["jsPosition"] 存在
|
|
|
2528 |
if(isset($conf["jsPosition"])){
|
|
|
2529 |
|
|
|
2530 |
#$conf["jsPosition"],字串,要匯入的js檔案位置,請與參數"fileArgu"一起設置.
|
|
|
2531 |
$conf["javaScript::start"]["jsPosition"]=$conf["jsPosition"];
|
|
|
2532 |
|
|
|
2533 |
}#if end
|
|
|
2534 |
|
|
|
2535 |
#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,於設為"true".
|
|
|
2536 |
#$conf["userDir"]="true";
|
|
|
2537 |
$start=javaScript::start($conf["javaScript::start"]);
|
|
|
2538 |
unset($conf["javaScript::start"]);
|
|
|
2539 |
|
|
|
2540 |
#如果建立匯入js的語法失敗
|
|
|
2541 |
if($start["status"]=="false"){
|
|
|
2542 |
|
|
|
2543 |
#設置錯誤狀態
|
|
|
2544 |
$result["status"]="false";
|
|
|
2545 |
|
|
|
2546 |
#設置錯誤提示
|
|
|
2547 |
$result["error"]=$start;
|
|
|
2548 |
|
|
|
2549 |
#回傳結果
|
|
|
2550 |
return $result;
|
|
|
2551 |
|
|
|
2552 |
}#if end
|
|
|
2553 |
|
|
|
2554 |
#取得匯入js的語法
|
|
|
2555 |
$result["importJS"]=$result["content"].$start["content"];
|
|
|
2556 |
|
|
|
2557 |
#script結束
|
|
|
2558 |
#函式說明:
|
|
|
2559 |
#script 語法結束
|
|
|
2560 |
#回傳結果:
|
|
|
2561 |
#javaScript語法
|
|
|
2562 |
$result["importJS"]=$result["importJS"].javaScript::end();
|
|
|
2563 |
|
|
|
2564 |
}#if end
|
|
|
2565 |
|
|
|
2566 |
#如果要 script tag
|
|
|
2567 |
if($conf["noScriptTag"]==="false"){
|
|
|
2568 |
|
|
|
2569 |
#函式說明:
|
|
|
2570 |
#script 語法開始
|
|
|
2571 |
#回傳結果:
|
|
|
2572 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
2573 |
#$result["error"],錯誤訊息陣列
|
|
|
2574 |
#$result["function"],當前執行的函數名稱
|
|
|
2575 |
#$result["content"],javaScript語法
|
|
|
2576 |
#必填參數:
|
|
|
2577 |
#$conf["include"],字串,是否要匯入外部js庫,"true"爲要匯入;"false"爲沒有要匯入。
|
|
|
2578 |
$conf["javaScript::start"]["include"]="true";
|
|
|
2579 |
#可省略參數:
|
|
|
2580 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑,請與參數"jsPosition"一起設置,預設為當前檔案的位置.
|
|
|
2581 |
#$conf["fileArgu"]=__FILE__;
|
|
|
2582 |
#$conf["jsPosition"],字串,要匯入的js檔案位置,請與參數"fileArgu"一起設置.
|
|
|
2583 |
$conf["javaScript::start"]["jsPosition"]=$conf["jsPosition"];
|
|
|
2584 |
#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,於設為"true".
|
|
|
2585 |
#$conf["userDir"]="true";
|
|
|
2586 |
$start=javaScript::start($conf["javaScript::start"]);
|
|
|
2587 |
unset($conf["javaScript::start"]);
|
|
|
2588 |
|
|
|
2589 |
#如果建立匯入js的語法失敗
|
|
|
2590 |
if($start["status"]=="false"){
|
|
|
2591 |
|
|
|
2592 |
#設置錯誤狀態
|
|
|
2593 |
$result["status"]="false";
|
|
|
2594 |
|
|
|
2595 |
#設置錯誤提示
|
|
|
2596 |
$result["error"]=$start;
|
|
|
2597 |
|
|
|
2598 |
#回傳結果
|
|
|
2599 |
return $result;
|
|
|
2600 |
|
|
|
2601 |
}#if end
|
|
|
2602 |
|
|
|
2603 |
#反之
|
|
|
2604 |
else{
|
|
|
2605 |
|
|
|
2606 |
#取得匯入js的語法
|
|
|
2607 |
$result["content"]=$result["content"].$start["content"];
|
|
|
2608 |
|
|
|
2609 |
}#else end
|
|
|
2610 |
|
|
|
2611 |
#$conf["jsProgramSection"] 有幾個元素就執行幾次
|
|
|
2612 |
foreach($conf["jsProgramSection"] as $script){
|
|
|
2613 |
|
|
|
2614 |
#換行,然後加上script程式
|
|
|
2615 |
$result["content"]=$result["content"]."\r\n".$script;
|
|
|
2616 |
|
|
|
2617 |
}#foreach end
|
|
|
2618 |
|
|
|
2619 |
#script結束
|
|
|
2620 |
#函式說明:
|
|
|
2621 |
#script 語法結束
|
|
|
2622 |
#回傳結果:
|
|
|
2623 |
#javaScript語法
|
|
|
2624 |
$result["content"]=$result["content"]."\r\n".javaScript::end();
|
|
|
2625 |
|
|
|
2626 |
}#if end
|
|
|
2627 |
|
|
|
2628 |
#反之不要 script tag
|
|
|
2629 |
else{
|
|
|
2630 |
|
|
|
2631 |
#$conf["jsProgramSection"] 有幾個元素就執行幾次
|
|
|
2632 |
foreach($conf["jsProgramSection"] as $script){
|
|
|
2633 |
|
|
|
2634 |
#換行,然後加上script程式
|
|
|
2635 |
$result["content"]=$result["content"]."\r\n".$script;
|
|
|
2636 |
|
|
|
2637 |
}#foreach end
|
|
|
2638 |
|
|
|
2639 |
}#else end
|
|
|
2640 |
|
|
|
2641 |
#設置執行正常
|
|
|
2642 |
$result["status"]="true";
|
|
|
2643 |
|
|
|
2644 |
#回傳結果
|
|
|
2645 |
return $result;
|
|
|
2646 |
|
|
|
2647 |
}#function addScriptTag end
|
|
|
2648 |
|
|
|
2649 |
/*
|
|
|
2650 |
#函式說明:
|
|
|
2651 |
#匯入js檔案
|
|
|
2652 |
#回傳結果:
|
|
|
2653 |
#$result["status"],字串,執行否正常,"true"代表正常,"false"代表不正常.
|
|
|
2654 |
#$result["functin"],字串,當前函數的名稱.
|
|
|
2655 |
#$result["error"],陣列,錯訊訊息.
|
|
|
2656 |
#$result["argu"],陣列,使用的參數.
|
|
|
2657 |
#$result["content"],字串,匯入js的語法.
|
|
|
2658 |
#必填參數:
|
|
|
2659 |
#$conf["jsFileLocation"],陣列字串,多個js檔案的位置與名稱,每個元素代表一個js檔案的位置,js副檔名會自動補上.
|
|
|
2660 |
$conf["jsFileLocation"]=array("");
|
|
|
2661 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
|
|
|
2662 |
$conf["fileArgu"]=__FILE__;
|
|
|
2663 |
#可省略參數:
|
|
|
2664 |
#$conf["web"],字串,true代表是網頁系統的位置,"false"代表是檔案系統的位置,預設為"true".
|
|
|
2665 |
#$conf["web"]="true";
|
|
|
2666 |
#參考資料:
|
|
|
2667 |
#php預設常數=>http://php.net/manual/zh/language.constants.predefined.php
|
|
|
2668 |
#備註:
|
|
|
2669 |
#無.
|
|
|
2670 |
*/
|
|
|
2671 |
public static function import(&$conf){
|
|
|
2672 |
|
|
|
2673 |
#初始化要回傳的內容
|
|
|
2674 |
$result=array();
|
|
|
2675 |
|
|
|
2676 |
#設置當前執行的函數
|
|
|
2677 |
$result["function"]=__FUNCTION__;
|
|
|
2678 |
|
|
|
2679 |
#如果 $conf 不為陣列
|
|
|
2680 |
if(gettype($conf)!="array"){
|
|
|
2681 |
|
|
|
2682 |
#設置執行失敗
|
|
|
2683 |
$result["status"]="false";
|
|
|
2684 |
|
|
|
2685 |
#設置執行錯誤訊息
|
|
|
2686 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
2687 |
|
|
|
2688 |
#如果傳入的參數為 null
|
|
|
2689 |
if($conf==null){
|
|
|
2690 |
|
|
|
2691 |
#設置執行錯誤訊息
|
|
|
2692 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
2693 |
|
|
|
2694 |
}#if end
|
|
|
2695 |
|
|
|
2696 |
#回傳結果
|
|
|
2697 |
return $result;
|
|
|
2698 |
|
|
|
2699 |
}#if end
|
|
|
2700 |
|
|
|
2701 |
#取得參數
|
|
|
2702 |
$result["argv"]=$conf;
|
|
|
2703 |
|
|
|
2704 |
#檢查參數
|
|
|
2705 |
#函式說明:
|
|
|
2706 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
2707 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2708 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2709 |
#$result["function"],當前執行的函式名稱.
|
|
|
2710 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
2711 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
2712 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
2713 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
2714 |
#必填參數:
|
|
|
2715 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
2716 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
2717 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
2718 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("jsFileLocation","fileArgu");
|
|
|
2719 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
|
|
2720 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string");
|
|
|
2721 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
2722 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
2723 |
#可以省略的參數:
|
|
|
2724 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
2725 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="true";
|
|
|
2726 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
2727 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("web");
|
|
|
2728 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
2729 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
2730 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
2731 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true");
|
|
|
2732 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
2733 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
2734 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
2735 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
2736 |
|
|
|
2737 |
#如果檢查失敗
|
|
|
2738 |
if($checkResult["status"]=="false"){
|
|
|
2739 |
|
|
|
2740 |
#設置執行不正常
|
|
|
2741 |
$result["status"]="false";
|
|
|
2742 |
|
|
|
2743 |
#設置錯誤訊息
|
|
|
2744 |
$result["error"]=$checkResult;
|
|
|
2745 |
|
|
|
2746 |
#回傳結果
|
|
|
2747 |
return $result;
|
|
|
2748 |
|
|
|
2749 |
}#if end
|
|
|
2750 |
|
|
|
2751 |
#如果檢查不通過
|
|
|
2752 |
if($checkResult["passed"]=="false"){
|
|
|
2753 |
|
|
|
2754 |
#設置執行不正常
|
|
|
2755 |
$result["status"]="false";
|
|
|
2756 |
|
|
|
2757 |
#設置錯誤訊息
|
|
|
2758 |
$result["error"]=$checkResult;
|
|
|
2759 |
|
|
|
2760 |
#回傳結果
|
|
|
2761 |
return $result;
|
|
|
2762 |
|
|
|
2763 |
}#if end
|
|
|
2764 |
|
|
|
2765 |
#初始化匯入js檔案的語法
|
|
|
2766 |
$result["content"]="";
|
|
|
2767 |
|
|
|
2768 |
#針對每個要匯入的javaScript樣式
|
|
|
2769 |
foreach($conf["jsFileLocation"] as $jsLocation){
|
|
|
2770 |
|
|
|
2771 |
#補上 js 副檔名
|
|
|
2772 |
$jsLocation=$jsLocation.".js";
|
|
|
2773 |
|
|
|
2774 |
#取得網頁位置
|
|
|
2775 |
#函式說明:
|
|
|
2776 |
#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
|
|
|
2777 |
#回傳結果:
|
|
|
2778 |
#$result["status"],"true"爲建立成功,"false"爲建立失敗.
|
|
|
2779 |
#$result["error"],錯誤訊息陣列.
|
| 226 |
liveuser |
2780 |
#$result["function"],函數名稱.
|
| 3 |
liveuser |
2781 |
#$result["argu"],使用的參數.
|
|
|
2782 |
#$result["content"],網址,若是在命令列執行,則為"null".
|
|
|
2783 |
#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
|
|
|
2784 |
#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
|
|
|
2785 |
#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
|
|
|
2786 |
#必填參數:
|
|
|
2787 |
#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
|
|
|
2788 |
$conf["fileAccess::getInternetAddressV2"]["address"]=$jsLocation;
|
|
|
2789 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
|
|
|
2790 |
$conf["fileAccess::getInternetAddressV2"]["fileArgu"]=$conf["fileArgu"];
|
|
|
2791 |
#可省略參數:
|
|
|
2792 |
#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
|
|
|
2793 |
$conf["fileAccess::getInternetAddressV2"]["web"]=$conf["web"];
|
|
|
2794 |
#備註:
|
|
|
2795 |
#建構中,fileSystemRelativePosition尚未實作,檢查參數尚未實作.
|
|
|
2796 |
$getInternetAddressV2=fileAccess::getInternetAddressV2($conf["fileAccess::getInternetAddressV2"]);
|
|
|
2797 |
unset($conf["fileAccess::getInternetAddressV2"]);
|
|
|
2798 |
|
|
|
2799 |
#如果執行失敗
|
|
|
2800 |
if($getInternetAddressV2["status"]==="false"){
|
| 226 |
liveuser |
2801 |
|
| 3 |
liveuser |
2802 |
#設置執行不正常
|
|
|
2803 |
$result["status"]="false";
|
|
|
2804 |
|
|
|
2805 |
#設置錯誤訊息
|
|
|
2806 |
$result["error"]=$getInternetAddressV2;
|
|
|
2807 |
|
|
|
2808 |
#回傳結果
|
|
|
2809 |
return $result;
|
| 226 |
liveuser |
2810 |
|
| 3 |
liveuser |
2811 |
}#if end
|
| 226 |
liveuser |
2812 |
|
|
|
2813 |
#取得網頁位置
|
| 3 |
liveuser |
2814 |
$jsLocation=$getInternetAddressV2["content"];
|
|
|
2815 |
|
|
|
2816 |
#var_dump($jsLocation);
|
|
|
2817 |
|
|
|
2818 |
#函式說明:
|
|
|
2819 |
#script 語法開始
|
|
|
2820 |
#回傳結果:
|
|
|
2821 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
2822 |
#$result["error"],錯誤訊息陣列
|
|
|
2823 |
#$result["function"],當前執行的函數名稱
|
|
|
2824 |
#$result["content"],javaScript語法
|
|
|
2825 |
#必填參數:
|
|
|
2826 |
$conf["javaScript::start"]["include"]="true";#是否要匯入外部js庫。"true"爲要匯入;"false"爲沒有要匯入。
|
|
|
2827 |
#可省略參數:
|
|
|
2828 |
$conf["javaScript::start"]["jsPosition"]=$jsLocation;#要匯入的js檔案位置。
|
|
|
2829 |
#$conf["javaScript::start"]["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
|
|
|
2830 |
$conf["javaScript::start"]["fileArgu"]=$conf["fileArgu"];
|
|
|
2831 |
#$conf["javaScript::start"]["web"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,於設為"true".
|
|
|
2832 |
$conf["javaScript::start"]["web"]=$conf["web"];
|
|
|
2833 |
$start=javaScript::start($conf["javaScript::start"]);
|
|
|
2834 |
unset($conf["javaScript::start"]);
|
|
|
2835 |
|
|
|
2836 |
#如果script語法開始失敗
|
|
|
2837 |
if($start["status"]=="false"){
|
|
|
2838 |
|
|
|
2839 |
#設置執行不正常
|
|
|
2840 |
$result["status"]="false";
|
|
|
2841 |
|
|
|
2842 |
#設置錯誤訊息
|
|
|
2843 |
$result["error"]=$start;
|
|
|
2844 |
|
|
|
2845 |
#回傳結果
|
|
|
2846 |
return $result;
|
|
|
2847 |
|
|
|
2848 |
}#if end
|
|
|
2849 |
|
|
|
2850 |
#串接每個要匯入js檔案的語法
|
|
|
2851 |
$result["content"]=$result["content"].$start["content"].javaScript::end();
|
|
|
2852 |
|
|
|
2853 |
}#foreach end
|
|
|
2854 |
|
|
|
2855 |
#設置執行正常
|
|
|
2856 |
$result["status"]="true";
|
|
|
2857 |
|
|
|
2858 |
#回傳結果
|
|
|
2859 |
return $result;
|
|
|
2860 |
|
|
|
2861 |
}#function import end
|
|
|
2862 |
|
|
|
2863 |
/*
|
|
|
2864 |
#函式說明:
|
|
|
2865 |
#將要執行的script語法透過該函式執行(會在程式外層用<script></script>包起來).
|
|
|
2866 |
#回傳結果:
|
|
|
2867 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
2868 |
#$result["error"],錯誤訊息陣列
|
|
|
2869 |
#$result["function"],當前執行的函數名稱
|
|
|
2870 |
#$result["content"],要執行的javaScript語法
|
|
|
2871 |
#必填參數:
|
|
|
2872 |
#$conf["script"],字串,要執行的javaScript語法.
|
|
|
2873 |
$conf["script"]="";
|
|
|
2874 |
#可省略參數:
|
|
|
2875 |
#$conf["onReady"],字串,是否要在網頁完全載入後再執行,"false"為不等載入完就先執行,預設為"true"要等載入完再執行.
|
|
|
2876 |
#$conf["onReady"]="true";
|
|
|
2877 |
#$conf["globalJs"],字串陣列,為要放入<script>標籤的js全域變數.
|
|
|
2878 |
#$conf["globalJs"]=array();
|
|
|
2879 |
#$conf["jsFunciton"],字串陣列,為要放入<script>標籤的js函數.
|
|
|
2880 |
#$conf["jsFunciton"]=array();
|
|
|
2881 |
#$conf["noScriptTag"],字串,是否不要輸出<script></script>,預設為"false",代表要輸出;反之為"true",代表不要輸出.
|
|
|
2882 |
#$conf["noScriptTag"]="false";
|
|
|
2883 |
#參考資料:
|
|
|
2884 |
#http://stackoverflow.com/questions/9899372/pure-javascript-equivalent-to-jquerys-ready-how-to-call-a-function-when-the
|
|
|
2885 |
#備註:
|
|
|
2886 |
#無.
|
|
|
2887 |
*/
|
|
|
2888 |
public static function toScript(&$conf){
|
|
|
2889 |
|
|
|
2890 |
#初始化要回傳的變數
|
|
|
2891 |
$result=array();
|
|
|
2892 |
|
|
|
2893 |
#初始化javaScript語法
|
|
|
2894 |
$result["content"]="";
|
|
|
2895 |
|
|
|
2896 |
#記錄當前執行的函數名稱
|
|
|
2897 |
$result["function"]=__FUNCTION__;
|
|
|
2898 |
|
|
|
2899 |
#如果 $conf 不為陣列
|
|
|
2900 |
if(gettype($conf)!="array"){
|
|
|
2901 |
|
|
|
2902 |
#設置執行失敗
|
|
|
2903 |
$result["status"]="false";
|
|
|
2904 |
|
|
|
2905 |
#設置執行錯誤訊息
|
|
|
2906 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
2907 |
|
|
|
2908 |
#如果傳入的參數為 null
|
|
|
2909 |
if($conf==null){
|
|
|
2910 |
|
|
|
2911 |
#設置執行錯誤訊息
|
|
|
2912 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
2913 |
|
|
|
2914 |
}#if end
|
|
|
2915 |
|
|
|
2916 |
#回傳結果
|
|
|
2917 |
return $result;
|
|
|
2918 |
|
|
|
2919 |
}#if end
|
|
|
2920 |
|
|
|
2921 |
#檢查參數
|
|
|
2922 |
#函式說明:
|
|
|
2923 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
2924 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2925 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2926 |
#$result["function"],當前執行的函式名稱.
|
|
|
2927 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
2928 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
2929 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
2930 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
2931 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
2932 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
2933 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
2934 |
#必填參數:
|
|
|
2935 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
2936 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
2937 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
2938 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("script");
|
|
|
2939 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
|
|
2940 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
2941 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
2942 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
2943 |
#可以省略的參數:
|
|
|
2944 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
2945 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="true";
|
|
|
2946 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
2947 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("onReady","jsFunciton","globalJs","noScriptTag");
|
|
|
2948 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
2949 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","array","array","string");
|
|
|
2950 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
2951 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true",null,null,"false");
|
|
|
2952 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
2953 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
|
|
|
2954 |
#參考資料來源:
|
|
|
2955 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
2956 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
2957 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
2958 |
|
|
|
2959 |
#如果檢查失敗
|
|
|
2960 |
if($checkResult["status"]=="false"){
|
|
|
2961 |
|
|
|
2962 |
#設置錯誤狀態
|
|
|
2963 |
$result["status"]="false";
|
|
|
2964 |
|
|
|
2965 |
#設置錯誤提示
|
|
|
2966 |
$result["error"]=$checkResult;
|
|
|
2967 |
|
|
|
2968 |
#回傳結果
|
|
|
2969 |
return $result;
|
|
|
2970 |
|
|
|
2971 |
}#if end
|
|
|
2972 |
|
|
|
2973 |
#如果檢查不通過
|
|
|
2974 |
if($checkResult["passed"]=="false"){
|
|
|
2975 |
|
|
|
2976 |
#設置錯誤狀態
|
|
|
2977 |
$result["status"]="false";
|
|
|
2978 |
|
|
|
2979 |
#設置錯誤提示
|
|
|
2980 |
$result["error"]=$checkResult;
|
|
|
2981 |
|
|
|
2982 |
#回傳結果
|
|
|
2983 |
return $result;
|
|
|
2984 |
|
|
|
2985 |
}#if end
|
|
|
2986 |
|
|
|
2987 |
#如果不要script標籤
|
|
|
2988 |
if($conf["noScriptTag"]==="true"){
|
| 226 |
liveuser |
2989 |
|
| 3 |
liveuser |
2990 |
#如果存在 $conf["globalJs"]
|
|
|
2991 |
if(isset($conf["globalJs"])){
|
| 226 |
liveuser |
2992 |
|
| 3 |
liveuser |
2993 |
#針對每個全域js
|
|
|
2994 |
foreach($conf["globalJs"] as $jsSection){
|
| 226 |
liveuser |
2995 |
|
| 3 |
liveuser |
2996 |
#取得javaScript開始的語法
|
|
|
2997 |
$result["content"]=$result["content"].$jsSection;
|
| 226 |
liveuser |
2998 |
|
| 3 |
liveuser |
2999 |
}#foreach end
|
| 226 |
liveuser |
3000 |
|
| 3 |
liveuser |
3001 |
}#if end
|
| 226 |
liveuser |
3002 |
|
| 3 |
liveuser |
3003 |
#如果存在 $conf["jsFunciton"]
|
|
|
3004 |
if(isset($conf["jsFunciton"])){
|
| 226 |
liveuser |
3005 |
|
| 3 |
liveuser |
3006 |
#針對每個js函式
|
|
|
3007 |
foreach($conf["jsFunciton"] as $jsSection){
|
| 226 |
liveuser |
3008 |
|
| 3 |
liveuser |
3009 |
#取得javaScript開始的語法
|
|
|
3010 |
$result["content"]=$result["content"].$jsSection;
|
| 226 |
liveuser |
3011 |
|
| 3 |
liveuser |
3012 |
}#foreach end
|
| 226 |
liveuser |
3013 |
|
| 3 |
liveuser |
3014 |
}#if end
|
| 226 |
liveuser |
3015 |
|
| 3 |
liveuser |
3016 |
#如果 $conf["onReady"] 為 "true"
|
|
|
3017 |
if($conf["onReady"]==="true"){
|
|
|
3018 |
|
|
|
3019 |
#用ready條件包住要執行的script內容
|
|
|
3020 |
$conf["script"]=
|
|
|
3021 |
"
|
|
|
3022 |
//run in last
|
|
|
3023 |
window.addEventListener('load',async function(event){
|
|
|
3024 |
//console.log('All resources finished loading!');
|
|
|
3025 |
".$conf["script"]."
|
|
|
3026 |
});
|
|
|
3027 |
";
|
|
|
3028 |
|
|
|
3029 |
#串接要執行的script
|
|
|
3030 |
$result["content"]=$result["content"].$conf["script"];
|
|
|
3031 |
|
|
|
3032 |
}#if end
|
| 226 |
liveuser |
3033 |
|
| 3 |
liveuser |
3034 |
}#if end
|
| 226 |
liveuser |
3035 |
|
| 3 |
liveuser |
3036 |
#反之
|
|
|
3037 |
else{
|
| 226 |
liveuser |
3038 |
|
| 3 |
liveuser |
3039 |
#javaScript開始
|
|
|
3040 |
$conf["javaScript"]["start"]["include"]="false";#是否要匯入外部js庫。"true"爲要匯入;"false"爲沒有要匯入。
|
|
|
3041 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑,請與參數"jsPosition"一起設置.
|
|
|
3042 |
#$conf["javaScript"]["start"]["fileArgu"]=$conf["fileArgu"];
|
|
|
3043 |
$javaScriptStart=javaScript::start($conf["javaScript"]["start"]);
|
|
|
3044 |
unset($conf["javaScript"]["start"]);
|
|
|
3045 |
|
|
|
3046 |
#如果 javaScript 開始失敗
|
|
|
3047 |
if($javaScriptStart["status"]=="false"){
|
|
|
3048 |
|
|
|
3049 |
#設置錯誤狀態
|
|
|
3050 |
$result["status"]="false";
|
|
|
3051 |
|
|
|
3052 |
#設置錯誤提示
|
|
|
3053 |
$result["error"]=$javaScriptStart;
|
|
|
3054 |
|
|
|
3055 |
#回傳結果
|
|
|
3056 |
return $result;
|
|
|
3057 |
|
|
|
3058 |
}#if end
|
|
|
3059 |
|
|
|
3060 |
#取得javaScript開始的語法
|
|
|
3061 |
$result["content"]=$result["content"].$javaScriptStart["content"];
|
|
|
3062 |
|
|
|
3063 |
#如果存在 $conf["globalJs"]
|
|
|
3064 |
if(isset($conf["globalJs"])){
|
|
|
3065 |
|
|
|
3066 |
#針對每個要放置的js全域變數宣告
|
|
|
3067 |
foreach($conf["globalJs"] as $gloJs){
|
|
|
3068 |
|
|
|
3069 |
#串接js全域變數宣告
|
|
|
3070 |
$result["content"]=$result["content"].$gloJs;
|
|
|
3071 |
|
|
|
3072 |
}#foreach end
|
|
|
3073 |
|
|
|
3074 |
}#if end
|
|
|
3075 |
|
|
|
3076 |
#如果存在 $conf["jsFunciton"]
|
|
|
3077 |
if(isset($conf["jsFunciton"])){
|
|
|
3078 |
|
|
|
3079 |
#針對每個要放置的js函數
|
|
|
3080 |
foreach($conf["jsFunciton"] as $jsFunc){
|
|
|
3081 |
|
|
|
3082 |
#串接js函數
|
|
|
3083 |
$result["content"]=$result["content"].$jsFunc;
|
|
|
3084 |
|
|
|
3085 |
}#foreach end
|
|
|
3086 |
|
|
|
3087 |
}#if end
|
| 226 |
liveuser |
3088 |
|
| 3 |
liveuser |
3089 |
#如果 $conf["onReady"] 為 "true"
|
|
|
3090 |
if($conf["onReady"]==="true"){
|
|
|
3091 |
|
|
|
3092 |
#用ready條件包住要執行的script內容
|
|
|
3093 |
$conf["script"]=
|
|
|
3094 |
"
|
|
|
3095 |
//run in last
|
|
|
3096 |
window.addEventListener('load',async function(event){
|
|
|
3097 |
//console.log('All resources finished loading!');
|
|
|
3098 |
".$conf["script"]."
|
|
|
3099 |
});
|
|
|
3100 |
";
|
|
|
3101 |
|
|
|
3102 |
#串接要執行的script
|
|
|
3103 |
$result["content"]=$result["content"].$conf["script"];
|
|
|
3104 |
|
|
|
3105 |
}#if end
|
|
|
3106 |
|
|
|
3107 |
#反之
|
|
|
3108 |
else{
|
|
|
3109 |
|
|
|
3110 |
#串接要執行的script
|
|
|
3111 |
$result["content"]=$result["content"].$conf["script"];
|
|
|
3112 |
|
|
|
3113 |
}#elsd end
|
|
|
3114 |
|
|
|
3115 |
#串接 <script>
|
|
|
3116 |
$result["content"]=$result["content"].javaScript::end();
|
| 226 |
liveuser |
3117 |
|
| 3 |
liveuser |
3118 |
}#else end
|
|
|
3119 |
|
|
|
3120 |
#設置執行正常
|
|
|
3121 |
$result["status"]="true";
|
|
|
3122 |
|
|
|
3123 |
#回傳結果
|
|
|
3124 |
return $result;
|
|
|
3125 |
|
|
|
3126 |
}#function toScript end
|
|
|
3127 |
|
|
|
3128 |
/*
|
|
|
3129 |
#函式說明:
|
|
|
3130 |
#測試 webStorage 是否有支援,若印出'Web Storage supported'則代表有支援;若為'Sorry! No Web Storage support..'則代表不支援.
|
|
|
3131 |
#回傳結果:
|
|
|
3132 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
3133 |
#$result["error"],錯誤訊息陣列
|
|
|
3134 |
#$result["function"],當前執行的函數名稱
|
|
|
3135 |
#$result["content"],要執行的javaScript語法
|
|
|
3136 |
#必填參數:
|
|
|
3137 |
#無.
|
|
|
3138 |
#可省略參數:
|
|
|
3139 |
#無.
|
|
|
3140 |
#參考資料:
|
|
|
3141 |
#無.
|
|
|
3142 |
#備註:
|
|
|
3143 |
#無.
|
|
|
3144 |
*/
|
|
|
3145 |
public static function localStorageTest(){
|
|
|
3146 |
|
|
|
3147 |
#初始化要回傳的變數
|
|
|
3148 |
$result=array();
|
|
|
3149 |
|
|
|
3150 |
#記錄當前執行的函數名稱
|
|
|
3151 |
$result["function"]=__FUNCTION__;
|
|
|
3152 |
|
|
|
3153 |
#測試 web storage js
|
|
|
3154 |
$jsStr="
|
|
|
3155 |
if(typeof(Storage) !== undefined){
|
|
|
3156 |
// Code for localStorage/sessionStorage.
|
|
|
3157 |
document.write('Web Storage supported');
|
|
|
3158 |
}
|
|
|
3159 |
else{
|
|
|
3160 |
document.write('Sorry! No Web Storage support..');
|
|
|
3161 |
}";
|
|
|
3162 |
|
|
|
3163 |
#函式說明:
|
|
|
3164 |
#將要執行的script語法透過該函式執行
|
|
|
3165 |
#回傳結果:
|
|
|
3166 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
3167 |
#$result["error"],錯誤訊息陣列
|
|
|
3168 |
#$result["function"],當前執行的函數名稱
|
|
|
3169 |
#$result["content"],要執行的javaScript語法
|
|
|
3170 |
#必填參數:
|
|
|
3171 |
#$conf["script"],字串,要執行的javaScript語法,標籤「<script></script>」會自動補上.
|
|
|
3172 |
$conf["javaScript::toScript"]["script"]=$jsStr;
|
|
|
3173 |
$toScript=javaScript::toScript($conf["javaScript::toScript"]);
|
|
|
3174 |
unset($conf["javaScript::toScript"]);
|
|
|
3175 |
|
|
|
3176 |
#如果轉換成js語法失敗
|
|
|
3177 |
if($toScript["status"]==="false"){
|
|
|
3178 |
|
|
|
3179 |
#設置錯誤狀態
|
|
|
3180 |
$result["status"]="false";
|
|
|
3181 |
|
|
|
3182 |
#設置錯誤提示
|
|
|
3183 |
$result["error"]=$toScript;
|
|
|
3184 |
|
|
|
3185 |
#回傳結果
|
|
|
3186 |
return $result;
|
|
|
3187 |
|
|
|
3188 |
}#if end
|
|
|
3189 |
|
|
|
3190 |
#取得js語法
|
|
|
3191 |
$result["content"]=$toScript["content"];
|
|
|
3192 |
|
|
|
3193 |
#設置執行正常
|
|
|
3194 |
$result["status"]="true";
|
|
|
3195 |
|
|
|
3196 |
#回傳結果
|
|
|
3197 |
return $result;
|
|
|
3198 |
|
|
|
3199 |
}#function webStorageTest end
|
|
|
3200 |
|
|
|
3201 |
/*
|
|
|
3202 |
#函式說明:
|
|
|
3203 |
#儲存變數到local storage
|
|
|
3204 |
#回傳結果:
|
|
|
3205 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
3206 |
#$result["error"],錯誤訊息陣列
|
|
|
3207 |
#$result["function"],當前執行的函數名稱
|
|
|
3208 |
#$result["content"],要執行的javaScript語法
|
|
|
3209 |
#必填參數:
|
|
|
3210 |
#$conf["key"],字串,要儲存的key為何.
|
|
|
3211 |
$conf["key"]="";
|
|
|
3212 |
#$conf["val"],字串,要儲存的val為何.
|
|
|
3213 |
$conf["val"]="";
|
|
|
3214 |
#可省略參數:
|
|
|
3215 |
#$conf["json"],字串,要儲存的內容是否為json,亦即javascript的物件,"true"代表是,會將$conf["val"]用json_encode函數處理;"false"代表不是,預設為"false".
|
|
|
3216 |
#$conf["json"]="";
|
|
|
3217 |
#$conf["noScriptTag"],字串,是否不要用script tag包住回傳的內容($result["content"]),"true"代表不要用,"false"代表要用,預設為"false".
|
|
|
3218 |
#$conf["noScriptTag"]="false";
|
|
|
3219 |
#參考資料:
|
|
|
3220 |
#無.
|
|
|
3221 |
#備註:
|
|
|
3222 |
#無.
|
|
|
3223 |
*/
|
|
|
3224 |
public static function saveToLocalStorage(&$conf){
|
|
|
3225 |
|
|
|
3226 |
#初始化要回傳的結果
|
|
|
3227 |
$result=array();
|
|
|
3228 |
|
|
|
3229 |
#取得當前執行的函數名稱
|
|
|
3230 |
$result["function"]=__FUNCTION__;
|
|
|
3231 |
|
|
|
3232 |
#如果沒有參數
|
|
|
3233 |
if(func_num_args()==0){
|
|
|
3234 |
|
|
|
3235 |
#設置執行失敗
|
|
|
3236 |
$result["status"]="false";
|
|
|
3237 |
|
|
|
3238 |
#設置執行錯誤訊息
|
|
|
3239 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
3240 |
|
|
|
3241 |
#回傳結果
|
|
|
3242 |
return $result;
|
|
|
3243 |
|
|
|
3244 |
}#if end
|
|
|
3245 |
|
|
|
3246 |
#取得參數
|
|
|
3247 |
$result["argu"]=$conf;
|
|
|
3248 |
|
|
|
3249 |
#如果 $conf 不為陣列
|
|
|
3250 |
if(gettype($conf)!="array"){
|
|
|
3251 |
|
|
|
3252 |
#設置執行失敗
|
|
|
3253 |
$result["status"]="false";
|
|
|
3254 |
|
|
|
3255 |
#設置執行錯誤訊息
|
|
|
3256 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
3257 |
|
|
|
3258 |
#如果傳入的參數為 null
|
|
|
3259 |
if($conf==null){
|
|
|
3260 |
|
|
|
3261 |
#設置執行錯誤訊息
|
|
|
3262 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
3263 |
|
|
|
3264 |
}#if end
|
|
|
3265 |
|
|
|
3266 |
#回傳結果
|
|
|
3267 |
return $result;
|
|
|
3268 |
|
|
|
3269 |
}#if end
|
|
|
3270 |
|
|
|
3271 |
#檢查參數
|
|
|
3272 |
#函式說明:
|
|
|
3273 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
3274 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3275 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
3276 |
#$result["function"],當前執行的函式名稱.
|
|
|
3277 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
3278 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
3279 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
3280 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
3281 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
3282 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
3283 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
3284 |
#必填參數:
|
|
|
3285 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
3286 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
3287 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
3288 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("key","val");
|
|
|
3289 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
|
|
3290 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
3291 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
3292 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
3293 |
#可以省略的參數:
|
|
|
3294 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
3295 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="true";
|
|
|
3296 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
3297 |
$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("key");
|
|
|
3298 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
3299 |
#$conf["canBeEmpty"]=array();
|
|
|
3300 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
3301 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("json","noScriptTag");
|
|
|
3302 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
3303 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
|
|
|
3304 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
3305 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","false");
|
|
|
3306 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
3307 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
|
|
|
3308 |
#參考資料來源:
|
|
|
3309 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
3310 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
3311 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
3312 |
|
|
|
3313 |
#如果檢查失敗
|
|
|
3314 |
if($checkResult["status"]=="false"){
|
|
|
3315 |
|
|
|
3316 |
#設置錯誤狀態
|
|
|
3317 |
$result["status"]="false";
|
|
|
3318 |
|
|
|
3319 |
#設置錯誤提示
|
|
|
3320 |
$result["error"]=$checkResult;
|
|
|
3321 |
|
|
|
3322 |
#回傳結果
|
|
|
3323 |
return $result;
|
|
|
3324 |
|
|
|
3325 |
}#if end
|
|
|
3326 |
|
|
|
3327 |
#如果檢查不通過
|
|
|
3328 |
if($checkResult["passed"]=="false"){
|
|
|
3329 |
|
|
|
3330 |
#設置錯誤狀態
|
|
|
3331 |
$result["status"]="false";
|
|
|
3332 |
|
|
|
3333 |
#設置錯誤提示
|
|
|
3334 |
$result["error"]=$checkResult;
|
|
|
3335 |
|
|
|
3336 |
#回傳結果
|
|
|
3337 |
return $result;
|
|
|
3338 |
|
|
|
3339 |
}#if end
|
|
|
3340 |
|
|
|
3341 |
#如果要轉成json字串
|
|
|
3342 |
if($conf["json"]==="true"){
|
|
|
3343 |
|
|
|
3344 |
#javascript 字串
|
|
|
3345 |
$jsStr="localStorage.".$conf["key"]." = '".json_encode($conf["val"])."';";
|
|
|
3346 |
|
|
|
3347 |
}#if end
|
|
|
3348 |
|
|
|
3349 |
#反之不用轉換
|
|
|
3350 |
else{
|
|
|
3351 |
|
|
|
3352 |
#javascript 字串
|
|
|
3353 |
$jsStr="localStorage.".$conf["key"]." = '".$conf["val"]."';";
|
|
|
3354 |
|
|
|
3355 |
}#else end
|
|
|
3356 |
|
|
|
3357 |
#如果要 script tag
|
|
|
3358 |
if($conf["noScriptTag"]=="false"){
|
|
|
3359 |
|
|
|
3360 |
#函式說明:
|
|
|
3361 |
#將要執行的script語法透過該函式執行
|
|
|
3362 |
#回傳結果:
|
|
|
3363 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
3364 |
#$result["error"],錯誤訊息陣列
|
|
|
3365 |
#$result["function"],當前執行的函數名稱
|
|
|
3366 |
#$result["content"],要執行的javaScript語法
|
|
|
3367 |
#必填參數:
|
|
|
3368 |
#$conf["script"],字串,要執行的javaScript語法,標籤「<script></script>」會自動補上.
|
|
|
3369 |
$conf["javaScript::toScript"]["script"]=$jsStr;
|
|
|
3370 |
$toScript=javaScript::toScript($conf["javaScript::toScript"]);
|
|
|
3371 |
unset($conf["javaScript::toScript"]);
|
|
|
3372 |
|
|
|
3373 |
#如果轉換成js語法失敗
|
|
|
3374 |
if($toScript["status"]==="false"){
|
|
|
3375 |
|
|
|
3376 |
#設置錯誤狀態
|
|
|
3377 |
$result["status"]="false";
|
|
|
3378 |
|
|
|
3379 |
#設置錯誤提示
|
|
|
3380 |
$result["error"]=$toScript;
|
|
|
3381 |
|
|
|
3382 |
#回傳結果
|
|
|
3383 |
return $result;
|
|
|
3384 |
|
|
|
3385 |
}#if end
|
|
|
3386 |
|
|
|
3387 |
#取得js語法
|
|
|
3388 |
$result["content"]=$toScript["content"];
|
|
|
3389 |
|
|
|
3390 |
}#if end
|
|
|
3391 |
|
|
|
3392 |
#反之不要 script tag
|
|
|
3393 |
else{
|
|
|
3394 |
|
|
|
3395 |
#取得js語法
|
|
|
3396 |
$result["content"]=$jsStr;
|
|
|
3397 |
|
|
|
3398 |
}#else end
|
|
|
3399 |
|
|
|
3400 |
#設置執行正常
|
|
|
3401 |
$result["status"]="true";
|
|
|
3402 |
|
|
|
3403 |
#回傳結果
|
|
|
3404 |
return $result;
|
|
|
3405 |
|
|
|
3406 |
}#function saveToLocalStorage end
|
|
|
3407 |
|
|
|
3408 |
/*
|
|
|
3409 |
#函式說明:
|
|
|
3410 |
#儲存變數到session storage
|
|
|
3411 |
#回傳結果:
|
|
|
3412 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
3413 |
#$result["error"],錯誤訊息陣列
|
|
|
3414 |
#$result["function"],當前執行的函數名稱
|
|
|
3415 |
#$result["content"],要執行的javaScript語法
|
|
|
3416 |
#必填參數:
|
|
|
3417 |
#$conf["key"],字串,要儲存的key為何.
|
|
|
3418 |
$conf["key"]="";
|
|
|
3419 |
#$conf["val"],字串,要儲存的val為何.
|
|
|
3420 |
$conf["val"]="";
|
|
|
3421 |
#可省略參數:
|
|
|
3422 |
#$conf["json"],字串,要儲存的內容是否為json,亦即javascript的物件,"true"代表是,會將$conf["val"]用json_encode函數處理;"false"代表不是,預設為"false".
|
|
|
3423 |
#$conf["json"]="";
|
|
|
3424 |
#$conf["noScriptTag"],字串,是否不要用script tag包住回傳的內容($result["content"]),"true"代表不要用,"false"代表要用,預設為"false".
|
|
|
3425 |
#$conf["noScriptTag"]="false";
|
|
|
3426 |
#參考資料:
|
|
|
3427 |
#無.
|
|
|
3428 |
#備註:
|
|
|
3429 |
#無.
|
|
|
3430 |
*/
|
|
|
3431 |
public static function saveToSessionStorage(&$conf){
|
|
|
3432 |
|
|
|
3433 |
#初始化要回傳的結果
|
|
|
3434 |
$result=array();
|
|
|
3435 |
|
|
|
3436 |
#取得當前執行的函數名稱
|
|
|
3437 |
$result["function"]=__FUNCTION__;
|
|
|
3438 |
|
|
|
3439 |
#如果沒有參數
|
|
|
3440 |
if(func_num_args()==0){
|
|
|
3441 |
|
|
|
3442 |
#設置執行失敗
|
|
|
3443 |
$result["status"]="false";
|
|
|
3444 |
|
|
|
3445 |
#設置執行錯誤訊息
|
|
|
3446 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
3447 |
|
|
|
3448 |
#回傳結果
|
|
|
3449 |
return $result;
|
|
|
3450 |
|
|
|
3451 |
}#if end
|
|
|
3452 |
|
|
|
3453 |
#取得參數
|
|
|
3454 |
$result["argu"]=$conf;
|
|
|
3455 |
|
|
|
3456 |
#如果 $conf 不為陣列
|
|
|
3457 |
if(gettype($conf)!="array"){
|
|
|
3458 |
|
|
|
3459 |
#設置執行失敗
|
|
|
3460 |
$result["status"]="false";
|
|
|
3461 |
|
|
|
3462 |
#設置執行錯誤訊息
|
|
|
3463 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
3464 |
|
|
|
3465 |
#如果傳入的參數為 null
|
|
|
3466 |
if($conf==null){
|
|
|
3467 |
|
|
|
3468 |
#設置執行錯誤訊息
|
|
|
3469 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
3470 |
|
|
|
3471 |
}#if end
|
|
|
3472 |
|
|
|
3473 |
#回傳結果
|
|
|
3474 |
return $result;
|
|
|
3475 |
|
|
|
3476 |
}#if end
|
|
|
3477 |
|
|
|
3478 |
#檢查參數
|
|
|
3479 |
#函式說明:
|
|
|
3480 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
3481 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3482 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
3483 |
#$result["function"],當前執行的函式名稱.
|
|
|
3484 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
3485 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
3486 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
3487 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
3488 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
3489 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
3490 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
3491 |
#必填參數:
|
|
|
3492 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
3493 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
3494 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
3495 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("key","val");
|
|
|
3496 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
|
|
3497 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
3498 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
3499 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
3500 |
#可以省略的參數:
|
|
|
3501 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
3502 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="true";
|
|
|
3503 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
3504 |
$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("key");
|
|
|
3505 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
3506 |
#$conf["canBeEmpty"]=array();
|
|
|
3507 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
3508 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("json","noScriptTag");
|
|
|
3509 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
3510 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
|
|
|
3511 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
3512 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","false");
|
|
|
3513 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
3514 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
|
|
|
3515 |
#參考資料來源:
|
|
|
3516 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
3517 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
3518 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
3519 |
|
|
|
3520 |
#如果檢查失敗
|
|
|
3521 |
if($checkResult["status"]=="false"){
|
|
|
3522 |
|
|
|
3523 |
#設置錯誤狀態
|
|
|
3524 |
$result["status"]="false";
|
|
|
3525 |
|
|
|
3526 |
#設置錯誤提示
|
|
|
3527 |
$result["error"]=$checkResult;
|
|
|
3528 |
|
|
|
3529 |
#回傳結果
|
|
|
3530 |
return $result;
|
|
|
3531 |
|
|
|
3532 |
}#if end
|
|
|
3533 |
|
|
|
3534 |
#如果檢查不通過
|
|
|
3535 |
if($checkResult["passed"]=="false"){
|
|
|
3536 |
|
|
|
3537 |
#設置錯誤狀態
|
|
|
3538 |
$result["status"]="false";
|
|
|
3539 |
|
|
|
3540 |
#設置錯誤提示
|
|
|
3541 |
$result["error"]=$checkResult;
|
|
|
3542 |
|
|
|
3543 |
#回傳結果
|
|
|
3544 |
return $result;
|
|
|
3545 |
|
|
|
3546 |
}#if end
|
|
|
3547 |
|
|
|
3548 |
#如果要轉成json字串
|
|
|
3549 |
if($conf["json"]==="true"){
|
|
|
3550 |
|
|
|
3551 |
#javascript 字串
|
|
|
3552 |
$jsStr="sessionStorage.".$conf["key"]." = '".json_encode($conf["val"])."';";
|
|
|
3553 |
|
|
|
3554 |
}#if end
|
|
|
3555 |
|
|
|
3556 |
#反之不用轉換
|
|
|
3557 |
else{
|
|
|
3558 |
|
|
|
3559 |
#javascript 字串
|
|
|
3560 |
$jsStr="sessionStorage.".$conf["key"]." = '".$conf["val"]."';";
|
|
|
3561 |
|
|
|
3562 |
}#else end
|
|
|
3563 |
|
|
|
3564 |
#如果要 script tag
|
|
|
3565 |
if($conf["noScriptTag"]=="false"){
|
|
|
3566 |
|
|
|
3567 |
#函式說明:
|
|
|
3568 |
#將要執行的script語法透過該函式執行
|
|
|
3569 |
#回傳結果:
|
|
|
3570 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
3571 |
#$result["error"],錯誤訊息陣列
|
|
|
3572 |
#$result["function"],當前執行的函數名稱
|
|
|
3573 |
#$result["content"],要執行的javaScript語法
|
|
|
3574 |
#必填參數:
|
|
|
3575 |
#$conf["script"],字串,要執行的javaScript語法,標籤「<script></script>」會自動補上.
|
|
|
3576 |
$conf["javaScript::toScript"]["script"]=$jsStr;
|
|
|
3577 |
$toScript=javaScript::toScript($conf["javaScript::toScript"]);
|
|
|
3578 |
unset($conf["javaScript::toScript"]);
|
|
|
3579 |
|
|
|
3580 |
#如果轉換成js語法失敗
|
|
|
3581 |
if($toScript["status"]==="false"){
|
|
|
3582 |
|
|
|
3583 |
#設置錯誤狀態
|
|
|
3584 |
$result["status"]="false";
|
|
|
3585 |
|
|
|
3586 |
#設置錯誤提示
|
|
|
3587 |
$result["error"]=$toScript;
|
|
|
3588 |
|
|
|
3589 |
#回傳結果
|
|
|
3590 |
return $result;
|
|
|
3591 |
|
|
|
3592 |
}#if end
|
|
|
3593 |
|
|
|
3594 |
#取得js語法
|
|
|
3595 |
$result["content"]=$toScript["content"];
|
|
|
3596 |
|
|
|
3597 |
}#if end
|
|
|
3598 |
|
|
|
3599 |
#反之不要 script tag
|
|
|
3600 |
else{
|
|
|
3601 |
|
|
|
3602 |
#取得js語法
|
|
|
3603 |
$result["content"]=$jsStr;
|
|
|
3604 |
|
|
|
3605 |
}#else end
|
|
|
3606 |
|
|
|
3607 |
#設置執行正常
|
|
|
3608 |
$result["status"]="true";
|
|
|
3609 |
|
|
|
3610 |
#回傳結果
|
|
|
3611 |
return $result;
|
|
|
3612 |
|
|
|
3613 |
}#function saveToSessionStorage end
|
|
|
3614 |
|
|
|
3615 |
/*
|
|
|
3616 |
#函式說明:
|
|
|
3617 |
#取得儲存在local storage的變數
|
|
|
3618 |
#回傳結果:
|
|
|
3619 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
3620 |
#$result["error"],錯誤訊息陣列
|
|
|
3621 |
#$result["function"],當前執行的函數名稱
|
|
|
3622 |
#$result["content"],要執行的javaScript語法
|
|
|
3623 |
#必填參數:
|
|
|
3624 |
#$conf["key"],字串,要儲存的key為何.
|
|
|
3625 |
$conf["key"]="";
|
|
|
3626 |
#$conf["storeVar"],字串,要儲存到哪個javascript變數裡面.
|
|
|
3627 |
$conf["storeVar"]="";
|
|
|
3628 |
#可省略參數:
|
|
|
3629 |
#$conf["noScriptTag"],字串,是否不要<script></script>,"true"代表不要,"false"代表不用,預設為"false".
|
|
|
3630 |
#$conf["noScriptTag"]="false";
|
|
|
3631 |
#$conf["json"],字串要取出的資料是否json,"true"代表是,"false"代表不是,預設為"false".
|
|
|
3632 |
#$conf["json"]="false";
|
|
|
3633 |
#參考資料:
|
|
|
3634 |
#無.
|
|
|
3635 |
#備註:
|
|
|
3636 |
#無.
|
|
|
3637 |
*/
|
|
|
3638 |
public static function getLocalStorage(&$conf){
|
|
|
3639 |
|
|
|
3640 |
#初始化要回傳的結果
|
|
|
3641 |
$result=array();
|
|
|
3642 |
|
|
|
3643 |
#取得當前執行的函數名稱
|
|
|
3644 |
$result["function"]=__FUNCTION__;
|
|
|
3645 |
|
|
|
3646 |
#如果沒有參數
|
|
|
3647 |
if(func_num_args()==0){
|
|
|
3648 |
|
|
|
3649 |
#設置執行失敗
|
|
|
3650 |
$result["status"]="false";
|
|
|
3651 |
|
|
|
3652 |
#設置執行錯誤訊息
|
|
|
3653 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
3654 |
|
|
|
3655 |
#回傳結果
|
|
|
3656 |
return $result;
|
|
|
3657 |
|
|
|
3658 |
}#if end
|
|
|
3659 |
|
|
|
3660 |
#取得參數
|
|
|
3661 |
$result["argu"]=$conf;
|
|
|
3662 |
|
|
|
3663 |
#如果 $conf 不為陣列
|
|
|
3664 |
if(gettype($conf)!="array"){
|
|
|
3665 |
|
|
|
3666 |
#設置執行失敗
|
|
|
3667 |
$result["status"]="false";
|
|
|
3668 |
|
|
|
3669 |
#設置執行錯誤訊息
|
|
|
3670 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
3671 |
|
|
|
3672 |
#如果傳入的參數為 null
|
|
|
3673 |
if($conf==null){
|
|
|
3674 |
|
|
|
3675 |
#設置執行錯誤訊息
|
|
|
3676 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
3677 |
|
|
|
3678 |
}#if end
|
|
|
3679 |
|
|
|
3680 |
#回傳結果
|
|
|
3681 |
return $result;
|
|
|
3682 |
|
|
|
3683 |
}#if end
|
|
|
3684 |
|
|
|
3685 |
#檢查參數
|
|
|
3686 |
#函式說明:
|
|
|
3687 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
3688 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3689 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
3690 |
#$result["function"],當前執行的函式名稱.
|
|
|
3691 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
3692 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
3693 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
3694 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
3695 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
3696 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
3697 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
3698 |
#必填參數:
|
|
|
3699 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
3700 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
3701 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
3702 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("key","storeVar");
|
|
|
3703 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
|
|
3704 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
3705 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
3706 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
3707 |
#可以省略的參數:
|
|
|
3708 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
3709 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
3710 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
3711 |
#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("key");
|
|
|
3712 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
3713 |
#$conf["canBeEmpty"]=array();
|
|
|
3714 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
3715 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("noScriptTag","json");
|
|
|
3716 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
3717 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
|
|
|
3718 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
3719 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","false");
|
|
|
3720 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
3721 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
|
|
|
3722 |
#參考資料來源:
|
|
|
3723 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
3724 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
3725 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
3726 |
|
|
|
3727 |
#如果檢查失敗
|
|
|
3728 |
if($checkResult["status"]=="false"){
|
|
|
3729 |
|
|
|
3730 |
#設置錯誤狀態
|
|
|
3731 |
$result["status"]="false";
|
|
|
3732 |
|
|
|
3733 |
#設置錯誤提示
|
|
|
3734 |
$result["error"]=$checkResult;
|
|
|
3735 |
|
|
|
3736 |
#回傳結果
|
|
|
3737 |
return $result;
|
|
|
3738 |
|
|
|
3739 |
}#if end
|
|
|
3740 |
|
|
|
3741 |
#如果檢查不通過
|
|
|
3742 |
if($checkResult["passed"]=="false"){
|
|
|
3743 |
|
|
|
3744 |
#設置錯誤狀態
|
|
|
3745 |
$result["status"]="false";
|
|
|
3746 |
|
|
|
3747 |
#設置錯誤提示
|
|
|
3748 |
$result["error"]=$checkResult;
|
|
|
3749 |
|
|
|
3750 |
#回傳結果
|
|
|
3751 |
return $result;
|
|
|
3752 |
|
|
|
3753 |
}#if end
|
|
|
3754 |
|
|
|
3755 |
#如果要抓的變數不是json
|
|
|
3756 |
if($conf["json"]==="false"){
|
|
|
3757 |
|
|
|
3758 |
#設置抓取local storage 變數的 js 語法
|
|
|
3759 |
$jsStr="
|
|
|
3760 |
//判斷 local storage 變數是否存在
|
|
|
3761 |
if(localStorage.".$conf["key"]."!=undefined)
|
|
|
3762 |
{
|
|
|
3763 |
//取得 local storage 變數
|
|
|
3764 |
".$conf["storeVar"]."=localStorage.".$conf["key"].";
|
|
|
3765 |
}";
|
|
|
3766 |
|
|
|
3767 |
}#if end
|
|
|
3768 |
|
|
|
3769 |
#反之為json變數
|
|
|
3770 |
else{
|
|
|
3771 |
|
|
|
3772 |
#設置抓取local storage 變數的 js 語法
|
|
|
3773 |
$jsStr="
|
|
|
3774 |
//判斷 local storage 變數是否存在
|
|
|
3775 |
if(localStorage.".$conf["key"]."!=undefined)
|
|
|
3776 |
{
|
|
|
3777 |
//取得 local storage 變數
|
|
|
3778 |
".$conf["storeVar"]."=JSON.parse(localStorage.".$conf["key"].");
|
|
|
3779 |
}";
|
|
|
3780 |
|
|
|
3781 |
}#else end
|
|
|
3782 |
|
|
|
3783 |
#如果要 script tag
|
|
|
3784 |
if($conf["noScriptTag"]==="false"){
|
|
|
3785 |
|
|
|
3786 |
#函式說明:
|
|
|
3787 |
#將要執行的script語法透過該函式執行
|
|
|
3788 |
#回傳結果:
|
|
|
3789 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
3790 |
#$result["error"],錯誤訊息陣列
|
|
|
3791 |
#$result["function"],當前執行的函數名稱
|
|
|
3792 |
#$result["content"],要執行的javaScript語法
|
|
|
3793 |
#必填參數:
|
|
|
3794 |
#$conf["script"],字串,要執行的javaScript語法,標籤「<script></script>」會自動補上.
|
|
|
3795 |
$conf["javaScript::toScript"]["script"]=$jsStr;
|
|
|
3796 |
$toScript=javaScript::toScript($conf["javaScript::toScript"]);
|
|
|
3797 |
unset($conf["javaScript::toScript"]);
|
|
|
3798 |
|
|
|
3799 |
#如果轉換成js語法失敗
|
|
|
3800 |
if($toScript["status"]==="false"){
|
|
|
3801 |
|
|
|
3802 |
#設置錯誤狀態
|
|
|
3803 |
$result["status"]="false";
|
|
|
3804 |
|
|
|
3805 |
#設置錯誤提示
|
|
|
3806 |
$result["error"]=$toScript;
|
|
|
3807 |
|
|
|
3808 |
#回傳結果
|
|
|
3809 |
return $result;
|
|
|
3810 |
|
|
|
3811 |
}#if end
|
|
|
3812 |
|
|
|
3813 |
#取得js語法
|
|
|
3814 |
$result["content"]=$toScript["content"];
|
|
|
3815 |
|
|
|
3816 |
}#if end
|
|
|
3817 |
|
|
|
3818 |
#反之不要<script></script>
|
|
|
3819 |
else{
|
|
|
3820 |
|
|
|
3821 |
$result["content"]=$jsStr;
|
|
|
3822 |
|
|
|
3823 |
}#else end
|
|
|
3824 |
|
|
|
3825 |
#設置執行正常
|
|
|
3826 |
$result["status"]="true";
|
|
|
3827 |
|
|
|
3828 |
#回傳結果
|
|
|
3829 |
return $result;
|
|
|
3830 |
|
|
|
3831 |
}#function getLocalStorage end
|
|
|
3832 |
|
|
|
3833 |
/*
|
|
|
3834 |
#函式說明:
|
|
|
3835 |
#取得儲存在session storage的變數
|
|
|
3836 |
#回傳結果:
|
|
|
3837 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
3838 |
#$result["error"],錯誤訊息陣列
|
|
|
3839 |
#$result["function"],當前執行的函數名稱
|
|
|
3840 |
#$result["content"],要執行的javaScript語法
|
|
|
3841 |
#必填參數:
|
|
|
3842 |
#$conf["key"],字串,要儲存的key為何.
|
|
|
3843 |
$conf["key"]="";
|
|
|
3844 |
#$conf["storeVar"],字串,要儲存到哪個javascript變數裡面.
|
|
|
3845 |
$conf["storeVar"]="";
|
|
|
3846 |
#可省略參數:
|
|
|
3847 |
#$conf["noScriptTag"],字串,是否不要<script></script>,"true"代表不要,"false"代表不用,預設為"false".
|
|
|
3848 |
#$conf["noScriptTag"]="false";
|
|
|
3849 |
#$conf["json"],字串要取出的資料是否json,"true"代表是,"false"代表不是,預設為"false".
|
|
|
3850 |
#$conf["json"]="false";
|
|
|
3851 |
#參考資料:
|
|
|
3852 |
#無.
|
|
|
3853 |
#備註:
|
|
|
3854 |
#無.
|
|
|
3855 |
*/
|
|
|
3856 |
public static function getSessionStorage(&$conf){
|
|
|
3857 |
|
|
|
3858 |
#初始化要回傳的結果
|
|
|
3859 |
$result=array();
|
|
|
3860 |
|
|
|
3861 |
#取得當前執行的函數名稱
|
|
|
3862 |
$result["function"]=__FUNCTION__;
|
|
|
3863 |
|
|
|
3864 |
#如果沒有參數
|
|
|
3865 |
if(func_num_args()==0){
|
|
|
3866 |
|
|
|
3867 |
#設置執行失敗
|
|
|
3868 |
$result["status"]="false";
|
|
|
3869 |
|
|
|
3870 |
#設置執行錯誤訊息
|
|
|
3871 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
3872 |
|
|
|
3873 |
#回傳結果
|
|
|
3874 |
return $result;
|
|
|
3875 |
|
|
|
3876 |
}#if end
|
|
|
3877 |
|
|
|
3878 |
#取得參數
|
|
|
3879 |
$result["argu"]=$conf;
|
|
|
3880 |
|
|
|
3881 |
#如果 $conf 不為陣列
|
|
|
3882 |
if(gettype($conf)!="array"){
|
|
|
3883 |
|
|
|
3884 |
#設置執行失敗
|
|
|
3885 |
$result["status"]="false";
|
|
|
3886 |
|
|
|
3887 |
#設置執行錯誤訊息
|
|
|
3888 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
3889 |
|
|
|
3890 |
#如果傳入的參數為 null
|
|
|
3891 |
if($conf==null){
|
|
|
3892 |
|
|
|
3893 |
#設置執行錯誤訊息
|
|
|
3894 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
3895 |
|
|
|
3896 |
}#if end
|
|
|
3897 |
|
|
|
3898 |
#回傳結果
|
|
|
3899 |
return $result;
|
|
|
3900 |
|
|
|
3901 |
}#if end
|
|
|
3902 |
|
|
|
3903 |
#檢查參數
|
|
|
3904 |
#函式說明:
|
|
|
3905 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
3906 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3907 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
3908 |
#$result["function"],當前執行的函式名稱.
|
|
|
3909 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
3910 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
3911 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
3912 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
3913 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
3914 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
3915 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
3916 |
#必填參數:
|
|
|
3917 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
3918 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
3919 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
3920 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("key","storeVar");
|
|
|
3921 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
|
|
3922 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
3923 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
3924 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
3925 |
#可以省略的參數:
|
|
|
3926 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
3927 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
3928 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
3929 |
#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("key");
|
|
|
3930 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
3931 |
#$conf["canBeEmpty"]=array();
|
|
|
3932 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
3933 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("noScriptTag","json");
|
|
|
3934 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
3935 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
|
|
|
3936 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
3937 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","false");
|
|
|
3938 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
3939 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
|
|
|
3940 |
#參考資料來源:
|
|
|
3941 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
3942 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
3943 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
3944 |
|
|
|
3945 |
#如果檢查失敗
|
|
|
3946 |
if($checkResult["status"]=="false"){
|
|
|
3947 |
|
|
|
3948 |
#設置錯誤狀態
|
|
|
3949 |
$result["status"]="false";
|
|
|
3950 |
|
|
|
3951 |
#設置錯誤提示
|
|
|
3952 |
$result["error"]=$checkResult;
|
|
|
3953 |
|
|
|
3954 |
#回傳結果
|
|
|
3955 |
return $result;
|
|
|
3956 |
|
|
|
3957 |
}#if end
|
|
|
3958 |
|
|
|
3959 |
#如果檢查不通過
|
|
|
3960 |
if($checkResult["passed"]=="false"){
|
|
|
3961 |
|
|
|
3962 |
#設置錯誤狀態
|
|
|
3963 |
$result["status"]="false";
|
|
|
3964 |
|
|
|
3965 |
#設置錯誤提示
|
|
|
3966 |
$result["error"]=$checkResult;
|
|
|
3967 |
|
|
|
3968 |
#回傳結果
|
|
|
3969 |
return $result;
|
|
|
3970 |
|
|
|
3971 |
}#if end
|
|
|
3972 |
|
|
|
3973 |
#如果要抓的變數不是json
|
|
|
3974 |
if($conf["json"]==="false"){
|
|
|
3975 |
|
|
|
3976 |
#設置抓取local storage 變數的 js 語法
|
|
|
3977 |
$jsStr="
|
|
|
3978 |
//判斷 local storage 變數是否存在
|
|
|
3979 |
if(sessionStorage.".$conf["key"]."!=undefined)
|
|
|
3980 |
{
|
|
|
3981 |
//取得 local storage 變數
|
|
|
3982 |
".$conf["storeVar"]."=sessionStorage.".$conf["key"].";
|
|
|
3983 |
}";
|
|
|
3984 |
|
|
|
3985 |
}#if end
|
|
|
3986 |
|
|
|
3987 |
#反之為json變數
|
|
|
3988 |
else{
|
|
|
3989 |
|
|
|
3990 |
#設置抓取local storage 變數的 js 語法
|
|
|
3991 |
$jsStr="
|
|
|
3992 |
//判斷 local storage 變數是否存在
|
|
|
3993 |
if(localStorage.".$conf["key"]."!=undefined)
|
|
|
3994 |
{
|
|
|
3995 |
//取得 local storage 變數
|
|
|
3996 |
".$conf["storeVar"]."=JSON.parse(localStorage.".$conf["key"].");
|
|
|
3997 |
}";
|
|
|
3998 |
|
|
|
3999 |
}#else end
|
|
|
4000 |
|
|
|
4001 |
#如果要 script tag
|
|
|
4002 |
if($conf["noScriptTag"]==="false"){
|
|
|
4003 |
|
|
|
4004 |
#函式說明:
|
|
|
4005 |
#將要執行的script語法透過該函式執行
|
|
|
4006 |
#回傳結果:
|
|
|
4007 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
4008 |
#$result["error"],錯誤訊息陣列
|
|
|
4009 |
#$result["function"],當前執行的函數名稱
|
|
|
4010 |
#$result["content"],要執行的javaScript語法
|
|
|
4011 |
#必填參數:
|
|
|
4012 |
#$conf["script"],字串,要執行的javaScript語法,標籤「<script></script>」會自動補上.
|
|
|
4013 |
$conf["javaScript::toScript"]["script"]=$jsStr;
|
|
|
4014 |
$toScript=javaScript::toScript($conf["javaScript::toScript"]);
|
|
|
4015 |
unset($conf["javaScript::toScript"]);
|
|
|
4016 |
|
|
|
4017 |
#如果轉換成js語法失敗
|
|
|
4018 |
if($toScript["status"]==="false"){
|
|
|
4019 |
|
|
|
4020 |
#設置錯誤狀態
|
|
|
4021 |
$result["status"]="false";
|
|
|
4022 |
|
|
|
4023 |
#設置錯誤提示
|
|
|
4024 |
$result["error"]=$toScript;
|
|
|
4025 |
|
|
|
4026 |
#回傳結果
|
|
|
4027 |
return $result;
|
|
|
4028 |
|
|
|
4029 |
}#if end
|
|
|
4030 |
|
|
|
4031 |
#取得js語法
|
|
|
4032 |
$result["content"]=$toScript["content"];
|
|
|
4033 |
|
|
|
4034 |
}#if end
|
|
|
4035 |
|
|
|
4036 |
#反之不要<script></script>
|
|
|
4037 |
else{
|
|
|
4038 |
|
|
|
4039 |
$result["content"]=$jsStr;
|
|
|
4040 |
|
|
|
4041 |
}#else end
|
|
|
4042 |
|
|
|
4043 |
#設置執行正常
|
|
|
4044 |
$result["status"]="true";
|
|
|
4045 |
|
|
|
4046 |
#回傳結果
|
|
|
4047 |
return $result;
|
|
|
4048 |
|
|
|
4049 |
}#function getSessionStorage end
|
|
|
4050 |
|
|
|
4051 |
/*
|
|
|
4052 |
#函式說明:
|
|
|
4053 |
#移除儲存在local storage的變數
|
|
|
4054 |
#回傳結果:
|
|
|
4055 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
4056 |
#$result["error"],錯誤訊息陣列
|
|
|
4057 |
#$result["function"],當前執行的函數名稱
|
|
|
4058 |
#$result["content"],要執行的javaScript語法
|
|
|
4059 |
#必填參數:
|
|
|
4060 |
#$conf["key"],字串,要儲存的key為何.
|
|
|
4061 |
$conf["key"]="";
|
|
|
4062 |
#可省略參數:
|
|
|
4063 |
#$conf["noScriptTag"],字串,是否不要用script tag包住回傳的內容($result["content"]),"true"代表不要用,"false"代表要用,預設為"false".
|
|
|
4064 |
#$conf["noScriptTag"]="false";
|
|
|
4065 |
#參考資料:
|
|
|
4066 |
#無.
|
|
|
4067 |
#備註:
|
|
|
4068 |
#無.
|
|
|
4069 |
*/
|
|
|
4070 |
public static function rmLocalStorage(&$conf){
|
|
|
4071 |
|
|
|
4072 |
#初始化要回傳的結果
|
|
|
4073 |
$result=array();
|
|
|
4074 |
|
|
|
4075 |
#取得當前執行的函數名稱
|
|
|
4076 |
$result["function"]=__FUNCTION__;
|
|
|
4077 |
|
|
|
4078 |
#如果沒有參數
|
|
|
4079 |
if(func_num_args()==0){
|
|
|
4080 |
|
|
|
4081 |
#設置執行失敗
|
|
|
4082 |
$result["status"]="false";
|
|
|
4083 |
|
|
|
4084 |
#設置執行錯誤訊息
|
|
|
4085 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
4086 |
|
|
|
4087 |
#回傳結果
|
|
|
4088 |
return $result;
|
|
|
4089 |
|
|
|
4090 |
}#if end
|
|
|
4091 |
|
|
|
4092 |
#取得參數
|
|
|
4093 |
$result["argu"]=$conf;
|
|
|
4094 |
|
|
|
4095 |
#如果 $conf 不為陣列
|
|
|
4096 |
if(gettype($conf)!="array"){
|
|
|
4097 |
|
|
|
4098 |
#設置執行失敗
|
|
|
4099 |
$result["status"]="false";
|
|
|
4100 |
|
|
|
4101 |
#設置執行錯誤訊息
|
|
|
4102 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
4103 |
|
|
|
4104 |
#如果傳入的參數為 null
|
|
|
4105 |
if($conf==null){
|
|
|
4106 |
|
|
|
4107 |
#設置執行錯誤訊息
|
|
|
4108 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
4109 |
|
|
|
4110 |
}#if end
|
|
|
4111 |
|
|
|
4112 |
#回傳結果
|
|
|
4113 |
return $result;
|
|
|
4114 |
|
|
|
4115 |
}#if end
|
|
|
4116 |
|
|
|
4117 |
#檢查參數
|
|
|
4118 |
#函式說明:
|
|
|
4119 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
4120 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4121 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
4122 |
#$result["function"],當前執行的函式名稱.
|
|
|
4123 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
4124 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
4125 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
4126 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
4127 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
4128 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
4129 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
4130 |
#必填參數:
|
|
|
4131 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
4132 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
4133 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
4134 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("key",);
|
|
|
4135 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
|
|
4136 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
4137 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
4138 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
4139 |
#可以省略的參數:
|
|
|
4140 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
4141 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
4142 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
4143 |
#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("key");
|
|
|
4144 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
4145 |
#$conf["canBeEmpty"]=array();
|
|
|
4146 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
4147 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("noScriptTag");
|
|
|
4148 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
4149 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
4150 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
4151 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
|
|
|
4152 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
4153 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
|
|
|
4154 |
#參考資料來源:
|
|
|
4155 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
4156 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
4157 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
4158 |
|
|
|
4159 |
#如果檢查失敗
|
|
|
4160 |
if($checkResult["status"]=="false"){
|
|
|
4161 |
|
|
|
4162 |
#設置錯誤狀態
|
|
|
4163 |
$result["status"]="false";
|
|
|
4164 |
|
|
|
4165 |
#設置錯誤提示
|
|
|
4166 |
$result["error"]=$checkResult;
|
|
|
4167 |
|
|
|
4168 |
#回傳結果
|
|
|
4169 |
return $result;
|
|
|
4170 |
|
|
|
4171 |
}#if end
|
|
|
4172 |
|
|
|
4173 |
#如果檢查不通過
|
|
|
4174 |
if($checkResult["passed"]=="false"){
|
|
|
4175 |
|
|
|
4176 |
#設置錯誤狀態
|
|
|
4177 |
$result["status"]="false";
|
|
|
4178 |
|
|
|
4179 |
#設置錯誤提示
|
|
|
4180 |
$result["error"]=$checkResult;
|
|
|
4181 |
|
|
|
4182 |
#回傳結果
|
|
|
4183 |
return $result;
|
|
|
4184 |
|
|
|
4185 |
}#if end
|
|
|
4186 |
|
|
|
4187 |
#javascript 字串
|
|
|
4188 |
$jsStr="localStorage.removeItem(\"".$conf["key"]."\");";
|
|
|
4189 |
|
|
|
4190 |
#如果要 script tag
|
|
|
4191 |
if($conf["noScriptTag"]=="false"){
|
|
|
4192 |
|
|
|
4193 |
#函式說明:
|
|
|
4194 |
#將要執行的script語法透過該函式執行
|
|
|
4195 |
#回傳結果:
|
|
|
4196 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
4197 |
#$result["error"],錯誤訊息陣列
|
|
|
4198 |
#$result["function"],當前執行的函數名稱
|
|
|
4199 |
#$result["content"],要執行的javaScript語法
|
|
|
4200 |
#必填參數:
|
|
|
4201 |
#$conf["script"],字串,要執行的javaScript語法,標籤「<script></script>」會自動補上.
|
|
|
4202 |
$conf["javaScript::toScript"]["script"]=$jsStr;
|
|
|
4203 |
$toScript=javaScript::toScript($conf["javaScript::toScript"]);
|
|
|
4204 |
unset($conf["javaScript::toScript"]);
|
|
|
4205 |
|
|
|
4206 |
#如果轉換成js語法失敗
|
|
|
4207 |
if($toScript["status"]==="false"){
|
|
|
4208 |
|
|
|
4209 |
#設置錯誤狀態
|
|
|
4210 |
$result["status"]="false";
|
|
|
4211 |
|
|
|
4212 |
#設置錯誤提示
|
|
|
4213 |
$result["error"]=$toScript;
|
|
|
4214 |
|
|
|
4215 |
#回傳結果
|
|
|
4216 |
return $result;
|
|
|
4217 |
|
|
|
4218 |
}#if end
|
|
|
4219 |
|
|
|
4220 |
#取得js語法
|
|
|
4221 |
$result["content"]=$toScript["content"];
|
|
|
4222 |
|
|
|
4223 |
}#if end
|
|
|
4224 |
|
|
|
4225 |
#反之不要 script tag
|
|
|
4226 |
else{
|
|
|
4227 |
|
|
|
4228 |
#取得js語法
|
|
|
4229 |
$result["content"]=$jsStr;
|
|
|
4230 |
|
|
|
4231 |
}#else end
|
|
|
4232 |
|
|
|
4233 |
#設置執行正常
|
|
|
4234 |
$result["status"]="true";
|
|
|
4235 |
|
|
|
4236 |
#回傳結果
|
|
|
4237 |
return $result;
|
|
|
4238 |
|
|
|
4239 |
}#function rmLocalStorage end
|
|
|
4240 |
|
|
|
4241 |
/*
|
|
|
4242 |
#函式說明:
|
|
|
4243 |
#透過作業系統顯示提示訊息
|
|
|
4244 |
#回傳結果:
|
|
|
4245 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4246 |
#$result["error"],錯誤訊息.
|
|
|
4247 |
#$result["function"],當前執行的函數名稱.
|
|
|
4248 |
#$result["argu"],所使用的參數.
|
|
|
4249 |
#$result["content"],js語法.
|
|
|
4250 |
#$result["jsFuncName"],使用的js函數名稱.
|
|
|
4251 |
#必填參數:
|
|
|
4252 |
#$conf["name"],字串,提示功能的名稱,用於建立js函數的名稱.
|
|
|
4253 |
$conf["name"]="";
|
|
|
4254 |
#$conf["text"],陣列字串,提示的內容,每個元素代表一列文字,目前似乎不會換行.
|
|
|
4255 |
$conf["text"]=array();
|
|
|
4256 |
#可省略參數:
|
|
|
4257 |
#$conf["bodyAndIcon"],字串,"true"代表要使用body與icon,預設為"false"代表不使用.
|
|
|
4258 |
#$conf["bodyAndIcon"]="false";
|
|
|
4259 |
#$conf["body"],字串陣列,提示的body內容,每個元素代表一列文字,預設為空陣列.
|
|
|
4260 |
#$conf["body"]=array();
|
|
|
4261 |
#$conf["icon"],字串,提示所用的icon位置,預設為null.
|
|
|
4262 |
#$conf["icon"]="";
|
|
|
4263 |
#$conf["sound"],字串,提示出現要使用的音效,預設為null,目前沒有瀏覽器支援.
|
|
|
4264 |
#$conf["sound"]="";
|
|
|
4265 |
#$conf["ms"],字串,訊息幾毫秒後要消失,預設為3000毫秒.
|
|
|
4266 |
#$conf["ms"]="3000";
|
|
|
4267 |
#$conf["runNow"],字串,是否要馬上執行,預設為"true"代表要,"false"代表不要.
|
|
|
4268 |
#$conf["runNow"]="true";
|
|
|
4269 |
#$conf["scriptTag"],字串,是否要用<script></script>包住js語法,預設為"true"要包住,"false"為不包住.
|
|
|
4270 |
#$conf["scriptTag"]="true"
|
|
|
4271 |
#參考資料:
|
|
|
4272 |
#https://developer.mozilla.org/en-US/docs/Web/API/notification
|
|
|
4273 |
#備註:
|
|
|
4274 |
#參數bodyAndIcon似乎可以移除
|
|
|
4275 |
#建議加上檢查icon與sound是否存在的檢查
|
|
|
4276 |
#如果沒有要求瀏覽器使用Notify的權限,則即便之前允許過,第一次也一定會失敗
|
|
|
4277 |
*/
|
|
|
4278 |
public static function systemNotify(&$conf){
|
|
|
4279 |
|
|
|
4280 |
#初始化要回傳的結果
|
|
|
4281 |
$result=array();
|
|
|
4282 |
|
|
|
4283 |
#取得當前執行的函數名稱
|
|
|
4284 |
$result["function"]=__FUNCTION__;
|
|
|
4285 |
|
|
|
4286 |
#如果沒有參數
|
|
|
4287 |
if(func_num_args()==0){
|
|
|
4288 |
|
|
|
4289 |
#設置執行失敗
|
|
|
4290 |
$result["status"]="false";
|
|
|
4291 |
|
|
|
4292 |
#設置執行錯誤訊息
|
|
|
4293 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
4294 |
|
|
|
4295 |
#回傳結果
|
|
|
4296 |
return $result;
|
|
|
4297 |
|
|
|
4298 |
}#if end
|
|
|
4299 |
|
|
|
4300 |
#取得參數
|
|
|
4301 |
$result["argu"]=$conf;
|
|
|
4302 |
|
|
|
4303 |
#如果 $conf 不為陣列
|
|
|
4304 |
if(gettype($conf)!=="array"){
|
|
|
4305 |
|
|
|
4306 |
#設置執行失敗
|
|
|
4307 |
$result["status"]="false";
|
|
|
4308 |
|
|
|
4309 |
#設置執行錯誤訊息
|
|
|
4310 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
4311 |
|
|
|
4312 |
#如果傳入的參數為 null
|
|
|
4313 |
if($conf===null){
|
|
|
4314 |
|
|
|
4315 |
#設置執行錯誤訊息
|
|
|
4316 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
4317 |
|
|
|
4318 |
}#if end
|
|
|
4319 |
|
|
|
4320 |
#回傳結果
|
|
|
4321 |
return $result;
|
|
|
4322 |
|
|
|
4323 |
}#if end
|
|
|
4324 |
|
|
|
4325 |
#檢查參數
|
|
|
4326 |
#函式說明:
|
|
|
4327 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
4328 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4329 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
4330 |
#$result["function"],當前執行的函式名稱.
|
|
|
4331 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
4332 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
4333 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
4334 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
4335 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
4336 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
4337 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
4338 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
4339 |
#必填參數:
|
|
|
4340 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
4341 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
4342 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
4343 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("name","text");
|
|
|
4344 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
4345 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","array");
|
|
|
4346 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
4347 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
4348 |
#可以省略的參數:
|
|
|
4349 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
4350 |
#$conf["canBeEmptyString"]="false";
|
|
|
4351 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
4352 |
#$conf["canNotBeEmpty"]=array();
|
|
|
4353 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
4354 |
#$conf["canBeEmpty"]=array();
|
|
|
4355 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
4356 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
4357 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
4358 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("bodyAndIcon","body","icon","sound","ms","runNow","scriptTag");
|
|
|
4359 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
4360 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","array","string","string","string","string","string");
|
|
|
4361 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
4362 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false",array(),"null","null","3000","true","true");
|
|
|
4363 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
4364 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
4365 |
#參考資料來源:
|
|
|
4366 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
4367 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
4368 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
4369 |
|
|
|
4370 |
#如果檢查參數失敗
|
|
|
4371 |
if($checkArguments["status"]==="false"){
|
|
|
4372 |
|
|
|
4373 |
#設置執行失敗
|
|
|
4374 |
$result["status"]="false";
|
|
|
4375 |
|
|
|
4376 |
#設置執行錯誤訊息
|
|
|
4377 |
$result["error"]=$checkArguments;
|
|
|
4378 |
|
|
|
4379 |
#回傳結果
|
|
|
4380 |
return $result;
|
|
|
4381 |
|
|
|
4382 |
}#if end
|
|
|
4383 |
|
|
|
4384 |
#如果參數檢查不通過
|
|
|
4385 |
if($checkArguments["passed"]==="false"){
|
|
|
4386 |
|
|
|
4387 |
#設置執行失敗
|
|
|
4388 |
$result["status"]="false";
|
|
|
4389 |
|
|
|
4390 |
#設置執行錯誤訊息
|
|
|
4391 |
$result["error"]=$checkArguments;
|
|
|
4392 |
|
|
|
4393 |
#回傳結果
|
|
|
4394 |
return $result;
|
|
|
4395 |
|
|
|
4396 |
}#if end
|
|
|
4397 |
|
|
|
4398 |
#轉換 $conf["text"] 為字串
|
|
|
4399 |
#函式說明:
|
|
|
4400 |
#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".
|
|
|
4401 |
#回傳結果:
|
|
|
4402 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4403 |
#$result["function"],當前執行的function名稱
|
|
|
4404 |
#$result["error"],錯誤訊息陣列.
|
|
|
4405 |
#$result["content"],處理好的字串.
|
|
|
4406 |
#必填參數:
|
|
|
4407 |
#$conf["inputArray"],字串陣列,要轉成字串的一維陣列.
|
|
|
4408 |
$conf["arrays::arrayToString"]["inputArray"]=$conf["text"];
|
|
|
4409 |
#可省略參數:
|
|
|
4410 |
#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為;
|
|
|
4411 |
$conf["arrays::arrayToString"]["spiltSymbol"]=" ";
|
|
|
4412 |
$conf["text"]=arrays::arrayToString($conf["arrays::arrayToString"]);
|
|
|
4413 |
unset($conf["arrays::arrayToString"]);
|
|
|
4414 |
|
|
|
4415 |
#如果轉換失敗
|
|
|
4416 |
if($conf["text"]["status"]==="false"){
|
|
|
4417 |
|
|
|
4418 |
#設置執行失敗
|
|
|
4419 |
$result["status"]="false";
|
|
|
4420 |
|
|
|
4421 |
#設置執行錯誤訊息
|
|
|
4422 |
$result["error"]=$conf["text"];
|
|
|
4423 |
|
|
|
4424 |
#回傳結果
|
|
|
4425 |
return $result;
|
|
|
4426 |
|
|
|
4427 |
}#if end
|
|
|
4428 |
|
|
|
4429 |
#取得處理好的字串
|
|
|
4430 |
$conf["text"]=$conf["text"]["content"];
|
|
|
4431 |
|
|
|
4432 |
#轉換 $conf["body"] 為字串
|
|
|
4433 |
#函式說明:
|
|
|
4434 |
#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".
|
|
|
4435 |
#回傳結果:
|
|
|
4436 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4437 |
#$result["function"],當前執行的function名稱
|
|
|
4438 |
#$result["error"],錯誤訊息陣列.
|
|
|
4439 |
#$result["content"],處理好的字串.
|
|
|
4440 |
#必填參數:
|
|
|
4441 |
#$conf["inputArray"],字串陣列,要轉成字串的一維陣列.
|
|
|
4442 |
$conf["arrays::arrayToString"]["inputArray"]=$conf["body"];
|
|
|
4443 |
#可省略參數:
|
|
|
4444 |
#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為;
|
|
|
4445 |
$conf["arrays::arrayToString"]["spiltSymbol"]=" ";
|
|
|
4446 |
$conf["body"]=arrays::arrayToString($conf["arrays::arrayToString"]);
|
|
|
4447 |
unset($conf["arrays::arrayToString"]);
|
|
|
4448 |
|
|
|
4449 |
#如果轉換失敗
|
|
|
4450 |
if($conf["body"]["status"]==="false"){
|
|
|
4451 |
|
|
|
4452 |
#設置執行失敗
|
|
|
4453 |
$result["status"]="false";
|
|
|
4454 |
|
|
|
4455 |
#設置執行錯誤訊息
|
|
|
4456 |
$result["error"]=$conf["body"];
|
|
|
4457 |
|
|
|
4458 |
#回傳結果
|
|
|
4459 |
return $result;
|
|
|
4460 |
|
|
|
4461 |
}#if end
|
|
|
4462 |
|
|
|
4463 |
#取得轉換好的內容
|
|
|
4464 |
$conf["body"]=$conf["body"]["content"];
|
|
|
4465 |
|
|
|
4466 |
#初始化js語法
|
|
|
4467 |
$js="";
|
|
|
4468 |
|
|
|
4469 |
#如果要馬上執行
|
|
|
4470 |
if($conf["runNow"]==="true"){
|
|
|
4471 |
|
|
|
4472 |
#語法
|
|
|
4473 |
$js="
|
|
|
4474 |
function notify_".$conf["name"]."()
|
|
|
4475 |
{
|
|
|
4476 |
// Let's check if the browser supports notifications
|
|
|
4477 |
if(!('Notification' in window))
|
|
|
4478 |
{
|
|
|
4479 |
//This browser does not support system notifications
|
|
|
4480 |
return false;
|
|
|
4481 |
}
|
|
|
4482 |
|
|
|
4483 |
// Let's check whether notification permissions have already been granted
|
|
|
4484 |
else if(Notification.permission==='granted')
|
|
|
4485 |
{
|
|
|
4486 |
useOp='".$conf["bodyAndIcon"]."';
|
|
|
4487 |
|
|
|
4488 |
// If the user accepts, let's create a notification
|
|
|
4489 |
//arguments
|
|
|
4490 |
var options=
|
|
|
4491 |
{
|
|
|
4492 |
tag:'".$conf["name"]."',
|
|
|
4493 |
body:'".$conf["body"]."',
|
|
|
4494 |
icon:'".$conf["icon"]."',
|
|
|
4495 |
sound:'".$conf["sound"]."',
|
|
|
4496 |
}
|
|
|
4497 |
|
|
|
4498 |
if(useOp==='false')
|
|
|
4499 |
{
|
|
|
4500 |
//show notify
|
|
|
4501 |
var notification = new Notification('".$conf["text"]."');
|
|
|
4502 |
}
|
|
|
4503 |
else if(useOp==='true')
|
|
|
4504 |
{
|
|
|
4505 |
//show notify with options
|
|
|
4506 |
var notification = new Notification('".$conf["text"]."',options);
|
|
|
4507 |
}
|
|
|
4508 |
|
|
|
4509 |
//notify window will disapear in ".$conf["ms"]."
|
|
|
4510 |
setTimeout(notification.close.bind(notification),".$conf["ms"].");
|
|
|
4511 |
|
|
|
4512 |
//debug
|
|
|
4513 |
notification.onerror=function(message, source, lineno, colno, error)
|
|
|
4514 |
{
|
|
|
4515 |
//alert(message.toSource());
|
|
|
4516 |
//alert(source.toSource());
|
|
|
4517 |
//alert(lineno.toSource());
|
|
|
4518 |
//alert(colno.toSource());
|
|
|
4519 |
//alert(error.toSource());
|
|
|
4520 |
};
|
|
|
4521 |
}
|
|
|
4522 |
|
|
|
4523 |
// Otherwise, we need to ask the user for permission
|
|
|
4524 |
else if(Notification.permission!=='denied')
|
|
|
4525 |
{
|
|
|
4526 |
Notification.requestPermission(function(permission)
|
|
|
4527 |
{
|
|
|
4528 |
useOp='".$conf["bodyAndIcon"]."';
|
|
|
4529 |
|
|
|
4530 |
// If the user accepts, let's create a notification
|
|
|
4531 |
if(permission==='granted')
|
|
|
4532 |
{
|
|
|
4533 |
//arguments
|
|
|
4534 |
var options=
|
|
|
4535 |
{
|
|
|
4536 |
tag:'".$conf["name"]."',
|
|
|
4537 |
body:'".$conf["body"]."',
|
|
|
4538 |
icon:'".$conf["icon"]."',
|
|
|
4539 |
sound:'".$conf["sound"]."',
|
|
|
4540 |
}
|
|
|
4541 |
|
|
|
4542 |
if(useOp==='false')
|
|
|
4543 |
{
|
|
|
4544 |
//show notify
|
|
|
4545 |
var notification = new Notification('".$conf["text"]."');
|
|
|
4546 |
}
|
|
|
4547 |
else if(useOp==='true')
|
|
|
4548 |
{
|
|
|
4549 |
//show notify with options
|
|
|
4550 |
var notification = new Notification('".$conf["text"]."',options);
|
|
|
4551 |
}
|
|
|
4552 |
|
|
|
4553 |
//notify window will disapear in ".$conf["ms"]."
|
|
|
4554 |
setTimeout(notification.close.bind(notification),".$conf["ms"].");
|
|
|
4555 |
|
|
|
4556 |
//debug
|
|
|
4557 |
notification.onerror=function(message, source, lineno, colno, error)
|
|
|
4558 |
{
|
|
|
4559 |
//alert(message.toSource());
|
|
|
4560 |
//alert(source.toSource());
|
|
|
4561 |
//alert(lineno.toSource());
|
|
|
4562 |
//alert(colno.toSource());
|
|
|
4563 |
//alert(error.toSource());
|
|
|
4564 |
};
|
|
|
4565 |
}
|
|
|
4566 |
});
|
|
|
4567 |
}
|
|
|
4568 |
}//notify js function end
|
|
|
4569 |
|
|
|
4570 |
//if have icon
|
|
|
4571 |
if('".$conf["icon"]."'!=='null')
|
|
|
4572 |
{
|
|
|
4573 |
//wait for icon to load
|
|
|
4574 |
var icon = new Image();
|
|
|
4575 |
icon.onload = function()
|
|
|
4576 |
{
|
|
|
4577 |
notify_".$conf["name"]."();
|
|
|
4578 |
}
|
|
|
4579 |
icon.src = '".$conf["icon"]."';
|
|
|
4580 |
}
|
|
|
4581 |
else
|
|
|
4582 |
{
|
|
|
4583 |
notify_".$conf["name"]."();
|
|
|
4584 |
}
|
|
|
4585 |
";
|
|
|
4586 |
|
|
|
4587 |
}#if end
|
|
|
4588 |
|
|
|
4589 |
#如果沒有要馬上執行
|
|
|
4590 |
else if($conf["runNow"]==="false"){
|
|
|
4591 |
|
|
|
4592 |
#語法
|
|
|
4593 |
$js="
|
|
|
4594 |
function notify_".$conf["name"]."()
|
|
|
4595 |
{
|
|
|
4596 |
// Let's check if the browser supports notifications
|
|
|
4597 |
if(!('Notification' in window))
|
|
|
4598 |
{
|
|
|
4599 |
//This browser does not support system notifications
|
|
|
4600 |
return false;
|
|
|
4601 |
}
|
|
|
4602 |
|
|
|
4603 |
// Let's check whether notification permissions have already been granted
|
|
|
4604 |
else if(Notification.permission==='granted')
|
|
|
4605 |
{
|
|
|
4606 |
useOp='".$conf["bodyAndIcon"]."';
|
|
|
4607 |
|
|
|
4608 |
// If the user accepts, let's create a notification
|
|
|
4609 |
//arguments
|
|
|
4610 |
var options=
|
|
|
4611 |
{
|
|
|
4612 |
tag:'".$conf["name"]."',
|
|
|
4613 |
body:'".$conf["body"]."',
|
|
|
4614 |
icon:'".$conf["icon"]."',
|
|
|
4615 |
sound:'".$conf["sound"]."',
|
|
|
4616 |
}
|
|
|
4617 |
|
|
|
4618 |
if(useOp==='false')
|
|
|
4619 |
{
|
|
|
4620 |
//show notify
|
|
|
4621 |
var notification = new Notification('".$conf["text"]."');
|
|
|
4622 |
}
|
|
|
4623 |
else if(useOp==='true')
|
|
|
4624 |
{
|
|
|
4625 |
//show notify with options
|
|
|
4626 |
var notification = new Notification('".$conf["text"]."',options);
|
|
|
4627 |
}
|
|
|
4628 |
|
|
|
4629 |
//notify window will disapear in ".$conf["ms"]."
|
|
|
4630 |
setTimeout(notification.close.bind(notification),".$conf["ms"].");
|
|
|
4631 |
}
|
|
|
4632 |
|
|
|
4633 |
// Otherwise, we need to ask the user for permission
|
|
|
4634 |
else if(Notification.permission!=='denied')
|
|
|
4635 |
{
|
|
|
4636 |
Notification.requestPermission(function(permission)
|
|
|
4637 |
{
|
|
|
4638 |
useOp='".$conf["bodyAndIcon"]."';
|
|
|
4639 |
|
|
|
4640 |
// If the user accepts, let's create a notification
|
|
|
4641 |
if(permission==='granted')
|
|
|
4642 |
{
|
|
|
4643 |
//arguments
|
|
|
4644 |
var options=
|
|
|
4645 |
{
|
|
|
4646 |
tag:'".$conf["name"]."',
|
|
|
4647 |
body:'".$conf["body"]."',
|
|
|
4648 |
icon:'".$conf["icon"]."',
|
|
|
4649 |
sound:'".$conf["sound"]."',
|
|
|
4650 |
}
|
|
|
4651 |
|
|
|
4652 |
if(useOp==='false')
|
|
|
4653 |
{
|
|
|
4654 |
//show notify
|
|
|
4655 |
var notification = new Notification('".$conf["text"]."');
|
|
|
4656 |
}
|
|
|
4657 |
else if(useOp==='true')
|
|
|
4658 |
{
|
|
|
4659 |
//show notify with options
|
|
|
4660 |
var notification = new Notification('".$conf["text"]."',options);
|
|
|
4661 |
}
|
|
|
4662 |
|
|
|
4663 |
//notify window will disapear in ".$conf["ms"]."
|
|
|
4664 |
setTimeout(notification.close.bind(notification),".$conf["ms"].");
|
|
|
4665 |
}
|
|
|
4666 |
});
|
|
|
4667 |
}
|
|
|
4668 |
}//notify js function end
|
|
|
4669 |
";
|
|
|
4670 |
|
|
|
4671 |
}#if end
|
|
|
4672 |
|
|
|
4673 |
#轉換 $conf["scriptTag"] 給 javaScript::addScriptTag 使用
|
|
|
4674 |
if($conf["scriptTag"]==="true"){
|
| 226 |
liveuser |
4675 |
|
| 3 |
liveuser |
4676 |
$conf["scriptTag"]="false";
|
| 226 |
liveuser |
4677 |
|
| 3 |
liveuser |
4678 |
}#if end
|
| 226 |
liveuser |
4679 |
|
| 3 |
liveuser |
4680 |
else if($conf["scriptTag"]==="false"){
|
| 226 |
liveuser |
4681 |
|
| 3 |
liveuser |
4682 |
$conf["scriptTag"]="true";
|
| 226 |
liveuser |
4683 |
|
| 3 |
liveuser |
4684 |
}#if end
|
|
|
4685 |
|
|
|
4686 |
#to js
|
|
|
4687 |
#函式說明:
|
|
|
4688 |
#依據需要加上<script></script>標籤,並且可以指定要匯入的js檔案.
|
|
|
4689 |
#回傳結果:
|
|
|
4690 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
4691 |
#$result["error"],錯誤訊息陣列
|
|
|
4692 |
#$result["function"],當前執行的函數名稱
|
|
|
4693 |
#$result["content"],javaScript語法
|
|
|
4694 |
#$result["importJS"],匯入js的語法,必定含有<script></script>標籤.
|
|
|
4695 |
#必填參數:
|
|
|
4696 |
#$conf["jsProgramSection"],陣列字串,不含<script></script>標籤的javsScript程式碼,可以放多個script程式.
|
|
|
4697 |
$conf["javaScript::addScriptTag"]["jsProgramSection"]=array($js);
|
|
|
4698 |
#可省略參數:
|
|
|
4699 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑,請與參數"jsPosition"一起設置,預設為當前檔案的位置.
|
|
|
4700 |
#$conf["fileArgu"]=__FILE__;
|
|
|
4701 |
#$conf["jsPosition"],字串,要匯入的js檔案位置.
|
|
|
4702 |
#$conf["jsPosition"]="";
|
|
|
4703 |
#$conf["noScriptTag"],字串,是否不要用script tag包住回傳的內容($result["content"]),"true"代表不要用,"false"代表要用,預設為"false".
|
|
|
4704 |
$conf["javaScript::addScriptTag"]["noScriptTag"]=$conf["scriptTag"];
|
|
|
4705 |
$addScriptTag=javaScript::addScriptTag($conf["javaScript::addScriptTag"]);
|
|
|
4706 |
unset($conf["javaScript::addScriptTag"]);
|
|
|
4707 |
|
|
|
4708 |
#如果轉成script失敗
|
|
|
4709 |
if($addScriptTag["status"]==="false"){
|
|
|
4710 |
|
|
|
4711 |
#設置執行失敗
|
|
|
4712 |
$result["status"]="false";
|
|
|
4713 |
|
|
|
4714 |
#設置執行錯誤訊息
|
|
|
4715 |
$result["error"]=$addScriptTag;
|
|
|
4716 |
|
|
|
4717 |
#回傳結果
|
|
|
4718 |
return $result;
|
|
|
4719 |
|
|
|
4720 |
}#if end
|
|
|
4721 |
|
|
|
4722 |
#取得js函數名稱
|
|
|
4723 |
$result["jsFuncName"]="notify_".$conf["name"];
|
|
|
4724 |
|
|
|
4725 |
#取得js語法
|
|
|
4726 |
$result["content"]=$addScriptTag["content"];
|
|
|
4727 |
|
|
|
4728 |
#設置執行正常
|
|
|
4729 |
$result["status"]="true";
|
|
|
4730 |
|
|
|
4731 |
#回傳結果
|
|
|
4732 |
return $result;
|
|
|
4733 |
|
|
|
4734 |
}#function systemNotify end
|
|
|
4735 |
|
|
|
4736 |
/*
|
|
|
4737 |
#函式說明:
|
|
|
4738 |
#開新視窗,可以隱藏瀏覽器的元件。
|
|
|
4739 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4740 |
#$result["error"],錯誤訊息.
|
|
|
4741 |
#$result["function"],當前執行的函數名稱.
|
|
|
4742 |
#$result["argu"],所使用的參數.
|
|
|
4743 |
#$result["content"],js語法.
|
|
|
4744 |
#$result["jsFuncName"],使用的js函數名稱.
|
|
|
4745 |
#必填參數:
|
|
|
4746 |
#$conf["url"],字串,要開新視窗的網址.
|
|
|
4747 |
$conf["url"]="";
|
|
|
4748 |
#$conf["function"],字串,js開新視窗函式的名稱.
|
|
|
4749 |
$conf["function"]="";
|
|
|
4750 |
#可省略參數:
|
|
|
4751 |
#$conf["name"],字串 ,視窗的名稱,指定後可以直接存取其內容.
|
|
|
4752 |
#$conf["name"]="";
|
|
|
4753 |
#$conf["width"],字串,新視窗的寬度.
|
|
|
4754 |
#$conf["width"]="";
|
|
|
4755 |
#$conf["height"],字串,新視窗的高度.
|
|
|
4756 |
#$conf["height"]="";
|
|
|
4757 |
#$conf["toolbar"],字串,是否要工具列,"true"代表要,"false"代表不要,預設為"false".
|
|
|
4758 |
#$conf["toolbar"]="";
|
|
|
4759 |
#$cpnf["menubar"],字串,是否要選單列,"true"代表要,"false"代表不要,預設為"false".
|
|
|
4760 |
#$conf["menubar"]="";
|
|
|
4761 |
#$conf["scrollbars"],字串,是否要滾軸,"true"代表要,"false"代表不要,預設為"true".
|
|
|
4762 |
#$conf["scrollbars"]="";
|
|
|
4763 |
#$conf["resizable"],字串,是否可以改變視窗大小,"true"代表可以,"false"代表不可以,預設為"true".
|
|
|
4764 |
#$conf["resizable"]="";
|
|
|
4765 |
#$conf["location"],字串,是否要顯示地址列,"true"代表要,"false"代表不要,預設為"false".
|
|
|
4766 |
#$conf["location"]="";
|
|
|
4767 |
#$conf["status"],字串,是否要顯示狀態列,"true"代表要,"false"代表不要,預設為"false".
|
|
|
4768 |
#$conf["status"]="";
|
|
|
4769 |
#$conf["titlebar"],字串,是否要顯示視窗標題,"true"代表要,"false"代表不要,預設為"true".
|
|
|
4770 |
#$conf["titlebar"]="";
|
|
|
4771 |
#$conf["returnWindowVarName"],字串,開啟的視窗要儲存到哪個全域變數,請提供window.後面的名稱即可,預設不使用,直接return.
|
|
|
4772 |
#$conf["returnWindowVarName"]="";
|
|
|
4773 |
#參考資料:
|
|
|
4774 |
#http://www.w3schools.com/jsref/met_win_open.asp
|
|
|
4775 |
#http://www.blueshop.com.tw/board/FUM20041006152641OLG/BRD20080107111600L3T.html
|
|
|
4776 |
#備註:
|
|
|
4777 |
#無.
|
|
|
4778 |
*/
|
|
|
4779 |
public static function openWindow(&$conf){
|
|
|
4780 |
|
|
|
4781 |
#初始化要回傳的結果
|
|
|
4782 |
$result=array();
|
|
|
4783 |
|
|
|
4784 |
#取得當前執行的函數名稱
|
|
|
4785 |
$result["function"]=__FUNCTION__;
|
|
|
4786 |
|
|
|
4787 |
#如果沒有參數
|
|
|
4788 |
if(func_num_args()==0){
|
|
|
4789 |
|
|
|
4790 |
#設置執行失敗
|
|
|
4791 |
$result["status"]="false";
|
|
|
4792 |
|
|
|
4793 |
#設置執行錯誤訊息
|
|
|
4794 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
4795 |
|
|
|
4796 |
#回傳結果
|
|
|
4797 |
return $result;
|
|
|
4798 |
|
|
|
4799 |
}#if end
|
|
|
4800 |
|
|
|
4801 |
#取得參數
|
|
|
4802 |
$result["argu"]=$conf;
|
|
|
4803 |
|
|
|
4804 |
#如果 $conf 不為陣列
|
|
|
4805 |
if(gettype($conf)!=="array"){
|
|
|
4806 |
|
|
|
4807 |
#設置執行失敗
|
|
|
4808 |
$result["status"]="false";
|
|
|
4809 |
|
|
|
4810 |
#設置執行錯誤訊息
|
|
|
4811 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
4812 |
|
|
|
4813 |
#如果傳入的參數為 null
|
|
|
4814 |
if($conf===null){
|
|
|
4815 |
|
|
|
4816 |
#設置執行錯誤訊息
|
|
|
4817 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
4818 |
|
|
|
4819 |
}#if end
|
|
|
4820 |
|
|
|
4821 |
#回傳結果
|
|
|
4822 |
return $result;
|
|
|
4823 |
|
|
|
4824 |
}#if end
|
|
|
4825 |
|
|
|
4826 |
#檢查參數
|
|
|
4827 |
#函式說明:
|
|
|
4828 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
4829 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4830 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
4831 |
#$result["function"],當前執行的函式名稱.
|
|
|
4832 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
4833 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
4834 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
4835 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
4836 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
4837 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
4838 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
4839 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
4840 |
#必填參數:
|
|
|
4841 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
4842 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
4843 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
4844 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("url","function");
|
|
|
4845 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
4846 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
4847 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
4848 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
4849 |
#可以省略的參數:
|
|
|
4850 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
4851 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="true";
|
|
|
4852 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
4853 |
$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("function");
|
|
|
4854 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
4855 |
#$conf["canBeEmpty"]=array();
|
|
|
4856 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
4857 |
#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("width","height");
|
|
|
4858 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
4859 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("name","width","height","toolbar","menubar","scrollbars","resizable","location","status","titlebar","returnWindowVarName");
|
|
|
4860 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
4861 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","string","string","string","string","string","string");
|
|
|
4862 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
4863 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("",null,null,"false","false","true","true","false","false","true",null);
|
|
|
4864 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
4865 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
4866 |
#參考資料來源:
|
|
|
4867 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
4868 |
#建議:
|
|
|
4869 |
#增加可省略參數全部不能為空字串或空陣列的參數功能.
|
|
|
4870 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
4871 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
4872 |
|
|
|
4873 |
#如果檢查參數失敗
|
|
|
4874 |
if($checkArguments["status"]==="false"){
|
|
|
4875 |
|
|
|
4876 |
#設置執行失敗
|
|
|
4877 |
$result["status"]="false";
|
|
|
4878 |
|
|
|
4879 |
#設置執行錯誤訊息
|
|
|
4880 |
$result["error"]=$checkArguments;
|
|
|
4881 |
|
|
|
4882 |
#回傳結果
|
|
|
4883 |
return $result;
|
|
|
4884 |
|
|
|
4885 |
}#if end
|
|
|
4886 |
|
|
|
4887 |
#如果參數檢查不通過
|
|
|
4888 |
if($checkArguments["passed"]==="false"){
|
|
|
4889 |
|
|
|
4890 |
#設置執行失敗
|
|
|
4891 |
$result["status"]="false";
|
|
|
4892 |
|
|
|
4893 |
#設置執行錯誤訊息
|
|
|
4894 |
$result["error"]=$checkArguments;
|
|
|
4895 |
|
|
|
4896 |
#回傳結果
|
|
|
4897 |
return $result;
|
|
|
4898 |
|
|
|
4899 |
}#if end
|
|
|
4900 |
|
|
|
4901 |
#取得js函數的名稱
|
|
|
4902 |
$result["jsFuncName"]=$conf["function"];
|
|
|
4903 |
|
|
|
4904 |
#開新視窗的參數
|
|
|
4905 |
$opt=array();
|
|
|
4906 |
|
|
|
4907 |
#如果有設定 $conf["width"]
|
|
|
4908 |
if(isset($conf["width"])){
|
|
|
4909 |
|
|
|
4910 |
#如果不是 "screen"
|
|
|
4911 |
if($conf["width"]!=="screen"){
|
|
|
4912 |
|
|
|
4913 |
#設定寬度
|
|
|
4914 |
$opt[]="width=".$conf["width"];
|
|
|
4915 |
|
|
|
4916 |
}#if end
|
|
|
4917 |
|
|
|
4918 |
}#if end
|
|
|
4919 |
|
|
|
4920 |
#如果有設定 $conf["height"]
|
|
|
4921 |
if(isset($conf["height"])){
|
|
|
4922 |
|
|
|
4923 |
#如果不是 "screen"
|
|
|
4924 |
if($conf["height"]!=="screen"){
|
|
|
4925 |
|
|
|
4926 |
#設定高度
|
|
|
4927 |
$opt[]="height=".$conf["height"];
|
|
|
4928 |
|
|
|
4929 |
}#if end
|
|
|
4930 |
|
|
|
4931 |
}#if end
|
|
|
4932 |
|
|
|
4933 |
#如果 $conf["toolbar"] 為 "true"
|
|
|
4934 |
if($conf["toolbar"]==="true"){
|
|
|
4935 |
|
|
|
4936 |
#設為 "yes"
|
|
|
4937 |
$conf["toolbar"]="yes";
|
|
|
4938 |
|
|
|
4939 |
}#if end
|
|
|
4940 |
|
|
|
4941 |
#反之
|
|
|
4942 |
else{
|
|
|
4943 |
|
|
|
4944 |
#設為 "no"
|
|
|
4945 |
$conf["toolbar"]="no";
|
|
|
4946 |
|
|
|
4947 |
}#if end
|
|
|
4948 |
|
|
|
4949 |
#設定 toolbar
|
|
|
4950 |
$opt[]="toolbar=".$conf["toolbar"];
|
|
|
4951 |
|
|
|
4952 |
#如果 $conf["menubar"] 為 "true"
|
|
|
4953 |
if($conf["menubar"]==="true"){
|
|
|
4954 |
|
|
|
4955 |
#設置為 "yes"
|
|
|
4956 |
$conf["menubar"]="yes";
|
|
|
4957 |
|
|
|
4958 |
}#if end
|
|
|
4959 |
|
|
|
4960 |
#反之
|
|
|
4961 |
else{
|
|
|
4962 |
|
|
|
4963 |
#設置為 "no"
|
|
|
4964 |
$conf["menubar"]="no";
|
|
|
4965 |
|
|
|
4966 |
}#else end
|
|
|
4967 |
|
|
|
4968 |
#設定 menubar
|
|
|
4969 |
$opt[]="menubar=".$conf["menubar"];
|
|
|
4970 |
|
|
|
4971 |
#如果滾軸要設置
|
|
|
4972 |
if($conf["scrollbars"]==="true"){
|
|
|
4973 |
|
|
|
4974 |
#設置為 "yes"
|
|
|
4975 |
$conf["scrollbars"]="yes";
|
|
|
4976 |
|
|
|
4977 |
}#if end
|
|
|
4978 |
|
|
|
4979 |
#反之
|
|
|
4980 |
else{
|
|
|
4981 |
|
|
|
4982 |
#設置為 "no"
|
|
|
4983 |
$conf["scrollbars"]="no";
|
|
|
4984 |
|
|
|
4985 |
}#else end
|
|
|
4986 |
|
|
|
4987 |
#設置 scrollbars
|
|
|
4988 |
$opt[]="scrollbars=".$conf["scrollbars"];
|
|
|
4989 |
|
|
|
4990 |
#如果 $conf["resizable"] 為 "true"
|
|
|
4991 |
if($conf["resizable"]==="true"){
|
|
|
4992 |
|
|
|
4993 |
#設置為 "yes"
|
|
|
4994 |
$conf["resizable"]="yes";
|
|
|
4995 |
|
|
|
4996 |
}#if end
|
|
|
4997 |
|
|
|
4998 |
#反之
|
|
|
4999 |
else{
|
|
|
5000 |
|
|
|
5001 |
#設置為 "no"
|
|
|
5002 |
$conf["resizable"]="no";
|
|
|
5003 |
|
|
|
5004 |
}#else end
|
|
|
5005 |
|
|
|
5006 |
#設置 resizable
|
|
|
5007 |
$opt[]="resizable=".$conf["resizable"];
|
|
|
5008 |
|
|
|
5009 |
#如果 $conf["location"] 為 "true"
|
|
|
5010 |
if($conf["location"]==="true"){
|
|
|
5011 |
|
|
|
5012 |
#設置為 "yes"
|
|
|
5013 |
$conf["location"]="yes";
|
|
|
5014 |
|
|
|
5015 |
}#if end
|
|
|
5016 |
|
|
|
5017 |
#反之
|
|
|
5018 |
else{
|
|
|
5019 |
|
|
|
5020 |
#設置為 "no"
|
|
|
5021 |
$conf["location"]="no";
|
|
|
5022 |
|
|
|
5023 |
}#else end
|
|
|
5024 |
|
|
|
5025 |
#設置 location
|
|
|
5026 |
$opt[]="location=".$conf["location"];
|
|
|
5027 |
|
|
|
5028 |
#如果 $conf["status"] 為 "true"
|
|
|
5029 |
if($conf["status"]==="true"){
|
|
|
5030 |
|
|
|
5031 |
#設置為 "yes"
|
|
|
5032 |
$conf["status"]="yes";
|
|
|
5033 |
|
|
|
5034 |
}#if end
|
|
|
5035 |
|
|
|
5036 |
#反之
|
|
|
5037 |
else{
|
|
|
5038 |
|
|
|
5039 |
#設置為 "no"
|
|
|
5040 |
$conf["status"]="no";
|
|
|
5041 |
|
|
|
5042 |
}#else end
|
|
|
5043 |
|
|
|
5044 |
#設置 status
|
|
|
5045 |
$opt[]="status=".$conf["status"];
|
|
|
5046 |
|
|
|
5047 |
#如果 $conf["titlebar"] 為 "true"
|
|
|
5048 |
if($conf["titlebar"]==="true"){
|
|
|
5049 |
|
|
|
5050 |
#設置為 "yes"
|
|
|
5051 |
$conf["titlebar"]="yes";
|
|
|
5052 |
|
|
|
5053 |
}#if end
|
|
|
5054 |
|
|
|
5055 |
#反之
|
|
|
5056 |
else{
|
|
|
5057 |
|
|
|
5058 |
#設置為 "no"
|
|
|
5059 |
$conf["titlebar"]="no";
|
|
|
5060 |
|
|
|
5061 |
}#else end
|
|
|
5062 |
|
|
|
5063 |
#設置 location
|
|
|
5064 |
$opt[]="titlebar=".$conf["titlebar"];
|
|
|
5065 |
|
|
|
5066 |
#設置開新視窗的opt
|
|
|
5067 |
#函式說明:
|
|
|
5068 |
#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".
|
|
|
5069 |
#回傳結果:
|
|
|
5070 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5071 |
#$result["function"],當前執行的function名稱
|
|
|
5072 |
#$result["error"],錯誤訊息陣列.
|
|
|
5073 |
#$result["content"],處理好的字串.
|
|
|
5074 |
#必填參數:
|
|
|
5075 |
#$conf["inputArray"],字串陣列,要轉成字串的一維陣列.
|
|
|
5076 |
$conf["arrays::arrayToString"]["inputArray"]=$opt;
|
|
|
5077 |
#可省略參數:
|
|
|
5078 |
#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為;
|
|
|
5079 |
$conf["arrays::arrayToString"]["spiltSymbol"]=",";
|
|
|
5080 |
#$conf["skipEnd"],字串,結尾是否不要加上符號,預設為"false",要加上符號,"true"代表不要加上符號。
|
|
|
5081 |
$conf["arrays::arrayToString"]["skipEnd"]="true";
|
|
|
5082 |
$arrayToString=arrays::arrayToString($conf["arrays::arrayToString"]);
|
|
|
5083 |
unset($conf["arrays::arrayToString"]);
|
|
|
5084 |
|
|
|
5085 |
#如果轉換失敗
|
|
|
5086 |
if($arrayToString["status"]==="false"){
|
|
|
5087 |
|
|
|
5088 |
#設置執行失敗
|
|
|
5089 |
$result["status"]="false";
|
|
|
5090 |
|
|
|
5091 |
#設置執行錯誤訊息
|
|
|
5092 |
$result["error"]=$arrayToString;
|
|
|
5093 |
|
|
|
5094 |
#回傳結果
|
|
|
5095 |
return $result;
|
|
|
5096 |
|
|
|
5097 |
}#if end
|
|
|
5098 |
|
|
|
5099 |
#儲存轉換好的字串
|
|
|
5100 |
$opt=$arrayToString["content"];
|
|
|
5101 |
|
|
|
5102 |
#如果 $conf["width"] 與 $conf["height"] 都是 "screen"
|
|
|
5103 |
if($conf["width"]==="screen" && $conf["height"]==="screen"){
|
|
|
5104 |
|
|
|
5105 |
#設置最大大小的視窗寬高
|
|
|
5106 |
$cusWidthHeight=",width='+window.screen.width+','+'height='+window.screen.height";
|
|
|
5107 |
|
|
|
5108 |
}#if end
|
|
|
5109 |
|
|
|
5110 |
#反之
|
|
|
5111 |
else{
|
|
|
5112 |
|
|
|
5113 |
#設置為 ""
|
|
|
5114 |
$cusWidthHeight="'";
|
|
|
5115 |
|
|
|
5116 |
}#else end
|
|
|
5117 |
|
|
|
5118 |
#如果有指定要儲存到window中的變數
|
|
|
5119 |
if(isset($conf["returnWindowVarName"])){
|
| 226 |
liveuser |
5120 |
|
| 3 |
liveuser |
5121 |
#設置儲存到指定的window中變數
|
|
|
5122 |
$conf["returnWindowVarName"]="window.".$conf["returnWindowVarName"]."=";
|
| 226 |
liveuser |
5123 |
|
| 3 |
liveuser |
5124 |
}#if end
|
| 226 |
liveuser |
5125 |
|
| 3 |
liveuser |
5126 |
#反之
|
|
|
5127 |
else{
|
| 226 |
liveuser |
5128 |
|
| 3 |
liveuser |
5129 |
#設置直接return
|
|
|
5130 |
$conf["returnWindowVarName"]="return ";
|
| 226 |
liveuser |
5131 |
|
| 3 |
liveuser |
5132 |
}#else end
|
|
|
5133 |
|
|
|
5134 |
#開新視窗的js function
|
|
|
5135 |
$js="
|
|
|
5136 |
//open window functino ".$conf["function"]."
|
|
|
5137 |
function ".$conf["function"]."(){
|
|
|
5138 |
|
|
|
5139 |
//開啟新視窗設定
|
|
|
5140 |
".$conf["returnWindowVarName"]."window.open('".$conf["url"]."','".$conf["name"]."','".$opt.$cusWidthHeight.");
|
|
|
5141 |
|
|
|
5142 |
}//function ".$conf["function"]." end
|
|
|
5143 |
";
|
|
|
5144 |
|
|
|
5145 |
#轉換成js語法
|
|
|
5146 |
#函式說明:
|
|
|
5147 |
#將要執行的script語法透過該函式執行(會在程式外層用<script></script>包起來).
|
|
|
5148 |
#回傳結果:
|
|
|
5149 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
5150 |
#$result["error"],錯誤訊息陣列
|
|
|
5151 |
#$result["function"],當前執行的函數名稱
|
|
|
5152 |
#$result["content"],要執行的javaScript語法
|
|
|
5153 |
#必填參數:
|
|
|
5154 |
#$conf["script"],字串,要執行的javaScript語法.
|
|
|
5155 |
$conf["javaScript::toScript"]["script"]="";
|
|
|
5156 |
#可省略參數:
|
|
|
5157 |
#$conf["onReady"],字串,是否要在網頁載入完再執行,"false"為不等載入完就先執行,預設為"true"要等載入完再執行.
|
|
|
5158 |
#$conf["onReady"]="true";
|
|
|
5159 |
#$conf["jsFunciton"],字串陣列,為要放入<script>標籤的js函數.
|
|
|
5160 |
$conf["javaScript::toScript"]["jsFunciton"]=array($js);
|
|
|
5161 |
#參考資料:
|
|
|
5162 |
#http://stackoverflow.com/questions/9899372/pure-javascript-equivalent-to-jquerys-ready-how-to-call-a-function-when-the
|
|
|
5163 |
$toScript=javaScript::toScript($conf["javaScript::toScript"]);
|
|
|
5164 |
unset($conf["javaScript::toScript"]);
|
|
|
5165 |
|
|
|
5166 |
#如果轉換成js失敗
|
|
|
5167 |
if($toScript["status"]==="false"){
|
|
|
5168 |
|
|
|
5169 |
#設置執行失敗
|
|
|
5170 |
$result["status"]="false";
|
|
|
5171 |
|
|
|
5172 |
#設置執行錯誤訊息
|
|
|
5173 |
$result["error"]=$toScript;
|
|
|
5174 |
|
|
|
5175 |
#回傳結果
|
|
|
5176 |
return $result;
|
|
|
5177 |
|
|
|
5178 |
}#if end
|
|
|
5179 |
|
|
|
5180 |
#取得js語法
|
|
|
5181 |
$result["content"]=$toScript["content"];
|
|
|
5182 |
|
|
|
5183 |
#設置執行正常
|
|
|
5184 |
$result["status"]="true";
|
|
|
5185 |
|
|
|
5186 |
#回傳結果
|
|
|
5187 |
return $result;
|
|
|
5188 |
|
|
|
5189 |
}#function openWindows end
|
|
|
5190 |
|
|
|
5191 |
/*
|
|
|
5192 |
#函式說明:
|
|
|
5193 |
#javascript的if...esle if...判斷式.
|
|
|
5194 |
#回傳結果:
|
|
|
5195 |
#$result["status"],執行正確與否,"true"代表執行正確,"false"代表執行失敗.
|
|
|
5196 |
#$result["error"],錯誤訊息陣列.
|
|
|
5197 |
#$result["content"],JavaScript的語法
|
|
|
5198 |
#$result["function"],當前執行的函數名稱
|
|
|
5199 |
#必填參數:
|
|
|
5200 |
#無:
|
|
|
5201 |
#可省略參數:
|
|
|
5202 |
#$conf["scriptTag"],是否要用<script></script>包住,預設為"false",不包住;"true"為包住.
|
|
|
5203 |
#$conf["scriptTag"]="false";
|
|
|
5204 |
#$conf["condition"],陣列,每個判斷式的條件,若有多個則會依序判斷下去.
|
|
|
5205 |
#$conf["condition"]=array();
|
|
|
5206 |
#$conf["conditionComment"],陣列,每個判斷式的註解,預設為$conf["condition"].
|
|
|
5207 |
#$conf["conditionComment"]=array();
|
|
|
5208 |
#$conf["todo"],陣列,每個判斷式成立時要做的事情.
|
|
|
5209 |
#$conf["todo"]=array();
|
|
|
5210 |
#$conf["todoComment"],陣列,每件要做的事情之註解,預設為"do something...".
|
|
|
5211 |
#$conf["todoComment"]=array();
|
|
|
5212 |
#參考資料:
|
|
|
5213 |
#無.
|
|
|
5214 |
#備註:
|
|
|
5215 |
#無.
|
|
|
5216 |
*/
|
|
|
5217 |
public static function jsIf(&$conf=array()){
|
|
|
5218 |
|
|
|
5219 |
#初始化要回傳的結果
|
|
|
5220 |
$result=array();
|
|
|
5221 |
|
|
|
5222 |
#取得當前執行的函數名稱
|
|
|
5223 |
$result["function"]=__FUNCTION__;
|
|
|
5224 |
|
|
|
5225 |
#取得參數
|
|
|
5226 |
$result["argu"]=$conf;
|
|
|
5227 |
|
|
|
5228 |
#如果 $conf 不為陣列
|
|
|
5229 |
if(gettype($conf)!="array"){
|
|
|
5230 |
|
|
|
5231 |
#設置執行失敗
|
|
|
5232 |
$result["status"]="false";
|
|
|
5233 |
|
|
|
5234 |
#設置執行錯誤訊息
|
|
|
5235 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
5236 |
|
|
|
5237 |
#如果傳入的參數為 null
|
|
|
5238 |
if($conf==null){
|
|
|
5239 |
|
|
|
5240 |
#設置執行錯誤訊息
|
|
|
5241 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
5242 |
|
|
|
5243 |
}#if end
|
|
|
5244 |
|
|
|
5245 |
#回傳結果
|
|
|
5246 |
return $result;
|
|
|
5247 |
|
|
|
5248 |
}#if end
|
|
|
5249 |
|
|
|
5250 |
#檢查參數
|
|
|
5251 |
#函式說明:
|
|
|
5252 |
#檢查一包含數個可省略變數的陣列變數,其型態是否正確,省略掉的陣列變數可以直接給定預設值。
|
|
|
5253 |
#回傳結果:
|
|
|
5254 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5255 |
#$result["error"],錯誤訊息陣列.
|
|
|
5256 |
#$result["function"],當前執行的函式名稱.
|
|
|
5257 |
#$result["passed"],參數是否都通過檢查,"true",代表有通過檢查,"false"代表沒有通過檢查。
|
|
|
5258 |
#必填參數:
|
|
|
5259 |
#$conf["checkedVar"],陣列,要檢查的變數陣列名稱為?
|
|
|
5260 |
$conf["variableCheck::checkSkipableVarType"]["checkedVar"]=$conf;
|
|
|
5261 |
#$conf["sikpableVarNameArray"],字串陣列,要檢查型態是否設定正確的變數名稱陣列.
|
|
|
5262 |
$conf["variableCheck::checkSkipableVarType"]["sikpableVarNameArray"]=array("scriptTag","condition","conditionComment","todo","todoComment");
|
|
|
5263 |
#$argu,要直接存取的陣列變數名稱,變數前面加上「&」,如果要在別的函式裡面使用本函式,請記得將變動過結果($argu)給使用該函式的設定變數(通常是$conf=$argu).
|
|
|
5264 |
$argu=&$conf;
|
|
|
5265 |
#可省略參數:
|
|
|
5266 |
#$conf["skipableVarTypeArray"],字串陣列,要檢查的每個變數,其型態應該要為何,null代表不指定變數形態.
|
|
|
5267 |
$conf["variableCheck::checkSkipableVarType"]["skipableVarTypeArray"]=array("string","array","array","array","array");
|
|
|
5268 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的變數要初始化為什麼,null代表不指定.
|
|
|
5269 |
$conf["variableCheck::checkSkipableVarType"]["skipableVarDefaultValue"]=array("false",null,null,null,null);
|
|
|
5270 |
$checkSkipableVarType=variableCheck::checkSkipableVarType($conf["variableCheck::checkSkipableVarType"],$argu);
|
|
|
5271 |
unset($conf["variableCheck::checkSkipableVarType"]);
|
|
|
5272 |
|
|
|
5273 |
#如果檢查失敗
|
|
|
5274 |
if($checkSkipableVarType["status"]=="false"){
|
|
|
5275 |
|
|
|
5276 |
#設置錯誤狀態
|
|
|
5277 |
$result["status"]="false";
|
|
|
5278 |
|
|
|
5279 |
#設置錯誤提示
|
|
|
5280 |
$result["error"]=$checkSkipableVarType;
|
|
|
5281 |
|
|
|
5282 |
#回傳結果
|
|
|
5283 |
return $result;
|
|
|
5284 |
|
|
|
5285 |
}#if end
|
|
|
5286 |
|
|
|
5287 |
#如果檢查不通過
|
|
|
5288 |
if($checkSkipableVarType["passed"]=="false"){
|
|
|
5289 |
|
|
|
5290 |
#設置錯誤狀態
|
|
|
5291 |
$result["status"]="false";
|
|
|
5292 |
|
|
|
5293 |
#設置錯誤提示
|
|
|
5294 |
$result["error"]=$checkSkipableVarType;
|
|
|
5295 |
|
|
|
5296 |
#回傳結果
|
|
|
5297 |
return $result;
|
|
|
5298 |
|
|
|
5299 |
}#if end
|
|
|
5300 |
|
|
|
5301 |
#初始化js script.
|
|
|
5302 |
$script="";
|
|
|
5303 |
|
|
|
5304 |
#產生判斷式與要做的事情.
|
|
|
5305 |
|
|
|
5306 |
#計數
|
|
|
5307 |
$times=0;
|
|
|
5308 |
|
|
|
5309 |
#有幾個判斷式就執行幾次
|
|
|
5310 |
foreach($conf["condition"] as $index=>$condi){
|
|
|
5311 |
|
|
|
5312 |
#如果沒有設置條件的註解
|
|
|
5313 |
if(!isset($conf["conditionComment"])){
|
|
|
5314 |
|
|
|
5315 |
#設置預設的註解
|
|
|
5316 |
$condiComment="if...";
|
|
|
5317 |
|
|
|
5318 |
}#if end
|
|
|
5319 |
|
|
|
5320 |
#反之單獨這條件沒設定註解
|
|
|
5321 |
else if(!isset($conf["conditionComment"][$index])){
|
|
|
5322 |
|
|
|
5323 |
#設置預設的註解
|
|
|
5324 |
$condiComment="if...";
|
|
|
5325 |
|
|
|
5326 |
}#if end
|
|
|
5327 |
|
|
|
5328 |
#反之
|
|
|
5329 |
else{
|
|
|
5330 |
|
|
|
5331 |
#設定條件式註解
|
|
|
5332 |
$condiComment=$conf["conditionComment"][$index];
|
|
|
5333 |
|
|
|
5334 |
}#else end
|
|
|
5335 |
|
|
|
5336 |
#如果沒有設置要做的事之註解
|
|
|
5337 |
if(!isset($conf["todoComment"])){
|
|
|
5338 |
|
|
|
5339 |
#設置預設的註解
|
|
|
5340 |
$todoComment="do something...";
|
|
|
5341 |
|
|
|
5342 |
}#if end
|
|
|
5343 |
|
|
|
5344 |
#反之單獨這條件沒設定設置要做的事之註解
|
|
|
5345 |
else if(!isset($conf["todoComment"][$index])){
|
|
|
5346 |
|
|
|
5347 |
#設置預設的註解
|
|
|
5348 |
$todoComment="do something...";
|
|
|
5349 |
|
|
|
5350 |
}#if end
|
|
|
5351 |
|
|
|
5352 |
#反之有設置註解
|
|
|
5353 |
else{
|
|
|
5354 |
|
|
|
5355 |
#設置的註解
|
|
|
5356 |
$todoComment=$conf["todoComment"][$index];
|
|
|
5357 |
|
|
|
5358 |
}#else end
|
|
|
5359 |
|
|
|
5360 |
#如果存在要做的事情
|
|
|
5361 |
if(isset($conf["todo"][$index])){
|
|
|
5362 |
|
|
|
5363 |
#計數加1
|
|
|
5364 |
$times++;
|
|
|
5365 |
|
|
|
5366 |
#判斷是第幾次,來決定if...else if...的呈現.
|
|
|
5367 |
switch($times){
|
|
|
5368 |
|
|
|
5369 |
#如果是第一個條件
|
|
|
5370 |
case 1:
|
|
|
5371 |
|
|
|
5372 |
#設置判斷與要做的事情
|
|
|
5373 |
$script=$script.
|
|
|
5374 |
"
|
|
|
5375 |
//if ".$condiComment."
|
|
|
5376 |
if(".$condi."){
|
|
|
5377 |
|
|
|
5378 |
//".$todoComment."
|
|
|
5379 |
".$conf["todo"][$index]."
|
|
|
5380 |
|
|
|
5381 |
}//if end
|
|
|
5382 |
";
|
|
|
5383 |
|
|
|
5384 |
#跳出switch
|
|
|
5385 |
break;
|
|
|
5386 |
|
|
|
5387 |
default:
|
|
|
5388 |
|
|
|
5389 |
#設置判斷與要做的事情
|
|
|
5390 |
$script=$script.
|
|
|
5391 |
"
|
|
|
5392 |
//else if ".$condiComment."
|
|
|
5393 |
else if(".$condi."){
|
|
|
5394 |
|
|
|
5395 |
//".$todoComment."
|
|
|
5396 |
".$conf["todo"][$index]."
|
|
|
5397 |
|
|
|
5398 |
}//if end
|
|
|
5399 |
";
|
|
|
5400 |
|
|
|
5401 |
}#switch end
|
|
|
5402 |
|
|
|
5403 |
}#if end
|
|
|
5404 |
|
|
|
5405 |
}#foreach end
|
|
|
5406 |
|
|
|
5407 |
#判斷有無要加<script></script>
|
|
|
5408 |
if($conf["scriptTag"]==="true"){
|
|
|
5409 |
|
|
|
5410 |
#函式說明:
|
|
|
5411 |
#依據需要加上<script></script>標籤,並且可以指定要匯入的js檔案.
|
|
|
5412 |
#回傳結果:
|
|
|
5413 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
5414 |
#$result["error"],錯誤訊息陣列
|
|
|
5415 |
#$result["function"],當前執行的函數名稱
|
|
|
5416 |
#$result["content"],javaScript語法
|
|
|
5417 |
#$result["importJS"],匯入js的語法,必定含有<script></script>標籤.
|
|
|
5418 |
#必填參數:
|
|
|
5419 |
#$conf["jsProgramSection"],陣列字串,不含<script></script>標籤的javsScript程式碼,可以放多個script程式.
|
|
|
5420 |
$conf["javaScript::addScriptTag"]["jsProgramSection"]=array($script);
|
|
|
5421 |
#可省略參數:
|
|
|
5422 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑,請與參數"jsPosition"一起設置,預設為當前檔案的位置.
|
|
|
5423 |
#$conf["fileArgu"]=__FILE__;
|
|
|
5424 |
#$conf["jsPosition"],字串,要匯入的js檔案位置.
|
|
|
5425 |
#$conf["jsPosition"]="";
|
|
|
5426 |
#$conf["noScriptTag"],字串,是否不要用script tag包住回傳的內容($result["content"]),"true"代表不要用,"false"代表要用,預設為"false".
|
|
|
5427 |
#$conf["noScriptTag"]="false";
|
|
|
5428 |
$addScriptTag=javaScript::addScriptTag($conf["javaScript::addScriptTag"]);
|
|
|
5429 |
unset($conf["javaScript::addScriptTag"]);
|
|
|
5430 |
|
|
|
5431 |
#如果加上script標籤失敗
|
|
|
5432 |
if($addScriptTag["status"]==="false"){
|
|
|
5433 |
|
|
|
5434 |
#設置錯誤狀態
|
|
|
5435 |
$result["status"]="false";
|
|
|
5436 |
|
|
|
5437 |
#設置錯誤提示
|
|
|
5438 |
$result["error"]=$addScriptTag;
|
|
|
5439 |
|
|
|
5440 |
#回傳結果
|
|
|
5441 |
return $result;
|
|
|
5442 |
|
|
|
5443 |
}#if end
|
|
|
5444 |
|
|
|
5445 |
#取得js語法
|
|
|
5446 |
$result["content"]=$addScriptTag["content"];
|
|
|
5447 |
|
|
|
5448 |
}#if end
|
|
|
5449 |
|
|
|
5450 |
#反之
|
|
|
5451 |
else{
|
|
|
5452 |
|
|
|
5453 |
#取得js語法
|
|
|
5454 |
$result["content"]=$script;
|
|
|
5455 |
|
|
|
5456 |
}#else end
|
|
|
5457 |
|
|
|
5458 |
#設置執行正常
|
|
|
5459 |
$result["status"]="true";
|
|
|
5460 |
|
|
|
5461 |
#回傳結果
|
|
|
5462 |
return $result;
|
|
|
5463 |
|
|
|
5464 |
}#function jsIF end
|
|
|
5465 |
|
|
|
5466 |
/*
|
|
|
5467 |
#函式說明:
|
|
|
5468 |
#建立qbpwcf專屬的js函式庫
|
|
|
5469 |
#回傳結果
|
|
|
5470 |
#$result["funciton"],當前函式的名稱.
|
|
|
5471 |
#$result["status"],執行的狀態,"true"代表正常,"false"代表不正常.
|
|
|
5472 |
#$result["error"],錯誤訊息
|
|
|
5473 |
#$result["content"],語法.
|
|
|
5474 |
#必填參數:
|
|
|
5475 |
#無.
|
|
|
5476 |
#可省略參數:
|
|
|
5477 |
#$conf["noScriptTag"],字串,是否不要輸出<script></script>,預設為"false",代表要輸出;反之為"true",代表不要輸出.
|
|
|
5478 |
#$conf["noScriptTag"]="false";
|
|
|
5479 |
#參考資料:
|
|
|
5480 |
#無.
|
|
|
5481 |
#備註:
|
|
|
5482 |
#無.
|
|
|
5483 |
*/
|
|
|
5484 |
public static function qbpwcfJavaScript(&$conf=array()){
|
|
|
5485 |
|
|
|
5486 |
#初始化要回傳的結果
|
|
|
5487 |
$result=array();
|
|
|
5488 |
|
|
|
5489 |
#取得當前執行的函數名稱
|
|
|
5490 |
$result["function"]=__FUNCTION__;
|
|
|
5491 |
|
|
|
5492 |
#檢查參數
|
|
|
5493 |
#函式說明:
|
|
|
5494 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
|
|
|
5495 |
#回傳結果:
|
|
|
5496 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5497 |
#$result["error"],執行不正常結束的錯訊息陣列.
|
|
|
5498 |
#$result["simpleError"],簡單表示的錯誤訊息.
|
|
|
5499 |
#$result["function"],當前執行的函式名稱.
|
|
|
5500 |
#$result["argu"],設置給予的參數.
|
|
|
5501 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
5502 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
5503 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
5504 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
5505 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
5506 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
5507 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
5508 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
5509 |
#必填參數:
|
|
|
5510 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
5511 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
5512 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
5513 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
5514 |
#可省略參數:
|
|
|
5515 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
5516 |
#$conf["mustBeFilledVariableName"]=array();
|
|
|
5517 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
|
|
|
5518 |
#$conf["mustBeFilledVariableType"]=array();
|
|
|
5519 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
5520 |
#$conf["canBeEmptyString"]="false";
|
|
|
5521 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
5522 |
#$conf["canNotBeEmpty"]=array();
|
|
|
5523 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
5524 |
#$conf["canBeEmpty"]=array();
|
|
|
5525 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
5526 |
#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array();
|
|
|
5527 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
5528 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("noScriptTag");
|
|
|
5529 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
5530 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
5531 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
5532 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
|
|
|
5533 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
5534 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
5535 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
5536 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
5537 |
#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
|
|
|
5538 |
#$conf["disallowAllSkipableVarNotExist"]="";
|
|
|
5539 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
5540 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
5541 |
#參考資料:
|
|
|
5542 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
5543 |
#備註:
|
|
|
5544 |
#無.
|
|
|
5545 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
5546 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
5547 |
|
|
|
5548 |
#如果執行出錯
|
|
|
5549 |
if($checkArguments["status"]==="false"){
|
|
|
5550 |
|
|
|
5551 |
#設置錯誤狀態
|
|
|
5552 |
$result["status"]="false";
|
|
|
5553 |
|
|
|
5554 |
#設置錯誤提示
|
|
|
5555 |
$result["error"]=$checkArguments;
|
|
|
5556 |
|
|
|
5557 |
#回傳結果
|
|
|
5558 |
return $result;
|
|
|
5559 |
|
|
|
5560 |
}#if end
|
| 226 |
liveuser |
5561 |
|
| 3 |
liveuser |
5562 |
#如果檢查不通過
|
|
|
5563 |
if($checkArguments["passed"]==="false"){
|
|
|
5564 |
|
|
|
5565 |
#設置錯誤狀態
|
|
|
5566 |
$result["status"]="false";
|
|
|
5567 |
|
|
|
5568 |
#設置錯誤提示
|
|
|
5569 |
$result["error"]=$checkArguments;
|
|
|
5570 |
|
|
|
5571 |
#回傳結果
|
|
|
5572 |
return $result;
|
|
|
5573 |
|
|
|
5574 |
}#if end
|
|
|
5575 |
|
|
|
5576 |
#函式說明:
|
|
|
5577 |
#將要執行的script語法透過該函式執行(會在程式外層用<script></script>包起來).
|
|
|
5578 |
#回傳結果:
|
|
|
5579 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
5580 |
#$result["error"],錯誤訊息陣列
|
|
|
5581 |
#$result["function"],當前執行的函數名稱
|
|
|
5582 |
#$result["content"],要執行的javaScript語法
|
|
|
5583 |
#必填參數:
|
|
|
5584 |
#$conf["script"],字串,要執行的javaScript語法.
|
|
|
5585 |
$conf["javaScript::toScript"]["script"]=
|
|
|
5586 |
"
|
|
|
5587 |
//debug
|
|
|
5588 |
console.log('override addEventListener');
|
| 226 |
liveuser |
5589 |
|
| 3 |
liveuser |
5590 |
//參考資料 https://stackoverflow.com/questions/446892/how-to-find-event-listeners-on-a-dom-node-when-debugging-or-from-the-javascript
|
|
|
5591 |
//override addEventListener, when not native code
|
| 226 |
liveuser |
5592 |
if(Element.prototype.addEventListener.toString().includes('native code')!==true){
|
| 3 |
liveuser |
5593 |
Element.prototype._addEventListener = Element.prototype.addEventListener;
|
|
|
5594 |
Element.prototype.addEventListener = function(a,b,c){
|
|
|
5595 |
this._addEventListener(a,b,c);
|
|
|
5596 |
if(!this.eventListenerList) {
|
|
|
5597 |
this.eventListenerList = {};
|
|
|
5598 |
}
|
|
|
5599 |
if(!this.eventListenerList[a]) {
|
|
|
5600 |
this.eventListenerList[a] = [];
|
|
|
5601 |
}
|
|
|
5602 |
this.eventListenerList[a].push(b);
|
|
|
5603 |
};
|
|
|
5604 |
}//if end
|
| 226 |
liveuser |
5605 |
|
| 3 |
liveuser |
5606 |
//debug
|
|
|
5607 |
//console.log('add scrollingListMiddleEvent');
|
|
|
5608 |
|
|
|
5609 |
//新增當視窗大小改變時的事件
|
|
|
5610 |
window.scrollingListMiddleEvent();
|
|
|
5611 |
|
|
|
5612 |
//frame 大小調整 - start
|
|
|
5613 |
|
|
|
5614 |
//立馬跑一次
|
|
|
5615 |
window.changeFrameEleHeightToFullLessSource.run.call();
|
|
|
5616 |
|
|
|
5617 |
//綁定事件
|
|
|
5618 |
window.addEventListener('resize',window.changeFrameEleHeightToFullLessSource.run);
|
|
|
5619 |
|
|
|
5620 |
//frame 大小調整 - end
|
|
|
5621 |
|
|
|
5622 |
//div frame 大小調整 - start
|
|
|
5623 |
|
|
|
5624 |
//立馬跑一次
|
|
|
5625 |
window.changeDivFrameEleHeightToFullLessSource.run.call();
|
|
|
5626 |
|
|
|
5627 |
//綁定事件
|
|
|
5628 |
window.addEventListener('resize',window.changeDivFrameEleHeightToFullLessSource.run);
|
|
|
5629 |
|
|
|
5630 |
//frame 大小調整 - end
|
|
|
5631 |
|
|
|
5632 |
//綁定檢查reCAPTCHA的事件
|
|
|
5633 |
getGoogle_reCAPTCHA_res_event();
|
|
|
5634 |
|
|
|
5635 |
//托移的事件
|
|
|
5636 |
window.dragEventHandler.func.call();
|
|
|
5637 |
|
|
|
5638 |
//如果沒有 window.qbpwcf
|
|
|
5639 |
if(window.qbpwcf===undefined){
|
| 226 |
liveuser |
5640 |
|
| 3 |
liveuser |
5641 |
//初始化為空物件
|
|
|
5642 |
window.qbpwcf={};
|
| 226 |
liveuser |
5643 |
|
| 3 |
liveuser |
5644 |
}//if end
|
|
|
5645 |
|
|
|
5646 |
//close Icon
|
|
|
5647 |
window.qbpwcf.closeIcon='data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjwhLS0gQ3JlYXRlZCB3aXRoIElua3NjYXBlIChodHRwOi8vd3d3Lmlua3NjYXBlLm9yZy8pIC0tPgoKPHN2ZwogICB4bWxuczpvc2I9Imh0dHA6Ly93d3cub3BlbnN3YXRjaGJvb2sub3JnL3VyaS8yMDA5L29zYiIKICAgeG1sbnM6ZGM9Imh0dHA6Ly9wdXJsLm9yZy9kYy9lbGVtZW50cy8xLjEvIgogICB4bWxuczpjYz0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvbnMjIgogICB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiCiAgIHhtbG5zOnN2Zz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCiAgIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIKICAgeG1sbnM6c29kaXBvZGk9Imh0dHA6Ly9zb2RpcG9kaS5zb3VyY2Vmb3JnZS5uZXQvRFREL3NvZGlwb2RpLTAuZHRkIgogICB4bWxuczppbmtzY2FwZT0iaHR0cDovL3d3dy5pbmtzY2FwZS5vcmcvbmFtZXNwYWNlcy9pbmtzY2FwZSIKICAgd2lkdGg9IjEwNS43ODE3Mm1tIgogICBoZWlnaHQ9IjEwNS4zNDM0NG1tIgogICB2aWV3Qm94PSIwIDAgMTA1Ljc4MTcyIDEwNS4zNDM0NCIKICAgdmVyc2lvbj0iMS4xIgogICBpZD0ic3ZnOCIKICAgaW5rc2NhcGU6dmVyc2lvbj0iMC45MitkZXZlbCB1bmtub3duIgogICBzb2RpcG9kaTpkb2NuYW1lPSJjbG9zZUljb24uc3ZnIj4KICA8ZGVmcwogICAgIGlkPSJkZWZzMiI+CiAgICA8bGluZWFyR3JhZGllbnQKICAgICAgIGlkPSJsaW5lYXJHcmFkaWVudDQzMTUiCiAgICAgICBvc2I6cGFpbnQ9InNvbGlkIj4KICAgICAgPHN0b3AKICAgICAgICAgc3R5bGU9InN0b3AtY29sb3I6IzAwMDAwMDtzdG9wLW9wYWNpdHk6MTsiCiAgICAgICAgIG9mZnNldD0iMCIKICAgICAgICAgaWQ9InN0b3A0MzEzIiAvPgogICAgPC9saW5lYXJHcmFkaWVudD4KICAgIDxmaWx0ZXIKICAgICAgIGlua3NjYXBlOmNvbGxlY3Q9ImFsd2F5cyIKICAgICAgIHN0eWxlPSJjb2xvci1pbnRlcnBvbGF0aW9uLWZpbHRlcnM6c1JHQiIKICAgICAgIGlkPSJmaWx0ZXI0MzkxIgogICAgICAgeD0iLTAuMDY4OTc3MTAzIgogICAgICAgd2lkdGg9IjEuMTM3OTU0MiIKICAgICAgIHk9Ii0wLjA3NTI5OTk5MyIKICAgICAgIGhlaWdodD0iMS4xNTA2Ij4KICAgICAgPGZlR2F1c3NpYW5CbHVyCiAgICAgICAgIGlua3NjYXBlOmNvbGxlY3Q9ImFsd2F5cyIKICAgICAgICAgc3RkRGV2aWF0aW9uPSIxLjAwNjI1NDMiCiAgICAgICAgIGlkPSJmZUdhdXNzaWFuQmx1cjQzOTMiIC8+CiAgICA8L2ZpbHRlcj4KICAgIDxmaWx0ZXIKICAgICAgIGlua3NjYXBlOmNvbGxlY3Q9ImFsd2F5cyIKICAgICAgIHN0eWxlPSJjb2xvci1pbnRlcnBvbGF0aW9uLWZpbHRlcnM6c1JHQiIKICAgICAgIGlkPSJmaWx0ZXI0NDM4IgogICAgICAgeD0iLTAuMDIyNjIyOTA0IgogICAgICAgd2lkdGg9IjEuMDQ1MjQ1OCIKICAgICAgIHk9Ii0wLjAyNTU1NTYxNCIKICAgICAgIGhlaWdodD0iMS4wNTExMTEyIj4KICAgICAgPGZlR2F1c3NpYW5CbHVyCiAgICAgICAgIGlua3NjYXBlOmNvbGxlY3Q9ImFsd2F5cyIKICAgICAgICAgc3RkRGV2aWF0aW9uPSIwLjIyMTcwNjAxIgogICAgICAgICBpZD0iZmVHYXVzc2lhbkJsdXI0NDQwIiAvPgogICAgPC9maWx0ZXI+CiAgICA8ZmlsdGVyCiAgICAgICBpbmtzY2FwZTpjb2xsZWN0PSJhbHdheXMiCiAgICAgICBzdHlsZT0iY29sb3ItaW50ZXJwb2xhdGlvbi1maWx0ZXJzOnNSR0IiCiAgICAgICBpZD0iZmlsdGVyNDQ0NiIKICAgICAgIHg9Ii0wLjAyMzIzMjg0NyIKICAgICAgIHdpZHRoPSIxLjA0NjQ2NTgiCiAgICAgICB5PSItMC4wMjQ4MTk1NDUiCiAgICAgICBoZWlnaHQ9IjEuMDQ5NjM5MSI+CiAgICAgIDxmZUdhdXNzaWFuQmx1cgogICAgICAgICBpbmtzY2FwZTpjb2xsZWN0PSJhbHdheXMiCiAgICAgICAgIHN0ZERldmlhdGlvbj0iMC4yMjIwOTQyOCIKICAgICAgICAgaWQ9ImZlR2F1c3NpYW5CbHVyNDQ0OCIgLz4KICAgIDwvZmlsdGVyPgogIDwvZGVmcz4KICA8c29kaXBvZGk6bmFtZWR2aWV3CiAgICAgaWQ9ImJhc2UiCiAgICAgcGFnZWNvbG9yPSIjZmZmZmZmIgogICAgIGJvcmRlcmNvbG9yPSIjNjY2NjY2IgogICAgIGJvcmRlcm9wYWNpdHk9IjEuMCIKICAgICBpbmtzY2FwZTpwYWdlb3BhY2l0eT0iMC4wIgogICAgIGlua3NjYXBlOnBhZ2VzaGFkb3c9IjIiCiAgICAgaW5rc2NhcGU6em9vbT0iMS40IgogICAgIGlua3NjYXBlOmN4PSIxMzAuNTY4NjgiCiAgICAgaW5rc2NhcGU6Y3k9IjIwMS4zNDg0NSIKICAgICBpbmtzY2FwZTpkb2N1bWVudC11bml0cz0ibW0iCiAgICAgaW5rc2NhcGU6Y3VycmVudC1sYXllcj0iZzQ0ODgiCiAgICAgaW5rc2NhcGU6ZG9jdW1lbnQtcm90YXRpb249IjAiCiAgICAgc2hvd2dyaWQ9ImZhbHNlIgogICAgIGlua3NjYXBlOndpbmRvdy13aWR0aD0iMTYwMCIKICAgICBpbmtzY2FwZTp3aW5kb3ctaGVpZ2h0PSI4MzYiCiAgICAgaW5rc2NhcGU6d2luZG93LXg9IjAiCiAgICAgaW5rc2NhcGU6d2luZG93LXk9IjI3IgogICAgIGlua3NjYXBlOndpbmRvdy1tYXhpbWl6ZWQ9IjEiIC8+CiAgPG1ldGFkYXRhCiAgICAgaWQ9Im1ldGFkYXRhNSI+CiAgICA8cmRmOlJERj4KICAgICAgPGNjOldvcmsKICAgICAgICAgcmRmOmFib3V0PSIiPgogICAgICAgIDxkYzpmb3JtYXQ+aW1hZ2Uvc3ZnK3htbDwvZGM6Zm9ybWF0PgogICAgICAgIDxkYzp0eXBlCiAgICAgICAgICAgcmRmOnJlc291cmNlPSJodHRwOi8vcHVybC5vcmcvZGMvZGNtaXR5cGUvU3RpbGxJbWFnZSIgLz4KICAgICAgICA8ZGM6dGl0bGUgLz4KICAgICAgPC9jYzpXb3JrPgogICAgPC9yZGY6UkRGPgogIDwvbWV0YWRhdGE+CiAgPGcKICAgICBpbmtzY2FwZTpsYWJlbD0iTGF5ZXIgMSIKICAgICBpbmtzY2FwZTpncm91cG1vZGU9ImxheWVyIgogICAgIGlkPSJsYXllcjEiCiAgICAgc3R5bGU9ImRpc3BsYXk6aW5saW5lIgogICAgIHRyYW5zZm9ybT0idHJhbnNsYXRlKC01MC4wNTQwMzQsLTg5LjA0MzUyMikiPgogICAgPGcKICAgICAgIGlkPSJnNDQ4OCIKICAgICAgIHRyYW5zZm9ybT0ibWF0cml4KDIuNjU1MDQ0MywwLDAsMi44NTQ2OTA3LC0xMTAuOTk1MTgsLTMyNi45MjY1MikiPgogICAgICA8ZWxsaXBzZQogICAgICAgICByeT0iMTYuMDM1OTI3IgogICAgICAgICByeD0iMTcuNTA1ODg0IgogICAgICAgICBjeT0iMTY0LjE2NTUxIgogICAgICAgICBjeD0iODAuNTc4NzIiCiAgICAgICAgIGlkPSJwYXRoMzQ3NCIKICAgICAgICAgc3R5bGU9Im9wYWNpdHk6MC4zO2ZpbGw6IzAwMDAwMDtmaWxsLW9wYWNpdHk6MTtmaWxsLXJ1bGU6bm9uemVybztzdHJva2U6IzAwMDAwMDtzdHJva2Utd2lkdGg6MC4yNjQ5OTk5OTtzdHJva2UtbWl0ZXJsaW1pdDo0O3N0cm9rZS1kYXNoYXJyYXk6bm9uZTtzdHJva2Utb3BhY2l0eToxO2ZpbHRlcjp1cmwoI2ZpbHRlcjQzOTEpO2ltYWdlLXJlbmRlcmluZzphdXRvIiAvPgogICAgICA8cmVjdAogICAgICAgICB0cmFuc2Zvcm09InJvdGF0ZSgtNDIuODA4OTU1KSIKICAgICAgICAgcnk9IjAiCiAgICAgICAgIHk9IjE3NC41NTY0OSIKICAgICAgICAgeD0iLTY3LjM5ODc1OCIKICAgICAgICAgaGVpZ2h0PSIyLjE1MjIwNjQiCiAgICAgICAgIHdpZHRoPSIyOS4yNzk2NDgiCiAgICAgICAgIGlkPSJyZWN0NDQxMyIKICAgICAgICAgc3R5bGU9Im9wYWNpdHk6MTtmaWxsOiNmZmZmMDA7ZmlsbC1vcGFjaXR5OjE7ZmlsbC1ydWxlOm5vbnplcm87c3Ryb2tlOiMwMDAwMDA7c3Ryb2tlLXdpZHRoOjA7c3Ryb2tlLW1pdGVybGltaXQ6NDtzdHJva2UtZGFzaGFycmF5Om5vbmU7c3Ryb2tlLW9wYWNpdHk6MTtmaWx0ZXI6dXJsKCNmaWx0ZXI0NDQ2KSIgLz4KICAgICAgPHJlY3QKICAgICAgICAgdHJhbnNmb3JtPSJyb3RhdGUoLTEzOS4wMzQ0MikiCiAgICAgICAgIHJ5PSIwIgogICAgICAgICB5PSItNzMuMDUwOTQ5IgogICAgICAgICB4PSItMTgyLjk2MjUyIgogICAgICAgICBoZWlnaHQ9IjIuMTUyMjA2NCIKICAgICAgICAgd2lkdGg9IjI5LjI3OTY0OCIKICAgICAgICAgaWQ9InJlY3Q0NDEzLTMiCiAgICAgICAgIHN0eWxlPSJvcGFjaXR5OjE7ZmlsbDojZmZmZjAwO2ZpbGwtb3BhY2l0eToxO2ZpbGwtcnVsZTpub256ZXJvO3N0cm9rZTojMDAwMDAwO3N0cm9rZS13aWR0aDowO3N0cm9rZS1taXRlcmxpbWl0OjQ7c3Ryb2tlLWRhc2hhcnJheTpub25lO3N0cm9rZS1vcGFjaXR5OjE7ZmlsdGVyOnVybCgjZmlsdGVyNDQzOCkiIC8+CiAgICA8L2c+CiAgPC9nPgo8L3N2Zz4K';
|
|
|
5648 |
|
|
|
5649 |
";
|
|
|
5650 |
#可省略參數:
|
|
|
5651 |
#$conf["onReady"],字串,是否要在網頁載入完再執行,"false"為不等載入完就先執行,預設為"true"要等載入完再執行.
|
|
|
5652 |
$conf["javaScript::toScript"]["onReady"]="true";
|
|
|
5653 |
#$conf["globalJs"],字串陣列,為要放入<script>標籤的js全域變數.
|
|
|
5654 |
#$conf["globalJs"]=array();
|
|
|
5655 |
#$conf["jsFunciton"],字串陣列,為要放入<script>標籤的js函數.
|
|
|
5656 |
$conf["javaScript::toScript"]["jsFunciton"][]=
|
|
|
5657 |
"
|
|
|
5658 |
//調整滾軸表單的置中效果事件
|
|
|
5659 |
function scrollingListMiddleEvent(){
|
|
|
5660 |
|
|
|
5661 |
//綁定視窗resize的事件
|
|
|
5662 |
window.addEventListener('resize',function(event){
|
|
|
5663 |
|
|
|
5664 |
//debug
|
|
|
5665 |
//console.log('resized');
|
|
|
5666 |
|
|
|
5667 |
//調整滾軸表單的置中效果
|
|
|
5668 |
scrollingListMiddleFunction();
|
|
|
5669 |
|
|
|
5670 |
});
|
|
|
5671 |
|
|
|
5672 |
}//function scrollingListMiddleEvent end
|
|
|
5673 |
";
|
|
|
5674 |
$conf["javaScript::toScript"]["jsFunciton"][]=
|
|
|
5675 |
"
|
|
|
5676 |
//調整滾軸表單的置中效果
|
|
|
5677 |
function scrollingListMiddleFunction(){
|
|
|
5678 |
|
|
|
5679 |
//取得下拉式選單的div
|
|
|
5680 |
var rootDiv=document.getElementById('scrollingListRootDiv');
|
|
|
5681 |
|
|
|
5682 |
//如果沒有下拉式選單的div
|
|
|
5683 |
if(rootDiv===null){
|
|
|
5684 |
|
|
|
5685 |
//debug
|
|
|
5686 |
//console.log('沒有下拉式選單的div');
|
|
|
5687 |
|
|
|
5688 |
return false;
|
|
|
5689 |
|
|
|
5690 |
}//if end
|
|
|
5691 |
|
|
|
5692 |
//取得下拉式選單的外框高度
|
|
|
5693 |
var listOutterDivHeight=rootDiv.children[0].clientHeight;
|
|
|
5694 |
|
|
|
5695 |
//下拉式選單的外框高度
|
|
|
5696 |
//console.log(listOutterDivHeight);
|
|
|
5697 |
|
|
|
5698 |
//取得下拉式選單的內寬高度
|
|
|
5699 |
var listInnerDivHeight=rootDiv.children[0].children[0].clientHeight;
|
|
|
5700 |
|
|
|
5701 |
//下拉式選單的內寬高度
|
|
|
5702 |
//console.log(listInnerDivHeight);
|
|
|
5703 |
|
|
|
5704 |
//如果有滾軸
|
|
|
5705 |
if(rootDiv.children[0].scrollTopMax!==0 && rootDiv.children[0].scrollTopMax!==undefined){
|
|
|
5706 |
|
|
|
5707 |
//debug
|
|
|
5708 |
//console.log('有滾軸');
|
|
|
5709 |
|
|
|
5710 |
//debug
|
|
|
5711 |
//console.log(rootDiv.children[0].scrollTopMax);
|
|
|
5712 |
|
|
|
5713 |
//取消選項內框與選單外框的高度
|
|
|
5714 |
rootDiv.children[0].children[0].style['margin-top']='unset';
|
|
|
5715 |
|
|
|
5716 |
//結束 event
|
|
|
5717 |
return false;
|
|
|
5718 |
|
|
|
5719 |
}//if end
|
|
|
5720 |
|
|
|
5721 |
//沒有滾軸
|
|
|
5722 |
|
|
|
5723 |
//debug
|
|
|
5724 |
//console.log('沒有滾軸');
|
|
|
5725 |
|
|
|
5726 |
//計算選項內框與選單外框的高度
|
|
|
5727 |
var marginTop=((listOutterDivHeight-listInnerDivHeight)/2).toString()+'px';
|
|
|
5728 |
|
|
|
5729 |
//debug
|
|
|
5730 |
//console.log(marginTop);
|
|
|
5731 |
|
|
|
5732 |
//如果是火狐瀏覽器
|
|
|
5733 |
if(navigator.userAgent.includes('Firefox')){
|
|
|
5734 |
|
|
|
5735 |
//設置選項內框與選單外框的高度,已便讓選項列表上下置中於選單外框
|
|
|
5736 |
rootDiv.children[0].children[0].style.marginTop=marginTop;
|
| 226 |
liveuser |
5737 |
|
| 3 |
liveuser |
5738 |
}//if end
|
|
|
5739 |
|
| 226 |
liveuser |
5740 |
|
| 3 |
liveuser |
5741 |
}//function scrollingListMiddleFunction end
|
|
|
5742 |
";
|
|
|
5743 |
$conf["javaScript::toScript"]["jsFunciton"][]=
|
|
|
5744 |
"
|
|
|
5745 |
//變更iframe自己的高度為螢幕高度減去來源iframe高度的function
|
|
|
5746 |
var changeFrameEleHeightToFullLessSource={
|
|
|
5747 |
|
|
|
5748 |
changeSizeFrameId:null,
|
|
|
5749 |
fixedSizeFrameId:null,
|
|
|
5750 |
run:function(){
|
|
|
5751 |
|
|
|
5752 |
var changeSizeFrameId=window.changeFrameEleHeightToFullLessSource.changeSizeFrameId;
|
|
|
5753 |
var fixedSizeFrameId=window.changeFrameEleHeightToFullLessSource.fixedSizeFrameId;
|
|
|
5754 |
|
|
|
5755 |
//如果未設置則結束函式
|
|
|
5756 |
if(changeSizeFrameId===null || fixedSizeFrameId===null)
|
|
|
5757 |
{
|
|
|
5758 |
return false;
|
|
|
5759 |
}
|
|
|
5760 |
|
|
|
5761 |
var bottomDiv=document.getElementById(fixedSizeFrameId).parentElement;
|
|
|
5762 |
var bottomDivH=bottomDiv.clientHeight;
|
|
|
5763 |
|
|
|
5764 |
var windowH=document.body.clientHeight;
|
|
|
5765 |
|
|
|
5766 |
var topDiv=document.getElementById(changeSizeFrameId).parentElement;
|
|
|
5767 |
var topDivH=topDiv.clientHeight;
|
|
|
5768 |
|
|
|
5769 |
var bottomDivStyle=window.getComputedStyle(bottomDiv,null);
|
|
|
5770 |
//console.log('original height is '+bottomDivStyle['height']);
|
|
|
5771 |
|
|
|
5772 |
//console.log('var windowH is '+windowH);
|
|
|
5773 |
//console.log('var topDivH is '+topDivH);
|
|
|
5774 |
var newBottomDivH=windowH-topDivH+'px';
|
|
|
5775 |
bottomDiv.style.height=windowH-topDivH+'px';
|
|
|
5776 |
//console.log('altered height is '+newBottomDivH);
|
|
|
5777 |
}
|
|
|
5778 |
}
|
|
|
5779 |
";
|
|
|
5780 |
$conf["javaScript::toScript"]["jsFunciton"][]=
|
|
|
5781 |
"
|
|
|
5782 |
//變更div frame 自己的高度為螢幕高度減去來源 div frame 高度的 function
|
|
|
5783 |
var changeDivFrameEleHeightToFullLessSource={
|
|
|
5784 |
|
|
|
5785 |
changeSizeFrameId:null,
|
|
|
5786 |
fixedSizeFrameId:null,
|
|
|
5787 |
run:function(){
|
|
|
5788 |
|
|
|
5789 |
var changeSizeFrameId=window.changeDivFrameEleHeightToFullLessSource.changeSizeFrameId;
|
|
|
5790 |
var fixedSizeFrameId=window.changeDivFrameEleHeightToFullLessSource.fixedSizeFrameId;
|
|
|
5791 |
|
|
|
5792 |
//如果未設置則結束函式
|
|
|
5793 |
if(changeSizeFrameId===null || fixedSizeFrameId===null)
|
|
|
5794 |
{
|
|
|
5795 |
//console.log('no target');
|
|
|
5796 |
return false;
|
|
|
5797 |
}
|
|
|
5798 |
|
|
|
5799 |
var bottomDiv=document.getElementById(fixedSizeFrameId);
|
|
|
5800 |
var bottomDivH=bottomDiv.clientHeight;
|
|
|
5801 |
|
|
|
5802 |
var windowH=document.body.clientHeight;
|
|
|
5803 |
|
|
|
5804 |
var topDiv=document.getElementById(changeSizeFrameId);
|
|
|
5805 |
var topDivH=topDiv.clientHeight;
|
|
|
5806 |
|
|
|
5807 |
var bottomDivStyle=window.getComputedStyle(bottomDiv,null);
|
|
|
5808 |
//console.log('original height is '+bottomDivStyle['height']);
|
|
|
5809 |
|
|
|
5810 |
//console.log('var windowH is '+windowH);
|
|
|
5811 |
//console.log('var topDivH is '+topDivH);
|
|
|
5812 |
var newBottomDivH=windowH-topDivH+'px';
|
|
|
5813 |
bottomDiv.style.height=windowH-topDivH+'px';
|
|
|
5814 |
//console.log('altered height is '+newBottomDivH);
|
|
|
5815 |
}
|
|
|
5816 |
}
|
|
|
5817 |
";
|
|
|
5818 |
$conf["javaScript::toScript"]["jsFunciton"][]=
|
|
|
5819 |
"
|
|
|
5820 |
// custom blob function start
|
|
|
5821 |
|
|
|
5822 |
var MyBlobBuilder = function() {
|
|
|
5823 |
this.parts = [];
|
|
|
5824 |
}
|
|
|
5825 |
|
|
|
5826 |
MyBlobBuilder.prototype.append = function(part) {
|
|
|
5827 |
this.parts.push(part);
|
|
|
5828 |
this.blob = undefined; // Invalidate the blob
|
|
|
5829 |
};
|
|
|
5830 |
|
|
|
5831 |
MyBlobBuilder.prototype.getBlob = function(mimeType) {
|
|
|
5832 |
if(mimeType===''){
|
|
|
5833 |
mimeType=\"text/plain\";
|
|
|
5834 |
}
|
|
|
5835 |
if (!this.blob) {
|
|
|
5836 |
this.blob = new Blob(this.parts, { type: mimeType });
|
|
|
5837 |
}
|
|
|
5838 |
return this.blob;
|
|
|
5839 |
};
|
|
|
5840 |
|
|
|
5841 |
// custom blob function end
|
|
|
5842 |
";
|
|
|
5843 |
$conf["javaScript::toScript"]["jsFunciton"][]=
|
|
|
5844 |
"
|
|
|
5845 |
// 建構子 conDownloadAgent start
|
|
|
5846 |
var conDownloadAgent=function(){
|
|
|
5847 |
|
|
|
5848 |
this.xmlhttp=''; //XMLHttpRequest
|
|
|
5849 |
this.fileUrl=''; //要下載的檔案url
|
|
|
5850 |
this.resHeaders=''; //回傳的header
|
|
|
5851 |
this.resHeadersArray=[];//回傳的header array
|
|
|
5852 |
this.fileContent=new Blob(); //檔案的2元碼
|
|
|
5853 |
this.filePartContent=[]; //2元碼檔案內容的片段陣列.
|
|
|
5854 |
this.fileContentBase64=''; //檔案的base64碼
|
|
|
5855 |
this.fileMimeType=''; //檔案的mime tpye
|
|
|
5856 |
this.fileName=''; //檔案的名稱
|
|
|
5857 |
this.start=0; //要下載的檔案部分bytes位置開頭
|
|
|
5858 |
this.end=0; //要下載的檔案部分bytes位置結束
|
|
|
5859 |
this.total=0; //要下載的檔案總共bytes數
|
|
|
5860 |
this.partSize=1024; //一次要下載多少bytes
|
|
|
5861 |
this.retryIn=3; //當下載的長度不對,或下載失敗,幾秒後重新連線.
|
|
|
5862 |
|
|
|
5863 |
this.getPart=function(){
|
|
|
5864 |
|
|
|
5865 |
//如果沒有指定檔案的網址
|
|
|
5866 |
if(this.fileUrl===''){
|
|
|
5867 |
|
|
|
5868 |
//提示錯誤
|
|
|
5869 |
console.log('fileUrl 未指定!');
|
|
|
5870 |
|
|
|
5871 |
//結束程式
|
|
|
5872 |
return false;
|
|
|
5873 |
|
|
|
5874 |
}//if end
|
|
|
5875 |
|
|
|
5876 |
//檢查檔案下載好了沒
|
|
|
5877 |
if(this.validateFile===false){
|
|
|
5878 |
|
|
|
5879 |
//結束程式
|
|
|
5880 |
return false;
|
|
|
5881 |
|
|
|
5882 |
}//if end
|
|
|
5883 |
|
|
|
5884 |
//如果存在 xml http request 屬性
|
|
|
5885 |
if(window.XMLHttpRequest){
|
|
|
5886 |
|
|
|
5887 |
// code for IE7+, Firefox, Chrome, Opera, Safari
|
|
|
5888 |
xmlhttp=new XMLHttpRequest();
|
|
|
5889 |
|
|
|
5890 |
}//if end
|
|
|
5891 |
|
|
|
5892 |
//反之代表為ie 5,6
|
|
|
5893 |
else{
|
|
|
5894 |
|
|
|
5895 |
// code for IE6, IE5
|
|
|
5896 |
xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
|
|
|
5897 |
|
|
|
5898 |
}// else end
|
|
|
5899 |
|
|
|
5900 |
//取得當前物件
|
|
|
5901 |
var thisClone=this;
|
|
|
5902 |
|
|
|
5903 |
//如果服務端有回傳完稱的狀態
|
|
|
5904 |
xmlhttp.addEventListener('loadend',function(){
|
|
|
5905 |
|
|
|
5906 |
//取得 xmlhttp 的回應
|
|
|
5907 |
var xmlhttp=this;
|
|
|
5908 |
|
|
|
5909 |
//取得 conDownloadAgent 的物件
|
|
|
5910 |
var conDownloadAgent=thisClone;
|
|
|
5911 |
|
|
|
5912 |
//將取得的內容用2元碼儲存
|
|
|
5913 |
var blob = new Blob([xmlhttp.response]);
|
|
|
5914 |
|
|
|
5915 |
//儲存該段的2元碼
|
|
|
5916 |
conDownloadAgent.filePartContent.push(blob);
|
|
|
5917 |
|
|
|
5918 |
//取得回傳的 header
|
|
|
5919 |
conDownloadAgent.resHeaders=xmlhttp.getAllResponseHeaders();
|
|
|
5920 |
|
|
|
5921 |
//取得回傳的 header 陣列
|
|
|
5922 |
conDownloadAgent.resHeadersArray=conDownloadAgent.resHeaders.split('\\r\\n');
|
|
|
5923 |
|
|
|
5924 |
//另存 header
|
|
|
5925 |
var headerArray=conDownloadAgent.resHeadersArray;
|
|
|
5926 |
|
|
|
5927 |
//針對每個 header
|
|
|
5928 |
for(var i=0;i<headerArray.length;i++){
|
|
|
5929 |
|
|
|
5930 |
//取得其中一個 header
|
|
|
5931 |
var oneHeader=headerArray[i];
|
|
|
5932 |
|
|
|
5933 |
//檢查有無關鍵字 'Content-Range: bytes '
|
|
|
5934 |
var foundKeyWord=oneHeader.includes('Content-Range: bytes ');
|
|
|
5935 |
|
|
|
5936 |
//如果有找到關鍵字
|
|
|
5937 |
if(foundKeyWord===true){
|
|
|
5938 |
|
|
|
5939 |
//取得實際應該要取得的 bytes 跟總共有多少 bytes
|
|
|
5940 |
var contentRange=oneHeader.split('Content-Range: bytes ');
|
|
|
5941 |
var contentRange=contentRange[1];
|
|
|
5942 |
var bytesInfo=contentRange.split('/');
|
|
|
5943 |
|
|
|
5944 |
//實際上的檔案總bytes
|
|
|
5945 |
conDownloadAgent.total=parseInt(bytesInfo[1]);
|
|
|
5946 |
|
|
|
5947 |
//解析本次取得的bytes位置開頭與結尾
|
|
|
5948 |
var revInfo=bytesInfo[0].split('-');
|
|
|
5949 |
|
|
|
5950 |
//本次取得的bytes位置開頭
|
|
|
5951 |
conDownloadAgent.start=parseInt(revInfo[0]);
|
|
|
5952 |
|
|
|
5953 |
//本次取得的bytes位置結束
|
|
|
5954 |
conDownloadAgent.end=parseInt(revInfo[1]);
|
|
|
5955 |
|
|
|
5956 |
}//if end
|
|
|
5957 |
|
|
|
5958 |
//檢查有無關鍵字 'Content-Disposition: inline; filename='
|
|
|
5959 |
var foundKeyWord=oneHeader.includes('Content-Disposition: inline; filename=');
|
|
|
5960 |
|
|
|
5961 |
//如果有找到關鍵字且尚未取得檔單的名稱
|
|
|
5962 |
if(foundKeyWord===true && conDownloadAgent.fileName===''){
|
|
|
5963 |
|
|
|
5964 |
//解析檔案的名稱
|
|
|
5965 |
var fileInfo=oneHeader.split('Content-Disposition: inline; filename=');
|
|
|
5966 |
|
|
|
5967 |
//取得檔案名稱
|
|
|
5968 |
conDownloadAgent.fileName=fileInfo[1];
|
|
|
5969 |
|
|
|
5970 |
}//if end
|
|
|
5971 |
|
|
|
5972 |
//檢查有無關鍵字 'Content-Type: '
|
|
|
5973 |
var foundKeyWord=oneHeader.includes('Content-Type: ');
|
|
|
5974 |
|
|
|
5975 |
//如果有找到關鍵字且尚未取得檔案的mimeType
|
|
|
5976 |
if(foundKeyWord===true && conDownloadAgent.fileMimeType===''){
|
|
|
5977 |
|
|
|
5978 |
//解析檔案的mimeType
|
|
|
5979 |
var fileInfo=oneHeader.split('Content-Type: ');
|
|
|
5980 |
|
|
|
5981 |
//取得檔案mimeType
|
|
|
5982 |
conDownloadAgent.fileMimeType=fileInfo[1];
|
|
|
5983 |
|
|
|
5984 |
}//if end
|
|
|
5985 |
|
|
|
5986 |
}//for end
|
|
|
5987 |
|
|
|
5988 |
//如果取得的檔案內容長度不為header提供的總長度.
|
|
|
5989 |
if(conDownloadAgent.filePartContent[conDownloadAgent.filePartContent.length-1].size!==conDownloadAgent.end-conDownloadAgent.start+1){
|
|
|
5990 |
|
|
|
5991 |
//換算要多少豪秒
|
|
|
5992 |
var retryInNms=conDownloadAgent.retryIn*1000;
|
|
|
5993 |
|
|
|
5994 |
//debug
|
|
|
5995 |
console.log('該段長度不對,'+conDownloadAgent.retryIn+'秒後重新下載');
|
|
|
5996 |
|
|
|
5997 |
//conDownloadAgent.retryIn秒後再度嘗試下載
|
|
|
5998 |
setTimeout(function(){
|
|
|
5999 |
|
|
|
6000 |
//遞迴呼叫自己,繼續下載
|
|
|
6001 |
conDownloadAgent.getPart();
|
|
|
6002 |
|
|
|
6003 |
},retryInNms);
|
|
|
6004 |
|
|
|
6005 |
//結束程式
|
|
|
6006 |
return;
|
|
|
6007 |
|
|
|
6008 |
}//if end
|
|
|
6009 |
|
|
|
6010 |
//如果取得的長度結尾不為 實際上的檔案總bytes-1
|
|
|
6011 |
if(conDownloadAgent.end!==conDownloadAgent.total-1){
|
|
|
6012 |
|
|
|
6013 |
//取得尚未下載到的bytes
|
|
|
6014 |
var unDownBytes=conDownloadAgent.total-1-conDownloadAgent.end;
|
|
|
6015 |
|
|
|
6016 |
//如果剩下的bytes大於 conDownloadAgent.partSize
|
|
|
6017 |
if(unDownBytes>conDownloadAgent.partSize){
|
|
|
6018 |
|
|
|
6019 |
//設置新的要下載bytes位置開頭
|
|
|
6020 |
conDownloadAgent.start=parseInt(conDownloadAgent.end)+1;
|
|
|
6021 |
|
|
|
6022 |
//設置新的要下載bytes位置結束
|
|
|
6023 |
conDownloadAgent.end=parseInt(conDownloadAgent.end)+parseInt(conDownloadAgent.partSize);
|
|
|
6024 |
|
|
|
6025 |
}//if end
|
|
|
6026 |
|
|
|
6027 |
//反之剩下不到 conDownloadAgent.partSize 未下載
|
|
|
6028 |
else{
|
|
|
6029 |
|
|
|
6030 |
//設置新的要下載bytes位置開頭
|
|
|
6031 |
conDownloadAgent.start=parseInt(conDownloadAgent.end)+1;
|
|
|
6032 |
|
|
|
6033 |
//設置新的要下載bytes位置結束
|
|
|
6034 |
conDownloadAgent.end=parseInt(conDownloadAgent.end)+unDownBytes;
|
|
|
6035 |
|
|
|
6036 |
}//else end
|
|
|
6037 |
|
|
|
6038 |
//遞迴呼叫自己,繼續下載
|
|
|
6039 |
conDownloadAgent.getPart();
|
|
|
6040 |
|
|
|
6041 |
}//if end
|
|
|
6042 |
|
|
|
6043 |
//反之代表下載完成
|
|
|
6044 |
else{
|
|
|
6045 |
|
|
|
6046 |
//debug
|
|
|
6047 |
console.log('下載完成');
|
|
|
6048 |
|
|
|
6049 |
//下載檔案
|
|
|
6050 |
conDownloadAgent.get();
|
|
|
6051 |
|
|
|
6052 |
}//else end
|
|
|
6053 |
|
|
|
6054 |
});
|
|
|
6055 |
|
|
|
6056 |
//設定要用get傳送的數值
|
|
|
6057 |
xmlhttp.open('GET',this.fileUrl,true);
|
|
|
6058 |
|
|
|
6059 |
//預設 mimeType
|
|
|
6060 |
var mimeType='application/x-www-form-urlencoded';
|
|
|
6061 |
|
|
|
6062 |
//如果有 fileMimeType
|
|
|
6063 |
if(this.fileMimeType!==''){
|
|
|
6064 |
|
|
|
6065 |
//另存 mimeType
|
|
|
6066 |
var mimeType=this.fileMimeType;
|
|
|
6067 |
|
|
|
6068 |
}//if end
|
|
|
6069 |
|
|
|
6070 |
//設定 header
|
|
|
6071 |
xmlhttp.setRequestHeader('Content-type',mimeType);
|
|
|
6072 |
|
|
|
6073 |
//設定要求為ajax 的 header
|
|
|
6074 |
xmlhttp.setRequestHeader('X-Requested-With','XMLHttpRequest');
|
|
|
6075 |
|
|
|
6076 |
//設置取得的回應為blob(2元密)
|
|
|
6077 |
xmlhttp.responseType = 'blob';
|
|
|
6078 |
|
|
|
6079 |
//設置要求的範圍
|
|
|
6080 |
xmlhttp.setRequestHeader('Range','bytes='+this.start+'-'+this.end);
|
|
|
6081 |
|
|
|
6082 |
//設置request的timeout(毫秒)
|
|
|
6083 |
//xmlhttp.timeout=this.timeout*1000;
|
|
|
6084 |
|
|
|
6085 |
//傳送要求
|
|
|
6086 |
xmlhttp.send();
|
|
|
6087 |
|
|
|
6088 |
};//function get part end
|
|
|
6089 |
|
|
|
6090 |
//產生下載檔案的連結,並點擊之
|
|
|
6091 |
this.get=function(){
|
|
|
6092 |
|
|
|
6093 |
//取得當前物件
|
|
|
6094 |
var conDownloadAgent=this;
|
|
|
6095 |
|
|
|
6096 |
//debug
|
|
|
6097 |
console.log('建立base64的link來下載檔案');
|
|
|
6098 |
|
|
|
6099 |
//檢查檔案下載好了沒
|
|
|
6100 |
if(this.validateFile===false){
|
|
|
6101 |
|
|
|
6102 |
//結束程式
|
|
|
6103 |
return false;
|
|
|
6104 |
|
|
|
6105 |
}//if end
|
|
|
6106 |
|
|
|
6107 |
//建立blob物件
|
|
|
6108 |
var myBlobBuilder = new MyBlobBuilder();
|
|
|
6109 |
|
|
|
6110 |
//針對每個blob部分
|
|
|
6111 |
for(var i=0;i<conDownloadAgent.filePartContent.length;i++){
|
|
|
6112 |
|
|
|
6113 |
//append該部分的blob
|
|
|
6114 |
myBlobBuilder.append(conDownloadAgent.filePartContent[i]);
|
|
|
6115 |
|
|
|
6116 |
}//for end
|
|
|
6117 |
|
|
|
6118 |
//取得append後的內容
|
|
|
6119 |
conDownloadAgent.fileContent = myBlobBuilder.getBlob(conDownloadAgent.fileMimeType);
|
|
|
6120 |
|
|
|
6121 |
//讀取blob的內容
|
|
|
6122 |
var reader = new FileReader();
|
|
|
6123 |
|
|
|
6124 |
//增加讀取完檔案後要做的事情
|
|
|
6125 |
reader.addEventListener('loadend',function(){
|
|
|
6126 |
|
|
|
6127 |
//return false;
|
|
|
6128 |
|
|
|
6129 |
//儲存base64的檔案內容
|
|
|
6130 |
conDownloadAgent.fileContentBase64=reader.result;
|
|
|
6131 |
|
|
|
6132 |
//建立元素a
|
|
|
6133 |
var aNode = document.createElement('a');
|
|
|
6134 |
|
|
|
6135 |
//組成link的內容
|
|
|
6136 |
aNode.href=conDownloadAgent.fileContentBase64;
|
|
|
6137 |
|
|
|
6138 |
//設置link為不顯示的樣式
|
|
|
6139 |
aNode.style.display='none';
|
|
|
6140 |
|
|
|
6141 |
//設置link的id為
|
|
|
6142 |
aNode.id='conDownloadLink';
|
|
|
6143 |
|
|
|
6144 |
//放置link
|
|
|
6145 |
document.body.appendChild(aNode);
|
|
|
6146 |
|
|
|
6147 |
//點擊下載的link
|
|
|
6148 |
document.getElementById(aNode.id).click();
|
|
|
6149 |
|
|
|
6150 |
//移除下載的link
|
|
|
6151 |
document.getElementById(aNode.id).remove();
|
|
|
6152 |
|
|
|
6153 |
});//reader.addEventListener end
|
|
|
6154 |
|
|
|
6155 |
//讀取檔案的2元碼
|
|
|
6156 |
reader.readAsDataURL(conDownloadAgent.fileContent);
|
|
|
6157 |
|
|
|
6158 |
};//function get end
|
|
|
6159 |
|
|
|
6160 |
//檢查檔案是否下載好了, return true/false
|
|
|
6161 |
this.validateFile=function(){
|
|
|
6162 |
|
|
|
6163 |
//如果沒有檔案大小
|
|
|
6164 |
if(conDownloadAgent.total===''){
|
|
|
6165 |
|
|
|
6166 |
//debug
|
|
|
6167 |
console.log('檔案未下載完成');
|
|
|
6168 |
|
|
|
6169 |
//結束程式
|
|
|
6170 |
return false;
|
|
|
6171 |
|
|
|
6172 |
}//if end
|
|
|
6173 |
|
|
|
6174 |
//取得所下載檔案的大小
|
|
|
6175 |
var fileSize=conDownloadAgent.total;
|
|
|
6176 |
|
|
|
6177 |
//初始化取得的檔案大小
|
|
|
6178 |
var gettedFileSize=0;
|
|
|
6179 |
|
|
|
6180 |
//檢查是否有下載完成檔案,針對每個blob部分
|
|
|
6181 |
for(var i=0;i<conDownloadAgent.filePartContent.length;i++){
|
|
|
6182 |
|
|
|
6183 |
//累加取得的檔案大小
|
|
|
6184 |
gettedFileSize=gettedFileSize+conDownloadAgent.filePartContent[i].size;
|
|
|
6185 |
|
|
|
6186 |
}//for end
|
|
|
6187 |
|
|
|
6188 |
//如果要下載檔案的大小不等於實際上所下載到的長度
|
|
|
6189 |
if(fileSize!==gettedFileSize){
|
|
|
6190 |
|
|
|
6191 |
//debug
|
|
|
6192 |
console.log('檔案未下載完成');
|
|
|
6193 |
|
|
|
6194 |
//結束程式
|
|
|
6195 |
return false;
|
|
|
6196 |
|
|
|
6197 |
}//if end
|
|
|
6198 |
|
|
|
6199 |
//回傳 true 檔案已經下載好了
|
|
|
6200 |
return true;
|
|
|
6201 |
|
|
|
6202 |
}//function validateFile end
|
|
|
6203 |
|
|
|
6204 |
};//function conDownloadAgent end
|
|
|
6205 |
";
|
|
|
6206 |
$conf["javaScript::toScript"]["jsFunciton"][]=
|
|
|
6207 |
"
|
|
|
6208 |
/*
|
|
|
6209 |
函式說明:
|
|
|
6210 |
驗證 gGoogle reCAPTCHA 的回應
|
|
|
6211 |
回傳結果:
|
|
|
6212 |
false,代表驗證失敗.
|
|
|
6213 |
true,代表有進行驗證流程
|
|
|
6214 |
必填參數
|
|
|
6215 |
key,session key
|
|
|
6216 |
value,value store in session key
|
|
|
6217 |
*/
|
|
|
6218 |
var getGoogle_reCAPTCHA_res=function(key='google_reCAPTCHA_pass',val=document.URL){
|
|
|
6219 |
|
|
|
6220 |
//如果沒有 recaptcha 元素存在
|
|
|
6221 |
if(document.getElementById('g-recaptcha-response')===null){
|
|
|
6222 |
|
|
|
6223 |
//回傳結果
|
|
|
6224 |
return false;
|
|
|
6225 |
|
|
|
6226 |
}//if end
|
|
|
6227 |
|
|
|
6228 |
//取得 reCAPTCHA 的回應
|
|
|
6229 |
res=document.getElementById('g-recaptcha-response').value;
|
|
|
6230 |
|
|
|
6231 |
//如果數值是空的,代表用戶沒有驗證
|
|
|
6232 |
if(res===''){
|
|
|
6233 |
|
|
|
6234 |
//回傳結果
|
|
|
6235 |
return false;
|
|
|
6236 |
|
|
|
6237 |
}//if end
|
|
|
6238 |
|
|
|
6239 |
//反之用 ajax 跟 Server 端驗證
|
|
|
6240 |
else{
|
|
|
6241 |
|
|
|
6242 |
//建立 XMLDoc
|
|
|
6243 |
if(window.XMLHttpRequest){
|
|
|
6244 |
|
|
|
6245 |
// code for IE7+, Firefox, Chrome, Opera, Safari
|
|
|
6246 |
xmlhttp=new XMLHttpRequest();
|
|
|
6247 |
|
|
|
6248 |
//設置 server 應該要回傳 json
|
|
|
6249 |
xmlhttp.responseType='json';
|
|
|
6250 |
|
|
|
6251 |
}//if end
|
|
|
6252 |
|
|
|
6253 |
else{
|
|
|
6254 |
|
|
|
6255 |
// code for IE6, IE5
|
|
|
6256 |
xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
|
|
|
6257 |
|
|
|
6258 |
}//else end
|
|
|
6259 |
|
|
|
6260 |
//如果服務端有回傳完成的狀態
|
|
|
6261 |
xmlhttp.onreadystatechange=function(){
|
|
|
6262 |
|
|
|
6263 |
//如果狀態為4且response code為200
|
|
|
6264 |
if(xmlhttp.readyState==4 && xmlhttp.status==200){
|
|
|
6265 |
|
|
|
6266 |
//如果回應為通過
|
|
|
6267 |
if(xmlhttp.response.status==='true' || xmlhttp.response.status===true){
|
|
|
6268 |
|
|
|
6269 |
//將 recaptcha 移除
|
|
|
6270 |
document.getElementsByClassName('g-recaptcha')[0].remove();
|
|
|
6271 |
|
|
|
6272 |
}//if end
|
|
|
6273 |
|
|
|
6274 |
}//if end
|
|
|
6275 |
|
|
|
6276 |
}//function end
|
|
|
6277 |
|
|
|
6278 |
//設定要求的屬性、目的、是否不要同步
|
|
|
6279 |
xmlhttp.open('POST','../json/authenticate/gl_reCAPTCHA_server.php',true);
|
|
|
6280 |
|
|
|
6281 |
//設定 header
|
|
|
6282 |
xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
|
|
|
6283 |
|
|
|
6284 |
//設定 要求為ajax 的 header
|
|
|
6285 |
xmlhttp.setRequestHeader('X-Requested-With','XMLHttpRequest');
|
|
|
6286 |
|
|
|
6287 |
//要傳送的數值名稱與數值內容,ex:num1=100&num2=50
|
|
|
6288 |
xmlhttp.send('response='+res+'&key='+key+'&val='+val);
|
|
|
6289 |
|
|
|
6290 |
}//else end
|
|
|
6291 |
|
|
|
6292 |
//有進入驗證流程
|
|
|
6293 |
return true;
|
|
|
6294 |
|
|
|
6295 |
}
|
|
|
6296 |
";
|
|
|
6297 |
$conf["javaScript::toScript"]["jsFunciton"][]=
|
|
|
6298 |
"
|
|
|
6299 |
/*
|
|
|
6300 |
涵式說明:
|
|
|
6301 |
提供偵測可能已經通過reCAPCHA,接着進行驗證回傳的結果是否正確.
|
|
|
6302 |
*/
|
|
|
6303 |
var getGoogle_reCAPTCHA_res_event=function(){
|
|
|
6304 |
|
|
|
6305 |
//如果沒有 recaptcha 元素存在
|
|
|
6306 |
if(document.getElementsByClassName('g-recaptcha').length===0){
|
|
|
6307 |
|
|
|
6308 |
//回傳結果
|
|
|
6309 |
return false;
|
|
|
6310 |
|
|
|
6311 |
}//if end
|
|
|
6312 |
|
|
|
6313 |
//取得產生reCAPCHA內容的div
|
|
|
6314 |
grdiv=document.getElementsByClassName('g-recaptcha')[0];
|
|
|
6315 |
|
|
|
6316 |
//滑鼠進來
|
|
|
6317 |
grdiv.addEventListener('mouseenter',function(){
|
|
|
6318 |
|
|
|
6319 |
//檢查有無通過驗證
|
|
|
6320 |
getGoogle_reCAPTCHA_res();
|
|
|
6321 |
|
|
|
6322 |
});
|
|
|
6323 |
|
|
|
6324 |
//滑鼠離開
|
|
|
6325 |
grdiv.addEventListener('mouseout',function(){
|
|
|
6326 |
|
|
|
6327 |
//檢查有無通過驗證
|
|
|
6328 |
getGoogle_reCAPTCHA_res();
|
|
|
6329 |
|
|
|
6330 |
});
|
|
|
6331 |
}
|
|
|
6332 |
";
|
|
|
6333 |
$conf["javaScript::toScript"]["jsFunciton"][]=
|
|
|
6334 |
"
|
|
|
6335 |
//如果 window.qbpwcf 不存在
|
|
|
6336 |
if(window.qbpwcf===undefined){
|
|
|
6337 |
|
|
|
6338 |
//初始化 window qbpwcf 物件
|
|
|
6339 |
window.qbpwcf={};
|
|
|
6340 |
|
|
|
6341 |
}//if end
|
| 226 |
liveuser |
6342 |
|
| 3 |
liveuser |
6343 |
/*
|
|
|
6344 |
涵式說明:
|
|
|
6345 |
將同 data-form-id 的input/textarea內容用表單的方式傳送出去(POST)
|
|
|
6346 |
params.ele, 要綁定事件的元素.
|
|
|
6347 |
params.formId, 用來識別表單群體的名稱.
|
|
|
6348 |
params.url, 表單要傳送到的地方.
|
|
|
6349 |
params.method, GET or POST.
|
|
|
6350 |
*/
|
|
|
6351 |
window.qbpwcf.sendByDataFormId=function(params){
|
| 226 |
liveuser |
6352 |
|
| 3 |
liveuser |
6353 |
//如果沒有ele
|
|
|
6354 |
if(params.ele===undefined){
|
| 226 |
liveuser |
6355 |
|
| 3 |
liveuser |
6356 |
//結束執行
|
|
|
6357 |
return;
|
| 226 |
liveuser |
6358 |
|
| 3 |
liveuser |
6359 |
}//if end
|
| 226 |
liveuser |
6360 |
|
| 3 |
liveuser |
6361 |
//取得要取得的ele
|
|
|
6362 |
var ele=params.ele;
|
| 226 |
liveuser |
6363 |
|
| 3 |
liveuser |
6364 |
//如果沒有formId
|
|
|
6365 |
if(params.formId===undefined){
|
| 226 |
liveuser |
6366 |
|
| 3 |
liveuser |
6367 |
//預設為 'qbpwcf_form'
|
|
|
6368 |
params.formId='qbpwcf_form';
|
| 226 |
liveuser |
6369 |
|
|
|
6370 |
}//if end
|
|
|
6371 |
|
| 3 |
liveuser |
6372 |
//取得要取得的formId
|
|
|
6373 |
var formId=params.formId;
|
| 226 |
liveuser |
6374 |
|
| 3 |
liveuser |
6375 |
//如果沒有formId
|
|
|
6376 |
if(params.url===undefined){
|
| 226 |
liveuser |
6377 |
|
| 3 |
liveuser |
6378 |
//預設為當前網址
|
|
|
6379 |
params.url=location.href;
|
| 226 |
liveuser |
6380 |
|
| 3 |
liveuser |
6381 |
}//if end
|
| 226 |
liveuser |
6382 |
|
| 3 |
liveuser |
6383 |
//取得表單要傳送到的地方
|
|
|
6384 |
var url=params.url;
|
| 226 |
liveuser |
6385 |
|
| 3 |
liveuser |
6386 |
//如果沒有method
|
|
|
6387 |
if(params.method===undefined){
|
| 226 |
liveuser |
6388 |
|
| 3 |
liveuser |
6389 |
//預設為post
|
|
|
6390 |
params.method='POST';
|
| 226 |
liveuser |
6391 |
|
| 3 |
liveuser |
6392 |
}//if end
|
| 226 |
liveuser |
6393 |
|
| 3 |
liveuser |
6394 |
//限定為post
|
|
|
6395 |
var method=params.method;
|
| 226 |
liveuser |
6396 |
|
| 3 |
liveuser |
6397 |
//綁定點擊事件
|
|
|
6398 |
params.ele.addEventListener('click',async function(event){
|
| 226 |
liveuser |
6399 |
|
| 3 |
liveuser |
6400 |
//如果沒有鎖頭
|
|
|
6401 |
if(this.dataset.lock===undefined){
|
| 226 |
liveuser |
6402 |
|
| 3 |
liveuser |
6403 |
//設置為上鎖
|
|
|
6404 |
this.dataset.lock==='false';
|
| 226 |
liveuser |
6405 |
|
| 3 |
liveuser |
6406 |
}//if end
|
| 226 |
liveuser |
6407 |
|
| 3 |
liveuser |
6408 |
//如果已經上鎖了
|
|
|
6409 |
if(this.dataset.lock==='true'){
|
| 226 |
liveuser |
6410 |
|
| 3 |
liveuser |
6411 |
//結束執行
|
|
|
6412 |
return false;
|
| 226 |
liveuser |
6413 |
|
| 3 |
liveuser |
6414 |
}//if end
|
| 226 |
liveuser |
6415 |
|
| 3 |
liveuser |
6416 |
//上鎖
|
|
|
6417 |
this.dataset.lock='true';
|
| 226 |
liveuser |
6418 |
|
| 3 |
liveuser |
6419 |
//取得所有 inputs
|
|
|
6420 |
var dataFormId='data-form-id=\"'+formId+'\"';
|
|
|
6421 |
dataFormId='input['+dataFormId+']';
|
|
|
6422 |
eval('var inputDataFormId=\''+dataFormId+'\'');
|
|
|
6423 |
var inputs=document.querySelectorAll(inputDataFormId);
|
| 226 |
liveuser |
6424 |
|
| 3 |
liveuser |
6425 |
//取得所有 textarea
|
|
|
6426 |
var dataFormId='data-form-id=\"'+formId+'\"';
|
|
|
6427 |
dataFormId='textarea['+dataFormId+']';
|
|
|
6428 |
eval('var textareaDataFormId=\''+dataFormId+'\'');
|
|
|
6429 |
var textareas=document.querySelectorAll(textareaDataFormId);
|
| 226 |
liveuser |
6430 |
|
| 3 |
liveuser |
6431 |
//debug
|
|
|
6432 |
console.log(inputs,textareas);
|
| 226 |
liveuser |
6433 |
|
| 3 |
liveuser |
6434 |
//初始化查詢的字串
|
|
|
6435 |
var queryStr='';
|
| 226 |
liveuser |
6436 |
|
| 3 |
liveuser |
6437 |
//如果有input
|
|
|
6438 |
if(inputs.length!==0){
|
| 226 |
liveuser |
6439 |
|
| 3 |
liveuser |
6440 |
//針對每個input
|
|
|
6441 |
for(var i=0;i<inputs.length;i++){
|
| 226 |
liveuser |
6442 |
|
| 3 |
liveuser |
6443 |
//如果不是空的
|
|
|
6444 |
if(queryStr!==''){
|
| 226 |
liveuser |
6445 |
|
| 3 |
liveuser |
6446 |
//串接'&'
|
|
|
6447 |
queryStr=queryStr+'&';
|
| 226 |
liveuser |
6448 |
|
| 3 |
liveuser |
6449 |
}//if end
|
| 226 |
liveuser |
6450 |
|
| 3 |
liveuser |
6451 |
//加上查詢內容
|
|
|
6452 |
queryStr=queryStr+inputs[i].name+'='+encodeURIComponent(inputs[i].value);
|
| 226 |
liveuser |
6453 |
|
| 3 |
liveuser |
6454 |
}//for end
|
| 226 |
liveuser |
6455 |
|
| 3 |
liveuser |
6456 |
}//if end
|
| 226 |
liveuser |
6457 |
|
| 3 |
liveuser |
6458 |
//如果有textarea
|
|
|
6459 |
if(textareas.length!==0){
|
| 226 |
liveuser |
6460 |
|
| 3 |
liveuser |
6461 |
//針對每個textarea
|
|
|
6462 |
for(var i=0;i<textareas.length;i++){
|
| 226 |
liveuser |
6463 |
|
| 3 |
liveuser |
6464 |
//如果不是空的
|
|
|
6465 |
if(queryStr!==''){
|
| 226 |
liveuser |
6466 |
|
| 3 |
liveuser |
6467 |
//串接'&'
|
|
|
6468 |
queryStr=queryStr+'&';
|
| 226 |
liveuser |
6469 |
|
| 3 |
liveuser |
6470 |
}//if end
|
| 226 |
liveuser |
6471 |
|
| 3 |
liveuser |
6472 |
//加上查詢內容
|
|
|
6473 |
queryStr=queryStr+textareas[i].name+'='+encodeURIComponent(textareas[i].value);
|
| 226 |
liveuser |
6474 |
|
| 3 |
liveuser |
6475 |
}//for end
|
| 226 |
liveuser |
6476 |
|
| 3 |
liveuser |
6477 |
}//if end
|
| 226 |
liveuser |
6478 |
|
| 3 |
liveuser |
6479 |
//初始化查詢的字串
|
|
|
6480 |
console.log('queryStr='+queryStr);
|
| 226 |
liveuser |
6481 |
|
| 3 |
liveuser |
6482 |
//如果沒有任何input
|
|
|
6483 |
if(inputs.length===0 && textareas.length===0){
|
| 226 |
liveuser |
6484 |
|
| 3 |
liveuser |
6485 |
//結束執行
|
| 226 |
liveuser |
6486 |
return;
|
|
|
6487 |
|
| 3 |
liveuser |
6488 |
}//if end
|
| 226 |
liveuser |
6489 |
|
| 3 |
liveuser |
6490 |
//debug
|
|
|
6491 |
console.log('params.method='+params.method);
|
|
|
6492 |
console.log('params.url='+params.url);
|
| 226 |
liveuser |
6493 |
|
| 3 |
liveuser |
6494 |
//傳送表單
|
|
|
6495 |
/*
|
|
|
6496 |
設置 window.qbpwcf.ajaxP 函數
|
|
|
6497 |
說明:
|
|
|
6498 |
傳送ajax,指定傳送前要做什麼事情,然後回傳一個Promise.
|
|
|
6499 |
參數:
|
|
|
6500 |
params={};
|
|
|
6501 |
params.method='POST' or 'GET' or 'HEAD' or 'OPTIONS';
|
|
|
6502 |
params.headers={name:value};
|
|
|
6503 |
params.url='url to request';
|
|
|
6504 |
params.preAc='function name to call before send request';
|
|
|
6505 |
params.data='data to contain','key1=encodeURIComponent(val1)&key2=encodeURIComponent(val2)';if no data please use {};
|
|
|
6506 |
參考資料:
|
|
|
6507 |
https://eyesofkids.gitbooks.io/javascript-start-es6-promise/content/contents/ch11_snippets.html
|
|
|
6508 |
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
|
|
|
6509 |
*/
|
|
|
6510 |
ajaxP_params={};
|
|
|
6511 |
ajaxP_params.data=queryStr;
|
|
|
6512 |
ajaxP_params.method=params.method;
|
|
|
6513 |
ajaxP_params.url=params.url;
|
|
|
6514 |
var res = await window.qbpwcf.ajaxP.call(this,ajaxP_params);
|
| 226 |
liveuser |
6515 |
|
| 3 |
liveuser |
6516 |
//debug
|
|
|
6517 |
console.log(res);
|
| 226 |
liveuser |
6518 |
|
| 3 |
liveuser |
6519 |
//解鎖
|
|
|
6520 |
this.dataset.lock='false';
|
| 226 |
liveuser |
6521 |
|
| 3 |
liveuser |
6522 |
});
|
| 226 |
liveuser |
6523 |
|
| 3 |
liveuser |
6524 |
}
|
|
|
6525 |
";
|
|
|
6526 |
$conf["javaScript::toScript"]["jsFunciton"][]=
|
|
|
6527 |
"
|
|
|
6528 |
//如果 window.qbpwcf 不存在
|
|
|
6529 |
if(window.qbpwcf===undefined){
|
|
|
6530 |
|
|
|
6531 |
//初始化 window qbpwcf 物件
|
|
|
6532 |
window.qbpwcf={};
|
|
|
6533 |
|
|
|
6534 |
}//if end
|
| 226 |
liveuser |
6535 |
|
| 3 |
liveuser |
6536 |
//初始化物件
|
|
|
6537 |
window.qbpwcf.postDataAttr={};
|
|
|
6538 |
|
|
|
6539 |
/*
|
| 226 |
liveuser |
6540 |
函式說明:
|
| 3 |
liveuser |
6541 |
設置點擊元素後會傳遞data屬性為名稱與其數值為表單數值給特定url,然後依照片段show到當前頁面.
|
|
|
6542 |
參數說明:
|
|
|
6543 |
element,要綁定事件的元素.
|
|
|
6544 |
url,表單要傳送到的位置.
|
| 226 |
liveuser |
6545 |
method,傳送的方法,有POST跟GET兩種
|
| 3 |
liveuser |
6546 |
範例用法:
|
|
|
6547 |
element=document.getElementsByClassName('quickDayLog')[0];
|
|
|
6548 |
window.qbpwcf.postDataAttr.func.call(this,element,'logRes.php','POST','rootDiv');
|
| 226 |
liveuser |
6549 |
*/
|
| 3 |
liveuser |
6550 |
window.qbpwcf.postDataAttr.func=function(element,url,method,rootDiv){
|
|
|
6551 |
|
|
|
6552 |
//綁定事件到元素上
|
|
|
6553 |
element.addEventListener('click',function(event){
|
|
|
6554 |
|
|
|
6555 |
//取得目標url
|
|
|
6556 |
window.qbpwcf.postDataAttr.url=url;
|
|
|
6557 |
|
|
|
6558 |
//取得表單傳遞方式
|
| 226 |
liveuser |
6559 |
window.qbpwcf.postDataAttr.method=method;
|
|
|
6560 |
|
| 3 |
liveuser |
6561 |
//取得抓取回應並要放置到哪個id的div裡面
|
|
|
6562 |
window.qbpwcf.postDataAttr.rootDiv=rootDiv;
|
|
|
6563 |
|
|
|
6564 |
//初始化要傳送的表單物件
|
|
|
6565 |
window.qbpwcf.postDataAttr.params={};
|
| 226 |
liveuser |
6566 |
|
| 3 |
liveuser |
6567 |
//取得元素的data
|
|
|
6568 |
dataset=element.dataset;
|
|
|
6569 |
|
|
|
6570 |
//針對每個表單名稱
|
|
|
6571 |
for(i=0;i<Object.keys(dataset).length;i++){
|
|
|
6572 |
|
|
|
6573 |
//取得表單名稱
|
|
|
6574 |
key=Object.keys(dataset)[i];
|
|
|
6575 |
|
|
|
6576 |
//取得表單內容
|
|
|
6577 |
val=eval('dataset.'+key);
|
|
|
6578 |
|
|
|
6579 |
//取得表單的內容
|
|
|
6580 |
eval('window.qbpwcf.postDataAttr.params.'+key+'='+val);
|
|
|
6581 |
|
|
|
6582 |
}//for end
|
| 226 |
liveuser |
6583 |
|
| 3 |
liveuser |
6584 |
//遞迴取得回應並放在特定div裡面
|
| 226 |
liveuser |
6585 |
window.qbpwcf.tailAny.func.call(this,window.qbpwcf.postDataAttr.params,window.qbpwcf.postDataAttr.url,window.qbpwcf.postDataAttr.method,window.qbpwcf.postDataAttr.rootDiv);
|
| 3 |
liveuser |
6586 |
|
|
|
6587 |
});//function end
|
|
|
6588 |
};
|
|
|
6589 |
";
|
|
|
6590 |
$conf["javaScript::toScript"]["jsFunciton"][]=
|
|
|
6591 |
"
|
|
|
6592 |
/*
|
|
|
6593 |
涵式說明:
|
|
|
6594 |
統一處理托移事件
|
|
|
6595 |
*/
|
|
|
6596 |
// drag event handler start
|
|
|
6597 |
window.dragEventHandler={};
|
| 226 |
liveuser |
6598 |
|
| 3 |
liveuser |
6599 |
//儲存被拖移的元素
|
|
|
6600 |
window.dragEventHandler.dragged={};
|
|
|
6601 |
|
|
|
6602 |
//儲存被壓住的元素
|
|
|
6603 |
window.dragEventHandler.dropped={};
|
|
|
6604 |
|
|
|
6605 |
/*
|
|
|
6606 |
可以被托移的物件範例
|
|
|
6607 |
<style>
|
|
|
6608 |
.dropzone {
|
|
|
6609 |
width: 200px;
|
|
|
6610 |
height: 20px;
|
|
|
6611 |
color: white;
|
|
|
6612 |
background: blue;
|
|
|
6613 |
margin-bottom: 10px;
|
|
|
6614 |
}
|
|
|
6615 |
</style>
|
| 226 |
liveuser |
6616 |
<div class='dropzone'>
|
|
|
6617 |
<div draggable='true'>
|
|
|
6618 |
This div is draggable
|
|
|
6619 |
</div>
|
|
|
6620 |
</div>
|
| 3 |
liveuser |
6621 |
<div class='dropzone'></div>
|
|
|
6622 |
<div class='dropzone'></div>
|
| 226 |
liveuser |
6623 |
<div class='dropzone'></div>
|
| 3 |
liveuser |
6624 |
*/
|
|
|
6625 |
|
|
|
6626 |
/*
|
|
|
6627 |
處理被拖移元素壓住其他元素後的事件處理函式,宣告即可設定如何處理.
|
|
|
6628 |
參數
|
|
|
6629 |
被托移的元素
|
|
|
6630 |
obj.dragged
|
|
|
6631 |
被壓住的元素
|
|
|
6632 |
obj.dropped
|
|
|
6633 |
window.dragEventHandler.handler=function(param){};
|
|
|
6634 |
若不宣告則,如果被壓住的div有 'dropzone' 類別,才會動作.
|
|
|
6635 |
*/
|
| 226 |
liveuser |
6636 |
|
| 3 |
liveuser |
6637 |
/*
|
|
|
6638 |
參考資料:
|
|
|
6639 |
https://developer.mozilla.org/en-US/docs/Web/API/Document/drag_event
|
|
|
6640 |
*/
|
|
|
6641 |
|
|
|
6642 |
//事件綁定的函式
|
|
|
6643 |
window.dragEventHandler.func=function(){
|
| 226 |
liveuser |
6644 |
|
| 3 |
liveuser |
6645 |
//events fired on the draggable target
|
|
|
6646 |
document.addEventListener('drag', function(event) {
|
|
|
6647 |
|
|
|
6648 |
});
|
|
|
6649 |
|
|
|
6650 |
//開始托移
|
|
|
6651 |
document.addEventListener('dragstart', function(event) {
|
|
|
6652 |
|
|
|
6653 |
//讓被托移的目標可以被被看到
|
|
|
6654 |
event.dataTransfer.setData('text/plain',null);
|
|
|
6655 |
|
|
|
6656 |
// store a ref. on the dragged elem
|
|
|
6657 |
window.dragEventHandler.dragged = event.target;
|
| 226 |
liveuser |
6658 |
|
| 3 |
liveuser |
6659 |
// make it half transparent
|
|
|
6660 |
event.target.style.opacity = .5;
|
| 226 |
liveuser |
6661 |
|
| 3 |
liveuser |
6662 |
});
|
| 226 |
liveuser |
6663 |
|
| 3 |
liveuser |
6664 |
//在被托移物品上移動時.
|
|
|
6665 |
/* events fired on the drop targets */
|
|
|
6666 |
document.addEventListener('dragover', function(event) {
|
| 226 |
liveuser |
6667 |
|
| 3 |
liveuser |
6668 |
// prevent default to allow drop
|
|
|
6669 |
event.preventDefault();
|
|
|
6670 |
|
|
|
6671 |
});
|
|
|
6672 |
|
|
|
6673 |
//移到別的元素時觸發
|
|
|
6674 |
document.addEventListener('dragenter', function(event) {
|
|
|
6675 |
|
|
|
6676 |
// highlight potential drop target when the draggable element enters it
|
|
|
6677 |
if (event.target.className == 'dropzone'){
|
| 226 |
liveuser |
6678 |
|
| 3 |
liveuser |
6679 |
event.target.style.opacity = .5;
|
| 226 |
liveuser |
6680 |
|
| 3 |
liveuser |
6681 |
}
|
| 226 |
liveuser |
6682 |
|
| 3 |
liveuser |
6683 |
});
|
|
|
6684 |
|
|
|
6685 |
//移開移動到的元素時觸發
|
|
|
6686 |
document.addEventListener('dragleave', function(event) {
|
|
|
6687 |
|
| 226 |
liveuser |
6688 |
// unhighlight of potential drop target when the draggable element leaves it
|
| 3 |
liveuser |
6689 |
if (event.target.className == 'dropzone') {
|
| 226 |
liveuser |
6690 |
|
| 3 |
liveuser |
6691 |
//設置不透明
|
|
|
6692 |
event.target.style.opacity = 1.0;
|
| 226 |
liveuser |
6693 |
|
| 3 |
liveuser |
6694 |
}
|
| 226 |
liveuser |
6695 |
|
| 3 |
liveuser |
6696 |
});
|
| 226 |
liveuser |
6697 |
|
| 3 |
liveuser |
6698 |
//放開移動中的元素時觸發
|
|
|
6699 |
document.addEventListener('drop', function(event) {
|
| 226 |
liveuser |
6700 |
|
| 3 |
liveuser |
6701 |
// prevent default action (open as link for some elements)
|
|
|
6702 |
event.preventDefault();
|
|
|
6703 |
|
|
|
6704 |
// 取得被壓的元素
|
|
|
6705 |
window.dragEventHandler.dropped=event.target
|
|
|
6706 |
|
|
|
6707 |
// move dragged elem to the selected drop target
|
|
|
6708 |
if (event.target.className == 'dropzone') {
|
| 226 |
liveuser |
6709 |
|
| 3 |
liveuser |
6710 |
//設置不透明
|
|
|
6711 |
event.target.style.opacity = 1.0;
|
| 226 |
liveuser |
6712 |
|
| 3 |
liveuser |
6713 |
}
|
| 226 |
liveuser |
6714 |
|
| 3 |
liveuser |
6715 |
});
|
| 226 |
liveuser |
6716 |
|
| 3 |
liveuser |
6717 |
}
|
| 226 |
liveuser |
6718 |
|
| 3 |
liveuser |
6719 |
//托移結束
|
|
|
6720 |
document.addEventListener('dragend', function(event) {
|
|
|
6721 |
|
|
|
6722 |
// reset the transparency
|
|
|
6723 |
event.target.style.opacity = '';
|
| 226 |
liveuser |
6724 |
|
| 3 |
liveuser |
6725 |
//初始化要回傳的元素
|
|
|
6726 |
obj={};
|
| 226 |
liveuser |
6727 |
|
| 3 |
liveuser |
6728 |
//設置被托移的元素
|
|
|
6729 |
obj.dragged=window.dragEventHandler.dragged;
|
| 226 |
liveuser |
6730 |
|
| 3 |
liveuser |
6731 |
//設置被壓住的元素
|
|
|
6732 |
obj.dropped=window.dragEventHandler.dropped;
|
| 226 |
liveuser |
6733 |
|
| 3 |
liveuser |
6734 |
//debug
|
|
|
6735 |
console.log(obj);
|
|
|
6736 |
|
|
|
6737 |
if(window.dragEventHandler.handler!==undefined){
|
|
|
6738 |
|
| 226 |
liveuser |
6739 |
if(typeof(window.dragEventHandler.handler)==='function'){
|
|
|
6740 |
|
| 3 |
liveuser |
6741 |
window.dragEventHandler.handler.call(this,obj);
|
|
|
6742 |
|
|
|
6743 |
}
|
|
|
6744 |
|
|
|
6745 |
}
|
| 226 |
liveuser |
6746 |
|
|
|
6747 |
//採用預設的做法
|
| 3 |
liveuser |
6748 |
else{
|
|
|
6749 |
//被壓住的不是div就停止
|
|
|
6750 |
if(window.dragEventHandler.dropped.tagName!=='DIV'){
|
| 226 |
liveuser |
6751 |
|
| 3 |
liveuser |
6752 |
return false;
|
| 226 |
liveuser |
6753 |
|
| 3 |
liveuser |
6754 |
}
|
| 226 |
liveuser |
6755 |
|
| 3 |
liveuser |
6756 |
//目標div有幾個類別就執行幾次
|
|
|
6757 |
for(i=0;i<window.dragEventHandler.dropped.classList.length;i++){
|
| 226 |
liveuser |
6758 |
|
| 3 |
liveuser |
6759 |
//如果被壓住的div有 'dropzone' 類別,才會動作.
|
|
|
6760 |
if(window.dragEventHandler.dropped.classList[i]==='dropzone'){
|
| 226 |
liveuser |
6761 |
|
| 3 |
liveuser |
6762 |
//覆蓋到目標元素
|
|
|
6763 |
window.dragEventHandler.dropped.innerHTML=window.dragEventHandler.dragged.outerHTML;
|
| 226 |
liveuser |
6764 |
|
| 3 |
liveuser |
6765 |
//移除被移開的元素
|
|
|
6766 |
window.dragEventHandler.dragged.innerHTML='';
|
| 226 |
liveuser |
6767 |
|
| 3 |
liveuser |
6768 |
//結束迴圈
|
|
|
6769 |
break;
|
| 226 |
liveuser |
6770 |
|
| 3 |
liveuser |
6771 |
}
|
|
|
6772 |
}
|
|
|
6773 |
}
|
|
|
6774 |
});
|
|
|
6775 |
// drag event handler end
|
|
|
6776 |
";
|
|
|
6777 |
$conf["javaScript::toScript"]["jsFunciton"][]=
|
|
|
6778 |
"
|
|
|
6779 |
/*
|
|
|
6780 |
導頁的函式:
|
|
|
6781 |
*/
|
|
|
6782 |
|
| 174 |
liveuser |
6783 |
//如果沒有 window.qbpwcf.redirectURL
|
|
|
6784 |
if(window.qbpwcf.redirectURL===undefined){
|
| 226 |
liveuser |
6785 |
|
| 174 |
liveuser |
6786 |
//宣告 window.qbpwcf.`redirectURL 為空物件
|
|
|
6787 |
window.qbpwcf.redirectURL={};
|
| 3 |
liveuser |
6788 |
|
|
|
6789 |
}//if end
|
|
|
6790 |
|
|
|
6791 |
//設置 window.redirectURL 變數為 function,參數為 params
|
| 174 |
liveuser |
6792 |
window.qbpwcf.redirectURL=function(params){
|
| 3 |
liveuser |
6793 |
|
|
|
6794 |
//如果 params.url 未定義
|
|
|
6795 |
if(params.url===undefined){
|
|
|
6796 |
|
|
|
6797 |
//設置要回傳的物件
|
|
|
6798 |
result={};
|
|
|
6799 |
|
|
|
6800 |
//設置執行錯誤
|
|
|
6801 |
result.status=false;
|
|
|
6802 |
|
|
|
6803 |
//設置錯誤訊息陣列
|
|
|
6804 |
result.error=[];
|
|
|
6805 |
|
|
|
6806 |
//設置錯誤訊息
|
|
|
6807 |
result.error.push('params.url undefined');
|
|
|
6808 |
|
|
|
6809 |
//回傳結果
|
|
|
6810 |
return result;
|
|
|
6811 |
|
|
|
6812 |
}//if end
|
|
|
6813 |
|
|
|
6814 |
//如果 params.countdownSec 未定義
|
|
|
6815 |
if(params.countdownSec===undefined){
|
|
|
6816 |
|
|
|
6817 |
//直接導頁到 params.url
|
|
|
6818 |
window.location.href=params.url;
|
|
|
6819 |
|
|
|
6820 |
}//if end
|
|
|
6821 |
|
|
|
6822 |
//反之
|
|
|
6823 |
else{
|
|
|
6824 |
|
|
|
6825 |
//設置過了 params.countdownSec 秒後要做的事情.
|
|
|
6826 |
setTimeout(function(){
|
| 226 |
liveuser |
6827 |
|
| 3 |
liveuser |
6828 |
//導頁到 params.url
|
| 174 |
liveuser |
6829 |
window.location.href=params.url;
|
| 226 |
liveuser |
6830 |
|
| 3 |
liveuser |
6831 |
},params.countdownSec*1000);
|
|
|
6832 |
|
|
|
6833 |
}//else end
|
|
|
6834 |
|
| 174 |
liveuser |
6835 |
}//if end
|
| 3 |
liveuser |
6836 |
";
|
|
|
6837 |
$conf["javaScript::toScript"]["jsFunciton"][]=
|
|
|
6838 |
"
|
|
|
6839 |
/*
|
|
|
6840 |
說明:
|
|
|
6841 |
遞迴取得特定頁面產生的內容.
|
|
|
6842 |
參數:
|
|
|
6843 |
parmas,要傳送的參數名稱與其數值.
|
|
|
6844 |
url,要求的網址.
|
|
|
6845 |
method,要求的方法,GET或POST二擇一.
|
|
|
6846 |
resRootDivId,回應的內容要放在div的id為resRootDivId的地方裡面.
|
|
|
6847 |
範例用法:
|
|
|
6848 |
params={};
|
|
|
6849 |
params.key=val;//用於查尋的變數名稱與數值內容
|
|
|
6850 |
continue=true;//是否要不斷執行.
|
|
|
6851 |
window.tailAny.func.call(this,params,'/tailLogRes.php','POST','rootDiv');
|
|
|
6852 |
要求的網址回應如下:
|
|
|
6853 |
res,回應的物件
|
|
|
6854 |
res.lines,回應的內容列.
|
|
|
6855 |
res.id,最新識別欄位與數值.
|
|
|
6856 |
*/
|
|
|
6857 |
|
|
|
6858 |
//如果未設定 window.qbpwcf 物件
|
|
|
6859 |
if(window.qbpwcf===undefined){
|
|
|
6860 |
|
|
|
6861 |
//設置 window.qbpwcf 為空物件
|
|
|
6862 |
window.qbpwcf={};
|
|
|
6863 |
|
|
|
6864 |
}//if end
|
|
|
6865 |
|
|
|
6866 |
//初始化 window.tailAny 物件
|
|
|
6867 |
window.qbpwcf.tailAny={};
|
| 226 |
liveuser |
6868 |
|
| 3 |
liveuser |
6869 |
//初始化 window.qbpwcf.tailAny.continue 為 true,代表遞迴執行.
|
|
|
6870 |
window.qbpwcf.tailAny.continue=true;
|
| 226 |
liveuser |
6871 |
|
| 3 |
liveuser |
6872 |
//初始化 將結果輸出到畫面上的函式
|
|
|
6873 |
//res,為ajax抓到的結果json.
|
|
|
6874 |
//rootDivId,為回應要放到id為rootDivId的div裡面.
|
|
|
6875 |
window.qbpwcf.tailAny.outputFunc=function(res,rootDivId){
|
| 226 |
liveuser |
6876 |
|
| 3 |
liveuser |
6877 |
//針對每個輸出的行
|
|
|
6878 |
for(var i=0;i<res.lines.length;i++){
|
| 226 |
liveuser |
6879 |
|
| 3 |
liveuser |
6880 |
//如果內容不為空
|
|
|
6881 |
if(res.lines[i]!==''){
|
| 226 |
liveuser |
6882 |
|
| 3 |
liveuser |
6883 |
//set output line
|
|
|
6884 |
div=document.createElement('div');
|
|
|
6885 |
text=document.createTextNode(res.lines[i]);
|
|
|
6886 |
div.appendChild(text);
|
| 226 |
liveuser |
6887 |
|
| 3 |
liveuser |
6888 |
}//if end
|
| 226 |
liveuser |
6889 |
|
| 3 |
liveuser |
6890 |
//反之
|
|
|
6891 |
else{
|
| 226 |
liveuser |
6892 |
|
| 3 |
liveuser |
6893 |
//set output line
|
|
|
6894 |
div=document.createElement('div');
|
| 226 |
liveuser |
6895 |
|
| 3 |
liveuser |
6896 |
//建立換行語法
|
|
|
6897 |
p=document.createElement('p');
|
| 226 |
liveuser |
6898 |
|
| 3 |
liveuser |
6899 |
//放置換行語法
|
|
|
6900 |
div.appendChild(p);
|
| 226 |
liveuser |
6901 |
|
| 3 |
liveuser |
6902 |
}//else end
|
| 226 |
liveuser |
6903 |
|
| 3 |
liveuser |
6904 |
//show output line
|
|
|
6905 |
rootDiv=document.getElementById(xmlhttp.mother.rootDivId);
|
|
|
6906 |
rootDiv.prepend(div);
|
|
|
6907 |
|
|
|
6908 |
}//for end
|
| 226 |
liveuser |
6909 |
|
| 3 |
liveuser |
6910 |
}//function window.qbpwcf.tailAny.outputFunc end
|
| 226 |
liveuser |
6911 |
|
| 3 |
liveuser |
6912 |
//初始化 window.tailAny 函式
|
|
|
6913 |
window.qbpwcf.tailAny.func=function(params,url,method,resRootDivId){
|
|
|
6914 |
|
|
|
6915 |
//取得使用的參數 params
|
|
|
6916 |
this.params=params;
|
|
|
6917 |
|
|
|
6918 |
//初始化儲存新的get and post變數
|
|
|
6919 |
this.newParams='';
|
| 226 |
liveuser |
6920 |
|
| 3 |
liveuser |
6921 |
//初始化要查尋的 url
|
|
|
6922 |
this.url=url;
|
|
|
6923 |
|
|
|
6924 |
//取得method
|
|
|
6925 |
this.method=method;
|
|
|
6926 |
|
|
|
6927 |
//初始化持續執行
|
|
|
6928 |
this.continue=window.qbpwcf.tailAny.continue;
|
| 226 |
liveuser |
6929 |
|
| 3 |
liveuser |
6930 |
//放置回應的 div id 字串
|
|
|
6931 |
this.rootDivId=resRootDivId;
|
|
|
6932 |
|
|
|
6933 |
//取得query參數長度
|
|
|
6934 |
pl=Object.keys(params).length;
|
|
|
6935 |
|
|
|
6936 |
//針對每隔 query 參數
|
|
|
6937 |
for(var i=0;i<pl;i++){
|
| 226 |
liveuser |
6938 |
|
| 3 |
liveuser |
6939 |
//&符號字串
|
|
|
6940 |
var andStr='&';
|
| 226 |
liveuser |
6941 |
|
| 3 |
liveuser |
6942 |
//如果是第一個 query 參數
|
|
|
6943 |
if(i===0){
|
| 226 |
liveuser |
6944 |
|
| 3 |
liveuser |
6945 |
//&符號字串
|
|
|
6946 |
andStr=''
|
| 226 |
liveuser |
6947 |
|
| 3 |
liveuser |
6948 |
}//if end
|
| 226 |
liveuser |
6949 |
|
| 3 |
liveuser |
6950 |
//串接查詢字串,並 url encode
|
|
|
6951 |
this.newParams=this.newParams+andStr+encodeURIComponent(Object.keys(params)[i])+'='+encodeURIComponent(Object.values(params)[i]);
|
| 226 |
liveuser |
6952 |
|
| 3 |
liveuser |
6953 |
}//for end
|
|
|
6954 |
|
|
|
6955 |
//如果是 GET 方法
|
|
|
6956 |
if(method==='GET'){
|
|
|
6957 |
|
|
|
6958 |
//設置查詢的url
|
|
|
6959 |
this.url=this.url+'?'+this.newParams;
|
|
|
6960 |
|
|
|
6961 |
}//if end
|
| 226 |
liveuser |
6962 |
|
| 3 |
liveuser |
6963 |
xmlhttp=new XMLHttpRequest();
|
|
|
6964 |
xmlhttp.mother=this;
|
|
|
6965 |
xmlhttp.responseType='json';
|
|
|
6966 |
xmlhttp.open(method,this.url,true);
|
|
|
6967 |
xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
|
|
|
6968 |
xmlhttp.setRequestHeader('X-Requested-With','XMLHttpRequest');
|
|
|
6969 |
xmlhttp.onreadystatechange=function(){
|
|
|
6970 |
|
|
|
6971 |
//如果狀態為4且response code為200
|
|
|
6972 |
if(xmlhttp.readyState===4 && xmlhttp.status===200){
|
|
|
6973 |
|
| 226 |
liveuser |
6974 |
//get response
|
| 3 |
liveuser |
6975 |
res=xmlhttp.response;
|
| 226 |
liveuser |
6976 |
|
| 3 |
liveuser |
6977 |
//將結果放到畫面上
|
| 226 |
liveuser |
6978 |
window.qbpwcf.tailAny.outputFunc.call(this,res,xmlhttp.mother.rootDivId);
|
|
|
6979 |
|
| 3 |
liveuser |
6980 |
//如果有新的識別欄位與數值
|
|
|
6981 |
if(res.id!==undefined){
|
|
|
6982 |
|
| 226 |
liveuser |
6983 |
//取消舊的識別欄位
|
|
|
6984 |
xmlhttp.mother.params={};
|
| 3 |
liveuser |
6985 |
|
|
|
6986 |
//如果有新的識別欄位
|
|
|
6987 |
for(i=0;i<Object.keys(res.id).length;i++){
|
|
|
6988 |
|
|
|
6989 |
//取得識別欄位
|
|
|
6990 |
col=Object.keys(res.id)[i];
|
|
|
6991 |
|
|
|
6992 |
//取得新的識別號碼
|
|
|
6993 |
val=eval('res.id.'+col);
|
|
|
6994 |
|
|
|
6995 |
//放上新的識別碼
|
|
|
6996 |
eval('xmlhttp.mother.params.'+col+'='+val);
|
|
|
6997 |
|
|
|
6998 |
}//for end
|
|
|
6999 |
|
|
|
7000 |
}//if end
|
|
|
7001 |
|
| 226 |
liveuser |
7002 |
//如果要繼續
|
| 3 |
liveuser |
7003 |
if(xmlhttp.mother.continue){
|
|
|
7004 |
|
|
|
7005 |
//遞迴
|
|
|
7006 |
window.qbpwcf.tailAny.func(xmlhttp.mother.params,xmlhttp.mother.url,xmlhttp.mother.method,xmlhttp.mother.rootDivId);
|
| 226 |
liveuser |
7007 |
|
| 3 |
liveuser |
7008 |
}//if end
|
| 226 |
liveuser |
7009 |
|
| 3 |
liveuser |
7010 |
//反之要暫停
|
|
|
7011 |
else{
|
| 226 |
liveuser |
7012 |
|
| 3 |
liveuser |
7013 |
//設置無限等待
|
|
|
7014 |
var intervalTail = window.setInterval(function(){
|
| 226 |
liveuser |
7015 |
|
| 3 |
liveuser |
7016 |
//console.log(window.qbpwcf.tailAny.continue);
|
| 226 |
liveuser |
7017 |
|
| 3 |
liveuser |
7018 |
//如果要繼續了
|
|
|
7019 |
if(xmlhttp.mother.continue){
|
| 226 |
liveuser |
7020 |
|
| 3 |
liveuser |
7021 |
//清除無限等待
|
|
|
7022 |
clearInterval(intervalTail);
|
| 226 |
liveuser |
7023 |
|
| 3 |
liveuser |
7024 |
//遞迴
|
|
|
7025 |
window.qbpwcf.tailAny.func(xmlhttp.mother.params,xmlhttp.mother.url,xmlhttp.mother.method,xmlhttp.mother.rootDivId);
|
| 226 |
liveuser |
7026 |
|
| 3 |
liveuser |
7027 |
}//if end
|
| 226 |
liveuser |
7028 |
|
| 3 |
liveuser |
7029 |
},1000);
|
| 226 |
liveuser |
7030 |
|
| 3 |
liveuser |
7031 |
}//else end
|
| 226 |
liveuser |
7032 |
|
| 3 |
liveuser |
7033 |
}//if end
|
|
|
7034 |
|
|
|
7035 |
}//function end
|
| 226 |
liveuser |
7036 |
|
| 3 |
liveuser |
7037 |
//如果是 GET 方法
|
|
|
7038 |
if(method==='GET'){
|
|
|
7039 |
|
|
|
7040 |
//不夾帶內容
|
|
|
7041 |
xmlhttp.send();
|
| 226 |
liveuser |
7042 |
|
| 3 |
liveuser |
7043 |
}//if end
|
|
|
7044 |
|
|
|
7045 |
//反之是 POST 方法
|
|
|
7046 |
else{
|
|
|
7047 |
|
|
|
7048 |
//夾帶內容
|
|
|
7049 |
xmlhttp.send(this.newParams);
|
|
|
7050 |
|
|
|
7051 |
}//else end
|
| 226 |
liveuser |
7052 |
|
| 3 |
liveuser |
7053 |
}//function end
|
|
|
7054 |
";
|
|
|
7055 |
$conf["javaScript::toScript"]["jsFunciton"][]=
|
|
|
7056 |
"
|
|
|
7057 |
//如果未設定 window.qbpwcf 物件
|
|
|
7058 |
if(window.qbpwcf===undefined){
|
|
|
7059 |
|
|
|
7060 |
//設置 window.qbpwcf 為空物件
|
|
|
7061 |
window.qbpwcf={};
|
|
|
7062 |
|
|
|
7063 |
}//if end
|
|
|
7064 |
|
|
|
7065 |
//設置 window.qbpwcf.gatDataDynamic 物件
|
|
|
7066 |
window.qbpwcf.gatDataDynamic={};
|
|
|
7067 |
|
|
|
7068 |
/*
|
|
|
7069 |
函式說明:
|
|
|
7070 |
當按下案鍵後放開時若元素數值長度符合則要連續取得資料.
|
|
|
7071 |
參數說明:
|
|
|
7072 |
element,要綁定事件的元素.
|
|
|
7073 |
length,目標算術數值長度要為多少才要執行
|
|
|
7074 |
params,篩選資料的參數物件.
|
|
|
7075 |
url,要求的網址.
|
|
|
7076 |
method,要求的方法,有'POST'跟'GET'.
|
|
|
7077 |
rootDiv,要放置回應到id為rootDiv的div裡面.
|
|
|
7078 |
範例呼叫方式:
|
|
|
7079 |
element=document.getElementById('customTime');
|
|
|
7080 |
params={};
|
|
|
7081 |
params.start=element.value;
|
|
|
7082 |
window.qbpwcf.gatDataDynamic.func.call(this,element,8,params,'/logRes.php','POST','rootDiv');
|
|
|
7083 |
*/
|
|
|
7084 |
|
|
|
7085 |
//設置當前函式的變數
|
|
|
7086 |
window.qbpwcf.gatDataDynamic.func=function(element,length,params,url,method,rootDiv){
|
| 226 |
liveuser |
7087 |
|
| 3 |
liveuser |
7088 |
//debug
|
|
|
7089 |
//console.log(element,length,params,url,method,rootDiv);
|
| 226 |
liveuser |
7090 |
|
| 3 |
liveuser |
7091 |
//儲存內容長度要為多少
|
|
|
7092 |
window.qbpwcf.gatDataDynamic.length=length;
|
|
|
7093 |
|
|
|
7094 |
//儲存要傳遞的條件
|
|
|
7095 |
window.qbpwcf.gatDataDynamic.params=params;
|
|
|
7096 |
|
|
|
7097 |
//儲存要傳送要求到哪個頁面
|
|
|
7098 |
window.qbpwcf.gatDataDynamic.url=url;
|
|
|
7099 |
|
|
|
7100 |
//儲存傳遞的方式
|
|
|
7101 |
window.qbpwcf.gatDataDynamic.method=method;
|
|
|
7102 |
|
|
|
7103 |
//儲存回應的div id
|
|
|
7104 |
window.qbpwcf.gatDataDynamic.rootDiv=rootDiv;
|
|
|
7105 |
|
|
|
7106 |
//初始化暫存的物件
|
|
|
7107 |
window.qbpwcf.gatDataDynamic.tmp={};
|
| 226 |
liveuser |
7108 |
|
| 3 |
liveuser |
7109 |
//初始化暫存最新表單數值的長度
|
|
|
7110 |
window.qbpwcf.gatDataDynamic.tmp.latestValueLength=0;
|
|
|
7111 |
|
|
|
7112 |
//綁定事件到該元素身上
|
|
|
7113 |
element.addEventListener('keyup',function(event){
|
|
|
7114 |
|
|
|
7115 |
//取得使用的參數名稱
|
|
|
7116 |
paramName=Object.keys(window.qbpwcf.gatDataDynamic.params)[0];
|
| 226 |
liveuser |
7117 |
|
| 3 |
liveuser |
7118 |
//取得事件觸發後的參數數值
|
|
|
7119 |
eval('window.qbpwcf.gatDataDynamic.params.'+paramName+'=\''+event.target.value+'\'');
|
|
|
7120 |
|
|
|
7121 |
//誤觸
|
|
|
7122 |
if(event.isComposing || event.keyCode === 229) {
|
| 226 |
liveuser |
7123 |
|
| 3 |
liveuser |
7124 |
//取消執行
|
|
|
7125 |
return false;
|
| 226 |
liveuser |
7126 |
|
| 3 |
liveuser |
7127 |
}//if end
|
| 226 |
liveuser |
7128 |
|
| 3 |
liveuser |
7129 |
//如果長度跟之前比沒有變化,且按下的不為Enter鍵
|
|
|
7130 |
if(event.target.value.length===window.qbpwcf.gatDataDynamic.tmp.latestValueLength && event.keyCode !== 13){
|
| 226 |
liveuser |
7131 |
|
| 3 |
liveuser |
7132 |
//取消執行
|
|
|
7133 |
return false;
|
| 226 |
liveuser |
7134 |
|
| 3 |
liveuser |
7135 |
}//if end
|
| 226 |
liveuser |
7136 |
|
| 3 |
liveuser |
7137 |
//反之長度有變化
|
|
|
7138 |
else{
|
| 226 |
liveuser |
7139 |
|
| 3 |
liveuser |
7140 |
//更新最新變化後的數值長度
|
|
|
7141 |
window.qbpwcf.gatDataDynamic.tmp.latestValueLength=event.target.value.length;
|
| 226 |
liveuser |
7142 |
|
| 3 |
liveuser |
7143 |
}//else end
|
| 226 |
liveuser |
7144 |
|
| 3 |
liveuser |
7145 |
//如果長度不對
|
|
|
7146 |
if(event.target.value.length!==window.qbpwcf.gatDataDynamic.length){
|
|
|
7147 |
|
|
|
7148 |
//取消執行
|
|
|
7149 |
return false;
|
|
|
7150 |
|
|
|
7151 |
}//if end
|
|
|
7152 |
|
|
|
7153 |
//連續取得內容
|
|
|
7154 |
window.qbpwcf.tailAny.func.call(this,window.qbpwcf.gatDataDynamic.params,window.qbpwcf.gatDataDynamic.url,window.qbpwcf.gatDataDynamic.method,window.qbpwcf.gatDataDynamic.rootDiv);
|
|
|
7155 |
|
|
|
7156 |
});//event end
|
|
|
7157 |
|
|
|
7158 |
}//function end
|
|
|
7159 |
";
|
|
|
7160 |
$conf["javaScript::toScript"]["jsFunciton"][]=
|
|
|
7161 |
"
|
|
|
7162 |
//如果未設定 window.qbpwcf 物件
|
|
|
7163 |
if(window.qbpwcf===undefined){
|
|
|
7164 |
|
|
|
7165 |
//設置 window.qbpwcf 為空物件
|
|
|
7166 |
window.qbpwcf={};
|
|
|
7167 |
|
|
|
7168 |
}//if end
|
|
|
7169 |
|
|
|
7170 |
//設置 window.qbpwcf.sequenceQuery 物件
|
|
|
7171 |
window.qbpwcf.sequenceQuery={};
|
|
|
7172 |
|
|
|
7173 |
/*
|
|
|
7174 |
涵式說明:
|
|
|
7175 |
循序query避免timeout.
|
|
|
7176 |
參數說明:
|
|
|
7177 |
url,字串,要query的網址.
|
|
|
7178 |
name,字串,欲傳送的post變數名稱.
|
|
|
7179 |
queue,代辦事項,陣列,遇到元素內容為'null'者,代表結束query;初次查詢設置為[]即可.
|
|
|
7180 |
callback,物件,要呼叫的涵式名稱與參數,結構如下:
|
|
|
7181 |
{
|
|
|
7182 |
func:'function name';
|
|
|
7183 |
params:'params';
|
|
|
7184 |
}
|
|
|
7185 |
範例:
|
|
|
7186 |
url='path2query';
|
|
|
7187 |
name='action';
|
|
|
7188 |
queue=[];
|
|
|
7189 |
callback=
|
|
|
7190 |
{
|
|
|
7191 |
name:'console.log',
|
|
|
7192 |
params:'debug',
|
|
|
7193 |
};
|
|
|
7194 |
window.qbpwcf.sequenceQuery.func.call(this,url,name,queue,callback);
|
|
|
7195 |
*/
|
| 226 |
liveuser |
7196 |
|
| 3 |
liveuser |
7197 |
//設置當前函式的變數
|
|
|
7198 |
window.qbpwcf.sequenceQuery.func=function(url,name,queue,callback){
|
|
|
7199 |
|
|
|
7200 |
//如果網址未指定
|
|
|
7201 |
if(url===undefined){
|
| 226 |
liveuser |
7202 |
|
| 3 |
liveuser |
7203 |
//結束執行
|
|
|
7204 |
return false;
|
| 226 |
liveuser |
7205 |
|
| 3 |
liveuser |
7206 |
}//if end
|
|
|
7207 |
|
|
|
7208 |
//save url to global
|
|
|
7209 |
window.qbpwcf.sequenceQuery.url=url;
|
|
|
7210 |
|
|
|
7211 |
//save name to global
|
|
|
7212 |
window.qbpwcf.sequenceQuery.name=name;
|
|
|
7213 |
|
|
|
7214 |
//save callback to global
|
|
|
7215 |
window.qbpwcf.sequenceQuery.callback={};
|
|
|
7216 |
window.qbpwcf.sequenceQuery.callback.name=callback.name;
|
|
|
7217 |
window.qbpwcf.sequenceQuery.callback.params=callback.params;
|
| 226 |
liveuser |
7218 |
|
| 3 |
liveuser |
7219 |
//debug
|
|
|
7220 |
//console.log(window.qbpwcf.sequenceQuery.callback);
|
|
|
7221 |
|
|
|
7222 |
//初始化參數
|
|
|
7223 |
params={};
|
|
|
7224 |
|
|
|
7225 |
//設置參數
|
|
|
7226 |
eval('params.'+name+'=queue');
|
| 226 |
liveuser |
7227 |
|
| 3 |
liveuser |
7228 |
//debug
|
|
|
7229 |
//console.log(params);
|
|
|
7230 |
|
|
|
7231 |
//初始化參數 window.tailAny.params 字串
|
|
|
7232 |
window.qbpwcf.sequenceQuery.params='';
|
|
|
7233 |
|
|
|
7234 |
//針對物件中的每個key
|
|
|
7235 |
Object.keys(params).forEach(function(key){
|
|
|
7236 |
|
|
|
7237 |
//&符號字串
|
|
|
7238 |
andStr='';
|
|
|
7239 |
|
|
|
7240 |
//如果參數目前不為空
|
|
|
7241 |
if(window.qbpwcf.sequenceQuery.params!==''){
|
| 226 |
liveuser |
7242 |
|
| 3 |
liveuser |
7243 |
//&符號字串
|
|
|
7244 |
andStr='\&';
|
| 226 |
liveuser |
7245 |
|
| 3 |
liveuser |
7246 |
}//if end
|
|
|
7247 |
|
|
|
7248 |
//串接查詢字串,並 url encode
|
|
|
7249 |
window.qbpwcf.sequenceQuery.params=window.qbpwcf.sequenceQuery.params+andStr+encodeURIComponent(key)+'='+encodeURIComponent(eval('params.'+key));
|
|
|
7250 |
|
|
|
7251 |
//debug
|
|
|
7252 |
//console.log(window.qbpwcf.sequenceQuery);
|
|
|
7253 |
|
|
|
7254 |
});
|
|
|
7255 |
|
|
|
7256 |
//debug
|
|
|
7257 |
//console.log(window.qbpwcf.sequenceQuery.params);
|
| 226 |
liveuser |
7258 |
|
| 3 |
liveuser |
7259 |
xmlhttp=new XMLHttpRequest();
|
|
|
7260 |
xmlhttp.responseType='json';
|
|
|
7261 |
xmlhttp.timeout=60000;
|
|
|
7262 |
xmlhttp.open('POST',url,true);
|
|
|
7263 |
xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
|
|
|
7264 |
xmlhttp.setRequestHeader('X-Requested-With','XMLHttpRequest');
|
|
|
7265 |
xmlhttp.onreadystatechange=function(){
|
|
|
7266 |
|
|
|
7267 |
//如果狀態為4且response code為200
|
|
|
7268 |
if(xmlhttp.readyState===4 && xmlhttp.status===200){
|
|
|
7269 |
|
| 226 |
liveuser |
7270 |
//get response
|
| 3 |
liveuser |
7271 |
res=xmlhttp.response;
|
| 226 |
liveuser |
7272 |
|
| 3 |
liveuser |
7273 |
//debug
|
|
|
7274 |
//console.log(res);
|
| 226 |
liveuser |
7275 |
|
| 3 |
liveuser |
7276 |
//如果執行失敗
|
|
|
7277 |
if(res.status==='false'){
|
| 226 |
liveuser |
7278 |
|
| 3 |
liveuser |
7279 |
//結束執行
|
|
|
7280 |
return false;
|
| 226 |
liveuser |
7281 |
|
| 3 |
liveuser |
7282 |
}//if end
|
| 226 |
liveuser |
7283 |
|
| 3 |
liveuser |
7284 |
//取得回應的內容
|
|
|
7285 |
content=res.content;
|
| 226 |
liveuser |
7286 |
|
| 3 |
liveuser |
7287 |
//debug
|
|
|
7288 |
//console.log(content);
|
| 226 |
liveuser |
7289 |
|
| 3 |
liveuser |
7290 |
//如果遇到null元素
|
|
|
7291 |
if(content[0]==='null'){
|
| 226 |
liveuser |
7292 |
|
| 3 |
liveuser |
7293 |
//callback
|
|
|
7294 |
eval(window.qbpwcf.sequenceQuery.callback.name+'.call(this,window.qbpwcf.sequenceQuery.callback.params)');
|
| 226 |
liveuser |
7295 |
|
| 3 |
liveuser |
7296 |
//結束執行
|
|
|
7297 |
return true;
|
| 226 |
liveuser |
7298 |
|
| 3 |
liveuser |
7299 |
}//if end
|
| 226 |
liveuser |
7300 |
|
| 3 |
liveuser |
7301 |
//遞迴
|
|
|
7302 |
window.qbpwcf.sequenceQuery.func.call(this,window.qbpwcf.sequenceQuery.url,window.qbpwcf.sequenceQuery.name,content,window.qbpwcf.sequenceQuery.callback);
|
|
|
7303 |
|
|
|
7304 |
}//if end
|
|
|
7305 |
|
|
|
7306 |
}//function end
|
|
|
7307 |
|
|
|
7308 |
//夾帶內容
|
|
|
7309 |
xmlhttp.send(window.qbpwcf.sequenceQuery.params);
|
| 226 |
liveuser |
7310 |
|
| 3 |
liveuser |
7311 |
};
|
|
|
7312 |
|
|
|
7313 |
";
|
|
|
7314 |
$conf["javaScript::toScript"]["jsFunciton"][]=
|
|
|
7315 |
"
|
|
|
7316 |
//如果未設定 window.qbpwcf 物件
|
|
|
7317 |
if(window.qbpwcf===undefined){
|
|
|
7318 |
|
|
|
7319 |
//設置 window.qbpwcf 為空物件
|
|
|
7320 |
window.qbpwcf={};
|
|
|
7321 |
|
|
|
7322 |
}//if end
|
|
|
7323 |
|
|
|
7324 |
//設置 window.qbpwcf.modal 物件
|
|
|
7325 |
window.qbpwcf.modal={};
|
| 226 |
liveuser |
7326 |
|
| 3 |
liveuser |
7327 |
//預設的 modal 標題是由 div 組成
|
|
|
7328 |
window.qbpwcf.modal.title=document.createElement('div');
|
|
|
7329 |
|
|
|
7330 |
//預設的 modal 標題
|
|
|
7331 |
window.qbpwcf.modal.title.innerText='Confirm window';
|
| 226 |
liveuser |
7332 |
|
| 3 |
liveuser |
7333 |
//預設的 modal 標題樣式
|
|
|
7334 |
window.qbpwcf.modal.title.style.fontWeight='bold';
|
| 226 |
liveuser |
7335 |
|
| 3 |
liveuser |
7336 |
//預設的 modal 標題背景顏色
|
|
|
7337 |
window.qbpwcf.modal.bgColor='#DDDDFF';
|
| 226 |
liveuser |
7338 |
|
| 3 |
liveuser |
7339 |
//預設的 modal 內文
|
|
|
7340 |
window.qbpwcf.modal.content=document.createTextNode('Are you sure?');
|
| 226 |
liveuser |
7341 |
|
| 3 |
liveuser |
7342 |
//預設的 取消 按鈕內容
|
|
|
7343 |
window.qbpwcf.modal.cancle='Cancel';
|
| 226 |
liveuser |
7344 |
|
| 3 |
liveuser |
7345 |
//預設的 取消 按鈕背景顏色
|
|
|
7346 |
window.qbpwcf.modal.cancleBgColor='#FFDDDD';
|
| 226 |
liveuser |
7347 |
|
| 3 |
liveuser |
7348 |
//預設的取消按鈕點擊後要做的事情
|
|
|
7349 |
window.qbpwcf.modal.cancelAction=function(e)
|
|
|
7350 |
{
|
|
|
7351 |
//delete whole confirm window
|
|
|
7352 |
document.getElementById('qbpwcf.bgDiv').remove();
|
|
|
7353 |
document.getElementById('qbpwcf.modalRootDiv').remove();
|
|
|
7354 |
}
|
| 226 |
liveuser |
7355 |
|
| 3 |
liveuser |
7356 |
//預設的 確認 按鈕內容
|
|
|
7357 |
window.qbpwcf.modal.confirm='Confirm';
|
| 226 |
liveuser |
7358 |
|
| 3 |
liveuser |
7359 |
//預設的 確認 按鈕背景顏色
|
|
|
7360 |
window.qbpwcf.modal.confirmBgColor='#DDFFFF';
|
| 226 |
liveuser |
7361 |
|
| 3 |
liveuser |
7362 |
//預設的確認按鈕要做的事情
|
|
|
7363 |
window.qbpwcf.modal.confirmAction=function(e)
|
|
|
7364 |
{
|
|
|
7365 |
alert('you click confirm');
|
|
|
7366 |
window.qbpwcf.modal.cancelAction.call(this);
|
|
|
7367 |
}
|
| 226 |
liveuser |
7368 |
|
| 3 |
liveuser |
7369 |
//modal的最寬高設定物件
|
|
|
7370 |
window.qbpwcf.modal.RootDiv={};
|
| 226 |
liveuser |
7371 |
|
| 3 |
liveuser |
7372 |
//modal的寬度比例,1~99
|
|
|
7373 |
window.qbpwcf.modal.RootDiv.width='80';
|
| 226 |
liveuser |
7374 |
|
| 3 |
liveuser |
7375 |
//modal距離高度的比例
|
|
|
7376 |
window.qbpwcf.modal.RootDiv.top='10';
|
| 226 |
liveuser |
7377 |
|
| 3 |
liveuser |
7378 |
//建立顯示 qbpwcf modal 的函式
|
|
|
7379 |
window.qbpwcf.modal.show=function(){
|
| 226 |
liveuser |
7380 |
|
| 3 |
liveuser |
7381 |
//建立背景div
|
|
|
7382 |
bgDiv=document.createElement('div');
|
| 226 |
liveuser |
7383 |
|
| 3 |
liveuser |
7384 |
//設定樣式為全螢幕
|
|
|
7385 |
bgDiv.style.width='100vw';
|
|
|
7386 |
bgDiv.style.height='100vh';
|
|
|
7387 |
bgDiv.style.backgroundColor='grey';
|
|
|
7388 |
bgDiv.style.opacity='0.7';
|
|
|
7389 |
bgDiv.style.position='fixed';
|
|
|
7390 |
bgDiv.style.top='0px';
|
|
|
7391 |
bgDiv.style.left='0px';
|
|
|
7392 |
bgDiv.style.zIndex='10000';
|
| 226 |
liveuser |
7393 |
|
| 3 |
liveuser |
7394 |
//設定id
|
|
|
7395 |
bgDiv.id='qbpwcf.bgDiv';
|
| 226 |
liveuser |
7396 |
|
| 3 |
liveuser |
7397 |
//確認視窗的div
|
|
|
7398 |
modalRootDiv=document.createElement('div');
|
| 226 |
liveuser |
7399 |
|
| 3 |
liveuser |
7400 |
//設定id
|
|
|
7401 |
modalRootDiv.id='qbpwcf.modalRootDiv';
|
| 226 |
liveuser |
7402 |
|
| 3 |
liveuser |
7403 |
//確認視窗的modal樣式
|
|
|
7404 |
modalRootDiv.style.width=window.qbpwcf.modal.RootDiv.width+'vw';
|
|
|
7405 |
modalRootDiv.style.top=window.qbpwcf.modal.RootDiv.top+'vh';
|
|
|
7406 |
modalRootDiv.style.backgroundColor='white';
|
|
|
7407 |
modalRootDiv.style.position='fixed';
|
|
|
7408 |
modalRootDiv.style.left=((100-window.qbpwcf.modal.RootDiv.width)/2)+'vw';
|
|
|
7409 |
modalRootDiv.style.zIndex='10001';
|
|
|
7410 |
modalRootDiv.style.borderRadius='10px';
|
| 226 |
liveuser |
7411 |
|
| 3 |
liveuser |
7412 |
//modal title div
|
|
|
7413 |
modalTitleDiv=document.createElement('div');
|
| 226 |
liveuser |
7414 |
|
| 3 |
liveuser |
7415 |
//set modal title content
|
|
|
7416 |
modalTitleDiv.appendChild(window.qbpwcf.modal.title);
|
| 226 |
liveuser |
7417 |
|
| 3 |
liveuser |
7418 |
//set modal title bg color
|
|
|
7419 |
modalTitleDiv.style.backgroundColor=window.qbpwcf.modal.bgColor;
|
| 226 |
liveuser |
7420 |
|
| 3 |
liveuser |
7421 |
//set modal title line height attr
|
|
|
7422 |
modalTitleDiv.style.minHeight='20px';
|
| 226 |
liveuser |
7423 |
|
| 3 |
liveuser |
7424 |
//set modal title line height attr
|
|
|
7425 |
modalTitleDiv.style.borderRadius='inherit';
|
| 226 |
liveuser |
7426 |
|
| 3 |
liveuser |
7427 |
//set modal title line height attr
|
|
|
7428 |
modalTitleDiv.style.paddingLeft='5px';
|
| 226 |
liveuser |
7429 |
|
| 3 |
liveuser |
7430 |
//put modal title to modal root div
|
|
|
7431 |
modalRootDiv.appendChild(modalTitleDiv);
|
| 226 |
liveuser |
7432 |
|
| 3 |
liveuser |
7433 |
//modal content div
|
|
|
7434 |
modalContentDiv=document.createElement('div');
|
| 226 |
liveuser |
7435 |
|
| 3 |
liveuser |
7436 |
//set modal content text
|
|
|
7437 |
modalContentDiv.appendChild(window.qbpwcf.modal.content);
|
| 226 |
liveuser |
7438 |
|
| 3 |
liveuser |
7439 |
//set modal content style
|
|
|
7440 |
modalContentDiv.style.textAlign='center';
|
|
|
7441 |
modalContentDiv.style.lineHeight=(window.qbpwcf.modal.RootDiv.height-10)+'vh';
|
| 226 |
liveuser |
7442 |
|
| 3 |
liveuser |
7443 |
//put modal content to modal root div
|
|
|
7444 |
modalRootDiv.appendChild(modalContentDiv);
|
| 226 |
liveuser |
7445 |
|
| 3 |
liveuser |
7446 |
//modal bottom div
|
| 226 |
liveuser |
7447 |
modalBottomDiv=document.createElement('div');
|
|
|
7448 |
|
| 3 |
liveuser |
7449 |
//set modal bottom line height
|
|
|
7450 |
modalBottomDiv.style.lineHeight='6vh';
|
| 226 |
liveuser |
7451 |
|
| 3 |
liveuser |
7452 |
//set modal bptton text align style to right
|
|
|
7453 |
modalBottomDiv.style.textAlign='right';
|
| 226 |
liveuser |
7454 |
|
| 3 |
liveuser |
7455 |
//set modal bottom 圓角
|
| 226 |
liveuser |
7456 |
modalBottomDiv.style.borderRadius='5px';
|
|
|
7457 |
|
| 3 |
liveuser |
7458 |
//set modal bottom background color
|
| 226 |
liveuser |
7459 |
modalBottomDiv.style.backgroundColor=modalRootDiv.style.backgroundColor;
|
|
|
7460 |
|
| 3 |
liveuser |
7461 |
//modal close button
|
| 226 |
liveuser |
7462 |
cancleSpan=document.createElement('span');
|
|
|
7463 |
|
| 3 |
liveuser |
7464 |
//字體為粗體字
|
| 226 |
liveuser |
7465 |
cancleSpan.style.fontWeight='bold';
|
|
|
7466 |
|
| 3 |
liveuser |
7467 |
//set model close button text content
|
| 226 |
liveuser |
7468 |
cancleSpan.innerText=window.qbpwcf.modal.cancle;
|
|
|
7469 |
|
| 3 |
liveuser |
7470 |
//set cancle button background color
|
|
|
7471 |
cancleSpan.style.backgroundColor=window.qbpwcf.modal.cancleBgColor;
|
| 226 |
liveuser |
7472 |
|
| 3 |
liveuser |
7473 |
//cancle button 元素間的距離
|
|
|
7474 |
cancleSpan.style.marging='5vw';
|
| 226 |
liveuser |
7475 |
|
| 3 |
liveuser |
7476 |
//cancle button 元素的範圍
|
|
|
7477 |
cancleSpan.style.padding='1vh';
|
| 226 |
liveuser |
7478 |
|
| 3 |
liveuser |
7479 |
//cancle button 不超出範圍
|
|
|
7480 |
cancleSpan.style.position='relative';
|
|
|
7481 |
cancleSpan.style.bottom='4vh';
|
| 226 |
liveuser |
7482 |
|
| 3 |
liveuser |
7483 |
//cancle button 圓角
|
|
|
7484 |
cancleSpan.style.borderRadius='100px';
|
| 226 |
liveuser |
7485 |
|
| 3 |
liveuser |
7486 |
//cancle button pointer
|
| 226 |
liveuser |
7487 |
cancleSpan.style.cursor='pointer';
|
|
|
7488 |
|
| 3 |
liveuser |
7489 |
//okSpan button right top & bottom
|
|
|
7490 |
cancleSpan.style.top='0px';
|
|
|
7491 |
cancleSpan.style.bottom='0px';
|
| 226 |
liveuser |
7492 |
|
| 3 |
liveuser |
7493 |
//設置點擊 cancle button 要做的事情.
|
|
|
7494 |
cancleSpan.addEventListener('click',function(e)
|
|
|
7495 |
{
|
|
|
7496 |
window.qbpwcf.modal.cancelAction(e);
|
|
|
7497 |
});
|
| 226 |
liveuser |
7498 |
|
| 3 |
liveuser |
7499 |
//modal ok button
|
| 226 |
liveuser |
7500 |
okSpan=document.createElement('span');
|
|
|
7501 |
|
| 3 |
liveuser |
7502 |
//字體為粗體字
|
|
|
7503 |
okSpan.style.fontWeight='bold';
|
| 226 |
liveuser |
7504 |
|
| 3 |
liveuser |
7505 |
//set model ok button text content
|
| 226 |
liveuser |
7506 |
okSpan.innerText=window.qbpwcf.modal.confirm;
|
|
|
7507 |
|
| 3 |
liveuser |
7508 |
//set ok button background color
|
| 226 |
liveuser |
7509 |
okSpan.style.backgroundColor=window.qbpwcf.modal.confirmBgColor;
|
|
|
7510 |
|
| 3 |
liveuser |
7511 |
//okSpan button 元素間的距離
|
|
|
7512 |
okSpan.style.marginLeft='5vw';
|
|
|
7513 |
okSpan.style.marginRight='5vw';
|
| 226 |
liveuser |
7514 |
|
| 3 |
liveuser |
7515 |
//okSpan button 元素的範圍
|
| 226 |
liveuser |
7516 |
okSpan.style.padding='1vh';
|
|
|
7517 |
|
| 3 |
liveuser |
7518 |
//okSpan button 不超出範圍
|
|
|
7519 |
okSpan.style.position='relative';
|
| 226 |
liveuser |
7520 |
okSpan.style.bottom='4vh';
|
|
|
7521 |
|
| 3 |
liveuser |
7522 |
//okSpan button 圓角
|
|
|
7523 |
okSpan.style.borderRadius='100px';
|
| 226 |
liveuser |
7524 |
|
| 3 |
liveuser |
7525 |
//okSpan button pointer
|
| 226 |
liveuser |
7526 |
okSpan.style.cursor='pointer';
|
|
|
7527 |
|
| 3 |
liveuser |
7528 |
//okSpan button right top & bottom
|
|
|
7529 |
okSpan.style.top='0px';
|
|
|
7530 |
okSpan.style.bottom='0px';
|
| 226 |
liveuser |
7531 |
|
| 3 |
liveuser |
7532 |
//設置點擊 cancle button 要做的事情.
|
|
|
7533 |
okSpan.addEventListener('click',function(e)
|
|
|
7534 |
{
|
|
|
7535 |
window.qbpwcf.modal.confirmAction(e);
|
|
|
7536 |
});
|
| 226 |
liveuser |
7537 |
|
| 3 |
liveuser |
7538 |
//put cancle and ok button to modal bottom div
|
|
|
7539 |
modalBottomDiv.appendChild(cancleSpan);
|
|
|
7540 |
modalBottomDiv.appendChild(okSpan);
|
| 226 |
liveuser |
7541 |
|
| 3 |
liveuser |
7542 |
//put modal bottom div to modal root div
|
| 226 |
liveuser |
7543 |
modalRootDiv.appendChild(modalBottomDiv);
|
|
|
7544 |
|
| 3 |
liveuser |
7545 |
//bgDiv放置到當前 window
|
|
|
7546 |
document.body.appendChild(bgDiv);
|
| 226 |
liveuser |
7547 |
|
| 3 |
liveuser |
7548 |
//put root modal div to body
|
|
|
7549 |
document.body.appendChild(modalRootDiv);
|
| 226 |
liveuser |
7550 |
|
|
|
7551 |
}//if end
|
| 3 |
liveuser |
7552 |
";
|
|
|
7553 |
$conf["javaScript::toScript"]["jsFunciton"][]=
|
|
|
7554 |
"
|
|
|
7555 |
//如果未設定 window.qbpwcf 物件
|
|
|
7556 |
if(window.qbpwcf===undefined){
|
|
|
7557 |
|
|
|
7558 |
//設置 window.qbpwcf 為空物件
|
|
|
7559 |
window.qbpwcf={};
|
|
|
7560 |
|
|
|
7561 |
}//if end
|
|
|
7562 |
|
|
|
7563 |
//如果未設定 window.qbpwcf.form 物件
|
|
|
7564 |
if(window.qbpwcf.form===undefined){
|
|
|
7565 |
|
|
|
7566 |
//設置 window.qbpwcf.form 為空物件
|
|
|
7567 |
window.qbpwcf.form={};
|
|
|
7568 |
|
|
|
7569 |
}//if end
|
| 226 |
liveuser |
7570 |
|
| 3 |
liveuser |
7571 |
/*
|
| 174 |
liveuser |
7572 |
如果回覆的結果是json,且具有error屬性,則會進行需要手動消除的提示.
|
|
|
7573 |
如果回覆的結果是json,且具有content性,則會進行會自動消失的提示.
|
| 3 |
liveuser |
7574 |
如果回覆的結果是json,且具有location屬性,則會進行導頁.
|
|
|
7575 |
window.qbpwcf.form.fakeScrollingList(),建構子,初始化fakeScrollingList.
|
| 174 |
liveuser |
7576 |
window.qbpwcf.form.eleId,選單呈現的元素 id 為什麼,亦即要點擊的元素其id,若有設定則忽略targetEle.
|
|
|
7577 |
window.qbpwcf.form.targetEle,選單呈現的元素為,若 eleId 為 '' 且該變數不等於 '' 就會採用,若有設定則忽略eleId.
|
|
|
7578 |
window.qbpwcf.from.autoStart,布林,若eleId與targetEle均未設定,則預設為true,代表要網頁載入後自動觸發;反之設置為false代表不會網頁載入後自動觸發.
|
|
|
7579 |
window.qbpwcf.form.closeIcon,關閉按鈕的設定.
|
|
|
7580 |
window.qbpwcf.form.disallowClose,布林,true代表不允許關閉選單;預設為false,代表允許關閉選單.
|
| 200 |
liveuser |
7581 |
window.qbpwcf.form.redirectAfterClose,字串,若有設定則會在按下關閉按鈕後進行導頁.
|
| 174 |
liveuser |
7582 |
window.qbpwcf.form.noActionOption,物件,選擇哪些選項不用動作,name為顯示的內容;value為選單的數值.
|
| 3 |
liveuser |
7583 |
window.qbpwcf.form.sendOnClickWhenOnly2options,布林值,預設為false,不啟用;反之為true代表點選元素後就直接送出最後一個選項的數值.啟用條件為window.qbpwcf.form.options只有一個元素.
|
|
|
7584 |
window.qbpwcf.form.donotSendFrom,布林值,預設為false,代表選擇了要傳送的項目後,會傳送表單,設置為true代表不會傳送表單只會將選項對應的數值內容交給 window.qbpwcf.form.callback 陣列中的 callback 處理.
|
|
|
7585 |
window.qbpwcf.form.hiddenVar,陣列,每個元素為物件,物件的屬性有name為變數的名稱;value為選單的數值.
|
|
|
7586 |
window.qbpwcf.form.defaultOption,物件,name為顯示的內容;value為選單的數值.
|
|
|
7587 |
window.qbpwcf.form.options,陣列,每個元素為物件,物件的屬性有name為顯示的內容;value為選單的數值.
|
|
|
7588 |
window.qbpwcf.form.recPage,字串,為接收要求的網址,預設為當前頁面.
|
|
|
7589 |
window.qbpwcf.form.sendVarName,傳送表單時的選項對應的變數名稱,預設為'variable'.
|
|
|
7590 |
window.qbpwcf.form.callback,針對所選擇的選項內容,要交由哪些函式處理,形態為陣列.
|
|
|
7591 |
window.qbpwcf.form.getTarget(),抓要變成fakeScrolling List的元素.
|
| 174 |
liveuser |
7592 |
window.qbpwcf.from.replaceCurrentPageToDomResponse,布林,預設為true,代表得到ajax回應為非json的dom時,會將其結果呈現到當前畫面;反之為false.
|
|
|
7593 |
window.qbpwcf.form.active(),啟用fake Scrolling list.
|
| 3 |
liveuser |
7594 |
*/
|
|
|
7595 |
//設置 this 物件,建構子.
|
|
|
7596 |
window.qbpwcf.form.fakeScrollingList=function(){
|
| 226 |
liveuser |
7597 |
|
| 3 |
liveuser |
7598 |
//要用 fake scrolling list 選單呈現的元素 id 為?
|
|
|
7599 |
this.eleId='';
|
| 226 |
liveuser |
7600 |
|
| 3 |
liveuser |
7601 |
//要用 fake scrolling list 選單呈現的元素為,若 eleId 為 '' 且該變數不等於 '' 就會採用.
|
| 174 |
liveuser |
7602 |
this.targetEle='';
|
| 226 |
liveuser |
7603 |
|
| 3 |
liveuser |
7604 |
//fake scrolling list 預設選單關閉的 叉叉按鈕
|
|
|
7605 |
this.closeIcon='data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjwhLS0gQ3JlYXRlZCB3aXRoIElua3NjYXBlIChodHRwOi8vd3d3Lmlua3NjYXBlLm9yZy8pIC0tPgoKPHN2ZwogICB4bWxuczpvc2I9Imh0dHA6Ly93d3cub3BlbnN3YXRjaGJvb2sub3JnL3VyaS8yMDA5L29zYiIKICAgeG1sbnM6ZGM9Imh0dHA6Ly9wdXJsLm9yZy9kYy9lbGVtZW50cy8xLjEvIgogICB4bWxuczpjYz0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvbnMjIgogICB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiCiAgIHhtbG5zOnN2Zz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCiAgIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIKICAgeG1sbnM6c29kaXBvZGk9Imh0dHA6Ly9zb2RpcG9kaS5zb3VyY2Vmb3JnZS5uZXQvRFREL3NvZGlwb2RpLTAuZHRkIgogICB4bWxuczppbmtzY2FwZT0iaHR0cDovL3d3dy5pbmtzY2FwZS5vcmcvbmFtZXNwYWNlcy9pbmtzY2FwZSIKICAgd2lkdGg9IjEwNS43ODE3Mm1tIgogICBoZWlnaHQ9IjEwNS4zNDM0NG1tIgogICB2aWV3Qm94PSIwIDAgMTA1Ljc4MTcyIDEwNS4zNDM0NCIKICAgdmVyc2lvbj0iMS4xIgogICBpZD0ic3ZnOCIKICAgaW5rc2NhcGU6dmVyc2lvbj0iMC45MitkZXZlbCB1bmtub3duIgogICBzb2RpcG9kaTpkb2NuYW1lPSJjbG9zZUljb24uc3ZnIj4KICA8ZGVmcwogICAgIGlkPSJkZWZzMiI+CiAgICA8bGluZWFyR3JhZGllbnQKICAgICAgIGlkPSJsaW5lYXJHcmFkaWVudDQzMTUiCiAgICAgICBvc2I6cGFpbnQ9InNvbGlkIj4KICAgICAgPHN0b3AKICAgICAgICAgc3R5bGU9InN0b3AtY29sb3I6IzAwMDAwMDtzdG9wLW9wYWNpdHk6MTsiCiAgICAgICAgIG9mZnNldD0iMCIKICAgICAgICAgaWQ9InN0b3A0MzEzIiAvPgogICAgPC9saW5lYXJHcmFkaWVudD4KICAgIDxmaWx0ZXIKICAgICAgIGlua3NjYXBlOmNvbGxlY3Q9ImFsd2F5cyIKICAgICAgIHN0eWxlPSJjb2xvci1pbnRlcnBvbGF0aW9uLWZpbHRlcnM6c1JHQiIKICAgICAgIGlkPSJmaWx0ZXI0MzkxIgogICAgICAgeD0iLTAuMDY4OTc3MTAzIgogICAgICAgd2lkdGg9IjEuMTM3OTU0MiIKICAgICAgIHk9Ii0wLjA3NTI5OTk5MyIKICAgICAgIGhlaWdodD0iMS4xNTA2Ij4KICAgICAgPGZlR2F1c3NpYW5CbHVyCiAgICAgICAgIGlua3NjYXBlOmNvbGxlY3Q9ImFsd2F5cyIKICAgICAgICAgc3RkRGV2aWF0aW9uPSIxLjAwNjI1NDMiCiAgICAgICAgIGlkPSJmZUdhdXNzaWFuQmx1cjQzOTMiIC8+CiAgICA8L2ZpbHRlcj4KICAgIDxmaWx0ZXIKICAgICAgIGlua3NjYXBlOmNvbGxlY3Q9ImFsd2F5cyIKICAgICAgIHN0eWxlPSJjb2xvci1pbnRlcnBvbGF0aW9uLWZpbHRlcnM6c1JHQiIKICAgICAgIGlkPSJmaWx0ZXI0NDM4IgogICAgICAgeD0iLTAuMDIyNjIyOTA0IgogICAgICAgd2lkdGg9IjEuMDQ1MjQ1OCIKICAgICAgIHk9Ii0wLjAyNTU1NTYxNCIKICAgICAgIGhlaWdodD0iMS4wNTExMTEyIj4KICAgICAgPGZlR2F1c3NpYW5CbHVyCiAgICAgICAgIGlua3NjYXBlOmNvbGxlY3Q9ImFsd2F5cyIKICAgICAgICAgc3RkRGV2aWF0aW9uPSIwLjIyMTcwNjAxIgogICAgICAgICBpZD0iZmVHYXVzc2lhbkJsdXI0NDQwIiAvPgogICAgPC9maWx0ZXI+CiAgICA8ZmlsdGVyCiAgICAgICBpbmtzY2FwZTpjb2xsZWN0PSJhbHdheXMiCiAgICAgICBzdHlsZT0iY29sb3ItaW50ZXJwb2xhdGlvbi1maWx0ZXJzOnNSR0IiCiAgICAgICBpZD0iZmlsdGVyNDQ0NiIKICAgICAgIHg9Ii0wLjAyMzIzMjg0NyIKICAgICAgIHdpZHRoPSIxLjA0NjQ2NTgiCiAgICAgICB5PSItMC4wMjQ4MTk1NDUiCiAgICAgICBoZWlnaHQ9IjEuMDQ5NjM5MSI+CiAgICAgIDxmZUdhdXNzaWFuQmx1cgogICAgICAgICBpbmtzY2FwZTpjb2xsZWN0PSJhbHdheXMiCiAgICAgICAgIHN0ZERldmlhdGlvbj0iMC4yMjIwOTQyOCIKICAgICAgICAgaWQ9ImZlR2F1c3NpYW5CbHVyNDQ0OCIgLz4KICAgIDwvZmlsdGVyPgogIDwvZGVmcz4KICA8c29kaXBvZGk6bmFtZWR2aWV3CiAgICAgaWQ9ImJhc2UiCiAgICAgcGFnZWNvbG9yPSIjZmZmZmZmIgogICAgIGJvcmRlcmNvbG9yPSIjNjY2NjY2IgogICAgIGJvcmRlcm9wYWNpdHk9IjEuMCIKICAgICBpbmtzY2FwZTpwYWdlb3BhY2l0eT0iMC4wIgogICAgIGlua3NjYXBlOnBhZ2VzaGFkb3c9IjIiCiAgICAgaW5rc2NhcGU6em9vbT0iMS40IgogICAgIGlua3NjYXBlOmN4PSIxMzAuNTY4NjgiCiAgICAgaW5rc2NhcGU6Y3k9IjIwMS4zNDg0NSIKICAgICBpbmtzY2FwZTpkb2N1bWVudC11bml0cz0ibW0iCiAgICAgaW5rc2NhcGU6Y3VycmVudC1sYXllcj0iZzQ0ODgiCiAgICAgaW5rc2NhcGU6ZG9jdW1lbnQtcm90YXRpb249IjAiCiAgICAgc2hvd2dyaWQ9ImZhbHNlIgogICAgIGlua3NjYXBlOndpbmRvdy13aWR0aD0iMTYwMCIKICAgICBpbmtzY2FwZTp3aW5kb3ctaGVpZ2h0PSI4MzYiCiAgICAgaW5rc2NhcGU6d2luZG93LXg9IjAiCiAgICAgaW5rc2NhcGU6d2luZG93LXk9IjI3IgogICAgIGlua3NjYXBlOndpbmRvdy1tYXhpbWl6ZWQ9IjEiIC8+CiAgPG1ldGFkYXRhCiAgICAgaWQ9Im1ldGFkYXRhNSI+CiAgICA8cmRmOlJERj4KICAgICAgPGNjOldvcmsKICAgICAgICAgcmRmOmFib3V0PSIiPgogICAgICAgIDxkYzpmb3JtYXQ+aW1hZ2Uvc3ZnK3htbDwvZGM6Zm9ybWF0PgogICAgICAgIDxkYzp0eXBlCiAgICAgICAgICAgcmRmOnJlc291cmNlPSJodHRwOi8vcHVybC5vcmcvZGMvZGNtaXR5cGUvU3RpbGxJbWFnZSIgLz4KICAgICAgICA8ZGM6dGl0bGUgLz4KICAgICAgPC9jYzpXb3JrPgogICAgPC9yZGY6UkRGPgogIDwvbWV0YWRhdGE+CiAgPGcKICAgICBpbmtzY2FwZTpsYWJlbD0iTGF5ZXIgMSIKICAgICBpbmtzY2FwZTpncm91cG1vZGU9ImxheWVyIgogICAgIGlkPSJsYXllcjEiCiAgICAgc3R5bGU9ImRpc3BsYXk6aW5saW5lIgogICAgIHRyYW5zZm9ybT0idHJhbnNsYXRlKC01MC4wNTQwMzQsLTg5LjA0MzUyMikiPgogICAgPGcKICAgICAgIGlkPSJnNDQ4OCIKICAgICAgIHRyYW5zZm9ybT0ibWF0cml4KDIuNjU1MDQ0MywwLDAsMi44NTQ2OTA3LC0xMTAuOTk1MTgsLTMyNi45MjY1MikiPgogICAgICA8ZWxsaXBzZQogICAgICAgICByeT0iMTYuMDM1OTI3IgogICAgICAgICByeD0iMTcuNTA1ODg0IgogICAgICAgICBjeT0iMTY0LjE2NTUxIgogICAgICAgICBjeD0iODAuNTc4NzIiCiAgICAgICAgIGlkPSJwYXRoMzQ3NCIKICAgICAgICAgc3R5bGU9Im9wYWNpdHk6MC4zO2ZpbGw6IzAwMDAwMDtmaWxsLW9wYWNpdHk6MTtmaWxsLXJ1bGU6bm9uemVybztzdHJva2U6IzAwMDAwMDtzdHJva2Utd2lkdGg6MC4yNjQ5OTk5OTtzdHJva2UtbWl0ZXJsaW1pdDo0O3N0cm9rZS1kYXNoYXJyYXk6bm9uZTtzdHJva2Utb3BhY2l0eToxO2ZpbHRlcjp1cmwoI2ZpbHRlcjQzOTEpO2ltYWdlLXJlbmRlcmluZzphdXRvIiAvPgogICAgICA8cmVjdAogICAgICAgICB0cmFuc2Zvcm09InJvdGF0ZSgtNDIuODA4OTU1KSIKICAgICAgICAgcnk9IjAiCiAgICAgICAgIHk9IjE3NC41NTY0OSIKICAgICAgICAgeD0iLTY3LjM5ODc1OCIKICAgICAgICAgaGVpZ2h0PSIyLjE1MjIwNjQiCiAgICAgICAgIHdpZHRoPSIyOS4yNzk2NDgiCiAgICAgICAgIGlkPSJyZWN0NDQxMyIKICAgICAgICAgc3R5bGU9Im9wYWNpdHk6MTtmaWxsOiNmZmZmMDA7ZmlsbC1vcGFjaXR5OjE7ZmlsbC1ydWxlOm5vbnplcm87c3Ryb2tlOiMwMDAwMDA7c3Ryb2tlLXdpZHRoOjA7c3Ryb2tlLW1pdGVybGltaXQ6NDtzdHJva2UtZGFzaGFycmF5Om5vbmU7c3Ryb2tlLW9wYWNpdHk6MTtmaWx0ZXI6dXJsKCNmaWx0ZXI0NDQ2KSIgLz4KICAgICAgPHJlY3QKICAgICAgICAgdHJhbnNmb3JtPSJyb3RhdGUoLTEzOS4wMzQ0MikiCiAgICAgICAgIHJ5PSIwIgogICAgICAgICB5PSItNzMuMDUwOTQ5IgogICAgICAgICB4PSItMTgyLjk2MjUyIgogICAgICAgICBoZWlnaHQ9IjIuMTUyMjA2NCIKICAgICAgICAgd2lkdGg9IjI5LjI3OTY0OCIKICAgICAgICAgaWQ9InJlY3Q0NDEzLTMiCiAgICAgICAgIHN0eWxlPSJvcGFjaXR5OjE7ZmlsbDojZmZmZjAwO2ZpbGwtb3BhY2l0eToxO2ZpbGwtcnVsZTpub256ZXJvO3N0cm9rZTojMDAwMDAwO3N0cm9rZS13aWR0aDowO3N0cm9rZS1taXRlcmxpbWl0OjQ7c3Ryb2tlLWRhc2hhcnJheTpub25lO3N0cm9rZS1vcGFjaXR5OjE7ZmlsdGVyOnVybCgjZmlsdGVyNDQzOCkiIC8+CiAgICA8L2c+CiAgPC9nPgo8L3N2Zz4K';
|
| 226 |
liveuser |
7606 |
|
| 3 |
liveuser |
7607 |
//fake scrolling list 預設選項選到哪個就不傳送表單
|
|
|
7608 |
this.noActionOption={name:'Please select one option',value:''};
|
| 226 |
liveuser |
7609 |
|
| 3 |
liveuser |
7610 |
//布林值,預設為false,不啟用;反之為true代表點選元素後就直接送出最後一個選項的數值.啟用條件為window.qbpwcf.form.options只有一個元素.
|
|
|
7611 |
this.sendOnClickWhenOnly2options=false;
|
| 226 |
liveuser |
7612 |
|
| 3 |
liveuser |
7613 |
//預設選擇了要傳送的項目後,會傳送表單,設置為true代表不會傳送表單只會將選項對應的數值內容交給 this.callback 陣列中的 callback 處理.
|
|
|
7614 |
this.donotSendFrom=false;
|
| 226 |
liveuser |
7615 |
|
| 3 |
liveuser |
7616 |
//fake scrolling list 選單傳送出去時要加上的隱藏變陣列
|
|
|
7617 |
this.hiddenVar=[];
|
| 226 |
liveuser |
7618 |
|
| 3 |
liveuser |
7619 |
//fake scrolling list 選單傳送出去時要加上的隱藏變數名稱與內容,預設為hiddenVarName數值為hiddenVarValue
|
|
|
7620 |
this.hiddenVar.push({name:'hiddenVarName',value:'hidenVarValue'});
|
| 226 |
liveuser |
7621 |
|
| 3 |
liveuser |
7622 |
//fake scrolling list 選項的預設項目
|
|
|
7623 |
this.defaultOption=this.noActionOption;
|
| 226 |
liveuser |
7624 |
|
| 3 |
liveuser |
7625 |
//fake scrolling list 的選項資訊
|
|
|
7626 |
this.options=[];
|
| 226 |
liveuser |
7627 |
|
| 3 |
liveuser |
7628 |
//預設只有一個選擇了不會送出的選項
|
|
|
7629 |
this.options.push(this.noActionOption);
|
| 226 |
liveuser |
7630 |
|
| 3 |
liveuser |
7631 |
//接受要求的頁面,預設為當前頁面
|
|
|
7632 |
this.recPage=location.href;
|
| 226 |
liveuser |
7633 |
|
| 3 |
liveuser |
7634 |
//傳送表單時的選項對應的變數名稱,預設為'variable'.
|
|
|
7635 |
this.sendVarName='variable';
|
| 226 |
liveuser |
7636 |
|
| 3 |
liveuser |
7637 |
//選項送出後,取得的回應要作為參數呼叫哪些 callback
|
|
|
7638 |
this.callback=[];
|
| 226 |
liveuser |
7639 |
|
| 3 |
liveuser |
7640 |
//預設的 callback 為 console.log
|
|
|
7641 |
this.callback.push(console.log);
|
| 226 |
liveuser |
7642 |
|
| 174 |
liveuser |
7643 |
//預設不自動觸發
|
|
|
7644 |
this.autoStart=false;
|
| 226 |
liveuser |
7645 |
|
| 174 |
liveuser |
7646 |
//預設為true,代表得到ajax回應為非json的dom時,會將其結果呈現到當前畫面;
|
|
|
7647 |
this.replaceCurrentPageToDomResponse=true;
|
| 226 |
liveuser |
7648 |
|
| 174 |
liveuser |
7649 |
//預設為false,代表允許關閉選單.
|
|
|
7650 |
this.disallowClose=false;
|
| 226 |
liveuser |
7651 |
|
| 200 |
liveuser |
7652 |
//預設關閉選單後不要進行轉地址.
|
|
|
7653 |
this.redirectAfterClose=false;
|
| 226 |
liveuser |
7654 |
|
| 3 |
liveuser |
7655 |
//取得目標元素的涵式
|
|
|
7656 |
this.getTarget=function(){
|
| 226 |
liveuser |
7657 |
|
| 174 |
liveuser |
7658 |
//如果有設置目標id
|
|
|
7659 |
if(this.eleId!==''){
|
| 226 |
liveuser |
7660 |
|
| 174 |
liveuser |
7661 |
//設置 targetEle
|
|
|
7662 |
this.targetEle=document.getElementById('this.eleId');
|
| 226 |
liveuser |
7663 |
|
| 174 |
liveuser |
7664 |
}//if end
|
| 226 |
liveuser |
7665 |
|
| 174 |
liveuser |
7666 |
//如果元素變數為空字串的話
|
|
|
7667 |
if(this.targetEle===''){
|
| 226 |
liveuser |
7668 |
|
| 174 |
liveuser |
7669 |
//設置要自動觸發
|
|
|
7670 |
this.autoStart=true;
|
| 226 |
liveuser |
7671 |
|
| 174 |
liveuser |
7672 |
}//if end
|
| 3 |
liveuser |
7673 |
|
| 174 |
liveuser |
7674 |
//反之元素如果是body
|
|
|
7675 |
else if(this.targetEle.tagName==='BODY'){
|
| 226 |
liveuser |
7676 |
|
| 174 |
liveuser |
7677 |
//提示錯誤
|
|
|
7678 |
console.error('Please define targetEle other than BODY');
|
| 226 |
liveuser |
7679 |
|
| 174 |
liveuser |
7680 |
//結束執行
|
|
|
7681 |
return false;
|
| 226 |
liveuser |
7682 |
|
| 174 |
liveuser |
7683 |
}//if end
|
| 226 |
liveuser |
7684 |
|
| 174 |
liveuser |
7685 |
//如果要自動觸發
|
|
|
7686 |
if(this.autoStart===true){
|
| 226 |
liveuser |
7687 |
|
| 174 |
liveuser |
7688 |
//建立div元素
|
|
|
7689 |
this.targetEle=document.createElement('div');
|
| 226 |
liveuser |
7690 |
|
| 174 |
liveuser |
7691 |
}//if end
|
| 226 |
liveuser |
7692 |
|
| 174 |
liveuser |
7693 |
//存元素參考
|
|
|
7694 |
var fakeScrollingList=this.targetEle;
|
| 226 |
liveuser |
7695 |
|
| 3 |
liveuser |
7696 |
//回傳點擊要觸發fakeScrollingList效果的元素
|
|
|
7697 |
return fakeScrollingList;
|
| 226 |
liveuser |
7698 |
|
| 3 |
liveuser |
7699 |
}//function end
|
| 226 |
liveuser |
7700 |
|
|
|
7701 |
//啟用 fake scrolling list
|
| 174 |
liveuser |
7702 |
this.active=function(){
|
| 226 |
liveuser |
7703 |
|
| 3 |
liveuser |
7704 |
//取得要綁定事件的元素
|
|
|
7705 |
var fakeScrollingList=this.getTarget();
|
| 226 |
liveuser |
7706 |
|
| 174 |
liveuser |
7707 |
//如果異常
|
|
|
7708 |
if(fakeScrollingList===false){
|
| 226 |
liveuser |
7709 |
|
| 174 |
liveuser |
7710 |
//結束執行
|
|
|
7711 |
return;
|
| 226 |
liveuser |
7712 |
|
| 174 |
liveuser |
7713 |
}//if end
|
| 226 |
liveuser |
7714 |
|
| 3 |
liveuser |
7715 |
//可以下拉的項目用手指頭圖示
|
|
|
7716 |
fakeScrollingList.style.cursor='pointer';
|
| 226 |
liveuser |
7717 |
|
| 3 |
liveuser |
7718 |
//設置 this 給 fakeScrollingList 的 addEventListener 事件
|
|
|
7719 |
fakeScrollingList.mother=this;
|
| 226 |
liveuser |
7720 |
|
| 3 |
liveuser |
7721 |
//點擊選單之後
|
|
|
7722 |
fakeScrollingList.addEventListener('click',function(event){
|
| 226 |
liveuser |
7723 |
|
| 3 |
liveuser |
7724 |
//取消預設點擊的效果
|
|
|
7725 |
event.preventDefault();
|
| 226 |
liveuser |
7726 |
|
| 3 |
liveuser |
7727 |
//取得下拉式選單內容
|
|
|
7728 |
var inputSelect=event.target;
|
|
|
7729 |
|
|
|
7730 |
//讓下拉式選單趕緊隱藏
|
|
|
7731 |
inputSelect.style.opacity='0';
|
|
|
7732 |
|
|
|
7733 |
//解析選項的資訊
|
|
|
7734 |
var optionsInfo=fakeScrollingList.mother.options;
|
|
|
7735 |
|
|
|
7736 |
//取得選項的數目
|
|
|
7737 |
var opLen=optionsInfo.length;
|
|
|
7738 |
|
|
|
7739 |
//新增覆蓋全螢幕的div
|
|
|
7740 |
var root=document.createElement('div');
|
|
|
7741 |
|
|
|
7742 |
//設置最外層div的id
|
|
|
7743 |
root.id='scrollingListRootDiv';
|
|
|
7744 |
|
|
|
7745 |
//移除重複的選單
|
|
|
7746 |
if(document.getElementById('scrollingListRootDiv')!==null){
|
| 226 |
liveuser |
7747 |
|
| 3 |
liveuser |
7748 |
//移除之
|
|
|
7749 |
document.getElementById('scrollingListRootDiv').remove();
|
| 226 |
liveuser |
7750 |
|
| 3 |
liveuser |
7751 |
}//if end
|
|
|
7752 |
|
|
|
7753 |
//設置最外層div的樣式
|
|
|
7754 |
root.classList.add('__qbpwcf_scrollingListRootDiv');
|
|
|
7755 |
|
|
|
7756 |
//新增為了將不足divForMiddle可見高度的選項們置中的div
|
|
|
7757 |
var divForMiddle=document.createElement('div');
|
|
|
7758 |
|
|
|
7759 |
//設置為了上下置中的div樣式
|
|
|
7760 |
divForMiddle.classList.add('__qbpwcf_scrollingListOutterDiv');
|
|
|
7761 |
|
|
|
7762 |
//初始化記錄選擇的選項index
|
|
|
7763 |
var selectedOptionIndex=0;
|
|
|
7764 |
|
|
|
7765 |
//針對每個選項
|
|
|
7766 |
for(var i=0;i<opLen;i++){
|
| 226 |
liveuser |
7767 |
|
| 3 |
liveuser |
7768 |
//取得選項實際數值
|
|
|
7769 |
var opVal=optionsInfo[i].value;
|
|
|
7770 |
|
|
|
7771 |
//取得選項顯示名稱
|
|
|
7772 |
var opShow=optionsInfo[i].name;
|
|
|
7773 |
|
|
|
7774 |
//建立選項的div
|
|
|
7775 |
var opDiv=document.createElement('div');
|
|
|
7776 |
|
|
|
7777 |
//讓選項上下置中
|
|
|
7778 |
opDiv.style.paddingTop='15px';
|
|
|
7779 |
|
| 174 |
liveuser |
7780 |
//如果是不可以點選的選項
|
|
|
7781 |
if(fakeScrollingList.mother.noActionOption.name==opShow && fakeScrollingList.mother.noActionOption.value==opVal){
|
| 226 |
liveuser |
7782 |
|
| 174 |
liveuser |
7783 |
//設置選項div的class
|
|
|
7784 |
opDiv.setAttribute('class','__qbpwcf_inputSelect');
|
| 226 |
liveuser |
7785 |
|
| 174 |
liveuser |
7786 |
}//if end
|
|
|
7787 |
|
|
|
7788 |
//反之為可以點選的選項
|
|
|
7789 |
else{
|
| 226 |
liveuser |
7790 |
|
| 174 |
liveuser |
7791 |
//設置選項div的class
|
|
|
7792 |
opDiv.setAttribute('class','__qbpwcf_inputSelect __qbpwcf_inputSelect_hover');
|
| 226 |
liveuser |
7793 |
|
| 174 |
liveuser |
7794 |
}//else end
|
| 226 |
liveuser |
7795 |
|
| 3 |
liveuser |
7796 |
//設置裡面的文字要換行的時候改用...表示
|
|
|
7797 |
opDiv.style.whiteSpace='nowrap';
|
| 174 |
liveuser |
7798 |
opDiv.style.width='100%';
|
| 3 |
liveuser |
7799 |
opDiv.style.overflow='hidden';
|
|
|
7800 |
opDiv.style.textOverflow='ellipsis';
|
| 226 |
liveuser |
7801 |
|
| 3 |
liveuser |
7802 |
//偶數欄位
|
| 174 |
liveuser |
7803 |
if(i%2===0){
|
| 226 |
liveuser |
7804 |
|
| 3 |
liveuser |
7805 |
//設置選項div底色為藍色
|
|
|
7806 |
opDiv.style.backgroundColor='CCCCFF';
|
| 226 |
liveuser |
7807 |
|
| 174 |
liveuser |
7808 |
}//if end
|
| 226 |
liveuser |
7809 |
|
| 3 |
liveuser |
7810 |
//反之為奇數欄位
|
| 174 |
liveuser |
7811 |
else{
|
| 226 |
liveuser |
7812 |
|
| 3 |
liveuser |
7813 |
//設置選項div底色為紅色
|
|
|
7814 |
opDiv.style.backgroundColor='FFCCCC';
|
| 226 |
liveuser |
7815 |
|
| 174 |
liveuser |
7816 |
}//else end
|
| 3 |
liveuser |
7817 |
|
|
|
7818 |
//解析選項的資訊
|
|
|
7819 |
var oriOptionsInfo=this.options;
|
|
|
7820 |
|
|
|
7821 |
//建立選項名稱文字節點
|
|
|
7822 |
var textnode = document.createTextNode(opShow);
|
|
|
7823 |
|
|
|
7824 |
//將文字放進選項的div
|
|
|
7825 |
opDiv.appendChild(textnode);
|
|
|
7826 |
|
|
|
7827 |
//設置選項對應的實際數值
|
|
|
7828 |
opDiv.dataset.val=opVal;
|
| 226 |
liveuser |
7829 |
|
| 3 |
liveuser |
7830 |
//設置選項對應的索引
|
|
|
7831 |
opDiv.dataset.index=i;
|
| 226 |
liveuser |
7832 |
|
| 3 |
liveuser |
7833 |
//將選項放進為了上下左右置中的div
|
|
|
7834 |
divForMiddle.appendChild(opDiv);
|
|
|
7835 |
|
|
|
7836 |
}//for end
|
|
|
7837 |
|
|
|
7838 |
//新增為了上下左右置中的div
|
|
|
7839 |
var divForCenterMiddle=document.createElement('div');
|
|
|
7840 |
|
|
|
7841 |
//設置為了內部元素都上下左右置中的div樣式
|
|
|
7842 |
divForCenterMiddle.classList.add('__qbpwcf_scrollingListInnerDiv');
|
|
|
7843 |
|
|
|
7844 |
//將上下置中的選項們放進可以上下左右置中的div
|
|
|
7845 |
divForCenterMiddle.appendChild(divForMiddle);
|
|
|
7846 |
|
|
|
7847 |
//將選項放進最外層的div
|
|
|
7848 |
root.appendChild(divForCenterMiddle);
|
|
|
7849 |
|
|
|
7850 |
//將整個div放到body裡面
|
|
|
7851 |
document.body.appendChild(root);
|
|
|
7852 |
|
|
|
7853 |
//調整滾軸表單的置中效果
|
|
|
7854 |
scrollingListMiddleFunction();
|
|
|
7855 |
|
|
|
7856 |
//取得所有選項
|
|
|
7857 |
var allOptions=document.getElementsByClassName('__qbpwcf_inputSelect_hover');
|
|
|
7858 |
|
|
|
7859 |
//移動滾軸讓原本選擇的選項盡量置中
|
|
|
7860 |
|
|
|
7861 |
//取得選單的滾軸上端位置最大值
|
|
|
7862 |
var scrollingListScrollTopMax=document.getElementById('scrollingListRootDiv').children[0].scrollTopMax;
|
|
|
7863 |
|
|
|
7864 |
//如果有滾軸
|
|
|
7865 |
if(scrollingListScrollTopMax!==0){
|
|
|
7866 |
|
|
|
7867 |
//如果是第一個選項
|
|
|
7868 |
if(selectedOptionIndex===0){
|
|
|
7869 |
|
|
|
7870 |
//滾軸拉到最上面
|
|
|
7871 |
document.getElementById('scrollingListRootDiv').children[0].scrollTop=0;
|
|
|
7872 |
|
|
|
7873 |
}//if end
|
|
|
7874 |
|
|
|
7875 |
//如果之前選擇的選項索引剛好等於 opLen/2
|
|
|
7876 |
else if(((selectedOptionIndex+1)===(opLen/2))){
|
|
|
7877 |
|
|
|
7878 |
//取得新的滾軸高度
|
|
|
7879 |
var newScrollTop=scrollingListScrollTopMax/2;
|
|
|
7880 |
|
|
|
7881 |
//設置滾軸的上端位置
|
|
|
7882 |
document.getElementById('scrollingListRootDiv').children[0].scrollTop=newScrollTop;
|
|
|
7883 |
|
|
|
7884 |
}//if end
|
|
|
7885 |
|
|
|
7886 |
//如果之前選擇的選項索引小於半
|
|
|
7887 |
else if((selectedOptionIndex+1)<(opLen/2)){
|
|
|
7888 |
|
|
|
7889 |
//取得新的滾軸高度
|
|
|
7890 |
var newScrollTop=scrollingListScrollTopMax/opLen*selectedOptionIndex+1;
|
|
|
7891 |
|
|
|
7892 |
//設置滾軸的上端位置
|
|
|
7893 |
document.getElementById('scrollingListRootDiv').children[0].scrollTop=newScrollTop;
|
|
|
7894 |
|
|
|
7895 |
}//if end
|
|
|
7896 |
|
|
|
7897 |
//如果之前選擇的選項索引過半
|
|
|
7898 |
else if((selectedOptionIndex+1)>(opLen/2)){
|
|
|
7899 |
|
|
|
7900 |
//取得新的滾軸高度
|
|
|
7901 |
var newScrollTop=scrollingListScrollTopMax-scrollingListScrollTopMax/opLen*(opLen-selectedOptionIndex-1);
|
|
|
7902 |
|
|
|
7903 |
//設置滾軸的上端位置
|
|
|
7904 |
document.getElementById('scrollingListRootDiv').children[0].scrollTop=newScrollTop;
|
|
|
7905 |
|
|
|
7906 |
}//if end
|
|
|
7907 |
|
|
|
7908 |
//如果是最後一個選項
|
|
|
7909 |
else if(selectedOptionIndex===opLen){
|
|
|
7910 |
|
|
|
7911 |
//如果是最後一個選項
|
|
|
7912 |
document.getElementById('scrollingListRootDiv').children[0].scrollTop=scrollingListScrollTopMax;
|
|
|
7913 |
|
|
|
7914 |
}//if end
|
|
|
7915 |
|
|
|
7916 |
//不應該跑到的地方
|
|
|
7917 |
else{
|
|
|
7918 |
|
|
|
7919 |
//debug
|
| 174 |
liveuser |
7920 |
console.error('error occur!');
|
| 3 |
liveuser |
7921 |
|
|
|
7922 |
}//else end
|
|
|
7923 |
|
|
|
7924 |
}//if end
|
|
|
7925 |
|
|
|
7926 |
//針對每個選項
|
|
|
7927 |
for(var i=0;i<allOptions.length;i++){
|
|
|
7928 |
|
|
|
7929 |
//取得this設定
|
|
|
7930 |
allOptions[i].mother=fakeScrollingList.mother;
|
|
|
7931 |
|
|
|
7932 |
//綁定所有選項的 'click' 事件
|
|
|
7933 |
allOptions[i].addEventListener('click',async function(event){
|
|
|
7934 |
|
|
|
7935 |
//取得點擊到的選項
|
|
|
7936 |
var clickedOption=event.target;
|
|
|
7937 |
|
|
|
7938 |
//取得點擊到的選項數值
|
|
|
7939 |
var clickedValue=clickedOption.dataset.val;
|
|
|
7940 |
|
|
|
7941 |
//取得點擊到的選項索引
|
|
|
7942 |
var clickedNo=clickedOption.dataset.index;
|
|
|
7943 |
|
|
|
7944 |
//取得點擊到的選項名稱
|
|
|
7945 |
var clickedName=clickedOption.innerHTML;
|
|
|
7946 |
|
|
|
7947 |
//如果不需要傳送表單
|
|
|
7948 |
if(this.mother.donotSendFrom){
|
| 226 |
liveuser |
7949 |
|
| 3 |
liveuser |
7950 |
//取得要移除 scrolling list 的 div
|
|
|
7951 |
var divToDel=document.getElementById('scrollingListRootDiv');
|
|
|
7952 |
|
|
|
7953 |
//移除 scrolling list div
|
|
|
7954 |
divToDel.remove();
|
| 226 |
liveuser |
7955 |
|
| 3 |
liveuser |
7956 |
//針對每個要呼叫的 callback func
|
|
|
7957 |
for(var j=0;j<this.mother.callback.length;j++){
|
| 226 |
liveuser |
7958 |
|
| 3 |
liveuser |
7959 |
//callback
|
|
|
7960 |
this.mother.callback[j].call(this,clickedValue);
|
| 226 |
liveuser |
7961 |
|
| 3 |
liveuser |
7962 |
}//for end
|
|
|
7963 |
|
|
|
7964 |
//復原下拉式選單
|
|
|
7965 |
inputSelect.style.opacity='unset';
|
| 226 |
liveuser |
7966 |
|
| 3 |
liveuser |
7967 |
//結束執行
|
|
|
7968 |
return true;
|
| 226 |
liveuser |
7969 |
|
| 3 |
liveuser |
7970 |
}//if end
|
|
|
7971 |
|
|
|
7972 |
//如果不是不需要傳送數值的選項
|
|
|
7973 |
if(fakeScrollingList.mother.noActionOption.name!==clickedName && fakeScrollingList.mother.noActionOption.value!==clickedValue){
|
| 226 |
liveuser |
7974 |
|
| 3 |
liveuser |
7975 |
//建立表單物件
|
|
|
7976 |
var queryStr='';
|
|
|
7977 |
|
|
|
7978 |
//新增表單的名稱與對應的數值
|
|
|
7979 |
queryStr=queryStr+fakeScrollingList.mother.sendVarName+'='+encodeURIComponent(clickedValue);
|
|
|
7980 |
|
|
|
7981 |
//針對每個隱藏的表單變數
|
|
|
7982 |
for(var j=0;j<fakeScrollingList.mother.hiddenVar.length;j++){
|
| 226 |
liveuser |
7983 |
|
| 3 |
liveuser |
7984 |
//附加到要傳算的表單變數裡面
|
|
|
7985 |
queryStr=queryStr+'&'+fakeScrollingList.mother.hiddenVar[j].name+'='+encodeURIComponent(fakeScrollingList.mother.hiddenVar[j].value);
|
| 226 |
liveuser |
7986 |
|
| 3 |
liveuser |
7987 |
}//for end
|
| 226 |
liveuser |
7988 |
|
| 3 |
liveuser |
7989 |
//復原下拉式選單
|
|
|
7990 |
inputSelect.style.opacity='unset';
|
| 226 |
liveuser |
7991 |
|
| 3 |
liveuser |
7992 |
/*
|
|
|
7993 |
設置 window.qbpwcf.ajaxP 函數
|
|
|
7994 |
說明:
|
|
|
7995 |
傳送ajax,指定傳送前要做什麼事情,然後回傳一個Promise.
|
|
|
7996 |
參數:
|
|
|
7997 |
params={};
|
|
|
7998 |
params.method='POST' or 'GET' or 'HEAD' or 'OPTIONS';
|
|
|
7999 |
params.headers={name:value};
|
|
|
8000 |
params.url='url to request';
|
|
|
8001 |
params.preAc='function name to call before send request';
|
|
|
8002 |
params.data='data to contain','key1=encodeURIComponent(val1)&key2=encodeURIComponent(val2)';if no data please use {};
|
|
|
8003 |
參考資料:
|
|
|
8004 |
https://eyesofkids.gitbooks.io/javascript-start-es6-promise/content/contents/ch11_snippets.html
|
|
|
8005 |
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
|
|
|
8006 |
*/
|
|
|
8007 |
var params={};
|
|
|
8008 |
params.method='POST';
|
|
|
8009 |
params.url=fakeScrollingList.mother.recPage;
|
|
|
8010 |
params.data=queryStr;
|
| 226 |
liveuser |
8011 |
|
| 3 |
liveuser |
8012 |
//取得回應
|
|
|
8013 |
var res = await window.qbpwcf.ajaxP.call(this,params);
|
| 226 |
liveuser |
8014 |
|
| 3 |
liveuser |
8015 |
//取得要移除 scrolling list 的 div
|
|
|
8016 |
var divToDel=document.getElementById('scrollingListRootDiv');
|
|
|
8017 |
|
|
|
8018 |
//移除 scrolling list div
|
|
|
8019 |
divToDel.remove();
|
| 226 |
liveuser |
8020 |
|
| 3 |
liveuser |
8021 |
//針對每個要呼叫的 callback func
|
|
|
8022 |
for(var j=0;j<fakeScrollingList.mother.callback.length;j++){
|
| 226 |
liveuser |
8023 |
|
| 3 |
liveuser |
8024 |
//callback
|
|
|
8025 |
fakeScrollingList.mother.callback[j].call(this,res);
|
| 226 |
liveuser |
8026 |
|
| 3 |
liveuser |
8027 |
}//for end
|
| 226 |
liveuser |
8028 |
|
| 174 |
liveuser |
8029 |
//如果回應是合法的json
|
|
|
8030 |
if(res.compliantJson==true){
|
| 226 |
liveuser |
8031 |
|
| 174 |
liveuser |
8032 |
//如果json的回應有error屬性
|
|
|
8033 |
if(res.json.hasOwnProperty('error')){
|
| 226 |
liveuser |
8034 |
|
| 174 |
liveuser |
8035 |
//警示訊息
|
|
|
8036 |
alert(res.json.error);
|
| 226 |
liveuser |
8037 |
|
| 174 |
liveuser |
8038 |
}//if end
|
| 226 |
liveuser |
8039 |
|
| 174 |
liveuser |
8040 |
//如果json的回應有content屬性
|
|
|
8041 |
else if(res.json.hasOwnProperty('content')){
|
| 226 |
liveuser |
8042 |
|
| 174 |
liveuser |
8043 |
//警示訊息
|
|
|
8044 |
alert(res.json.content);
|
| 226 |
liveuser |
8045 |
|
| 174 |
liveuser |
8046 |
}//else end
|
| 226 |
liveuser |
8047 |
|
| 174 |
liveuser |
8048 |
//如果json的回應有 location屬性
|
|
|
8049 |
if(res.json.hasOwnProperty('location')){
|
| 226 |
liveuser |
8050 |
|
| 174 |
liveuser |
8051 |
//導頁
|
|
|
8052 |
location.href=res.json.location;
|
| 226 |
liveuser |
8053 |
|
| 174 |
liveuser |
8054 |
}//if end
|
| 226 |
liveuser |
8055 |
|
| 174 |
liveuser |
8056 |
}//if end
|
| 226 |
liveuser |
8057 |
|
| 174 |
liveuser |
8058 |
//反之為非json,且要將dom取代當前頁面的內容
|
|
|
8059 |
else if(replaceCurrentPageToDomResponse==true){
|
| 226 |
liveuser |
8060 |
|
| 174 |
liveuser |
8061 |
//清空畫面
|
|
|
8062 |
document.replaceChildren();
|
| 226 |
liveuser |
8063 |
|
| 174 |
liveuser |
8064 |
//建立html
|
|
|
8065 |
var html=document.createElement('html');
|
| 226 |
liveuser |
8066 |
|
| 174 |
liveuser |
8067 |
//建立head
|
|
|
8068 |
var head=document.createElement('head');
|
| 226 |
liveuser |
8069 |
|
| 174 |
liveuser |
8070 |
//建立body
|
|
|
8071 |
var body=document.createElement('body');
|
| 226 |
liveuser |
8072 |
|
| 174 |
liveuser |
8073 |
//將回應的dom放到body
|
|
|
8074 |
body.append(res.dom);
|
| 226 |
liveuser |
8075 |
|
| 174 |
liveuser |
8076 |
//將head放到html裡面
|
|
|
8077 |
html.append(head);
|
| 226 |
liveuser |
8078 |
|
| 174 |
liveuser |
8079 |
//將body放到html裡面
|
|
|
8080 |
html.append(body);
|
| 226 |
liveuser |
8081 |
|
| 174 |
liveuser |
8082 |
//置換畫面為新的內榮
|
|
|
8083 |
document.replaceChildren(html);
|
| 226 |
liveuser |
8084 |
|
| 174 |
liveuser |
8085 |
}//if end
|
| 226 |
liveuser |
8086 |
|
| 3 |
liveuser |
8087 |
}//if end
|
|
|
8088 |
|
|
|
8089 |
});//function end
|
|
|
8090 |
|
|
|
8091 |
}//for end
|
|
|
8092 |
|
| 174 |
liveuser |
8093 |
//如果允許關閉選單
|
|
|
8094 |
if(fakeScrollingList.mother.disallowClose==false){
|
| 226 |
liveuser |
8095 |
|
| 174 |
liveuser |
8096 |
//建立 close icon
|
|
|
8097 |
var closeIcon = document.createElement('img');
|
| 3 |
liveuser |
8098 |
|
| 174 |
liveuser |
8099 |
//設置 close icon 的樣式
|
|
|
8100 |
closeIcon.style['position']='fixed';
|
|
|
8101 |
closeIcon.style['top']='15%';
|
|
|
8102 |
closeIcon.style['left']='85%';
|
|
|
8103 |
closeIcon.style['width']='5%';
|
|
|
8104 |
closeIcon.style['min-width']='30px';
|
|
|
8105 |
closeIcon.style['max-width']='50px';
|
|
|
8106 |
closeIcon.style['cursor']='pointer';
|
| 3 |
liveuser |
8107 |
|
| 174 |
liveuser |
8108 |
//設置 close icon img 的 src 屬性
|
|
|
8109 |
closeIcon.src=fakeScrollingList.mother.closeIcon;
|
| 3 |
liveuser |
8110 |
|
| 174 |
liveuser |
8111 |
//設置 close icon img 的id
|
|
|
8112 |
closeIcon.id='qbpwcfScrollingListCloseIcon';
|
| 3 |
liveuser |
8113 |
|
| 174 |
liveuser |
8114 |
//取得 scrollingList 的 root div
|
|
|
8115 |
var slrd=document.getElementById('scrollingListRootDiv');
|
| 3 |
liveuser |
8116 |
|
| 174 |
liveuser |
8117 |
//將 close icon 放到 scrollingList 的 root div 裡面
|
|
|
8118 |
document.getElementById('scrollingListRootDiv').appendChild(closeIcon);
|
| 3 |
liveuser |
8119 |
|
| 174 |
liveuser |
8120 |
//取得 close icon img
|
|
|
8121 |
var closeIcon=document.getElementById('qbpwcfScrollingListCloseIcon');
|
| 3 |
liveuser |
8122 |
|
| 174 |
liveuser |
8123 |
//新增 close icon img 的點擊事件
|
|
|
8124 |
closeIcon.addEventListener('click',function(){
|
| 3 |
liveuser |
8125 |
|
| 174 |
liveuser |
8126 |
//取得要移除 scrolling list 的 div
|
|
|
8127 |
var divToDel=document.getElementById('scrollingListRootDiv');
|
| 3 |
liveuser |
8128 |
|
| 174 |
liveuser |
8129 |
//移除 scrolling list div
|
|
|
8130 |
divToDel.remove();
|
| 3 |
liveuser |
8131 |
|
| 174 |
liveuser |
8132 |
//復原下拉式選單
|
|
|
8133 |
inputSelect.style.opacity='unset';
|
| 226 |
liveuser |
8134 |
|
| 200 |
liveuser |
8135 |
//如果有設置要到導頁到的位置
|
|
|
8136 |
if(fakeScrollingList.mother.redirectAfterClose!=false){
|
| 226 |
liveuser |
8137 |
|
| 200 |
liveuser |
8138 |
//進行導頁
|
|
|
8139 |
window.location.href=fakeScrollingList.mother.redirectAfterClose;
|
| 226 |
liveuser |
8140 |
|
| 200 |
liveuser |
8141 |
}//if end
|
| 3 |
liveuser |
8142 |
|
| 174 |
liveuser |
8143 |
});//addEventLister
|
| 3 |
liveuser |
8144 |
|
| 174 |
liveuser |
8145 |
//如果有啟用且只有一個選項則自動點擊最後一個選項
|
|
|
8146 |
if(fakeScrollingList.mother.sendOnClickWhenOnly2options && opLen===2){
|
| 226 |
liveuser |
8147 |
|
| 174 |
liveuser |
8148 |
//debug
|
|
|
8149 |
console.log('try auto click last option');
|
| 226 |
liveuser |
8150 |
|
| 174 |
liveuser |
8151 |
//取得選項們的外框
|
|
|
8152 |
var optionOutBoderDiv=document.querySelector('div#scrollingListRootDiv').children[0].children[0];
|
| 226 |
liveuser |
8153 |
|
| 174 |
liveuser |
8154 |
//點擊最後一個選項
|
|
|
8155 |
optionOutBoderDiv.children[1].click();
|
| 226 |
liveuser |
8156 |
|
| 174 |
liveuser |
8157 |
}//if end
|
| 226 |
liveuser |
8158 |
|
| 3 |
liveuser |
8159 |
}//if end
|
|
|
8160 |
|
|
|
8161 |
});//function end
|
| 226 |
liveuser |
8162 |
|
| 174 |
liveuser |
8163 |
//如果要自動觸發
|
|
|
8164 |
if(this.autoStart===true){
|
| 226 |
liveuser |
8165 |
|
| 174 |
liveuser |
8166 |
//觸發之
|
|
|
8167 |
this.targetEle.click();
|
| 226 |
liveuser |
8168 |
|
| 174 |
liveuser |
8169 |
}//if end
|
| 226 |
liveuser |
8170 |
|
| 174 |
liveuser |
8171 |
}//function active end
|
| 226 |
liveuser |
8172 |
|
| 3 |
liveuser |
8173 |
}//function end
|
| 226 |
liveuser |
8174 |
|
| 3 |
liveuser |
8175 |
";
|
|
|
8176 |
#js function
|
|
|
8177 |
$conf["javaScript::toScript"]["jsFunciton"][]=
|
|
|
8178 |
"
|
|
|
8179 |
//如果未設定 window.qbpwcf 物件
|
|
|
8180 |
if(window.qbpwcf===undefined){
|
|
|
8181 |
|
|
|
8182 |
//設置 window.qbpwcf 為空物件
|
|
|
8183 |
window.qbpwcf={};
|
|
|
8184 |
|
|
|
8185 |
}//if end
|
|
|
8186 |
|
|
|
8187 |
//如果未設定 window.qbpwcf.ajax 物件
|
|
|
8188 |
if(window.qbpwcf.ajax===undefined){
|
|
|
8189 |
|
|
|
8190 |
//設置 window.qbpwcf.ajax 為空物件
|
|
|
8191 |
window.qbpwcf.ajax={};
|
|
|
8192 |
|
|
|
8193 |
}//if end
|
| 226 |
liveuser |
8194 |
|
| 3 |
liveuser |
8195 |
/*
|
|
|
8196 |
設置 window.qbpwcf.ajax 函數
|
|
|
8197 |
說明:
|
|
|
8198 |
傳送ajax,指定傳送前要做什麼事情,傳送後要做什麼事情.
|
|
|
8199 |
參數:
|
|
|
8200 |
params={};
|
|
|
8201 |
params.method='POST' or 'GET' or 'HEAD' or 'OPTIONS';
|
|
|
8202 |
params.headers={name:value};
|
|
|
8203 |
params.url='url to request';
|
|
|
8204 |
params.resType='json';
|
|
|
8205 |
params.preAc='function name to call before send request';
|
|
|
8206 |
params.aftAc='function name to call after send request,default params is data to send';
|
|
|
8207 |
params.data='data to contain','key1=encodeURIComponent(val1)&key2=encodeURIComponent(val2)';if no data please use {};
|
|
|
8208 |
*/
|
|
|
8209 |
window.qbpwcf.ajax=function(params){
|
| 226 |
liveuser |
8210 |
|
| 3 |
liveuser |
8211 |
//檢查參數 params.method
|
|
|
8212 |
if(params.method===undefined){
|
| 226 |
liveuser |
8213 |
|
| 3 |
liveuser |
8214 |
//初始化為 'POST'
|
|
|
8215 |
params.method='POST';
|
| 226 |
liveuser |
8216 |
|
| 3 |
liveuser |
8217 |
}//if end
|
| 226 |
liveuser |
8218 |
|
| 3 |
liveuser |
8219 |
//檢查參數 params.url
|
|
|
8220 |
if(params.url===undefined){
|
| 226 |
liveuser |
8221 |
|
| 3 |
liveuser |
8222 |
//初始化為當前頁面
|
|
|
8223 |
params.url=location.href;
|
| 226 |
liveuser |
8224 |
|
| 3 |
liveuser |
8225 |
}//if end
|
| 226 |
liveuser |
8226 |
|
| 3 |
liveuser |
8227 |
//檢查參數 params.resType
|
|
|
8228 |
if(params.resType===undefined){
|
| 226 |
liveuser |
8229 |
|
| 3 |
liveuser |
8230 |
//初始化為'json'
|
|
|
8231 |
params.resType='json';
|
| 226 |
liveuser |
8232 |
|
| 3 |
liveuser |
8233 |
}//if end
|
| 226 |
liveuser |
8234 |
|
| 3 |
liveuser |
8235 |
//檢查參數 params.preAc
|
|
|
8236 |
if(params.preAc===undefined){
|
| 226 |
liveuser |
8237 |
|
| 3 |
liveuser |
8238 |
//初始化為提示傳送 ajax 前
|
|
|
8239 |
params.preAc=function(){
|
| 226 |
liveuser |
8240 |
|
| 3 |
liveuser |
8241 |
//debug
|
|
|
8242 |
if(window.debug){
|
| 226 |
liveuser |
8243 |
|
| 3 |
liveuser |
8244 |
//提示傳送 ajax 前
|
|
|
8245 |
console.log('before sand request...');
|
| 226 |
liveuser |
8246 |
|
| 3 |
liveuser |
8247 |
}//if end
|
| 226 |
liveuser |
8248 |
|
| 3 |
liveuser |
8249 |
};//funcitno end
|
| 226 |
liveuser |
8250 |
|
| 3 |
liveuser |
8251 |
}//if end
|
| 226 |
liveuser |
8252 |
|
| 3 |
liveuser |
8253 |
//檢查參數 params.aftAc
|
|
|
8254 |
if(params.aftAc===undefined){
|
| 226 |
liveuser |
8255 |
|
| 3 |
liveuser |
8256 |
//初始化為提示傳送 ajax 後
|
|
|
8257 |
params.aftAc=function(){
|
| 226 |
liveuser |
8258 |
|
| 3 |
liveuser |
8259 |
//debug
|
|
|
8260 |
if(window.debug){
|
| 226 |
liveuser |
8261 |
|
| 3 |
liveuser |
8262 |
//提示傳送 ajax 後
|
|
|
8263 |
console.log('after sand request...');
|
| 226 |
liveuser |
8264 |
|
| 3 |
liveuser |
8265 |
}//if end
|
| 226 |
liveuser |
8266 |
|
| 3 |
liveuser |
8267 |
};//funcitno end
|
| 226 |
liveuser |
8268 |
|
| 3 |
liveuser |
8269 |
}//if end
|
| 226 |
liveuser |
8270 |
|
| 3 |
liveuser |
8271 |
//檢查參數 params.data
|
|
|
8272 |
if(params.data===undefined){
|
| 226 |
liveuser |
8273 |
|
| 3 |
liveuser |
8274 |
//初始化變數q
|
|
|
8275 |
key1='q';
|
| 226 |
liveuser |
8276 |
|
| 3 |
liveuser |
8277 |
//初始化變數q的數值內容為'test by qbpwcf'
|
|
|
8278 |
v1='test by qbpwcf';
|
| 226 |
liveuser |
8279 |
|
| 3 |
liveuser |
8280 |
//初始要傳送的參數
|
|
|
8281 |
params.data=key1+'='+encodeURIComponent(v1);
|
| 226 |
liveuser |
8282 |
|
| 3 |
liveuser |
8283 |
}//if end
|
| 226 |
liveuser |
8284 |
|
| 3 |
liveuser |
8285 |
//如果支援 ajax
|
|
|
8286 |
if(window.XMLHttpRequest){
|
|
|
8287 |
|
|
|
8288 |
// code for IE7+, Firefox, Chrome, Opera, Safari
|
|
|
8289 |
var xmlhttp=new XMLHttpRequest();
|
|
|
8290 |
|
|
|
8291 |
}//if end
|
|
|
8292 |
|
|
|
8293 |
//不支援,應該是IE5、IE6
|
|
|
8294 |
else{
|
|
|
8295 |
|
|
|
8296 |
// code for IE6, IE5
|
|
|
8297 |
var xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
|
|
|
8298 |
|
|
|
8299 |
}// else end
|
|
|
8300 |
|
|
|
8301 |
//如果服務端有回傳完稱的狀態
|
|
|
8302 |
xmlhttp.onreadystatechange=function(){
|
|
|
8303 |
|
|
|
8304 |
//debug
|
|
|
8305 |
//console.log(xmlhttp);
|
|
|
8306 |
|
|
|
8307 |
//如果狀態為1
|
|
|
8308 |
if(xmlhttp.readyState==1){
|
|
|
8309 |
|
|
|
8310 |
//傳送 ajax 前要做的事情
|
|
|
8311 |
params.preAc.call(this);
|
|
|
8312 |
|
|
|
8313 |
}//if end
|
|
|
8314 |
|
|
|
8315 |
//如果狀態為4
|
|
|
8316 |
if(xmlhttp.readyState==4){
|
|
|
8317 |
|
|
|
8318 |
//且response code為200
|
|
|
8319 |
if(xmlhttp.status==200){
|
|
|
8320 |
|
|
|
8321 |
//得到回傳結果後要做的事情,參數為回傳的結果.
|
|
|
8322 |
params.aftAc.call(this,xmlhttp.response);
|
|
|
8323 |
|
|
|
8324 |
|
| 226 |
liveuser |
8325 |
|
| 3 |
liveuser |
8326 |
}//if end
|
| 226 |
liveuser |
8327 |
|
|
|
8328 |
//反之回傳狀態碼
|
| 3 |
liveuser |
8329 |
else{
|
| 226 |
liveuser |
8330 |
|
| 3 |
liveuser |
8331 |
//得到回傳結果後要做的事情,參數為回傳的結果.
|
|
|
8332 |
params.aftAc.call(this,xmlhttp.status);
|
| 226 |
liveuser |
8333 |
|
| 3 |
liveuser |
8334 |
}//else end
|
|
|
8335 |
|
|
|
8336 |
}//if end
|
|
|
8337 |
|
|
|
8338 |
}//function end
|
|
|
8339 |
|
|
|
8340 |
//設定回傳的資料形態
|
|
|
8341 |
xmlhttp.responseType=params.resType;
|
|
|
8342 |
|
| 226 |
liveuser |
8343 |
//如果是 'GET'
|
| 3 |
liveuser |
8344 |
if(params.method==='GET'){
|
| 226 |
liveuser |
8345 |
|
| 3 |
liveuser |
8346 |
//如果data不為空物件
|
|
|
8347 |
if(params.data.toString()!=='[object Object]'){
|
| 226 |
liveuser |
8348 |
|
| 3 |
liveuser |
8349 |
//加上get用的'?'
|
|
|
8350 |
params.url=params.url+'?'+params.data;
|
| 226 |
liveuser |
8351 |
|
| 3 |
liveuser |
8352 |
}//if end
|
| 226 |
liveuser |
8353 |
|
| 3 |
liveuser |
8354 |
}//if end
|
|
|
8355 |
|
|
|
8356 |
//設定要用get傳送的數值
|
|
|
8357 |
xmlhttp.open(params.method,params.url,true);
|
|
|
8358 |
|
|
|
8359 |
//如果有設置 header
|
|
|
8360 |
if(params.headers!==undefined){
|
| 226 |
liveuser |
8361 |
|
| 3 |
liveuser |
8362 |
//儲存迴圈的次數
|
|
|
8363 |
var count=Object.keys(params.headers).length;
|
| 226 |
liveuser |
8364 |
|
| 3 |
liveuser |
8365 |
//針對每個自己加的 header
|
|
|
8366 |
for(var i=0;i<count;i++){
|
| 226 |
liveuser |
8367 |
|
| 3 |
liveuser |
8368 |
//加上自定的 header
|
|
|
8369 |
xmlhttp.setRequestHeader(Object.keys(params.headers)[i],Object.values(params.headers)[i]);
|
| 226 |
liveuser |
8370 |
|
| 3 |
liveuser |
8371 |
}//for end
|
| 226 |
liveuser |
8372 |
|
| 3 |
liveuser |
8373 |
}//if end
|
|
|
8374 |
|
|
|
8375 |
//設定 header
|
|
|
8376 |
xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
|
|
|
8377 |
|
|
|
8378 |
//設定要求為ajax 的 header
|
|
|
8379 |
xmlhttp.setRequestHeader('X-Requested-With','XMLHttpRequest');
|
|
|
8380 |
|
| 226 |
liveuser |
8381 |
//如果是 'POST'
|
| 3 |
liveuser |
8382 |
if(params.method==='POST'){
|
|
|
8383 |
|
|
|
8384 |
//如果data不為空物件
|
|
|
8385 |
if(params.data.toString()!=='[object Object]'){
|
|
|
8386 |
|
|
|
8387 |
//傳送要求
|
|
|
8388 |
xmlhttp.send(params.data);
|
|
|
8389 |
|
|
|
8390 |
}//if end
|
| 226 |
liveuser |
8391 |
|
|
|
8392 |
//反之data存在資料
|
| 3 |
liveuser |
8393 |
else{
|
|
|
8394 |
//傳送要求,POST為空
|
|
|
8395 |
xmlhttp.send();
|
| 226 |
liveuser |
8396 |
|
| 3 |
liveuser |
8397 |
}//else end
|
|
|
8398 |
|
|
|
8399 |
}//if end
|
|
|
8400 |
|
|
|
8401 |
//反之是 GET 或 HEAD 或 OPTIONS
|
|
|
8402 |
else if(params.method==='GET' || params.method==='HEAD' || params.method==='OPTIONS'){
|
| 226 |
liveuser |
8403 |
|
| 3 |
liveuser |
8404 |
//直接傳送要求
|
|
|
8405 |
xmlhttp.send();
|
| 226 |
liveuser |
8406 |
|
| 3 |
liveuser |
8407 |
}//else end
|
| 226 |
liveuser |
8408 |
|
| 3 |
liveuser |
8409 |
}//function window.qbpwcf.ajax end
|
|
|
8410 |
";
|
|
|
8411 |
#js function
|
|
|
8412 |
$conf["javaScript::toScript"]["jsFunciton"][]=
|
|
|
8413 |
"
|
|
|
8414 |
//如果未設定 window.qbpwcf 物件
|
|
|
8415 |
if(window.qbpwcf===undefined){
|
|
|
8416 |
|
|
|
8417 |
//設置 window.qbpwcf 為空物件
|
|
|
8418 |
window.qbpwcf={};
|
|
|
8419 |
|
|
|
8420 |
}//if end
|
|
|
8421 |
|
|
|
8422 |
//如果未設定 window.qbpwcf.ajaxP 物件
|
|
|
8423 |
if(window.qbpwcf.ajaxP===undefined){
|
|
|
8424 |
|
|
|
8425 |
//設置 window.qbpwcf.ajax 為空物件
|
|
|
8426 |
window.qbpwcf.ajaxP={};
|
|
|
8427 |
|
|
|
8428 |
}//if end
|
| 226 |
liveuser |
8429 |
|
| 3 |
liveuser |
8430 |
/*
|
|
|
8431 |
設置 window.qbpwcf.ajaxP 函數
|
|
|
8432 |
說明:
|
|
|
8433 |
傳送ajax,指定傳送前要做什麼事情,然後回傳一個Promise.
|
| 174 |
liveuser |
8434 |
await完成後的回傳結果為一物件(res).
|
|
|
8435 |
res.dom,content of html which can be directly access.
|
|
|
8436 |
res.json,json string
|
|
|
8437 |
res.compliantJson,true代表合法的json;false代表不合法的.
|
|
|
8438 |
res.text,plain test
|
| 3 |
liveuser |
8439 |
參數:
|
|
|
8440 |
params={};
|
|
|
8441 |
params.method='POST' or 'GET' or 'HEAD' or 'OPTIONS';
|
|
|
8442 |
params.headers={name:value};
|
|
|
8443 |
params.url='url to request';
|
|
|
8444 |
params.preAc='function name to call before send request';
|
|
|
8445 |
params.data='data to contain','key1=encodeURIComponent(val1)&key2=encodeURIComponent(val2)';if no data please use {};
|
|
|
8446 |
參考資料:
|
|
|
8447 |
https://eyesofkids.gitbooks.io/javascript-start-es6-promise/content/contents/ch11_snippets.html
|
|
|
8448 |
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
|
|
|
8449 |
*/
|
|
|
8450 |
window.qbpwcf.ajaxP=function(params){
|
| 226 |
liveuser |
8451 |
|
| 3 |
liveuser |
8452 |
return new Promise(function(resolve, reject){
|
| 226 |
liveuser |
8453 |
|
| 3 |
liveuser |
8454 |
//檢查參數 params.method
|
|
|
8455 |
if(params.method===undefined){
|
| 226 |
liveuser |
8456 |
|
| 3 |
liveuser |
8457 |
//初始化為 'POST'
|
|
|
8458 |
params.method='POST';
|
| 226 |
liveuser |
8459 |
|
| 3 |
liveuser |
8460 |
}//if end
|
| 226 |
liveuser |
8461 |
|
| 3 |
liveuser |
8462 |
//檢查參數 params.url
|
|
|
8463 |
if(params.url===undefined){
|
| 226 |
liveuser |
8464 |
|
| 3 |
liveuser |
8465 |
//初始化為當前頁面
|
|
|
8466 |
params.url=location.href;
|
| 226 |
liveuser |
8467 |
|
| 3 |
liveuser |
8468 |
}//if end
|
| 226 |
liveuser |
8469 |
|
| 3 |
liveuser |
8470 |
//檢查參數 params.preAc
|
|
|
8471 |
if(params.preAc===undefined){
|
| 226 |
liveuser |
8472 |
|
| 3 |
liveuser |
8473 |
//初始化為提示傳送 ajax 前
|
|
|
8474 |
params.preAc=function(){
|
| 226 |
liveuser |
8475 |
|
| 3 |
liveuser |
8476 |
//debug
|
|
|
8477 |
if(window.debug){
|
| 226 |
liveuser |
8478 |
|
| 3 |
liveuser |
8479 |
//提示傳送 ajax 前
|
|
|
8480 |
console.log('before sand request...');
|
| 226 |
liveuser |
8481 |
|
| 3 |
liveuser |
8482 |
}//if end
|
| 226 |
liveuser |
8483 |
|
| 3 |
liveuser |
8484 |
};//funcitno end
|
| 226 |
liveuser |
8485 |
|
| 3 |
liveuser |
8486 |
}//if end
|
| 226 |
liveuser |
8487 |
|
| 3 |
liveuser |
8488 |
//檢查參數 params.data
|
|
|
8489 |
if(params.data===undefined){
|
| 226 |
liveuser |
8490 |
|
| 3 |
liveuser |
8491 |
//初始化變數q
|
|
|
8492 |
key1='q';
|
| 226 |
liveuser |
8493 |
|
| 3 |
liveuser |
8494 |
//初始化變數q的數值內容為'test by qbpwcf'
|
|
|
8495 |
v1='test by qbpwcf';
|
| 226 |
liveuser |
8496 |
|
| 3 |
liveuser |
8497 |
//初始要傳送的參數
|
|
|
8498 |
params.data=key1+'='+encodeURIComponent(v1);
|
| 226 |
liveuser |
8499 |
|
| 3 |
liveuser |
8500 |
}//if end
|
| 226 |
liveuser |
8501 |
|
| 3 |
liveuser |
8502 |
//如果支援 ajax
|
|
|
8503 |
if(window.XMLHttpRequest){
|
|
|
8504 |
|
|
|
8505 |
// code for IE7+, Firefox, Chrome, Opera, Safari
|
|
|
8506 |
var xmlhttp=new XMLHttpRequest();
|
|
|
8507 |
|
|
|
8508 |
}//if end
|
|
|
8509 |
|
|
|
8510 |
//不支援,應該是IE5、IE6
|
|
|
8511 |
else{
|
|
|
8512 |
|
|
|
8513 |
// code for IE6, IE5
|
|
|
8514 |
var xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
|
|
|
8515 |
|
|
|
8516 |
}// else end
|
|
|
8517 |
|
|
|
8518 |
//如果服務端有回傳完稱的狀態
|
|
|
8519 |
xmlhttp.onreadystatechange=function(){
|
|
|
8520 |
|
|
|
8521 |
//debug
|
|
|
8522 |
//console.log(xmlhttp);
|
|
|
8523 |
|
|
|
8524 |
//如果狀態為1
|
|
|
8525 |
if(xmlhttp.readyState==1){
|
|
|
8526 |
|
|
|
8527 |
//傳送 ajax 前要做的事情
|
|
|
8528 |
params.preAc.call(this);
|
|
|
8529 |
|
|
|
8530 |
}//if end
|
|
|
8531 |
|
|
|
8532 |
//如果狀態為4
|
|
|
8533 |
if(xmlhttp.readyState==4){
|
|
|
8534 |
|
|
|
8535 |
//且response code為200
|
|
|
8536 |
if(xmlhttp.status===200){
|
|
|
8537 |
|
|
|
8538 |
var tmp=document.createElement('div');
|
|
|
8539 |
tmp.innerHTML=xmlhttp.response;
|
| 226 |
liveuser |
8540 |
|
| 3 |
liveuser |
8541 |
//初始化記錄結果的變數
|
|
|
8542 |
var res={};
|
| 226 |
liveuser |
8543 |
|
| 3 |
liveuser |
8544 |
//記錄指定解讀格式的內容
|
|
|
8545 |
res.dom=tmp;
|
|
|
8546 |
|
|
|
8547 |
//記錄得到的純文字內容
|
|
|
8548 |
res.text=xmlhttp.responseText;
|
|
|
8549 |
|
|
|
8550 |
//嘗試
|
|
|
8551 |
try{
|
| 226 |
liveuser |
8552 |
|
| 3 |
liveuser |
8553 |
//記錄json格式的內容
|
|
|
8554 |
res.json=JSON.parse(res.text);
|
| 226 |
liveuser |
8555 |
|
| 3 |
liveuser |
8556 |
}
|
|
|
8557 |
|
|
|
8558 |
//抓取例外
|
|
|
8559 |
catch(exception){
|
| 226 |
liveuser |
8560 |
|
| 3 |
liveuser |
8561 |
//記錄錯誤訊息
|
|
|
8562 |
res.json=exception;
|
| 226 |
liveuser |
8563 |
|
| 3 |
liveuser |
8564 |
}
|
|
|
8565 |
|
| 174 |
liveuser |
8566 |
//設置回應內容為合規的json
|
|
|
8567 |
res.compliantJson=true;
|
|
|
8568 |
|
|
|
8569 |
//如果json的回應有name屬性
|
|
|
8570 |
if(res.json.hasOwnProperty('name')){
|
| 226 |
liveuser |
8571 |
|
| 174 |
liveuser |
8572 |
//如果是 SyntaxError
|
|
|
8573 |
if(res.json.name=='SyntaxError'){
|
| 226 |
liveuser |
8574 |
|
| 174 |
liveuser |
8575 |
//設置回應內容不為合規的json
|
|
|
8576 |
res.compliantJson=false;
|
| 226 |
liveuser |
8577 |
|
| 174 |
liveuser |
8578 |
}//if end
|
| 226 |
liveuser |
8579 |
|
| 174 |
liveuser |
8580 |
}//if end
|
| 226 |
liveuser |
8581 |
|
| 3 |
liveuser |
8582 |
//receive
|
|
|
8583 |
resolve(res);
|
| 226 |
liveuser |
8584 |
|
| 3 |
liveuser |
8585 |
}//if end
|
| 226 |
liveuser |
8586 |
|
|
|
8587 |
//反之回傳狀態碼
|
| 3 |
liveuser |
8588 |
else{
|
| 226 |
liveuser |
8589 |
|
| 3 |
liveuser |
8590 |
//reject
|
|
|
8591 |
reject(xmlhttp.status);
|
| 226 |
liveuser |
8592 |
|
| 3 |
liveuser |
8593 |
}//else end
|
|
|
8594 |
|
|
|
8595 |
}//if end
|
|
|
8596 |
|
|
|
8597 |
}//function end
|
|
|
8598 |
|
| 226 |
liveuser |
8599 |
//如果是 'GET'
|
| 3 |
liveuser |
8600 |
if(params.method==='GET'){
|
| 226 |
liveuser |
8601 |
|
| 3 |
liveuser |
8602 |
//如果data不為空物件
|
|
|
8603 |
if(params.data.toString()!=='[object Object]'){
|
| 226 |
liveuser |
8604 |
|
| 3 |
liveuser |
8605 |
//加上get用的'?'
|
|
|
8606 |
params.url=params.url+'?'+params.data;
|
| 226 |
liveuser |
8607 |
|
| 3 |
liveuser |
8608 |
}//if end
|
| 226 |
liveuser |
8609 |
|
| 3 |
liveuser |
8610 |
}//if end
|
|
|
8611 |
|
|
|
8612 |
//設定要用get傳送的數值
|
|
|
8613 |
xmlhttp.open(params.method,params.url,true);
|
|
|
8614 |
|
|
|
8615 |
//如果有設置 header
|
|
|
8616 |
if(params.headers!==undefined){
|
| 226 |
liveuser |
8617 |
|
| 3 |
liveuser |
8618 |
//儲存迴圈的次數
|
|
|
8619 |
var count=Object.keys(params.headers).length;
|
| 226 |
liveuser |
8620 |
|
| 3 |
liveuser |
8621 |
//針對每個自己加的 header
|
|
|
8622 |
for(var i=0;i<count;i++){
|
| 226 |
liveuser |
8623 |
|
| 3 |
liveuser |
8624 |
//加上自定的 header
|
|
|
8625 |
xmlhttp.setRequestHeader(Object.keys(params.headers)[i],Object.values(params.headers)[i]);
|
| 226 |
liveuser |
8626 |
|
| 3 |
liveuser |
8627 |
}//for end
|
| 226 |
liveuser |
8628 |
|
| 3 |
liveuser |
8629 |
}//if end
|
|
|
8630 |
|
|
|
8631 |
//設定 header
|
|
|
8632 |
xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
|
|
|
8633 |
|
|
|
8634 |
//設定要求為ajax 的 header
|
|
|
8635 |
xmlhttp.setRequestHeader('X-Requested-With','XMLHttpRequest');
|
|
|
8636 |
|
| 226 |
liveuser |
8637 |
//如果是 'POST'
|
| 3 |
liveuser |
8638 |
if(params.method==='POST'){
|
|
|
8639 |
|
|
|
8640 |
//如果data不為空物件
|
|
|
8641 |
if(params.data.toString()!=='[object Object]'){
|
|
|
8642 |
|
|
|
8643 |
//傳送要求
|
|
|
8644 |
xmlhttp.send(params.data);
|
|
|
8645 |
|
|
|
8646 |
}//if end
|
| 226 |
liveuser |
8647 |
|
| 174 |
liveuser |
8648 |
//反之data存在資料
|
| 3 |
liveuser |
8649 |
else{
|
|
|
8650 |
//傳送要求,POST為空
|
|
|
8651 |
xmlhttp.send();
|
| 226 |
liveuser |
8652 |
|
| 3 |
liveuser |
8653 |
}//else end
|
|
|
8654 |
|
|
|
8655 |
}//if end
|
|
|
8656 |
|
|
|
8657 |
//反之是 GET 或 HEAD 或 OPTIONS
|
|
|
8658 |
else if(params.method==='GET' || params.method==='HEAD' || params.method==='OPTIONS'){
|
| 226 |
liveuser |
8659 |
|
| 3 |
liveuser |
8660 |
//直接傳送要求
|
|
|
8661 |
xmlhttp.send();
|
| 226 |
liveuser |
8662 |
|
| 174 |
liveuser |
8663 |
}//else end
|
| 226 |
liveuser |
8664 |
|
| 3 |
liveuser |
8665 |
});//Promise end
|
| 226 |
liveuser |
8666 |
|
| 3 |
liveuser |
8667 |
}//function window.qbpwcf.ajaxP end
|
|
|
8668 |
";
|
|
|
8669 |
#js function
|
|
|
8670 |
$conf["javaScript::toScript"]["jsFunciton"][]=
|
|
|
8671 |
"
|
|
|
8672 |
/*
|
|
|
8673 |
說明:
|
|
|
8674 |
window.qbpwcf.tail ,物件,提供遞迴執行取得內容並顯示的功能.
|
|
|
8675 |
window.qbpwcf.tail.url, 提供連線內容的頁面,預設為當前頁面.
|
|
|
8676 |
window.qbpwcf.tail.continue ,true代表繼續執行;false代表暫停.
|
|
|
8677 |
window.qbpwcf.tail.rootDiv.id ,儲存回應的div其id,預設為'qbbpwcfTailRootDivID'.
|
|
|
8678 |
window.qbpwcf.tail.ajax(line2start) ,啟用該功能的函式,參數line2start為要從第幾行開始讀取,-1代表從最尾端開始.
|
|
|
8679 |
*/
|
| 226 |
liveuser |
8680 |
|
| 3 |
liveuser |
8681 |
//initial window.qbpwcf
|
|
|
8682 |
if(window.qbpwcf===undefined){
|
|
|
8683 |
|
|
|
8684 |
//初始化 window.qbpwcf
|
|
|
8685 |
window.qbpwcf={};
|
|
|
8686 |
|
|
|
8687 |
}//if end
|
| 226 |
liveuser |
8688 |
|
| 3 |
liveuser |
8689 |
//initial window.qbpwcf.tail
|
|
|
8690 |
if(window.qbpwcf.tail===undefined){
|
|
|
8691 |
|
|
|
8692 |
//初始化 window.qbpwf.tail
|
|
|
8693 |
window.qbpwcf.tail={};
|
|
|
8694 |
|
|
|
8695 |
//初始化繼續執行
|
|
|
8696 |
window.qbpwcf.tail.continue=true;
|
|
|
8697 |
|
|
|
8698 |
}//if end
|
| 226 |
liveuser |
8699 |
|
| 3 |
liveuser |
8700 |
//如果沒有指定要求內容的頁面
|
|
|
8701 |
if(window.qbpwcf.tail.url===undefined){
|
| 226 |
liveuser |
8702 |
|
| 3 |
liveuser |
8703 |
//初始化為當前頁面
|
|
|
8704 |
window.qbpwcf.tail.url=location.href;
|
| 226 |
liveuser |
8705 |
|
| 3 |
liveuser |
8706 |
}//if end
|
| 226 |
liveuser |
8707 |
|
| 3 |
liveuser |
8708 |
//create root div
|
|
|
8709 |
window.qbpwcf.tail.rootDiv = document.createElement('div');
|
| 226 |
liveuser |
8710 |
|
| 3 |
liveuser |
8711 |
//如果位指定div id
|
|
|
8712 |
if(window.qbpwcf.tail.rootDiv.id===undefined || window.qbpwcf.tail.rootDiv.id==='')
|
|
|
8713 |
{
|
|
|
8714 |
//預設為 qbbpwcfTailRootDivID
|
|
|
8715 |
window.qbpwcf.tail.rootDiv.id='qbpwcfTailRootDivID';
|
| 226 |
liveuser |
8716 |
|
| 3 |
liveuser |
8717 |
}//if end
|
| 226 |
liveuser |
8718 |
|
| 3 |
liveuser |
8719 |
//設置周期執行的涵式
|
|
|
8720 |
window.qbpwcf.tail.ajax = function(line2start){
|
| 226 |
liveuser |
8721 |
|
| 3 |
liveuser |
8722 |
console.log(window.qbpwcf.tail.rootDiv.id);
|
| 226 |
liveuser |
8723 |
|
| 3 |
liveuser |
8724 |
//初始化 root div 的 selector
|
|
|
8725 |
var selector='div.'+window.qbpwcf.tail.rootDiv.id;
|
| 226 |
liveuser |
8726 |
|
| 3 |
liveuser |
8727 |
//若 root div 不存在
|
|
|
8728 |
if(document.querySelector(selector)===null){
|
| 226 |
liveuser |
8729 |
|
| 3 |
liveuser |
8730 |
//建立之
|
|
|
8731 |
document.body.appendChild(window.qbpwcf.tail.rootDiv);
|
| 226 |
liveuser |
8732 |
|
| 3 |
liveuser |
8733 |
}//if end
|
| 226 |
liveuser |
8734 |
|
| 3 |
liveuser |
8735 |
xmlhttp=new XMLHttpRequest();
|
|
|
8736 |
//xmlhttp.responseType='json';
|
|
|
8737 |
xmlhttp.open('POST',window.qbpwcf.tail.url,true);
|
|
|
8738 |
xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
|
|
|
8739 |
xmlhttp.setRequestHeader('X-Requested-With','XMLHttpRequest');
|
|
|
8740 |
xmlhttp.onreadystatechange=function(){
|
|
|
8741 |
|
|
|
8742 |
//如果狀態為4且response code為200
|
|
|
8743 |
if(xmlhttp.readyState===4 && xmlhttp.status===200){
|
|
|
8744 |
|
| 226 |
liveuser |
8745 |
//get response
|
| 3 |
liveuser |
8746 |
res=xmlhttp.response;
|
| 226 |
liveuser |
8747 |
|
| 3 |
liveuser |
8748 |
//try parse res to json
|
|
|
8749 |
//參考資料
|
|
|
8750 |
//https://stackoverflow.com/questions/4467044/proper-way-to-catch-exception-from-json-parse
|
|
|
8751 |
try{
|
| 226 |
liveuser |
8752 |
json=JSON.parse(res);
|
| 3 |
liveuser |
8753 |
}
|
|
|
8754 |
catch(e){
|
|
|
8755 |
//console.log(e);
|
|
|
8756 |
}
|
| 226 |
liveuser |
8757 |
|
|
|
8758 |
console.log(json);
|
|
|
8759 |
|
| 3 |
liveuser |
8760 |
//如果json不存在
|
|
|
8761 |
if(json===undefined || json===null){
|
| 226 |
liveuser |
8762 |
|
| 3 |
liveuser |
8763 |
//取得文字結果
|
|
|
8764 |
res=xmlhttp.responseText
|
| 226 |
liveuser |
8765 |
|
| 3 |
liveuser |
8766 |
//如果輸出有逗號.
|
|
|
8767 |
if(res.includes(',')){
|
| 226 |
liveuser |
8768 |
|
| 3 |
liveuser |
8769 |
//用逗號分割回應
|
|
|
8770 |
res=res.split(',');
|
| 226 |
liveuser |
8771 |
|
| 3 |
liveuser |
8772 |
//取得回應的陣列長度
|
|
|
8773 |
rLength=res.length;
|
| 226 |
liveuser |
8774 |
|
| 3 |
liveuser |
8775 |
}//if end
|
| 226 |
liveuser |
8776 |
|
| 3 |
liveuser |
8777 |
//儲存最新的行內容
|
|
|
8778 |
window.qbpwcf.tail.latsLineContent=null;
|
| 226 |
liveuser |
8779 |
|
| 3 |
liveuser |
8780 |
//針對每個回應
|
|
|
8781 |
for(i=0;i<rLength-1;i++){
|
| 226 |
liveuser |
8782 |
|
|
|
8783 |
//解密內容
|
| 3 |
liveuser |
8784 |
res[i]=JSON.parse(decodeURIComponent(atob(res[i])).replaceAll('+',' '));
|
| 226 |
liveuser |
8785 |
|
| 3 |
liveuser |
8786 |
//取得讀取到的行數.
|
| 226 |
liveuser |
8787 |
window.qbpwcf.tail.lineNum=res[i].lineNum;
|
|
|
8788 |
|
| 3 |
liveuser |
8789 |
//針對每行輸出
|
|
|
8790 |
for(var j=0;j<res[i].lines;j++){
|
| 226 |
liveuser |
8791 |
|
| 3 |
liveuser |
8792 |
//如果內容跟上一行相同.
|
|
|
8793 |
if(window.qbpwcf.tail.latsLineContent===res[i].content[j]){
|
| 226 |
liveuser |
8794 |
|
| 3 |
liveuser |
8795 |
//跳過
|
|
|
8796 |
continue;
|
| 226 |
liveuser |
8797 |
|
|
|
8798 |
}//if end
|
|
|
8799 |
|
| 3 |
liveuser |
8800 |
//反之
|
|
|
8801 |
else{
|
| 226 |
liveuser |
8802 |
|
| 3 |
liveuser |
8803 |
//更新最新一列的內容
|
|
|
8804 |
window.qbpwcf.tail.latsLineContent=res[i].content[j];
|
| 226 |
liveuser |
8805 |
|
| 3 |
liveuser |
8806 |
}//else end
|
| 226 |
liveuser |
8807 |
|
| 3 |
liveuser |
8808 |
//set output line
|
|
|
8809 |
var div=document.createElement('div');
|
|
|
8810 |
var text=document.createTextNode(res[i].content[j]);
|
|
|
8811 |
div.appendChild(text);
|
| 226 |
liveuser |
8812 |
|
| 3 |
liveuser |
8813 |
//如果內容為空
|
|
|
8814 |
if(res[i].content[j]==='')
|
|
|
8815 |
{
|
|
|
8816 |
//建立<br>
|
|
|
8817 |
var br=document.createElement('br');
|
| 226 |
liveuser |
8818 |
|
| 3 |
liveuser |
8819 |
//遷入<br>
|
|
|
8820 |
div.appendChild(br);
|
|
|
8821 |
}
|
| 226 |
liveuser |
8822 |
|
| 3 |
liveuser |
8823 |
//show output line
|
|
|
8824 |
var rootDiv=document.getElementById(window.qbpwcf.tail.rootDiv.id);
|
|
|
8825 |
rootDiv.prepend(div);
|
| 226 |
liveuser |
8826 |
|
| 3 |
liveuser |
8827 |
}//for end
|
| 226 |
liveuser |
8828 |
|
| 3 |
liveuser |
8829 |
}//for end
|
| 226 |
liveuser |
8830 |
|
| 3 |
liveuser |
8831 |
}//if end
|
| 226 |
liveuser |
8832 |
|
| 3 |
liveuser |
8833 |
//反之有pasrer出json
|
|
|
8834 |
else{
|
| 226 |
liveuser |
8835 |
|
| 3 |
liveuser |
8836 |
//取得json
|
|
|
8837 |
res=json;
|
| 226 |
liveuser |
8838 |
|
| 3 |
liveuser |
8839 |
//取得真實內容
|
|
|
8840 |
res=res.content;
|
| 226 |
liveuser |
8841 |
|
| 3 |
liveuser |
8842 |
//取得回應的陣列長度
|
|
|
8843 |
rLength=res.length;
|
| 226 |
liveuser |
8844 |
|
| 3 |
liveuser |
8845 |
//針對每筆輸出
|
|
|
8846 |
for(var i=0;i<rLength;i++){
|
| 226 |
liveuser |
8847 |
|
| 3 |
liveuser |
8848 |
//針對每行輸出
|
|
|
8849 |
for(var j=0;j<rLength;j++){
|
| 226 |
liveuser |
8850 |
|
| 3 |
liveuser |
8851 |
//set output line
|
|
|
8852 |
var div=document.createElement('div');
|
|
|
8853 |
var text=document.createTextNode(res[j]);
|
|
|
8854 |
div.appendChild(text);
|
| 226 |
liveuser |
8855 |
|
| 3 |
liveuser |
8856 |
//如果內容為空
|
|
|
8857 |
if(res[j]==='')
|
|
|
8858 |
{
|
|
|
8859 |
//建立<br>
|
|
|
8860 |
var br=document.createElement('br');
|
| 226 |
liveuser |
8861 |
|
| 3 |
liveuser |
8862 |
//遷入<br>
|
|
|
8863 |
div.appendChild(br);
|
|
|
8864 |
}
|
| 226 |
liveuser |
8865 |
|
| 3 |
liveuser |
8866 |
//show output line
|
|
|
8867 |
var rootDiv=document.getElementById(window.qbpwcf.tail.rootDiv.id);
|
|
|
8868 |
rootDiv.prepend(div);
|
| 226 |
liveuser |
8869 |
|
| 3 |
liveuser |
8870 |
}//for end
|
| 226 |
liveuser |
8871 |
|
| 3 |
liveuser |
8872 |
}//for end
|
| 226 |
liveuser |
8873 |
|
| 3 |
liveuser |
8874 |
}//else end
|
| 226 |
liveuser |
8875 |
|
| 3 |
liveuser |
8876 |
//if json !=null
|
|
|
8877 |
if(json!=null){
|
| 226 |
liveuser |
8878 |
|
| 3 |
liveuser |
8879 |
console.log(json.lineNum);
|
| 226 |
liveuser |
8880 |
|
| 3 |
liveuser |
8881 |
//遞迴
|
|
|
8882 |
window.qbpwcf.tail.ajax.call(this,json.lineNum+1);
|
|
|
8883 |
|
|
|
8884 |
//清空變數
|
|
|
8885 |
json=null;
|
| 226 |
liveuser |
8886 |
|
| 3 |
liveuser |
8887 |
}//if end
|
| 226 |
liveuser |
8888 |
|
| 3 |
liveuser |
8889 |
else{
|
| 226 |
liveuser |
8890 |
|
| 3 |
liveuser |
8891 |
//如果當前行數不等於空
|
|
|
8892 |
if(window.qbpwcf.tail.lineNum!==undefined && window.qbpwcf.tail.lineNum!==null){
|
| 226 |
liveuser |
8893 |
|
| 3 |
liveuser |
8894 |
//遞迴
|
|
|
8895 |
window.qbpwcf.tail.ajax.call(this,window.qbpwcf.tail.lineNum);
|
| 226 |
liveuser |
8896 |
|
| 3 |
liveuser |
8897 |
}//if end
|
| 226 |
liveuser |
8898 |
|
| 3 |
liveuser |
8899 |
else{
|
| 226 |
liveuser |
8900 |
|
| 3 |
liveuser |
8901 |
//遞迴
|
|
|
8902 |
window.qbpwcf.tail.ajax.call(this,-1);
|
| 226 |
liveuser |
8903 |
|
| 3 |
liveuser |
8904 |
}//else end
|
| 226 |
liveuser |
8905 |
|
| 3 |
liveuser |
8906 |
}//else end
|
|
|
8907 |
|
|
|
8908 |
}//if end
|
|
|
8909 |
|
|
|
8910 |
}//function end
|
| 226 |
liveuser |
8911 |
|
|
|
8912 |
//如果要繼續
|
| 3 |
liveuser |
8913 |
if(window.qbpwcf.tail.continue){
|
|
|
8914 |
|
|
|
8915 |
//繼續
|
|
|
8916 |
xmlhttp.send('line2start='+line2start);
|
|
|
8917 |
|
|
|
8918 |
}//if end
|
| 226 |
liveuser |
8919 |
|
| 3 |
liveuser |
8920 |
//反之要暫停
|
|
|
8921 |
else{
|
| 226 |
liveuser |
8922 |
|
| 3 |
liveuser |
8923 |
//設置無限等待
|
|
|
8924 |
var intervalTail = window.setInterval(function(){
|
| 226 |
liveuser |
8925 |
|
| 3 |
liveuser |
8926 |
//提示已經暫停
|
|
|
8927 |
console.log('paused');
|
| 226 |
liveuser |
8928 |
|
| 3 |
liveuser |
8929 |
//如果要繼續了
|
|
|
8930 |
if(window.qbpwcf.tail.continue){
|
| 226 |
liveuser |
8931 |
|
| 3 |
liveuser |
8932 |
//清除無限等待
|
|
|
8933 |
clearInterval(intervalTail);
|
| 226 |
liveuser |
8934 |
|
| 3 |
liveuser |
8935 |
//繼續
|
|
|
8936 |
xmlhttp.send('line2start='+line2start);
|
| 226 |
liveuser |
8937 |
|
| 3 |
liveuser |
8938 |
}//if end
|
| 226 |
liveuser |
8939 |
|
| 3 |
liveuser |
8940 |
},1000);
|
| 226 |
liveuser |
8941 |
|
| 3 |
liveuser |
8942 |
}//else end
|
|
|
8943 |
|
|
|
8944 |
}//function end
|
|
|
8945 |
";
|
|
|
8946 |
#js function
|
|
|
8947 |
$conf["javaScript::toScript"]["jsFunciton"][]=
|
|
|
8948 |
"
|
|
|
8949 |
//initial window.qbpwcf
|
|
|
8950 |
if(window.qbpwcf===undefined){
|
|
|
8951 |
|
|
|
8952 |
//初始化 window.qbpwcf
|
|
|
8953 |
window.qbpwcf={};
|
|
|
8954 |
|
|
|
8955 |
}//if end
|
| 226 |
liveuser |
8956 |
|
| 3 |
liveuser |
8957 |
//initial window.qbpwcf.screenShare
|
|
|
8958 |
if(window.qbpwcf.screenShare===undefined){
|
|
|
8959 |
|
|
|
8960 |
//初始化 window.qbpwcf.screenShare
|
|
|
8961 |
window.qbpwcf.screenShare={};
|
|
|
8962 |
|
|
|
8963 |
}//if end
|
| 226 |
liveuser |
8964 |
|
| 3 |
liveuser |
8965 |
/*
|
|
|
8966 |
函式說明:
|
|
|
8967 |
分享螢幕畫面.
|
|
|
8968 |
參數說明:
|
|
|
8969 |
parmas={};
|
|
|
8970 |
params.displayOptions={};
|
|
|
8971 |
params.startEle=''; //點擊後開始分享螢幕的元素id
|
|
|
8972 |
參考資料:
|
|
|
8973 |
https://developer.mozilla.org/en-US/docs/Web/API/Screen_Capture_API/Using_Screen_Capture
|
|
|
8974 |
https://developer.mozilla.org/en-US/docs/Web/API/MediaStream_Recording_API
|
|
|
8975 |
https://developer.mozilla.org/en-US/docs/Web/API/MediaSource/addSourceBuffer
|
|
|
8976 |
https://developer.mozilla.org/en-US/docs/Web/API/Blob
|
|
|
8977 |
https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Global_Objects/Array/shift
|
|
|
8978 |
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer
|
|
|
8979 |
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int8Array
|
|
|
8980 |
https://ithelp.ithome.com.tw/articles/10195525
|
|
|
8981 |
https://developer.mozilla.org/zh-TW/docs/Web/API/Blob
|
|
|
8982 |
#備註:
|
|
|
8983 |
#錄製好的畫面無法在別的畫面播放.
|
|
|
8984 |
*/
|
|
|
8985 |
window.qbpwcf.screenShare.init=function(params){
|
| 226 |
liveuser |
8986 |
|
| 3 |
liveuser |
8987 |
//初始化參數
|
|
|
8988 |
if(params.startEle===undefined){
|
| 226 |
liveuser |
8989 |
|
| 3 |
liveuser |
8990 |
params.startEle='';
|
| 226 |
liveuser |
8991 |
|
| 3 |
liveuser |
8992 |
}//if end
|
| 226 |
liveuser |
8993 |
|
| 3 |
liveuser |
8994 |
//初始化參數
|
|
|
8995 |
if(params.displayOptions===undefined){
|
| 226 |
liveuser |
8996 |
|
| 3 |
liveuser |
8997 |
//參數
|
|
|
8998 |
params.displayOptions={
|
|
|
8999 |
video: {
|
|
|
9000 |
cursor: 'always',
|
|
|
9001 |
},
|
|
|
9002 |
audio: {
|
|
|
9003 |
echoCancellation: true,
|
|
|
9004 |
noiseSuppression: true,
|
|
|
9005 |
sampleRate: 44100,
|
|
|
9006 |
},
|
|
|
9007 |
};
|
| 226 |
liveuser |
9008 |
|
| 3 |
liveuser |
9009 |
}// if end
|
| 226 |
liveuser |
9010 |
|
| 3 |
liveuser |
9011 |
//全域化 displayOptions
|
|
|
9012 |
window.qbpwcf.screenShare.displayOptions=params.displayOptions;
|
| 226 |
liveuser |
9013 |
|
| 3 |
liveuser |
9014 |
//如果無指定點擊後開始分享畫面的元素
|
|
|
9015 |
if(params.startEle==='')
|
|
|
9016 |
{
|
|
|
9017 |
//移除既有的分享畫面div
|
|
|
9018 |
screenShareBtn=document.getElementById('window.qbpwcf.screenShare.startId');
|
| 226 |
liveuser |
9019 |
|
| 3 |
liveuser |
9020 |
//如果有該按鈕
|
|
|
9021 |
if(screenShareBtn!==null)
|
|
|
9022 |
{
|
|
|
9023 |
//移除之
|
|
|
9024 |
screenShareBtn.remove();
|
|
|
9025 |
}
|
| 226 |
liveuser |
9026 |
|
| 3 |
liveuser |
9027 |
//建立 div 物件
|
|
|
9028 |
div=document.createElement('div');
|
| 226 |
liveuser |
9029 |
|
| 3 |
liveuser |
9030 |
//綁定點擊事件
|
|
|
9031 |
div.addEventListener('click',function()
|
|
|
9032 |
{
|
|
|
9033 |
window.qbpwcf.screenShare.startCapture();
|
|
|
9034 |
});
|
| 226 |
liveuser |
9035 |
|
| 3 |
liveuser |
9036 |
//設置固位置的 css 樣式
|
|
|
9037 |
div.style.position='fixed';
|
|
|
9038 |
div.style.bottom='10px';
|
|
|
9039 |
div.style.right='10px';
|
| 226 |
liveuser |
9040 |
|
| 3 |
liveuser |
9041 |
//設置背景顏色為藍色
|
|
|
9042 |
div.style.backgroundColor='#AAAAFF';
|
| 226 |
liveuser |
9043 |
|
| 3 |
liveuser |
9044 |
//設置滑鼠指標過去為 pointer
|
|
|
9045 |
div.style.cursor='pointer';
|
| 226 |
liveuser |
9046 |
|
| 3 |
liveuser |
9047 |
//設置 div 的 id
|
|
|
9048 |
div.id='window.qbpwcf.screenShare.startId';
|
| 226 |
liveuser |
9049 |
|
| 3 |
liveuser |
9050 |
//給予提文字
|
|
|
9051 |
div.innerText='按我開始分享畫面';
|
| 226 |
liveuser |
9052 |
|
| 3 |
liveuser |
9053 |
//取得預設的開始錄影參數;
|
| 226 |
liveuser |
9054 |
params.startEle=div;
|
|
|
9055 |
|
| 3 |
liveuser |
9056 |
//放置 div
|
| 226 |
liveuser |
9057 |
document.body.appendChild(div);
|
|
|
9058 |
|
| 3 |
liveuser |
9059 |
}//if end
|
| 226 |
liveuser |
9060 |
|
| 3 |
liveuser |
9061 |
//反之
|
|
|
9062 |
else
|
|
|
9063 |
{
|
|
|
9064 |
//設置點擊就開始分享畫面的事件
|
|
|
9065 |
params.startEle.addEventListener('click',function()
|
|
|
9066 |
{
|
|
|
9067 |
window.qbpwcf.screenShare.startCapture();
|
|
|
9068 |
});
|
| 226 |
liveuser |
9069 |
|
| 3 |
liveuser |
9070 |
}//else end
|
| 226 |
liveuser |
9071 |
|
| 3 |
liveuser |
9072 |
//建立 video div 物件
|
|
|
9073 |
window.qbpwcf.screenShare.videoElem=document.createElement('video');
|
|
|
9074 |
window.qbpwcf.screenShare.videoElem.autoplay=true;
|
|
|
9075 |
window.qbpwcf.screenShare.videoElem.style.width='100vw';
|
|
|
9076 |
window.qbpwcf.screenShare.videoElem.style.height='100vh';
|
|
|
9077 |
window.qbpwcf.screenShare.videoElem.style.border='solid 1px silver';
|
|
|
9078 |
window.qbpwcf.screenShare.videoElem.id='video';
|
| 226 |
liveuser |
9079 |
|
| 3 |
liveuser |
9080 |
//放置 video div
|
|
|
9081 |
document.body.appendChild(window.qbpwcf.screenShare.videoElem);
|
| 226 |
liveuser |
9082 |
|
| 3 |
liveuser |
9083 |
}//function window.qbpwcf.screenShare.init end
|
| 226 |
liveuser |
9084 |
|
| 3 |
liveuser |
9085 |
//開始截取畫面
|
|
|
9086 |
window.qbpwcf.screenShare.startCapture = async function(){
|
| 226 |
liveuser |
9087 |
|
| 3 |
liveuser |
9088 |
//try start
|
|
|
9089 |
try{
|
|
|
9090 |
//顯示畫面
|
|
|
9091 |
window.qbpwcf.screenShare.videoElem.srcObject = await navigator.mediaDevices.getDisplayMedia(window.qbpwcf.screenShare.displayOptions);
|
|
|
9092 |
window.qbpwcf.screenShare.dumpOptionsInfo();
|
| 226 |
liveuser |
9093 |
|
| 3 |
liveuser |
9094 |
//設定錄製畫面的設定
|
|
|
9095 |
var options = { mimeType: 'video/webm; codecs=vp8' };
|
|
|
9096 |
window.qbpwcf.screenShare.mediaRecorder = new MediaRecorder(window.qbpwcf.screenShare.videoElem.srcObject, options);
|
| 226 |
liveuser |
9097 |
|
| 3 |
liveuser |
9098 |
//初始化儲存錄影的片段
|
|
|
9099 |
window.qbpwcf.screenShare.recordedChunks=[];
|
| 226 |
liveuser |
9100 |
|
| 3 |
liveuser |
9101 |
//當有資料可以錄製時
|
|
|
9102 |
window.qbpwcf.screenShare.mediaRecorder.ondataavailable=window.qbpwcf.screenShare.handleDataAvailable;
|
| 226 |
liveuser |
9103 |
|
| 3 |
liveuser |
9104 |
//開始錄製
|
|
|
9105 |
window.qbpwcf.screenShare.mediaRecorder.start();
|
| 226 |
liveuser |
9106 |
|
| 3 |
liveuser |
9107 |
//設置每1秒就要求一次錄取的資料
|
|
|
9108 |
window.qbpwcf.screenShare.interval = setInterval(function(){
|
| 226 |
liveuser |
9109 |
|
| 3 |
liveuser |
9110 |
//debug
|
|
|
9111 |
if(window.debug){
|
| 226 |
liveuser |
9112 |
|
| 3 |
liveuser |
9113 |
console.log(window.qbpwcf.screenShare.mediaRecorder);
|
| 226 |
liveuser |
9114 |
|
| 3 |
liveuser |
9115 |
}//if end
|
| 226 |
liveuser |
9116 |
|
| 3 |
liveuser |
9117 |
//如果停止錄影了
|
|
|
9118 |
if(window.qbpwcf.screenShare.mediaRecorder.state==='inactive'){
|
| 226 |
liveuser |
9119 |
|
| 3 |
liveuser |
9120 |
//結束循環要求錄取的資料
|
|
|
9121 |
clearInterval(window.qbpwcf.screenShare.interval);
|
| 226 |
liveuser |
9122 |
|
| 3 |
liveuser |
9123 |
}//if end
|
| 226 |
liveuser |
9124 |
|
| 3 |
liveuser |
9125 |
//手動要求目前錄製
|
|
|
9126 |
window.qbpwcf.screenShare.mediaRecorder.requestData();
|
| 226 |
liveuser |
9127 |
|
| 3 |
liveuser |
9128 |
//如果要繼續了
|
|
|
9129 |
if(window.qbpwcf.screenShare.continue){
|
| 226 |
liveuser |
9130 |
|
| 3 |
liveuser |
9131 |
//清除無限等待
|
|
|
9132 |
clearInterval(window.qbpwcf.screenShare.interval);
|
| 226 |
liveuser |
9133 |
|
| 3 |
liveuser |
9134 |
}//if end
|
| 226 |
liveuser |
9135 |
|
| 3 |
liveuser |
9136 |
},1000);
|
| 226 |
liveuser |
9137 |
|
| 3 |
liveuser |
9138 |
} //try end
|
| 226 |
liveuser |
9139 |
|
| 3 |
liveuser |
9140 |
//catch error
|
|
|
9141 |
catch(err){
|
| 226 |
liveuser |
9142 |
|
| 3 |
liveuser |
9143 |
//debug
|
|
|
9144 |
console.error(err);
|
| 226 |
liveuser |
9145 |
|
| 3 |
liveuser |
9146 |
}//catch end
|
| 226 |
liveuser |
9147 |
|
| 3 |
liveuser |
9148 |
}//function end
|
| 226 |
liveuser |
9149 |
|
| 3 |
liveuser |
9150 |
//結束截取畫面跟音訊
|
|
|
9151 |
window.qbpwcf.screenShare.stopCapture = function(){
|
| 226 |
liveuser |
9152 |
|
| 3 |
liveuser |
9153 |
let tracks = window.qbpwcf.screenShare.videoElem.srcObject.getTracks();
|
|
|
9154 |
|
|
|
9155 |
tracks.forEach(track => track.stop());
|
| 226 |
liveuser |
9156 |
|
| 3 |
liveuser |
9157 |
videoElem.srcObject = null;
|
| 226 |
liveuser |
9158 |
|
| 3 |
liveuser |
9159 |
}//funciton end
|
| 226 |
liveuser |
9160 |
|
| 3 |
liveuser |
9161 |
//輸出當前錄影的各項資訊
|
|
|
9162 |
window.qbpwcf.screenShare.dumpOptionsInfo = function(){
|
| 226 |
liveuser |
9163 |
|
| 3 |
liveuser |
9164 |
//debug
|
|
|
9165 |
if(window.debug){
|
| 226 |
liveuser |
9166 |
|
| 3 |
liveuser |
9167 |
//debug
|
|
|
9168 |
console.log(window.qbpwcf.screenShare.videoElem.srcObject);
|
| 226 |
liveuser |
9169 |
|
| 3 |
liveuser |
9170 |
}//if end
|
| 226 |
liveuser |
9171 |
|
| 3 |
liveuser |
9172 |
const videoTrack = window.qbpwcf.screenShare.videoElem.srcObject.getVideoTracks()[0];
|
|
|
9173 |
|
|
|
9174 |
//debug
|
|
|
9175 |
if(window.debug){
|
|
|
9176 |
|
|
|
9177 |
console.log('Track settings:');
|
|
|
9178 |
console.log(JSON.stringify(videoTrack.getSettings(), null, 2));
|
|
|
9179 |
console.log('Track constraints:');
|
|
|
9180 |
console.log(JSON.stringify(videoTrack.getConstraints(), null, 2));
|
| 226 |
liveuser |
9181 |
|
| 3 |
liveuser |
9182 |
}//if end
|
| 226 |
liveuser |
9183 |
|
| 3 |
liveuser |
9184 |
}//function end
|
| 226 |
liveuser |
9185 |
|
| 3 |
liveuser |
9186 |
//ondataavailable event 要執行的函式
|
|
|
9187 |
window.qbpwcf.screenShare.handleDataAvailable = function(e){
|
| 226 |
liveuser |
9188 |
|
| 3 |
liveuser |
9189 |
//debug
|
|
|
9190 |
if(window.debug){
|
| 226 |
liveuser |
9191 |
|
| 3 |
liveuser |
9192 |
console.log('data-available');
|
| 226 |
liveuser |
9193 |
|
| 3 |
liveuser |
9194 |
}//if end
|
| 226 |
liveuser |
9195 |
|
| 3 |
liveuser |
9196 |
//如果有資料
|
|
|
9197 |
if (e.data.size > 0){
|
| 226 |
liveuser |
9198 |
|
| 3 |
liveuser |
9199 |
//記錄資料
|
|
|
9200 |
window.qbpwcf.screenShare.recordedChunks.push(e.data);
|
| 226 |
liveuser |
9201 |
|
| 3 |
liveuser |
9202 |
//debug
|
|
|
9203 |
if(window.debug){
|
| 226 |
liveuser |
9204 |
|
| 3 |
liveuser |
9205 |
console.log(window.qbpwcf.screenShare.recordedChunks);
|
| 226 |
liveuser |
9206 |
|
| 3 |
liveuser |
9207 |
}//if end
|
| 226 |
liveuser |
9208 |
|
| 3 |
liveuser |
9209 |
//取得最舊的資料
|
|
|
9210 |
blob=window.qbpwcf.screenShare.recordedChunks.shift();
|
| 226 |
liveuser |
9211 |
|
| 3 |
liveuser |
9212 |
//debug
|
| 226 |
liveuser |
9213 |
if(window.debug){
|
|
|
9214 |
|
| 3 |
liveuser |
9215 |
//blob.type='video/webm; codecs=vp8'
|
| 226 |
liveuser |
9216 |
console.log(blob);
|
|
|
9217 |
|
| 3 |
liveuser |
9218 |
}//if end
|
| 226 |
liveuser |
9219 |
|
| 3 |
liveuser |
9220 |
//建立 reader 物件
|
|
|
9221 |
reader = new FileReader();
|
| 226 |
liveuser |
9222 |
|
| 3 |
liveuser |
9223 |
//如果開啟完畢
|
|
|
9224 |
reader.addEventListener('loadend',function(e){
|
| 226 |
liveuser |
9225 |
|
| 3 |
liveuser |
9226 |
//debug
|
|
|
9227 |
if(window.debug){
|
| 226 |
liveuser |
9228 |
|
| 3 |
liveuser |
9229 |
console.log(e);
|
| 226 |
liveuser |
9230 |
|
| 3 |
liveuser |
9231 |
}//if end
|
| 226 |
liveuser |
9232 |
|
| 3 |
liveuser |
9233 |
//取得 arrayBUffer
|
|
|
9234 |
buf=e.originalTarget.result;
|
| 226 |
liveuser |
9235 |
|
| 3 |
liveuser |
9236 |
//debug
|
|
|
9237 |
if(window.debug){
|
| 226 |
liveuser |
9238 |
|
| 3 |
liveuser |
9239 |
console.log(buf);
|
| 226 |
liveuser |
9240 |
|
| 3 |
liveuser |
9241 |
}//if end
|
| 226 |
liveuser |
9242 |
|
| 3 |
liveuser |
9243 |
//用8位數2進位來表示
|
|
|
9244 |
intArray = new Int8Array(buf);
|
| 226 |
liveuser |
9245 |
|
| 3 |
liveuser |
9246 |
//儲存成json字串
|
|
|
9247 |
json = JSON.stringify(intArray);
|
| 226 |
liveuser |
9248 |
|
| 3 |
liveuser |
9249 |
//初始化要傳遞的變數物件內容
|
|
|
9250 |
toDb={};
|
|
|
9251 |
toDb.dbAddr='localhost';
|
|
|
9252 |
toDb.dbName='qbpwcf';
|
|
|
9253 |
toDb.dbUser='root';
|
|
|
9254 |
toDb.dbPass='dolbyhometheater';
|
|
|
9255 |
toDb.dtName='int8array';
|
|
|
9256 |
toDb.cols=['json'];
|
|
|
9257 |
toDb.vals=[json];
|
| 226 |
liveuser |
9258 |
|
| 3 |
liveuser |
9259 |
//加密要傳輸的變數
|
|
|
9260 |
toDb=btoa(encodeURIComponent(JSON.stringify(toDb)));
|
| 226 |
liveuser |
9261 |
|
| 3 |
liveuser |
9262 |
//儲存到資料庫
|
|
|
9263 |
params={};
|
|
|
9264 |
params.method='POST';
|
|
|
9265 |
params.url='/qbpwcf/db/toDb.php';
|
|
|
9266 |
params.resType='json';
|
|
|
9267 |
//params.preAc='function name to call before send request';
|
|
|
9268 |
//params.aftAc='function name to call after send request';
|
|
|
9269 |
params.data='params='+toDb;
|
|
|
9270 |
window.qbpwcf.ajax(params);
|
| 226 |
liveuser |
9271 |
|
| 3 |
liveuser |
9272 |
});//funciton end
|
| 226 |
liveuser |
9273 |
|
| 3 |
liveuser |
9274 |
//讀取 blob 成 arrayBuffer
|
|
|
9275 |
reader.readAsArrayBuffer(blob);
|
| 226 |
liveuser |
9276 |
|
| 3 |
liveuser |
9277 |
}//if end
|
| 226 |
liveuser |
9278 |
|
| 3 |
liveuser |
9279 |
}//function end
|
| 226 |
liveuser |
9280 |
|
|
|
9281 |
//用戶觀賞分享的畫面
|
| 3 |
liveuser |
9282 |
window.qbpwcf.screenShare.client=function(){
|
| 226 |
liveuser |
9283 |
|
| 3 |
liveuser |
9284 |
//建立 videoR div 物件
|
|
|
9285 |
window.qbpwcf.screenShare.videoR=document.createElement('video');
|
|
|
9286 |
window.qbpwcf.screenShare.videoR.autoplay=true;
|
|
|
9287 |
window.qbpwcf.screenShare.videoR.style.width='100vw';
|
|
|
9288 |
window.qbpwcf.screenShare.videoR.style.height='100vh';
|
|
|
9289 |
window.qbpwcf.screenShare.videoR.style.border='solid 1px silver';
|
|
|
9290 |
window.qbpwcf.screenShare.videoR.id='videoR';
|
| 226 |
liveuser |
9291 |
|
| 3 |
liveuser |
9292 |
//放置 videoR div
|
|
|
9293 |
document.body.appendChild(window.qbpwcf.screenShare.videoR);
|
| 226 |
liveuser |
9294 |
|
| 3 |
liveuser |
9295 |
//建立 media source 物件
|
| 226 |
liveuser |
9296 |
window.qbpwcf.screenShare.mediaSourceForR = new MediaSource();
|
|
|
9297 |
|
|
|
9298 |
//設置 video tag 的內容來源
|
| 3 |
liveuser |
9299 |
//window.qbpwcf.screenShare.videoR.src=URL.createObjectURL(window.qbpwcf.screenShare.mediaSourceForR); //old method
|
|
|
9300 |
window.qbpwcf.screenShare.videoR.srcObject=window.qbpwcf.screenShare.mediaSourceForR; //new method
|
| 226 |
liveuser |
9301 |
|
| 3 |
liveuser |
9302 |
//初始化用戶取得的最新視訊片段id
|
|
|
9303 |
window.qbpwcf.screenShare.clientDataId=0;
|
| 226 |
liveuser |
9304 |
|
| 3 |
liveuser |
9305 |
//建立當打開媒體來源時
|
|
|
9306 |
window.qbpwcf.screenShare.mediaSourceForR.addEventListener('sourceopen',window.qbpwcf.screenShare.clientRecursive);
|
| 226 |
liveuser |
9307 |
|
| 3 |
liveuser |
9308 |
}//functino end
|
| 226 |
liveuser |
9309 |
|
| 3 |
liveuser |
9310 |
//用戶觀賞分享的畫面用的遞回函式
|
|
|
9311 |
window.qbpwcf.screenShare.clientRecursive=function(event){
|
| 226 |
liveuser |
9312 |
|
| 3 |
liveuser |
9313 |
//debug
|
|
|
9314 |
if(window.debug){
|
| 226 |
liveuser |
9315 |
|
| 3 |
liveuser |
9316 |
console.log(event);
|
| 226 |
liveuser |
9317 |
|
| 3 |
liveuser |
9318 |
}//if end
|
| 226 |
liveuser |
9319 |
|
| 3 |
liveuser |
9320 |
//如果尚無資料
|
|
|
9321 |
if(window.qbpwcf.screenShare.clientDataId===0){
|
| 226 |
liveuser |
9322 |
|
|
|
9323 |
//設置輸出的編碼
|
| 3 |
liveuser |
9324 |
window.qbpwcf.screenShare.sourceBuffer = window.qbpwcf.screenShare.mediaSourceForR.addSourceBuffer('video/webm; codecs=vp8');
|
| 226 |
liveuser |
9325 |
|
| 3 |
liveuser |
9326 |
}//if end
|
| 226 |
liveuser |
9327 |
|
| 3 |
liveuser |
9328 |
//初始化要傳遞的變數物件內容
|
|
|
9329 |
toDb={};
|
|
|
9330 |
toDb.dbAddr='localhost';
|
|
|
9331 |
toDb.dbName='qbpwcf';
|
|
|
9332 |
toDb.dbUser='root';
|
|
|
9333 |
toDb.dbPass='dolbyhometheater';
|
|
|
9334 |
toDb.dtName='int8array';
|
|
|
9335 |
toDb.cols=['id','json'];
|
|
|
9336 |
toDb.orderItem='id';
|
|
|
9337 |
toDb.ascORdesc='desc';
|
|
|
9338 |
toDb.numLimit='1';
|
|
|
9339 |
//toDb.WhereColumnName=['id'];
|
|
|
9340 |
//toDb.WhereColumnOperator=['>'];
|
|
|
9341 |
//toDb.WhereColumnValue=[window.qbpwcf.screenShare.clientDataId+''];
|
| 226 |
liveuser |
9342 |
|
| 3 |
liveuser |
9343 |
//debug
|
|
|
9344 |
if(window.debug){
|
| 226 |
liveuser |
9345 |
|
| 3 |
liveuser |
9346 |
console.log(toDb);
|
| 226 |
liveuser |
9347 |
|
|
|
9348 |
}//if end
|
|
|
9349 |
|
| 3 |
liveuser |
9350 |
//加密要傳輸的變數
|
|
|
9351 |
toDb=btoa(encodeURIComponent(JSON.stringify(toDb)));
|
| 226 |
liveuser |
9352 |
|
| 3 |
liveuser |
9353 |
//從Server取得資料
|
|
|
9354 |
params={};
|
|
|
9355 |
params.method='POST';
|
|
|
9356 |
params.url='/qbpwcf/db/dbOut.php';
|
|
|
9357 |
params.resType='json';
|
|
|
9358 |
params.preAc=function(res){
|
| 226 |
liveuser |
9359 |
|
| 3 |
liveuser |
9360 |
//debug
|
|
|
9361 |
if(window.debug){
|
| 226 |
liveuser |
9362 |
|
| 3 |
liveuser |
9363 |
console.log('loading');
|
| 226 |
liveuser |
9364 |
|
| 3 |
liveuser |
9365 |
}//if end
|
|
|
9366 |
};
|
|
|
9367 |
params.aftAc=function(res){
|
| 226 |
liveuser |
9368 |
|
| 3 |
liveuser |
9369 |
//debug
|
|
|
9370 |
if(window.debug){
|
| 226 |
liveuser |
9371 |
|
| 3 |
liveuser |
9372 |
console.log(res);
|
| 226 |
liveuser |
9373 |
|
| 3 |
liveuser |
9374 |
}//if end
|
| 226 |
liveuser |
9375 |
|
| 3 |
liveuser |
9376 |
//如果尚無資料
|
|
|
9377 |
if(res.dataContent===null){
|
| 226 |
liveuser |
9378 |
|
| 3 |
liveuser |
9379 |
//debug
|
|
|
9380 |
if(window.debug){
|
| 226 |
liveuser |
9381 |
|
| 3 |
liveuser |
9382 |
//提示讀取到結尾了
|
|
|
9383 |
console.log('read EOL');
|
| 226 |
liveuser |
9384 |
|
| 3 |
liveuser |
9385 |
}//if end
|
| 226 |
liveuser |
9386 |
|
| 3 |
liveuser |
9387 |
//遞迴
|
|
|
9388 |
window.qbpwcf.screenShare.clientRecursive();
|
| 226 |
liveuser |
9389 |
|
| 3 |
liveuser |
9390 |
//結束執行
|
|
|
9391 |
return true;
|
| 226 |
liveuser |
9392 |
|
| 3 |
liveuser |
9393 |
}//if end
|
| 226 |
liveuser |
9394 |
|
| 3 |
liveuser |
9395 |
//取得id
|
|
|
9396 |
id=res.dataContent.id[0];
|
| 226 |
liveuser |
9397 |
|
| 3 |
liveuser |
9398 |
//如果id有變
|
|
|
9399 |
if(window.qbpwcf.screenShare.clientDataId!==id){
|
| 226 |
liveuser |
9400 |
|
| 3 |
liveuser |
9401 |
//取得新id
|
|
|
9402 |
window.qbpwcf.screenShare.clientDataId=id;
|
| 226 |
liveuser |
9403 |
|
| 3 |
liveuser |
9404 |
//讀取片段資料
|
|
|
9405 |
json=res.dataContent.json[0];
|
| 226 |
liveuser |
9406 |
|
| 3 |
liveuser |
9407 |
//debug
|
|
|
9408 |
if(window.debug){
|
| 226 |
liveuser |
9409 |
|
| 3 |
liveuser |
9410 |
console.log(json);
|
| 226 |
liveuser |
9411 |
|
| 3 |
liveuser |
9412 |
}//if end
|
| 226 |
liveuser |
9413 |
|
|
|
9414 |
//parse json
|
| 3 |
liveuser |
9415 |
json=JSON.parse(json);
|
| 226 |
liveuser |
9416 |
|
| 3 |
liveuser |
9417 |
//debug
|
|
|
9418 |
if(window.debug){
|
| 226 |
liveuser |
9419 |
|
| 3 |
liveuser |
9420 |
console.log(json);
|
| 226 |
liveuser |
9421 |
|
| 3 |
liveuser |
9422 |
}//if end
|
| 226 |
liveuser |
9423 |
|
| 3 |
liveuser |
9424 |
//用int8Array的方式儲存
|
|
|
9425 |
intArray=new Int8Array(Object.values(json));
|
| 226 |
liveuser |
9426 |
|
| 3 |
liveuser |
9427 |
//debug
|
|
|
9428 |
if(window.debug){
|
| 226 |
liveuser |
9429 |
|
| 3 |
liveuser |
9430 |
console.log(intArray);
|
| 226 |
liveuser |
9431 |
|
| 3 |
liveuser |
9432 |
}//if end
|
| 226 |
liveuser |
9433 |
|
|
|
9434 |
|
| 3 |
liveuser |
9435 |
//debug
|
|
|
9436 |
if(window.debug){
|
| 226 |
liveuser |
9437 |
|
| 3 |
liveuser |
9438 |
console.log(intArray.buffer);
|
| 226 |
liveuser |
9439 |
|
| 3 |
liveuser |
9440 |
}//if end
|
| 226 |
liveuser |
9441 |
|
| 3 |
liveuser |
9442 |
//轉換成blob
|
|
|
9443 |
blob=new Blob(intArray,{type:'video/webm'});
|
| 226 |
liveuser |
9444 |
|
| 3 |
liveuser |
9445 |
//debug
|
|
|
9446 |
if(window.debug){
|
| 226 |
liveuser |
9447 |
|
| 3 |
liveuser |
9448 |
console.log(blob);
|
| 226 |
liveuser |
9449 |
|
| 3 |
liveuser |
9450 |
}//if end
|
| 226 |
liveuser |
9451 |
|
| 3 |
liveuser |
9452 |
//建立 reader 物件
|
|
|
9453 |
readerR = new FileReader();
|
| 226 |
liveuser |
9454 |
|
| 3 |
liveuser |
9455 |
//如果開啟完畢
|
|
|
9456 |
readerR.addEventListener('loadend',function(e){
|
| 226 |
liveuser |
9457 |
|
| 3 |
liveuser |
9458 |
//debug
|
|
|
9459 |
if(window.debug){
|
| 226 |
liveuser |
9460 |
|
| 3 |
liveuser |
9461 |
console.log(e);
|
| 226 |
liveuser |
9462 |
|
| 3 |
liveuser |
9463 |
}//if end
|
| 226 |
liveuser |
9464 |
|
| 3 |
liveuser |
9465 |
//取得 arrayBUffer
|
|
|
9466 |
buf=e.originalTarget.result;
|
| 226 |
liveuser |
9467 |
|
| 3 |
liveuser |
9468 |
//debug
|
|
|
9469 |
if(window.debug){
|
| 226 |
liveuser |
9470 |
|
| 3 |
liveuser |
9471 |
console.log(buf);
|
| 226 |
liveuser |
9472 |
|
|
|
9473 |
}//if end
|
|
|
9474 |
|
| 3 |
liveuser |
9475 |
//debug
|
|
|
9476 |
if(window.debug){
|
| 226 |
liveuser |
9477 |
|
|
|
9478 |
console.log(window.qbpwcf.screenShare.sourceBuffer);
|
|
|
9479 |
|
| 3 |
liveuser |
9480 |
}//if end
|
| 226 |
liveuser |
9481 |
|
| 3 |
liveuser |
9482 |
//append buffer
|
| 226 |
liveuser |
9483 |
window.qbpwcf.screenShare.sourceBuffer.appendBuffer(buf);
|
|
|
9484 |
|
| 3 |
liveuser |
9485 |
// Wait for the sourcebuffer to be ready to load all other chunks
|
|
|
9486 |
window.qbpwcf.screenShare.sourceBuffer.addEventListener('updateend',window.qbpwcf.screenShare.clientRecursive);
|
| 226 |
liveuser |
9487 |
|
| 3 |
liveuser |
9488 |
//debug
|
|
|
9489 |
if(window.debug){
|
| 226 |
liveuser |
9490 |
|
|
|
9491 |
console.log(window.qbpwcf.screenShare.sourceBuffer);
|
|
|
9492 |
|
|
|
9493 |
}//if end
|
|
|
9494 |
|
|
|
9495 |
});//addEventListener end
|
|
|
9496 |
|
| 3 |
liveuser |
9497 |
//讀取 blob 成 arrayBuffer
|
|
|
9498 |
readerR.readAsArrayBuffer(blob);
|
| 226 |
liveuser |
9499 |
|
| 3 |
liveuser |
9500 |
//遞迴
|
| 226 |
liveuser |
9501 |
window.qbpwcf.screenShare.clientRecursive();
|
|
|
9502 |
|
| 3 |
liveuser |
9503 |
}//if end
|
| 226 |
liveuser |
9504 |
|
| 3 |
liveuser |
9505 |
//反之
|
|
|
9506 |
else{
|
| 226 |
liveuser |
9507 |
|
| 3 |
liveuser |
9508 |
//遞迴
|
| 226 |
liveuser |
9509 |
window.qbpwcf.screenShare.clientRecursive();
|
|
|
9510 |
|
| 3 |
liveuser |
9511 |
}//else end
|
| 226 |
liveuser |
9512 |
|
| 3 |
liveuser |
9513 |
}//function end
|
| 226 |
liveuser |
9514 |
|
| 3 |
liveuser |
9515 |
params.data='params='+toDb;
|
|
|
9516 |
window.qbpwcf.ajax(params);
|
| 226 |
liveuser |
9517 |
|
| 3 |
liveuser |
9518 |
}//function end
|
|
|
9519 |
";
|
| 226 |
liveuser |
9520 |
|
| 3 |
liveuser |
9521 |
/*
|
|
|
9522 |
desc:
|
|
|
9523 |
等待既有圖片讀取完畢後,再讀取更清楚的圖片,取代之.
|
|
|
9524 |
參考資料:
|
|
|
9525 |
https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
|
|
|
9526 |
*/
|
|
|
9527 |
$conf["javaScript::toScript"]["jsFunciton"][]=
|
|
|
9528 |
"
|
|
|
9529 |
//img thumbnails 效果
|
|
|
9530 |
window.qbpwcf.imgThumbnails=function(thumbnails,oriImgUrl){
|
| 226 |
liveuser |
9531 |
|
| 3 |
liveuser |
9532 |
//如果變數 thumbnails 跟 oriImg 其中一個不是 object
|
|
|
9533 |
if( typeof(thumbnails)!=='object' || typeof(oriImgUrl)!=='string' ){
|
| 226 |
liveuser |
9534 |
|
| 3 |
liveuser |
9535 |
//提示錯誤訊息
|
|
|
9536 |
console.error('thumbnails not a object');
|
| 226 |
liveuser |
9537 |
|
| 3 |
liveuser |
9538 |
//提示錯誤訊息
|
|
|
9539 |
console.error('oriImgUrl not a string');
|
| 226 |
liveuser |
9540 |
|
| 3 |
liveuser |
9541 |
//結束執行
|
|
|
9542 |
return false;
|
| 226 |
liveuser |
9543 |
|
| 3 |
liveuser |
9544 |
}//if end
|
|
|
9545 |
|
|
|
9546 |
//event只跑一次的設定參數
|
|
|
9547 |
var Optional={};
|
|
|
9548 |
Optional.once=true;
|
|
|
9549 |
|
|
|
9550 |
//事件,當圖片檔案讀取完畢後執行
|
|
|
9551 |
thumbnails.addEventListener('load',function(e){
|
| 226 |
liveuser |
9552 |
|
| 3 |
liveuser |
9553 |
/*
|
|
|
9554 |
設置 window.qbpwcf.ajax 函數
|
|
|
9555 |
說明:
|
|
|
9556 |
傳送ajax,指定傳送前要做什麼事情,傳送後要做什麼事情.
|
|
|
9557 |
參數:
|
|
|
9558 |
params={};
|
|
|
9559 |
params.method='POST' or 'GET';
|
|
|
9560 |
params.headers={name:value};
|
|
|
9561 |
params.url='url to request';
|
|
|
9562 |
params.resType='json';
|
|
|
9563 |
params.preAc='function name to call before send request';
|
|
|
9564 |
params.aftAc='function name to call after send request';
|
|
|
9565 |
params.data='data to contain','key1=encodeURIComponent(val1)&key2=encodeURIComponent(val2)';if no data please use '';
|
|
|
9566 |
*/
|
|
|
9567 |
params={};
|
|
|
9568 |
params.method='GET';
|
|
|
9569 |
params.url=oriImgUrl;
|
|
|
9570 |
params.resType='blob';
|
|
|
9571 |
//帶入 img obj
|
| 226 |
liveuser |
9572 |
params.imgObj=e.target;
|
| 3 |
liveuser |
9573 |
params.aftAc=function(res){
|
| 226 |
liveuser |
9574 |
|
| 3 |
liveuser |
9575 |
//new reader obj
|
|
|
9576 |
var reader = new FileReader();
|
| 226 |
liveuser |
9577 |
|
| 3 |
liveuser |
9578 |
//reader evevnt
|
|
|
9579 |
reader.addEventListener('loadend', function(e){
|
| 226 |
liveuser |
9580 |
|
| 3 |
liveuser |
9581 |
//置換圖片位置為 base64 data url
|
|
|
9582 |
reader.imgObj.src=e.target.result;
|
|
|
9583 |
});
|
| 226 |
liveuser |
9584 |
|
| 3 |
liveuser |
9585 |
//帶入 img obj
|
|
|
9586 |
reader.imgObj=params.imgObj;
|
| 226 |
liveuser |
9587 |
|
| 3 |
liveuser |
9588 |
//讀取圖片為 data url
|
|
|
9589 |
reader.readAsDataURL(res);
|
|
|
9590 |
|
|
|
9591 |
};
|
|
|
9592 |
window.qbpwcf.ajax(params);
|
|
|
9593 |
|
|
|
9594 |
},Optional);//functino end
|
| 226 |
liveuser |
9595 |
|
| 3 |
liveuser |
9596 |
}//function end
|
|
|
9597 |
";
|
| 226 |
liveuser |
9598 |
|
| 3 |
liveuser |
9599 |
/*
|
|
|
9600 |
desc:
|
|
|
9601 |
低解析度的指定圖片讀取完畢後,再讀取更清楚的圖片,取代之.
|
|
|
9602 |
參考資料:
|
|
|
9603 |
https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous
|
|
|
9604 |
*/
|
|
|
9605 |
$conf["javaScript::toScript"]["jsFunciton"][]=
|
|
|
9606 |
"
|
|
|
9607 |
//img thumbnails 效果,用 async 實作
|
|
|
9608 |
window.qbpwcf.imgThumbAsync=async function(element,thumbUrl,oriImgUrl){
|
| 226 |
liveuser |
9609 |
|
| 3 |
liveuser |
9610 |
//如果變數 element 不是 object 或 thumbUrl 跟 oriImg 其中一個不是 string
|
|
|
9611 |
if( typeof(element)!=='object' || typeof(thumbUrl)!=='string' || typeof(oriImgUrl)!=='string' ){
|
| 226 |
liveuser |
9612 |
|
| 3 |
liveuser |
9613 |
//提示錯誤訊息
|
|
|
9614 |
console.error('element is not a object');
|
| 226 |
liveuser |
9615 |
|
| 3 |
liveuser |
9616 |
//提示錯誤訊息
|
|
|
9617 |
console.error('thumbUrl is not a string');
|
| 226 |
liveuser |
9618 |
|
| 3 |
liveuser |
9619 |
//提示錯誤訊息
|
|
|
9620 |
console.error('oriImgUrl is not a string');
|
| 226 |
liveuser |
9621 |
|
| 3 |
liveuser |
9622 |
//結束執行
|
|
|
9623 |
return false;
|
| 226 |
liveuser |
9624 |
|
| 3 |
liveuser |
9625 |
}//if end
|
| 226 |
liveuser |
9626 |
|
| 3 |
liveuser |
9627 |
//載入低解析度的圖片,將Promise儲存到res裡面
|
|
|
9628 |
var res = await fetch(thumbUrl);
|
| 226 |
liveuser |
9629 |
|
| 3 |
liveuser |
9630 |
//如果沒有讀取成功
|
|
|
9631 |
if(await res.status!==200){
|
| 226 |
liveuser |
9632 |
|
| 3 |
liveuser |
9633 |
//回傳失敗
|
|
|
9634 |
return false;
|
| 226 |
liveuser |
9635 |
|
| 3 |
liveuser |
9636 |
}//if end
|
| 226 |
liveuser |
9637 |
|
| 3 |
liveuser |
9638 |
//顯示低解析度的圖片
|
|
|
9639 |
element.src=URL.createObjectURL(await res.blob());
|
| 226 |
liveuser |
9640 |
|
| 3 |
liveuser |
9641 |
//載入原始圖片,將Promise儲存到res裡面
|
|
|
9642 |
var res = await fetch(oriImgUrl);
|
| 226 |
liveuser |
9643 |
|
| 3 |
liveuser |
9644 |
//如果沒有讀取成功
|
|
|
9645 |
if(await res.status!==200){
|
| 226 |
liveuser |
9646 |
|
| 3 |
liveuser |
9647 |
//回傳失敗
|
|
|
9648 |
return false;
|
| 226 |
liveuser |
9649 |
|
| 3 |
liveuser |
9650 |
}//if end
|
| 226 |
liveuser |
9651 |
|
| 3 |
liveuser |
9652 |
//顯示原始的圖片
|
|
|
9653 |
element.src=URL.createObjectURL(await res.blob());
|
| 226 |
liveuser |
9654 |
|
| 3 |
liveuser |
9655 |
//回傳正確
|
|
|
9656 |
return true;
|
| 226 |
liveuser |
9657 |
|
| 3 |
liveuser |
9658 |
}//function end
|
|
|
9659 |
";
|
| 226 |
liveuser |
9660 |
|
| 3 |
liveuser |
9661 |
/*
|
|
|
9662 |
desc:
|
|
|
9663 |
低解析度的多個指定圖片讀取完畢後,再讀取更清楚的圖片,取代之,且同步執行.
|
|
|
9664 |
參考資料:
|
|
|
9665 |
https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Async_await
|
|
|
9666 |
*/
|
|
|
9667 |
$conf["javaScript::toScript"]["jsFunciton"][]=
|
|
|
9668 |
"
|
|
|
9669 |
//多張img thumbnails 效果,用 async 實作
|
|
|
9670 |
window.qbpwcf.multiImgThumbAsync=async function(element,thumbUrl,oriImgUrl){
|
| 226 |
liveuser |
9671 |
|
| 3 |
liveuser |
9672 |
//儲存要同步執行的工作
|
|
|
9673 |
var tasks=[];
|
| 226 |
liveuser |
9674 |
|
| 3 |
liveuser |
9675 |
//針對每個陣列元素做事情,不需要中斷.
|
|
|
9676 |
element.forEach(function(value,key)
|
|
|
9677 |
{
|
|
|
9678 |
//不等待結果趕緊執行下一個
|
|
|
9679 |
tasks.push(window.qbpwcf.imgThumbAsync(value,thumbUrl[key],oriImgUrl[key]));
|
|
|
9680 |
});
|
| 226 |
liveuser |
9681 |
|
| 3 |
liveuser |
9682 |
//等待每個工作執行結束
|
|
|
9683 |
await Promise.all(tasks);
|
| 226 |
liveuser |
9684 |
|
| 3 |
liveuser |
9685 |
//回傳正確
|
| 226 |
liveuser |
9686 |
return true;
|
|
|
9687 |
|
| 3 |
liveuser |
9688 |
}//function end
|
|
|
9689 |
";
|
| 226 |
liveuser |
9690 |
|
| 3 |
liveuser |
9691 |
$conf["javaScript::toScript"]["jsFunciton"][]=
|
|
|
9692 |
"
|
|
|
9693 |
/*
|
|
|
9694 |
說明:
|
|
|
9695 |
偷偷摸摸地傳送表單,並觸發事件
|
|
|
9696 |
參數:
|
|
|
9697 |
params={};參數為一物件
|
|
|
9698 |
params.formEle=[];為每個表單元素.
|
|
|
9699 |
params.target='';為表單要傳送到的目的地.
|
|
|
9700 |
params.successFunc='';為表單回覆為成功時要做的事情,回應為一物件,有一屬性為'status',其數值為'true'.
|
|
|
9701 |
params.failedFunc='';為表單回覆為失敗時要做的事情,回應為一物件,有一屬性為'status',其數值為'false'.
|
|
|
9702 |
*/
|
|
|
9703 |
window.qbpwcf.slientSubmit=function(params){
|
| 226 |
liveuser |
9704 |
|
| 3 |
liveuser |
9705 |
//取得表單元素的key
|
|
|
9706 |
var formKeys=Object.keys(params.formEle);
|
| 226 |
liveuser |
9707 |
|
| 3 |
liveuser |
9708 |
//取得表單key的數量
|
|
|
9709 |
var formLength=formKeys.length;
|
| 226 |
liveuser |
9710 |
|
| 3 |
liveuser |
9711 |
//針對每個 key
|
|
|
9712 |
for(var i=0;i<formLength;i++){
|
| 226 |
liveuser |
9713 |
|
| 3 |
liveuser |
9714 |
//該表單,綁定失去焦點的事件,看其來沒有效果
|
|
|
9715 |
params.formEle[i].addEventListener('focusout',function(e){
|
| 226 |
liveuser |
9716 |
|
| 3 |
liveuser |
9717 |
//如果輸入內容為空
|
|
|
9718 |
if(e.target.value===''){
|
| 226 |
liveuser |
9719 |
|
| 3 |
liveuser |
9720 |
//聚焦選單
|
|
|
9721 |
e.target.focus();
|
| 226 |
liveuser |
9722 |
|
| 3 |
liveuser |
9723 |
}//if end
|
| 226 |
liveuser |
9724 |
|
| 3 |
liveuser |
9725 |
});//event blur end
|
| 226 |
liveuser |
9726 |
|
| 3 |
liveuser |
9727 |
//該表單,綁定內容變化的事件
|
|
|
9728 |
params.formEle[i].addEventListener('change',function(e){
|
| 226 |
liveuser |
9729 |
|
| 3 |
liveuser |
9730 |
//針對每個表單
|
|
|
9731 |
for(var j=0;j<formLength;j++){
|
| 226 |
liveuser |
9732 |
|
| 3 |
liveuser |
9733 |
//如果有表單未填寫
|
|
|
9734 |
if(params.formEle[j].value===''){
|
| 226 |
liveuser |
9735 |
|
|
|
9736 |
//結束迴圈
|
| 3 |
liveuser |
9737 |
break;
|
| 226 |
liveuser |
9738 |
|
| 3 |
liveuser |
9739 |
}//if end
|
| 226 |
liveuser |
9740 |
|
| 3 |
liveuser |
9741 |
//到這邊代表表單都有填寫
|
|
|
9742 |
if(j===formLength-1){
|
| 226 |
liveuser |
9743 |
|
|
|
9744 |
//驗證表單 - start
|
|
|
9745 |
|
| 3 |
liveuser |
9746 |
//初始化表單變數
|
|
|
9747 |
var post='';
|
| 226 |
liveuser |
9748 |
|
| 3 |
liveuser |
9749 |
//針對每個表單
|
|
|
9750 |
for(var k=0;k<formLength;k++){
|
| 226 |
liveuser |
9751 |
|
| 3 |
liveuser |
9752 |
//記錄表單名稱
|
|
|
9753 |
var formName=params.formEle[k].name;
|
| 226 |
liveuser |
9754 |
|
| 3 |
liveuser |
9755 |
//記錄表單數值
|
|
|
9756 |
var formValue=params.formEle[k].value;
|
| 226 |
liveuser |
9757 |
|
| 3 |
liveuser |
9758 |
//當是第一個表單時
|
|
|
9759 |
if(k==0){
|
| 226 |
liveuser |
9760 |
|
| 3 |
liveuser |
9761 |
//串接變數
|
|
|
9762 |
post=post+formName+'='+encodeURIComponent(formValue);
|
| 226 |
liveuser |
9763 |
|
| 3 |
liveuser |
9764 |
}//if end
|
| 226 |
liveuser |
9765 |
|
| 3 |
liveuser |
9766 |
//中間的表單
|
|
|
9767 |
else{
|
| 226 |
liveuser |
9768 |
|
| 3 |
liveuser |
9769 |
//串接變數
|
|
|
9770 |
post=post+'&'+formName+'='+encodeURIComponent(formValue);
|
| 226 |
liveuser |
9771 |
|
| 3 |
liveuser |
9772 |
}//else end
|
| 226 |
liveuser |
9773 |
|
| 3 |
liveuser |
9774 |
}//for end
|
| 226 |
liveuser |
9775 |
|
| 3 |
liveuser |
9776 |
/*
|
|
|
9777 |
設置 window.qbpwcf.ajax 函數
|
|
|
9778 |
說明:
|
|
|
9779 |
傳送ajax,指定傳送前要做什麼事情,傳送後要做什麼事情.
|
|
|
9780 |
參數:
|
|
|
9781 |
params={};
|
|
|
9782 |
params.method='POST' or 'GET';
|
|
|
9783 |
params.headers={name:value};
|
|
|
9784 |
params.url='url to request';
|
|
|
9785 |
params.resType='json';
|
|
|
9786 |
params.preAc='function name to call before send request';
|
|
|
9787 |
params.aftAc='function name to call after send request';
|
|
|
9788 |
params.data='data to contain','key1=encodeURIComponent(val1)&key2=encodeURIComponent(val2)';if no data please use '';
|
|
|
9789 |
*/
|
|
|
9790 |
var ajParams={};
|
|
|
9791 |
ajParams.method='POST';
|
|
|
9792 |
ajParams.url=params.target;
|
|
|
9793 |
ajParams.resType='json';
|
|
|
9794 |
ajParams.data=post;
|
|
|
9795 |
ajParams.aftAc=function(res){
|
| 226 |
liveuser |
9796 |
|
| 3 |
liveuser |
9797 |
//驗證正確
|
|
|
9798 |
if(res.status==='true'){
|
| 226 |
liveuser |
9799 |
|
| 3 |
liveuser |
9800 |
//運行驗證成功的函式
|
|
|
9801 |
params.successFunc(res);
|
| 226 |
liveuser |
9802 |
|
| 3 |
liveuser |
9803 |
}//if end
|
| 226 |
liveuser |
9804 |
|
| 3 |
liveuser |
9805 |
//反之驗證失敗
|
|
|
9806 |
else if(params.failedFunc!==undefined){
|
| 226 |
liveuser |
9807 |
|
| 3 |
liveuser |
9808 |
//運行驗證失敗的函式
|
|
|
9809 |
params.failedFunc(res);
|
| 226 |
liveuser |
9810 |
|
| 3 |
liveuser |
9811 |
}//if end
|
| 226 |
liveuser |
9812 |
|
| 3 |
liveuser |
9813 |
};
|
| 226 |
liveuser |
9814 |
|
| 3 |
liveuser |
9815 |
window.qbpwcf.ajax(ajParams);
|
| 226 |
liveuser |
9816 |
|
|
|
9817 |
|
| 3 |
liveuser |
9818 |
//驗證表單 - end
|
| 226 |
liveuser |
9819 |
|
| 3 |
liveuser |
9820 |
}//if end
|
| 226 |
liveuser |
9821 |
|
| 3 |
liveuser |
9822 |
}//for end
|
| 226 |
liveuser |
9823 |
|
| 3 |
liveuser |
9824 |
//結束程式
|
|
|
9825 |
return false;
|
| 226 |
liveuser |
9826 |
|
| 3 |
liveuser |
9827 |
});//event blur end
|
| 226 |
liveuser |
9828 |
|
| 3 |
liveuser |
9829 |
}//for end
|
| 226 |
liveuser |
9830 |
|
| 3 |
liveuser |
9831 |
}//function end
|
|
|
9832 |
";
|
| 226 |
liveuser |
9833 |
|
| 3 |
liveuser |
9834 |
#js function
|
|
|
9835 |
$conf["javaScript::toScript"]["jsFunciton"][]=
|
|
|
9836 |
"
|
|
|
9837 |
/*
|
|
|
9838 |
說明:
|
|
|
9839 |
偵測目標是否可以連線後要做的事情.
|
|
|
9840 |
參數:
|
|
|
9841 |
params,物件.
|
|
|
9842 |
params.url,服務網址.
|
|
|
9843 |
params.timeout,偵測的毫秒數上限.
|
|
|
9844 |
params.callback,偵測完服務後要執行的函式,參數為偵測的結果可以連線為true,不可連線為false.
|
|
|
9845 |
*/
|
|
|
9846 |
window.qbpwcf.connectable={};
|
|
|
9847 |
window.qbpwcf.connectable.func=function(params){
|
| 226 |
liveuser |
9848 |
|
| 3 |
liveuser |
9849 |
//如果 url 未定義
|
|
|
9850 |
if(params===undefined){
|
| 226 |
liveuser |
9851 |
|
| 3 |
liveuser |
9852 |
//回傳 false
|
|
|
9853 |
return false;
|
| 226 |
liveuser |
9854 |
|
| 3 |
liveuser |
9855 |
}//if end
|
| 226 |
liveuser |
9856 |
|
| 3 |
liveuser |
9857 |
//如果 url 未定義
|
|
|
9858 |
if(params.url===undefined){
|
| 226 |
liveuser |
9859 |
|
| 3 |
liveuser |
9860 |
//初始化為 https://www.google.com
|
|
|
9861 |
this.url='https://www.google.com';
|
| 226 |
liveuser |
9862 |
|
| 3 |
liveuser |
9863 |
}//if end
|
| 226 |
liveuser |
9864 |
|
| 3 |
liveuser |
9865 |
//反之
|
|
|
9866 |
else{
|
|
|
9867 |
//設置 url
|
|
|
9868 |
this.url=params.url;
|
| 226 |
liveuser |
9869 |
|
| 3 |
liveuser |
9870 |
}//else end
|
| 226 |
liveuser |
9871 |
|
| 3 |
liveuser |
9872 |
//如果 timeout 未定義
|
|
|
9873 |
if(params.timeout===undefined){
|
| 226 |
liveuser |
9874 |
|
| 3 |
liveuser |
9875 |
//初始化為1秒鐘
|
|
|
9876 |
this.timeout=1000;
|
| 226 |
liveuser |
9877 |
|
| 3 |
liveuser |
9878 |
}//if end
|
| 226 |
liveuser |
9879 |
|
| 3 |
liveuser |
9880 |
//反之
|
|
|
9881 |
else{
|
| 226 |
liveuser |
9882 |
|
| 3 |
liveuser |
9883 |
//設置 timeout
|
|
|
9884 |
this.timeout=params.timeout;
|
| 226 |
liveuser |
9885 |
|
| 3 |
liveuser |
9886 |
}//else end
|
| 226 |
liveuser |
9887 |
|
| 3 |
liveuser |
9888 |
//如果 callback 未定義
|
|
|
9889 |
if(params.callback===undefined){
|
| 226 |
liveuser |
9890 |
|
| 3 |
liveuser |
9891 |
//初始化 callback
|
|
|
9892 |
this.callback=function(res){
|
| 226 |
liveuser |
9893 |
|
| 3 |
liveuser |
9894 |
console.log(res);
|
| 226 |
liveuser |
9895 |
|
| 3 |
liveuser |
9896 |
}//function end
|
| 226 |
liveuser |
9897 |
|
| 3 |
liveuser |
9898 |
}//if end
|
| 226 |
liveuser |
9899 |
|
| 3 |
liveuser |
9900 |
//反之
|
|
|
9901 |
else{
|
| 226 |
liveuser |
9902 |
|
| 3 |
liveuser |
9903 |
//設置 callback
|
|
|
9904 |
this.callback=params.callback;
|
| 226 |
liveuser |
9905 |
|
| 3 |
liveuser |
9906 |
}//else end
|
| 226 |
liveuser |
9907 |
|
| 3 |
liveuser |
9908 |
//預設尚未偵測完成 params.url 的服務狀況
|
|
|
9909 |
this.detectServiceFin=false;
|
| 226 |
liveuser |
9910 |
|
| 3 |
liveuser |
9911 |
//預設 params.url 的服務狀況為正常
|
|
|
9912 |
this.serviceBlock=false;
|
| 226 |
liveuser |
9913 |
|
| 3 |
liveuser |
9914 |
//儲存timeout物件
|
|
|
9915 |
this.checkServiceBlockTimeout={};
|
| 226 |
liveuser |
9916 |
|
| 3 |
liveuser |
9917 |
/*
|
|
|
9918 |
說明:
|
|
|
9919 |
傳送ajax,指定傳送前要做什麼事情,傳送後要做什麼事情.
|
|
|
9920 |
參數:
|
|
|
9921 |
params={};
|
|
|
9922 |
params.method='POST' or 'GET' or 'HEAD' or 'OPTIONS';
|
|
|
9923 |
params.headers={name:value};
|
|
|
9924 |
params.url='url to request';
|
|
|
9925 |
params.resType='json';
|
|
|
9926 |
params.preAc='function name to call before send request';
|
|
|
9927 |
params.aftAc='function name to call after send request';
|
|
|
9928 |
params.data='data to contain','key1=encodeURIComponent(val1)&key2=encodeURIComponent(val2)';if no data please use {};
|
|
|
9929 |
*/
|
|
|
9930 |
var params={};
|
|
|
9931 |
params.timeout=this.timeout;
|
|
|
9932 |
params.detectServiceFin=this.detectServiceFin;
|
|
|
9933 |
params.serviceBlock=this.serviceBlock;
|
|
|
9934 |
params.checkServiceBlockTimeout=this.checkServiceBlockTimeout;
|
|
|
9935 |
params.callback=this.callback;
|
|
|
9936 |
params.method='GET';
|
|
|
9937 |
params.data={};
|
|
|
9938 |
params.url=this.url;
|
|
|
9939 |
params.preAc=function(){
|
| 226 |
liveuser |
9940 |
|
| 3 |
liveuser |
9941 |
//取得 xmlhttp物件
|
|
|
9942 |
var xmlhttp=this;
|
| 226 |
liveuser |
9943 |
|
| 3 |
liveuser |
9944 |
//設置過了 params.timeout 秒中後要做的事情.
|
|
|
9945 |
params.checkServiceBlockTimeout=setTimeout(function(){
|
| 226 |
liveuser |
9946 |
|
| 3 |
liveuser |
9947 |
//中斷連線
|
|
|
9948 |
xmlhttp.abort();
|
| 226 |
liveuser |
9949 |
|
| 3 |
liveuser |
9950 |
//提示目標被封鎖了
|
|
|
9951 |
console.log(params.url+' is blocked');
|
| 226 |
liveuser |
9952 |
|
| 3 |
liveuser |
9953 |
//設置服務不正常,被阻擋了
|
|
|
9954 |
params.serviceBlock=true;
|
| 226 |
liveuser |
9955 |
|
| 3 |
liveuser |
9956 |
//設置偵測google連線完畢
|
|
|
9957 |
params.detectServiceFin=true;
|
| 226 |
liveuser |
9958 |
|
| 3 |
liveuser |
9959 |
},params.timeout,xmlhttp);
|
| 226 |
liveuser |
9960 |
|
| 3 |
liveuser |
9961 |
}
|
|
|
9962 |
params.aftAc=function(res){
|
| 226 |
liveuser |
9963 |
|
| 3 |
liveuser |
9964 |
//debug
|
|
|
9965 |
console.log('res='+res);
|
| 226 |
liveuser |
9966 |
|
| 3 |
liveuser |
9967 |
//清除 timeout 的 flag
|
|
|
9968 |
clearTimeout(params.checkServiceBlockTimeout);
|
| 226 |
liveuser |
9969 |
|
| 3 |
liveuser |
9970 |
//設置偵測google連線完畢
|
|
|
9971 |
params.detectServiceFin=true;
|
| 226 |
liveuser |
9972 |
|
| 3 |
liveuser |
9973 |
}
|
|
|
9974 |
window.qbpwcf.ajax(params);
|
| 226 |
liveuser |
9975 |
|
| 3 |
liveuser |
9976 |
//設置無限等待
|
|
|
9977 |
var intervalTail = window.setInterval(function(){
|
| 226 |
liveuser |
9978 |
|
| 3 |
liveuser |
9979 |
//如果已經偵測好google的連線狀況
|
|
|
9980 |
if(params.detectServiceFin){
|
| 226 |
liveuser |
9981 |
|
| 3 |
liveuser |
9982 |
//清除無限等待
|
|
|
9983 |
clearInterval(intervalTail);
|
| 226 |
liveuser |
9984 |
|
| 3 |
liveuser |
9985 |
console.log(params.callback);
|
| 226 |
liveuser |
9986 |
|
| 3 |
liveuser |
9987 |
//如果存在要callback的函式
|
|
|
9988 |
if(params.callback!==undefined){
|
| 226 |
liveuser |
9989 |
|
| 3 |
liveuser |
9990 |
//debug
|
|
|
9991 |
console.log('beafore callback');
|
| 226 |
liveuser |
9992 |
|
| 3 |
liveuser |
9993 |
//callback
|
|
|
9994 |
params.callback.call(this,params.serviceBlock);
|
| 226 |
liveuser |
9995 |
|
| 3 |
liveuser |
9996 |
}//if end
|
| 226 |
liveuser |
9997 |
|
| 3 |
liveuser |
9998 |
}//if end
|
| 226 |
liveuser |
9999 |
|
| 3 |
liveuser |
10000 |
},100);
|
| 226 |
liveuser |
10001 |
|
| 3 |
liveuser |
10002 |
}//function window.qbpwcf.connectable end
|
|
|
10003 |
";
|
| 226 |
liveuser |
10004 |
|
| 3 |
liveuser |
10005 |
#js function
|
|
|
10006 |
$conf["javaScript::toScript"]["jsFunciton"][]=
|
|
|
10007 |
"
|
|
|
10008 |
/*
|
|
|
10009 |
說明:
|
|
|
10010 |
設置網頁要套用的字形.
|
|
|
10011 |
參數:
|
| 207 |
liveuser |
10012 |
window.qbpwcf.fonts.bufferArray,預設的字形檔案binary.
|
|
|
10013 |
await window.qbpwcf.fonts.load(),將指定的字形套用在body.
|
| 3 |
liveuser |
10014 |
參考資料:
|
|
|
10015 |
https://developer.mozilla.org/en-US/docs/Web/API/FontFace
|
|
|
10016 |
https://developer.mozilla.org/en-US/docs/Web/API/FontFace/FontFace
|
|
|
10017 |
https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face => 直接用 CSS 下載字形
|
|
|
10018 |
https://fontlibrary.org/ => 免費字體下載
|
|
|
10019 |
https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet => CSS 樣式 in Javascript
|
|
|
10020 |
https://developer.mozilla.org/en-US/docs/Web/API/Document/styleSheets => 取得 CSS 樣式集合
|
|
|
10021 |
https://developer.mozilla.org/en-US/docs/Web/API/StyleSheet
|
|
|
10022 |
https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet
|
|
|
10023 |
https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet/insertRule => 新增 css 樣式
|
| 207 |
liveuser |
10024 |
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer => ArrayBuffer
|
|
|
10025 |
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/fromBase64 => bytes array from base64 encode string
|
|
|
10026 |
#備註:
|
|
|
10027 |
#server必須要有該字形.
|
| 3 |
liveuser |
10028 |
*/
|
|
|
10029 |
window.qbpwcf.fonts={};
|
| 226 |
liveuser |
10030 |
|
| 207 |
liveuser |
10031 |
//default font binary
|
|
|
10032 |
window.qbpwcf.fonts.bufferArray=new ArrayBuffer();
|
| 226 |
liveuser |
10033 |
|
| 3 |
liveuser |
10034 |
//load font function
|
| 207 |
liveuser |
10035 |
window.qbpwcf.fonts.load=async function(){
|
| 226 |
liveuser |
10036 |
|
| 3 |
liveuser |
10037 |
//建立font物件
|
| 207 |
liveuser |
10038 |
var font = new FontFace('qbpwcfFont', window.qbpwcf.fonts.bufferArray);
|
| 226 |
liveuser |
10039 |
|
| 3 |
liveuser |
10040 |
//告訴瀏覽器載入字形,並等待其執行完再往下執行
|
|
|
10041 |
//因為 FontFace 類別的 load 方法回傳為 Promise ,因此要等待其回傳結果所以要用 await 關鍵字.
|
|
|
10042 |
await font.load();
|
| 226 |
liveuser |
10043 |
|
| 3 |
liveuser |
10044 |
//新增字形到網頁文件
|
|
|
10045 |
document.fonts.add(font);
|
| 226 |
liveuser |
10046 |
|
| 3 |
liveuser |
10047 |
//新增 qbpwcfFont 類別的網頁字形
|
|
|
10048 |
document.styleSheets[0].insertRule("."'.qbpwcfFont {font-family:qbpwcfFont;}'".");
|
| 226 |
liveuser |
10049 |
|
| 3 |
liveuser |
10050 |
//避免重複新增class,先移除之
|
|
|
10051 |
document.body.classList.remove('qbpwcfFont');
|
| 226 |
liveuser |
10052 |
|
| 3 |
liveuser |
10053 |
//套用字形
|
|
|
10054 |
document.body.classList.add('qbpwcfFont');
|
| 226 |
liveuser |
10055 |
|
| 207 |
liveuser |
10056 |
}//function end
|
| 226 |
liveuser |
10057 |
|
| 3 |
liveuser |
10058 |
//list aviable fonts
|
| 207 |
liveuser |
10059 |
window.qbpwcf.fonts.list=function(){
|
| 226 |
liveuser |
10060 |
|
| 3 |
liveuser |
10061 |
//開發中
|
|
|
10062 |
console.log('list fonts');
|
| 226 |
liveuser |
10063 |
|
| 207 |
liveuser |
10064 |
}//function end
|
| 3 |
liveuser |
10065 |
|
|
|
10066 |
";
|
| 226 |
liveuser |
10067 |
|
| 3 |
liveuser |
10068 |
#js function
|
|
|
10069 |
$conf["javaScript::toScript"]["jsFunciton"][]=
|
|
|
10070 |
"
|
|
|
10071 |
//記錄點擊當下的用戶資訊
|
|
|
10072 |
window.qbpwcf.recordClientInfo=function(){
|
| 226 |
liveuser |
10073 |
|
| 3 |
liveuser |
10074 |
console.log('建構中');
|
| 226 |
liveuser |
10075 |
|
| 3 |
liveuser |
10076 |
}//function end
|
|
|
10077 |
";
|
| 226 |
liveuser |
10078 |
|
| 3 |
liveuser |
10079 |
#js function
|
|
|
10080 |
$conf["javaScript::toScript"]["jsFunciton"][]=
|
|
|
10081 |
"
|
|
|
10082 |
/*
|
|
|
10083 |
說明:
|
|
|
10084 |
解析cookie資料
|
|
|
10085 |
*/
|
|
|
10086 |
window.qbpwcf.cookie={};
|
| 226 |
liveuser |
10087 |
|
| 3 |
liveuser |
10088 |
//記錄原始cookie
|
|
|
10089 |
window.qbpwcf.cookie.ori=document.cookie;
|
| 226 |
liveuser |
10090 |
|
| 3 |
liveuser |
10091 |
//如果有 cookie 存在
|
|
|
10092 |
if(window.qbpwcf.cookie.ori!=''){
|
| 226 |
liveuser |
10093 |
|
| 3 |
liveuser |
10094 |
//記錄cookie的數量
|
|
|
10095 |
window.qbpwcf.cookie.count=document.cookie.split(';').length;
|
| 226 |
liveuser |
10096 |
|
| 3 |
liveuser |
10097 |
//初始化用名稱來記錄cookie的內容
|
|
|
10098 |
window.qbpwcf.cookie.byName={};
|
| 226 |
liveuser |
10099 |
|
| 3 |
liveuser |
10100 |
//有幾個cookie就執行幾次
|
|
|
10101 |
for(var i=0;i<window.qbpwcf.cookie.count;i++){
|
| 226 |
liveuser |
10102 |
|
| 3 |
liveuser |
10103 |
//取得cookie
|
|
|
10104 |
var cookieStr=document.cookie.split(';')[i];
|
| 226 |
liveuser |
10105 |
|
| 3 |
liveuser |
10106 |
//取得cookie名稱
|
|
|
10107 |
var cookieName=cookieStr.split('=')[0];
|
| 226 |
liveuser |
10108 |
|
| 3 |
liveuser |
10109 |
//取得cookie內容
|
|
|
10110 |
var cookieValue=cookieStr.split('=')[1];
|
| 226 |
liveuser |
10111 |
|
| 3 |
liveuser |
10112 |
//記錄coockie
|
|
|
10113 |
eval('window.qbpwcf.cookie.byName[\''+cookieName+'\']=cookieValue');
|
| 226 |
liveuser |
10114 |
|
| 3 |
liveuser |
10115 |
//如果有經過編碼
|
|
|
10116 |
if(cookieValue!==decodeURIComponent(cookieValue)){
|
| 226 |
liveuser |
10117 |
|
| 3 |
liveuser |
10118 |
/*
|
|
|
10119 |
設置 window.qbpwcf.ajax 函數
|
|
|
10120 |
說明:
|
|
|
10121 |
傳送ajax,指定傳送前要做什麼事情,傳送後要做什麼事情.
|
|
|
10122 |
參數:
|
|
|
10123 |
params={};
|
|
|
10124 |
params.method='POST' or 'GET' or 'HEAD' or 'OPTIONS';
|
|
|
10125 |
params.headers={name:value};
|
|
|
10126 |
params.url='url to request';
|
|
|
10127 |
params.resType='json';
|
|
|
10128 |
params.preAc='function name to call before send request';
|
|
|
10129 |
params.aftAc='function name to call after send request,default params is data to send';
|
|
|
10130 |
params.data='data to contain','key1=encodeURIComponent(val1)&key2=encodeURIComponent(val2)';if no data please use {};
|
|
|
10131 |
*/
|
|
|
10132 |
params={};
|
|
|
10133 |
params.method='POST';
|
|
|
10134 |
params.url='/qbpwcf/unserialize/';
|
| 226 |
liveuser |
10135 |
|
| 3 |
liveuser |
10136 |
//帶入 cookieName
|
| 226 |
liveuser |
10137 |
params.cookieName=cookieName;
|
|
|
10138 |
|
| 3 |
liveuser |
10139 |
params.aftAc=function(res){
|
|
|
10140 |
|
| 226 |
liveuser |
10141 |
//如果有json回應
|
| 3 |
liveuser |
10142 |
if(res!==null){
|
|
|
10143 |
|
|
|
10144 |
//取得cookie解析後的結果
|
|
|
10145 |
eval('window.qbpwcf.cookie.byName.'+params.cookieName+'=res');
|
| 226 |
liveuser |
10146 |
|
| 3 |
liveuser |
10147 |
}//if end
|
| 226 |
liveuser |
10148 |
|
| 3 |
liveuser |
10149 |
};
|
| 226 |
liveuser |
10150 |
|
| 3 |
liveuser |
10151 |
params.data='data='+cookieValue;
|
|
|
10152 |
window.qbpwcf.ajax.call(this,params);
|
| 226 |
liveuser |
10153 |
|
| 3 |
liveuser |
10154 |
}//if end
|
|
|
10155 |
|
|
|
10156 |
}//for end
|
| 226 |
liveuser |
10157 |
|
| 3 |
liveuser |
10158 |
}//if end
|
| 226 |
liveuser |
10159 |
|
| 3 |
liveuser |
10160 |
";
|
| 226 |
liveuser |
10161 |
|
| 3 |
liveuser |
10162 |
#js function
|
|
|
10163 |
$conf["javaScript::toScript"]["jsFunciton"][]=
|
|
|
10164 |
"
|
|
|
10165 |
/*
|
|
|
10166 |
說明:
|
|
|
10167 |
dialog,類似modal的方法.
|
|
|
10168 |
*/
|
|
|
10169 |
window.qbpwcf.dialog={};
|
| 226 |
liveuser |
10170 |
|
| 3 |
liveuser |
10171 |
/*
|
|
|
10172 |
用dialog確認要做的事情
|
|
|
10173 |
*/
|
|
|
10174 |
//初始化儲存 confirm dialog 物件
|
|
|
10175 |
window.qbpwcf.dialog.confirm={};
|
| 226 |
liveuser |
10176 |
|
| 3 |
liveuser |
10177 |
//初始化相關屬性
|
|
|
10178 |
window.qbpwcf.dialog.confirm.clear=function(){
|
| 226 |
liveuser |
10179 |
|
| 3 |
liveuser |
10180 |
//初始化儲存 confirm dialog 的實體
|
|
|
10181 |
window.qbpwcf.dialog.confirm.instance=null;
|
| 226 |
liveuser |
10182 |
|
| 3 |
liveuser |
10183 |
//初始化儲存 confirm dialog 結束後取得的內容
|
|
|
10184 |
window.qbpwcf.dialog.confirm.result={};
|
| 226 |
liveuser |
10185 |
|
| 3 |
liveuser |
10186 |
//初始化儲存 confirm dialog 詢問的內容文字
|
|
|
10187 |
window.qbpwcf.dialog.confirm.text='Are you sure?';
|
| 226 |
liveuser |
10188 |
|
| 3 |
liveuser |
10189 |
//初始化儲存 confirm dialog 取消按鈕的顯示文字
|
|
|
10190 |
window.qbpwcf.dialog.confirm.cancelBtnText='Cancel';
|
| 226 |
liveuser |
10191 |
|
| 3 |
liveuser |
10192 |
//初始化儲存 confirm dialog 確定按鈕的顯示文字
|
|
|
10193 |
window.qbpwcf.dialog.confirm.okBtnText='Confirm';
|
| 226 |
liveuser |
10194 |
|
| 3 |
liveuser |
10195 |
//初始化 confirm dialog 的內容
|
|
|
10196 |
window.qbpwcf.dialog.confirm.content='';
|
| 226 |
liveuser |
10197 |
|
| 3 |
liveuser |
10198 |
//初始化 confirm dialog 的 dom 內容
|
|
|
10199 |
window.qbpwcf.dialog.confirm.customDom={};
|
| 226 |
liveuser |
10200 |
|
| 3 |
liveuser |
10201 |
}//function end
|
|
|
10202 |
|
|
|
10203 |
//立刻初始化相關屬性
|
|
|
10204 |
window.qbpwcf.dialog.confirm.clear();
|
| 226 |
liveuser |
10205 |
|
| 3 |
liveuser |
10206 |
//初始化設置好 confirm dialog 後要觸發的函式
|
|
|
10207 |
window.qbpwcf.dialog.confirm.prepareCallback=function(){
|
| 226 |
liveuser |
10208 |
|
| 3 |
liveuser |
10209 |
//取得 cancel 的按鈕
|
|
|
10210 |
var cancel_btn=document.querySelector('button#dialog_cancel_btn');
|
| 226 |
liveuser |
10211 |
|
| 3 |
liveuser |
10212 |
//按鈕的事件
|
|
|
10213 |
cancel_btn.addEventListener('click',function(){
|
| 226 |
liveuser |
10214 |
|
| 3 |
liveuser |
10215 |
//設置結果為 'false'
|
|
|
10216 |
window.qbpwcf.dialog.confirm.result='false';
|
| 226 |
liveuser |
10217 |
|
| 3 |
liveuser |
10218 |
//關閉dialog
|
|
|
10219 |
window.qbpwcf.dialog.confirm.instance.close();
|
| 226 |
liveuser |
10220 |
|
| 3 |
liveuser |
10221 |
});
|
| 226 |
liveuser |
10222 |
|
| 3 |
liveuser |
10223 |
//取得 confirm 的按鈕
|
|
|
10224 |
var confirm_btn=document.querySelector('button#dialog_confirm_btn');
|
| 226 |
liveuser |
10225 |
|
| 3 |
liveuser |
10226 |
//按鈕的事件
|
|
|
10227 |
confirm_btn.addEventListener('click',function(){
|
| 226 |
liveuser |
10228 |
|
| 3 |
liveuser |
10229 |
//設置結果為 'true'
|
|
|
10230 |
window.qbpwcf.dialog.confirm.result='true';
|
| 226 |
liveuser |
10231 |
|
| 3 |
liveuser |
10232 |
//關閉dialog
|
|
|
10233 |
window.qbpwcf.dialog.confirm.instance.close();
|
| 226 |
liveuser |
10234 |
|
| 3 |
liveuser |
10235 |
});
|
| 226 |
liveuser |
10236 |
|
| 3 |
liveuser |
10237 |
}//function end
|
| 226 |
liveuser |
10238 |
|
| 3 |
liveuser |
10239 |
/*
|
|
|
10240 |
初始化關閉 confirm dialog 後要觸發的函式
|
|
|
10241 |
params為取得的內容結果.
|
|
|
10242 |
*/
|
|
|
10243 |
window.qbpwcf.dialog.confirm.closeCallback=function(params){
|
| 226 |
liveuser |
10244 |
|
| 3 |
liveuser |
10245 |
//debug
|
|
|
10246 |
console.log(params);
|
| 226 |
liveuser |
10247 |
|
| 3 |
liveuser |
10248 |
}//fucntion end
|
| 226 |
liveuser |
10249 |
|
| 3 |
liveuser |
10250 |
//顯示 confirm dialog
|
|
|
10251 |
window.qbpwcf.dialog.confirm.func=function(){
|
| 226 |
liveuser |
10252 |
|
| 3 |
liveuser |
10253 |
//回傳 Promise
|
|
|
10254 |
return new Promise(function(resolve, reject){
|
| 226 |
liveuser |
10255 |
|
| 3 |
liveuser |
10256 |
//建立dialog物件
|
|
|
10257 |
var dialog=document.createElement('dialog');
|
| 226 |
liveuser |
10258 |
|
| 3 |
liveuser |
10259 |
//取得參考
|
|
|
10260 |
window.qbpwcf.dialog.confirm.instance=dialog;
|
| 226 |
liveuser |
10261 |
|
| 3 |
liveuser |
10262 |
//dialog的確認內容
|
|
|
10263 |
var dialogConfirmText=document.createTextNode(window.qbpwcf.dialog.confirm.text);
|
| 226 |
liveuser |
10264 |
|
| 3 |
liveuser |
10265 |
//建立放置按鈕的div
|
|
|
10266 |
var divDialogButton=document.createElement('div');
|
| 226 |
liveuser |
10267 |
|
| 3 |
liveuser |
10268 |
//建立放置取消按鈕的span
|
|
|
10269 |
var spanCancelButton=document.createElement('span');
|
| 226 |
liveuser |
10270 |
|
| 3 |
liveuser |
10271 |
//設置取消按鈕靠左對齊
|
|
|
10272 |
spanCancelButton.style.float='left';
|
| 226 |
liveuser |
10273 |
|
| 3 |
liveuser |
10274 |
//建立dialog cancel按鈕
|
|
|
10275 |
var buttonDialogCancel=document.createElement('button');
|
| 226 |
liveuser |
10276 |
|
| 3 |
liveuser |
10277 |
//設置dialog cancel按鈕的id
|
|
|
10278 |
buttonDialogCancel.id='dialog_cancel_btn';
|
| 226 |
liveuser |
10279 |
|
| 3 |
liveuser |
10280 |
//設置dialog cancel按鈕的文字內容
|
|
|
10281 |
buttonDialogCancel.innerText=window.qbpwcf.dialog.confirm.cancelBtnText;
|
| 226 |
liveuser |
10282 |
|
| 3 |
liveuser |
10283 |
//將取消按鈕放置到span
|
|
|
10284 |
spanCancelButton.appendChild(buttonDialogCancel);
|
| 226 |
liveuser |
10285 |
|
| 3 |
liveuser |
10286 |
//放置取消按鈕span到div
|
|
|
10287 |
divDialogButton.append(spanCancelButton);
|
| 226 |
liveuser |
10288 |
|
| 3 |
liveuser |
10289 |
//建立放置確認按鈕的span
|
|
|
10290 |
var spanConfirmButton=document.createElement('span');
|
| 226 |
liveuser |
10291 |
|
| 3 |
liveuser |
10292 |
//設置確認按鈕靠右對齊
|
|
|
10293 |
spanConfirmButton.style.float='right';
|
| 226 |
liveuser |
10294 |
|
| 3 |
liveuser |
10295 |
//建立dialog confirm按鈕
|
|
|
10296 |
var buttonDialogConfirm=document.createElement('button');
|
| 226 |
liveuser |
10297 |
|
| 3 |
liveuser |
10298 |
//設置dialog confirm按鈕的id
|
|
|
10299 |
buttonDialogConfirm.id='dialog_confirm_btn';
|
| 226 |
liveuser |
10300 |
|
| 3 |
liveuser |
10301 |
//設置dialog confirm按鈕的文字內容
|
|
|
10302 |
buttonDialogConfirm.innerText=window.qbpwcf.dialog.confirm.okBtnText;
|
| 226 |
liveuser |
10303 |
|
| 3 |
liveuser |
10304 |
//將確認鈕放置到span
|
|
|
10305 |
spanConfirmButton.appendChild(buttonDialogConfirm);
|
| 226 |
liveuser |
10306 |
|
| 3 |
liveuser |
10307 |
//放置確認按鈕span到div
|
|
|
10308 |
divDialogButton.append(spanConfirmButton);
|
| 226 |
liveuser |
10309 |
|
| 3 |
liveuser |
10310 |
//建立要作為dialog內容的div
|
|
|
10311 |
var divDialogConent=document.createElement('div');
|
| 226 |
liveuser |
10312 |
|
| 3 |
liveuser |
10313 |
//建立dialog確認內容的div
|
|
|
10314 |
var divDialogConfrimText=document.createElement('div');
|
| 226 |
liveuser |
10315 |
|
| 3 |
liveuser |
10316 |
//設置dialog確認內容的文字要置中
|
|
|
10317 |
divDialogConfrimText.style.textAlign='center';
|
| 226 |
liveuser |
10318 |
|
| 3 |
liveuser |
10319 |
//設置dialog確認內容的文字
|
|
|
10320 |
divDialogConfrimText.appendChild(dialogConfirmText);
|
| 226 |
liveuser |
10321 |
|
| 3 |
liveuser |
10322 |
//放置dialog的確認內容
|
|
|
10323 |
divDialogConent.appendChild(divDialogConfrimText);
|
| 226 |
liveuser |
10324 |
|
| 3 |
liveuser |
10325 |
//放置dialog的按鈕
|
|
|
10326 |
divDialogConent.appendChild(divDialogButton);
|
| 226 |
liveuser |
10327 |
|
| 3 |
liveuser |
10328 |
//如果有指定 dom 內容
|
|
|
10329 |
if(window.qbpwcf.dialog.confirm.customDom.outerHTML!=undefined){
|
| 226 |
liveuser |
10330 |
|
| 3 |
liveuser |
10331 |
//建立 div
|
|
|
10332 |
var div=document.createElement('div');
|
| 226 |
liveuser |
10333 |
|
| 3 |
liveuser |
10334 |
//將dom放置到div裡面
|
|
|
10335 |
div.appendChild(window.qbpwcf.dialog.confirm.customDom);
|
| 226 |
liveuser |
10336 |
|
| 3 |
liveuser |
10337 |
//設置 div dom 內容在前
|
|
|
10338 |
divDialogConent.prepend(div);
|
| 226 |
liveuser |
10339 |
|
| 3 |
liveuser |
10340 |
}//if end
|
| 226 |
liveuser |
10341 |
|
| 3 |
liveuser |
10342 |
//更新 confirm dialog 的內容
|
|
|
10343 |
window.qbpwcf.dialog.confirm.content=divDialogConent;
|
| 226 |
liveuser |
10344 |
|
| 3 |
liveuser |
10345 |
//設置dialog的內容
|
|
|
10346 |
dialog.appendChild(window.qbpwcf.dialog.confirm.content);
|
| 226 |
liveuser |
10347 |
|
| 3 |
liveuser |
10348 |
//設置id
|
|
|
10349 |
dialog.id='qbpwcf_dialog';
|
| 226 |
liveuser |
10350 |
|
| 3 |
liveuser |
10351 |
//放置dialog
|
|
|
10352 |
document.body.appendChild(dialog);
|
| 226 |
liveuser |
10353 |
|
| 3 |
liveuser |
10354 |
//呼叫 window.qbpwcf.dialog.confirm.prepareCallback
|
|
|
10355 |
window.qbpwcf.dialog.confirm.prepareCallback.call(this);
|
| 226 |
liveuser |
10356 |
|
| 3 |
liveuser |
10357 |
//取得dialog
|
|
|
10358 |
var qbpwcf_dialog=document.querySelector('dialog#qbpwcf_dialog');
|
| 226 |
liveuser |
10359 |
|
| 3 |
liveuser |
10360 |
//顯示modal
|
|
|
10361 |
qbpwcf_dialog.showModal();
|
| 226 |
liveuser |
10362 |
|
| 3 |
liveuser |
10363 |
//當dialog關閉時觸發
|
|
|
10364 |
qbpwcf_dialog.addEventListener('close',function(event){
|
| 226 |
liveuser |
10365 |
|
| 3 |
liveuser |
10366 |
//取得dialog回傳的結果
|
|
|
10367 |
var result=window.qbpwcf.dialog.confirm.result;
|
| 226 |
liveuser |
10368 |
|
| 3 |
liveuser |
10369 |
//將回傳結果交給函式 window.qbpwcf.dialog.confirm.callback處理
|
|
|
10370 |
window.qbpwcf.dialog.confirm.closeCallback.call(this,result);
|
| 226 |
liveuser |
10371 |
|
| 3 |
liveuser |
10372 |
//回傳結果給Promise
|
|
|
10373 |
resolve(result);
|
| 226 |
liveuser |
10374 |
|
| 3 |
liveuser |
10375 |
//移除dialog元素
|
|
|
10376 |
qbpwcf_dialog.remove();
|
| 226 |
liveuser |
10377 |
|
| 3 |
liveuser |
10378 |
});
|
| 226 |
liveuser |
10379 |
|
| 3 |
liveuser |
10380 |
});
|
| 226 |
liveuser |
10381 |
|
| 3 |
liveuser |
10382 |
}//function end
|
| 226 |
liveuser |
10383 |
|
| 3 |
liveuser |
10384 |
/*
|
|
|
10385 |
用dialog取得密碼.
|
|
|
10386 |
*/
|
|
|
10387 |
//初始化儲存 getPassword dialog 的物件
|
|
|
10388 |
window.qbpwcf.dialog.getPassword={};
|
| 226 |
liveuser |
10389 |
|
| 3 |
liveuser |
10390 |
//初始化儲存 getPassword dialog 的實體
|
|
|
10391 |
window.qbpwcf.dialog.getPassword.instance=null;
|
| 226 |
liveuser |
10392 |
|
| 3 |
liveuser |
10393 |
//初始化儲存 getPassword dialog 結束後取得的內容
|
|
|
10394 |
window.qbpwcf.dialog.getPassword.result={};
|
| 226 |
liveuser |
10395 |
|
| 3 |
liveuser |
10396 |
//初始化儲存 getPassword dialog 確認輸入的按鈕顯示文字
|
|
|
10397 |
window.qbpwcf.dialog.getPassword.text='Next';
|
| 226 |
liveuser |
10398 |
|
| 3 |
liveuser |
10399 |
//初始化getPassword dialog的內容
|
|
|
10400 |
window.qbpwcf.dialog.getPassword.content='';
|
| 226 |
liveuser |
10401 |
|
| 3 |
liveuser |
10402 |
//初始化設置好getPassword dialog內容要觸發的函式
|
|
|
10403 |
window.qbpwcf.dialog.getPassword.prepareCallback=function(){
|
| 226 |
liveuser |
10404 |
|
| 3 |
liveuser |
10405 |
//取得輸入的密碼
|
|
|
10406 |
var password=document.querySelector('input#dialog_pass');
|
| 226 |
liveuser |
10407 |
|
| 3 |
liveuser |
10408 |
//如果輸入內容改變
|
|
|
10409 |
password.addEventListener('change',function(){
|
| 226 |
liveuser |
10410 |
|
| 3 |
liveuser |
10411 |
//儲存輸入的密碼
|
|
|
10412 |
window.qbpwcf.dialog.getPassword.result=password.value;
|
| 226 |
liveuser |
10413 |
|
| 3 |
liveuser |
10414 |
});
|
| 226 |
liveuser |
10415 |
|
| 3 |
liveuser |
10416 |
//取得關閉的按鈕
|
|
|
10417 |
var closeBtn=document.querySelector('button#dialog_btn');
|
| 226 |
liveuser |
10418 |
|
| 3 |
liveuser |
10419 |
//關閉按鈕的事件
|
|
|
10420 |
closeBtn.addEventListener('click',function(){
|
| 226 |
liveuser |
10421 |
|
| 3 |
liveuser |
10422 |
//關閉dialog
|
|
|
10423 |
window.qbpwcf.dialog.getPassword.instance.close();
|
| 226 |
liveuser |
10424 |
|
| 3 |
liveuser |
10425 |
});
|
| 226 |
liveuser |
10426 |
|
| 3 |
liveuser |
10427 |
}//function end
|
| 226 |
liveuser |
10428 |
|
| 3 |
liveuser |
10429 |
/*
|
|
|
10430 |
初始化關閉getPassword dialog後要觸發的函式
|
|
|
10431 |
params為取得的內容結果.
|
|
|
10432 |
*/
|
|
|
10433 |
window.qbpwcf.dialog.getPassword.closeCallback=function(params){
|
| 226 |
liveuser |
10434 |
|
| 3 |
liveuser |
10435 |
//debug
|
|
|
10436 |
console.log(params);
|
| 226 |
liveuser |
10437 |
|
| 3 |
liveuser |
10438 |
}//fucntion end
|
| 226 |
liveuser |
10439 |
|
| 3 |
liveuser |
10440 |
//顯示 getPassword dialog
|
|
|
10441 |
window.qbpwcf.dialog.getPassword.func=function(){
|
| 226 |
liveuser |
10442 |
|
| 3 |
liveuser |
10443 |
//建立dialog物件
|
|
|
10444 |
var dialog=document.createElement('dialog');
|
| 226 |
liveuser |
10445 |
|
| 3 |
liveuser |
10446 |
//取得參考
|
|
|
10447 |
window.qbpwcf.dialog.getPassword.instance=dialog;
|
| 226 |
liveuser |
10448 |
|
| 3 |
liveuser |
10449 |
//更新 dialog 的內容
|
|
|
10450 |
window.qbpwcf.dialog.getPassword.content='<input type=\'password\' value=\'\' autocomplete=\'off\' id=\'dialog_pass\'><button id=\'dialog_btn\'>'+window.qbpwcf.dialog.getPassword.text+'</button>';
|
| 226 |
liveuser |
10451 |
|
| 3 |
liveuser |
10452 |
//設置dialog的內容
|
|
|
10453 |
dialog.innerHTML=window.qbpwcf.dialog.getPassword.content;
|
| 226 |
liveuser |
10454 |
|
| 3 |
liveuser |
10455 |
//設置id
|
|
|
10456 |
dialog.id='qbpwcf_dialog';
|
| 226 |
liveuser |
10457 |
|
| 3 |
liveuser |
10458 |
//放置dialog
|
|
|
10459 |
document.body.appendChild(dialog);
|
| 226 |
liveuser |
10460 |
|
| 3 |
liveuser |
10461 |
//呼叫 window.qbpwcf.dialog.getPassword.prepareCallback
|
|
|
10462 |
window.qbpwcf.dialog.getPassword.prepareCallback.call(this);
|
| 226 |
liveuser |
10463 |
|
| 3 |
liveuser |
10464 |
//取得dialog
|
|
|
10465 |
var qbpwcf_dialog=document.querySelector('dialog#qbpwcf_dialog');
|
| 226 |
liveuser |
10466 |
|
| 3 |
liveuser |
10467 |
//顯示modal
|
|
|
10468 |
qbpwcf_dialog.showModal();
|
| 226 |
liveuser |
10469 |
|
| 3 |
liveuser |
10470 |
//當dialog關閉時觸發
|
|
|
10471 |
qbpwcf_dialog.addEventListener('close',function(event){
|
| 226 |
liveuser |
10472 |
|
| 3 |
liveuser |
10473 |
//取得輸入的密碼
|
|
|
10474 |
var password=document.querySelector('input#dialog_pass');
|
| 226 |
liveuser |
10475 |
|
| 3 |
liveuser |
10476 |
//儲存輸入的密碼
|
|
|
10477 |
window.qbpwcf.dialog.getPassword.result=password.value;
|
| 226 |
liveuser |
10478 |
|
| 3 |
liveuser |
10479 |
//取得dialog回傳的結果
|
|
|
10480 |
var result=window.qbpwcf.dialog.getPassword.result;
|
| 226 |
liveuser |
10481 |
|
| 3 |
liveuser |
10482 |
//將回傳結果交給函式 window.qbpwcf.dialog.getPassword.callback處理
|
|
|
10483 |
window.qbpwcf.dialog.getPassword.closeCallback.call(this,result);
|
| 226 |
liveuser |
10484 |
|
| 3 |
liveuser |
10485 |
//移除dialog元素
|
|
|
10486 |
qbpwcf_dialog.remove();
|
| 226 |
liveuser |
10487 |
|
| 3 |
liveuser |
10488 |
});
|
| 226 |
liveuser |
10489 |
|
| 3 |
liveuser |
10490 |
}//function end
|
|
|
10491 |
";
|
| 226 |
liveuser |
10492 |
|
| 3 |
liveuser |
10493 |
#js function
|
|
|
10494 |
$conf["javaScript::toScript"]["jsFunciton"][]=
|
|
|
10495 |
"
|
|
|
10496 |
/*
|
|
|
10497 |
說明:
|
|
|
10498 |
sleep
|
|
|
10499 |
*/
|
| 226 |
liveuser |
10500 |
|
| 3 |
liveuser |
10501 |
//初始化
|
|
|
10502 |
window.qbpwcf.sleep={};
|
| 226 |
liveuser |
10503 |
|
| 3 |
liveuser |
10504 |
//執行的定義
|
|
|
10505 |
//參數sec代表要sleep多久,單位為秒.
|
|
|
10506 |
window.qbpwcf.sleep.func=function(sec){
|
| 226 |
liveuser |
10507 |
|
| 3 |
liveuser |
10508 |
//回傳 Promise
|
|
|
10509 |
return new Promise(resolve => {
|
| 226 |
liveuser |
10510 |
|
| 3 |
liveuser |
10511 |
//sec秒後才會結束
|
|
|
10512 |
setTimeout(() => {
|
| 226 |
liveuser |
10513 |
|
| 3 |
liveuser |
10514 |
resolve(sec);
|
| 226 |
liveuser |
10515 |
|
| 3 |
liveuser |
10516 |
}, sec*1000);
|
| 226 |
liveuser |
10517 |
|
| 3 |
liveuser |
10518 |
});
|
| 226 |
liveuser |
10519 |
|
| 3 |
liveuser |
10520 |
}//window.qbpwcf.sleep.func end
|
|
|
10521 |
";
|
| 226 |
liveuser |
10522 |
|
| 3 |
liveuser |
10523 |
#js function
|
|
|
10524 |
$conf["javaScript::toScript"]["jsFunciton"][]=
|
|
|
10525 |
"
|
|
|
10526 |
/*
|
|
|
10527 |
說明:
|
|
|
10528 |
slide,輪播任何東西.
|
|
|
10529 |
*/
|
| 226 |
liveuser |
10530 |
|
| 3 |
liveuser |
10531 |
//初始化
|
|
|
10532 |
window.qbpwcf.slide={};
|
| 226 |
liveuser |
10533 |
|
| 3 |
liveuser |
10534 |
//初始化要播放的內容 html、css、javaScript 字串.
|
|
|
10535 |
//https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Unterminated_string_literal
|
|
|
10536 |
window.qbpwcf.slide.eles=[];
|
| 226 |
liveuser |
10537 |
|
| 3 |
liveuser |
10538 |
//初始化放置投影片的div區域
|
|
|
10539 |
window.qbpwcf.slide.displayDivByQuerySelector='div#slide';
|
| 226 |
liveuser |
10540 |
|
| 3 |
liveuser |
10541 |
//初始化投影片的滯留時間,預設為3秒,時間到就換下一個投影片.
|
|
|
10542 |
window.qbpwcf.slide.showTime=3;
|
| 226 |
liveuser |
10543 |
|
| 3 |
liveuser |
10544 |
//說明:
|
|
|
10545 |
//將 html、css、javaScript 轉換為 dom
|
|
|
10546 |
//參數:
|
|
|
10547 |
//htmlStr 內容必須有此結構 html > body > div > anyTag(content to show)
|
|
|
10548 |
window.qbpwcf.slide.toDom=function(htmlStr){
|
| 226 |
liveuser |
10549 |
|
| 3 |
liveuser |
10550 |
//回傳 Promise
|
|
|
10551 |
return new Promise(resolve => {
|
| 226 |
liveuser |
10552 |
|
| 3 |
liveuser |
10553 |
//debug
|
|
|
10554 |
//console.log(htmlStr);
|
| 226 |
liveuser |
10555 |
|
| 3 |
liveuser |
10556 |
//initial DOMParser
|
|
|
10557 |
var domParser = new DOMParser();
|
| 226 |
liveuser |
10558 |
|
| 3 |
liveuser |
10559 |
//確保內容格式正確,若為影片,則播放結束後才會結束.
|
| 226 |
liveuser |
10560 |
|
| 3 |
liveuser |
10561 |
//script start
|
|
|
10562 |
htmlStr=htmlStr+'\<script\>';
|
| 226 |
liveuser |
10563 |
|
| 3 |
liveuser |
10564 |
//綁定 load 事件
|
|
|
10565 |
htmlStr=htmlStr+'window.addEventListener(\'load\',function(event){';
|
| 226 |
liveuser |
10566 |
|
| 3 |
liveuser |
10567 |
//debug
|
|
|
10568 |
//htmlStr=htmlStr+'console.log(document.querySelector(\'div\'));';
|
| 226 |
liveuser |
10569 |
|
| 3 |
liveuser |
10570 |
//取得第一個div
|
|
|
10571 |
htmlStr=htmlStr+'var containerDiv=document.querySelector(\'div\');';
|
| 226 |
liveuser |
10572 |
|
| 3 |
liveuser |
10573 |
//debug
|
|
|
10574 |
//htmlStr=htmlStr+'console.log(event);';
|
|
|
10575 |
//htmlStr=htmlStr+'console.log(containerDiv);';
|
| 226 |
liveuser |
10576 |
|
| 3 |
liveuser |
10577 |
//如果不存在,則提示錯誤
|
|
|
10578 |
htmlStr=htmlStr+'if(containerDiv===null){console.error(\'containerDiv div not exixt\');}';
|
| 226 |
liveuser |
10579 |
|
| 3 |
liveuser |
10580 |
//設置container div 的 id 為 window_qbpwcf_slide
|
|
|
10581 |
htmlStr=htmlStr+'containerDiv.id=\'window_qbpwcf_slide\';';
|
| 226 |
liveuser |
10582 |
|
|
|
10583 |
//設置container div 為背景
|
| 3 |
liveuser |
10584 |
htmlStr=htmlStr+'containerDiv.style.zIndex=-1;';
|
| 226 |
liveuser |
10585 |
|
| 3 |
liveuser |
10586 |
//設置container div 為透明
|
|
|
10587 |
htmlStr=htmlStr+'containerDiv.style.opacity=0;';
|
| 226 |
liveuser |
10588 |
|
| 3 |
liveuser |
10589 |
//設置container div 為相對位置
|
|
|
10590 |
htmlStr=htmlStr+'containerDiv.style.position=\'absolute\';';
|
| 226 |
liveuser |
10591 |
|
| 3 |
liveuser |
10592 |
//設置最小寬度跟父元素一樣
|
|
|
10593 |
htmlStr=htmlStr+'containerDiv.style.minWidth=\'inherit\';';
|
| 226 |
liveuser |
10594 |
|
| 3 |
liveuser |
10595 |
//設置最大寬度跟父元素一樣
|
|
|
10596 |
htmlStr=htmlStr+'containerDiv.style.maxWidth=\'inherit\';';
|
| 226 |
liveuser |
10597 |
|
| 3 |
liveuser |
10598 |
//設置最小高度跟父元素一樣
|
|
|
10599 |
htmlStr=htmlStr+'containerDiv.style.minHeight=\'inherit\';';
|
| 226 |
liveuser |
10600 |
|
| 3 |
liveuser |
10601 |
//設置最大高度跟父元素一樣
|
|
|
10602 |
htmlStr=htmlStr+'containerDiv.style.maxHeight=\'inherit\';';
|
| 226 |
liveuser |
10603 |
|
| 3 |
liveuser |
10604 |
//如果有里層元素 - start
|
|
|
10605 |
htmlStr=htmlStr+'if(containerDiv.children.length!==0){';
|
| 226 |
liveuser |
10606 |
|
| 3 |
liveuser |
10607 |
//設置最小寬度跟父元素一樣
|
|
|
10608 |
htmlStr=htmlStr+'containerDiv.children[0].style.minWidth=\'inherit\';';
|
| 226 |
liveuser |
10609 |
|
| 3 |
liveuser |
10610 |
//設置最大寬度跟父元素一樣
|
|
|
10611 |
htmlStr=htmlStr+'containerDiv.children[0].style.maxWidth=\'inherit\';';
|
| 226 |
liveuser |
10612 |
|
| 3 |
liveuser |
10613 |
//設置最小高度跟父元素一樣
|
|
|
10614 |
htmlStr=htmlStr+'containerDiv.children[0].style.minHeight=\'inherit\';';
|
| 226 |
liveuser |
10615 |
|
| 3 |
liveuser |
10616 |
//設置最大高度跟父元素一樣
|
|
|
10617 |
htmlStr=htmlStr+'containerDiv.children[0].style.maxHeight=\'inherit\';';
|
| 226 |
liveuser |
10618 |
|
| 3 |
liveuser |
10619 |
//取得要呈現的內容
|
|
|
10620 |
htmlStr=htmlStr+'var contentToShow=containerDiv.children[0];';
|
| 226 |
liveuser |
10621 |
|
| 3 |
liveuser |
10622 |
//如果有里層元素 - end
|
|
|
10623 |
htmlStr=htmlStr+'}';
|
| 226 |
liveuser |
10624 |
|
| 3 |
liveuser |
10625 |
//反之裡層不為element,可能為textNode - start
|
|
|
10626 |
htmlStr=htmlStr+'else{';
|
| 226 |
liveuser |
10627 |
|
| 3 |
liveuser |
10628 |
//取得要呈現的內容
|
|
|
10629 |
htmlStr=htmlStr+'var contentToShow=containerDiv.childNodes[0];';
|
| 226 |
liveuser |
10630 |
|
| 3 |
liveuser |
10631 |
//設置內容左右置中
|
|
|
10632 |
htmlStr=htmlStr+'containerDiv.style.textAlign=\'center\';';
|
| 226 |
liveuser |
10633 |
|
| 3 |
liveuser |
10634 |
//設置內容高度為 100vh
|
|
|
10635 |
htmlStr=htmlStr+'containerDiv.style.lineHeight=\'100vh\';';
|
| 226 |
liveuser |
10636 |
|
| 3 |
liveuser |
10637 |
//反之裡層不為element,可能為textNode - end
|
|
|
10638 |
htmlStr=htmlStr+'}';
|
| 226 |
liveuser |
10639 |
|
| 3 |
liveuser |
10640 |
//若內容是不為video,設置可立即換頁.
|
|
|
10641 |
htmlStr=htmlStr+'if(contentToShow.tagName!==\'VIDEO\'){containerDiv.dataset.canChangeNow=true;}';
|
| 226 |
liveuser |
10642 |
|
| 3 |
liveuser |
10643 |
//反之內容為video
|
|
|
10644 |
htmlStr=htmlStr+'else{';
|
| 226 |
liveuser |
10645 |
|
| 3 |
liveuser |
10646 |
//設置不可立即換頁
|
|
|
10647 |
htmlStr=htmlStr+'containerDiv.dataset.canChangeNow=false;';
|
| 226 |
liveuser |
10648 |
|
| 3 |
liveuser |
10649 |
//設置影片靜音
|
|
|
10650 |
htmlStr=htmlStr+'contentToShow.muted=true;';
|
| 226 |
liveuser |
10651 |
|
| 3 |
liveuser |
10652 |
//禁止影片自動播放
|
|
|
10653 |
htmlStr=htmlStr+'contentToShow.autoplay=false;';
|
| 226 |
liveuser |
10654 |
|
| 3 |
liveuser |
10655 |
//新增影片播放完之後的事件
|
|
|
10656 |
htmlStr=htmlStr+'contentToShow.addEventListener(\'ended\',function(){';
|
| 226 |
liveuser |
10657 |
|
| 3 |
liveuser |
10658 |
//設置可立即換頁
|
|
|
10659 |
htmlStr=htmlStr+'containerDiv.dataset.canChangeNow=true;';
|
| 226 |
liveuser |
10660 |
|
| 3 |
liveuser |
10661 |
//ended 事件結束
|
|
|
10662 |
htmlStr=htmlStr+'});';
|
| 226 |
liveuser |
10663 |
|
| 3 |
liveuser |
10664 |
//else end
|
|
|
10665 |
htmlStr=htmlStr+'}';
|
| 226 |
liveuser |
10666 |
|
| 3 |
liveuser |
10667 |
//若內容是img,設置按照比例自動縮放
|
|
|
10668 |
//https://code-boxx.com/keep-image-aspect-ratio/
|
|
|
10669 |
htmlStr=htmlStr+'if(contentToShow.tagName===\'IMG\'){contentToShow.style.objectFit=\'scale-down\';}';
|
| 226 |
liveuser |
10670 |
|
| 3 |
liveuser |
10671 |
//load 事件結束
|
| 226 |
liveuser |
10672 |
htmlStr=htmlStr+'});';
|
|
|
10673 |
|
| 3 |
liveuser |
10674 |
//script end
|
|
|
10675 |
htmlStr=htmlStr+'\</script\>';
|
| 226 |
liveuser |
10676 |
|
| 3 |
liveuser |
10677 |
//html to dom
|
|
|
10678 |
var dom=domParser.parseFromString(htmlStr,'text/html');
|
| 226 |
liveuser |
10679 |
|
| 3 |
liveuser |
10680 |
//回傳轉成 dom 的 html
|
|
|
10681 |
resolve(dom.documentElement);
|
| 226 |
liveuser |
10682 |
|
| 3 |
liveuser |
10683 |
});
|
| 226 |
liveuser |
10684 |
|
| 3 |
liveuser |
10685 |
}//window.qbpwcf.slide.toDom end
|
| 226 |
liveuser |
10686 |
|
| 3 |
liveuser |
10687 |
//將多個 html、css、javaScript 轉換為 dom
|
|
|
10688 |
window.qbpwcf.slide.toDoms=function(htmlStrArray){
|
| 226 |
liveuser |
10689 |
|
| 3 |
liveuser |
10690 |
//回傳 Promise
|
|
|
10691 |
return new Promise(resolve => {
|
| 226 |
liveuser |
10692 |
|
| 3 |
liveuser |
10693 |
//初始化要回傳的內容
|
|
|
10694 |
var doms=[];
|
| 226 |
liveuser |
10695 |
|
| 3 |
liveuser |
10696 |
//初始化用來存放排序後的 doms
|
|
|
10697 |
var tempDoms=[];
|
| 226 |
liveuser |
10698 |
|
| 3 |
liveuser |
10699 |
//針對每個要輪播的內容
|
|
|
10700 |
htmlStrArray.forEach(async function(value,key){
|
| 226 |
liveuser |
10701 |
|
| 3 |
liveuser |
10702 |
//將 html to dom
|
|
|
10703 |
var dom=await window.qbpwcf.slide.toDom.call(this,value);
|
| 226 |
liveuser |
10704 |
|
| 3 |
liveuser |
10705 |
//記錄排序順序
|
|
|
10706 |
dom.order=key;
|
| 226 |
liveuser |
10707 |
|
| 3 |
liveuser |
10708 |
//保存到 doms 陣列裡面
|
|
|
10709 |
doms.push(dom);
|
| 226 |
liveuser |
10710 |
|
| 3 |
liveuser |
10711 |
//如果每個都解析成 dom 了
|
|
|
10712 |
if(doms.length===htmlStrArray.length){
|
| 226 |
liveuser |
10713 |
|
| 3 |
liveuser |
10714 |
//初始化要尋找的索引
|
|
|
10715 |
var indexToFind=0;
|
| 226 |
liveuser |
10716 |
|
| 3 |
liveuser |
10717 |
//初始化最後的索引
|
|
|
10718 |
var maxlidex=htmlStrArray.length-1;
|
| 226 |
liveuser |
10719 |
|
| 3 |
liveuser |
10720 |
//按照 order 重新排序
|
|
|
10721 |
for(var i=0;i<=maxlidex;i++){
|
| 226 |
liveuser |
10722 |
|
| 3 |
liveuser |
10723 |
//如果是要找的索引
|
|
|
10724 |
if(doms[i].order===indexToFind){
|
| 226 |
liveuser |
10725 |
|
| 3 |
liveuser |
10726 |
//放置dom
|
|
|
10727 |
tempDoms.push(doms[i]);
|
| 226 |
liveuser |
10728 |
|
| 3 |
liveuser |
10729 |
//要尋找的索引+1
|
|
|
10730 |
indexToFind++;
|
| 226 |
liveuser |
10731 |
|
| 3 |
liveuser |
10732 |
//重新搜尋
|
|
|
10733 |
i=-1;
|
| 226 |
liveuser |
10734 |
|
| 3 |
liveuser |
10735 |
//繼續迴圈
|
|
|
10736 |
continue;
|
| 226 |
liveuser |
10737 |
|
| 3 |
liveuser |
10738 |
}//if end
|
| 226 |
liveuser |
10739 |
|
| 3 |
liveuser |
10740 |
}//for end
|
| 226 |
liveuser |
10741 |
|
| 3 |
liveuser |
10742 |
//回傳轉成 dom 的 array
|
|
|
10743 |
resolve(tempDoms);
|
| 226 |
liveuser |
10744 |
|
| 3 |
liveuser |
10745 |
}//if end
|
| 226 |
liveuser |
10746 |
|
| 3 |
liveuser |
10747 |
});//forEach end
|
| 226 |
liveuser |
10748 |
|
| 3 |
liveuser |
10749 |
});//回傳 Promise end
|
| 226 |
liveuser |
10750 |
|
| 3 |
liveuser |
10751 |
}//window.qbpwcf.slide.toDoms end
|
| 226 |
liveuser |
10752 |
|
|
|
10753 |
//將 dom 給 ifrmae 執行完後,回傳其 document
|
| 3 |
liveuser |
10754 |
window.qbpwcf.slide.loadDom=function(dom){
|
| 226 |
liveuser |
10755 |
|
| 3 |
liveuser |
10756 |
//回傳 Promise
|
|
|
10757 |
return new Promise(resolve => {
|
| 226 |
liveuser |
10758 |
|
| 3 |
liveuser |
10759 |
//建立 iframe
|
|
|
10760 |
var iframe=document.createElement('iframe');
|
| 226 |
liveuser |
10761 |
|
| 3 |
liveuser |
10762 |
//隱藏 iframe
|
|
|
10763 |
iframe.style.display='none';
|
| 226 |
liveuser |
10764 |
|
| 3 |
liveuser |
10765 |
//放置 iframe
|
| 174 |
liveuser |
10766 |
document.body.appendChild(iframe);
|
| 226 |
liveuser |
10767 |
|
| 3 |
liveuser |
10768 |
//取得 iframe 的 document
|
|
|
10769 |
var documentInIframe=iframe.contentDocument;
|
| 226 |
liveuser |
10770 |
|
| 3 |
liveuser |
10771 |
//讓 iframe 開始接收內容
|
|
|
10772 |
documentInIframe.open();
|
| 226 |
liveuser |
10773 |
|
| 3 |
liveuser |
10774 |
//綁定 iframe load 事件
|
|
|
10775 |
iframe.addEventListener('load',function(){
|
| 226 |
liveuser |
10776 |
|
| 3 |
liveuser |
10777 |
//回傳 iframe document
|
|
|
10778 |
resolve(documentInIframe.documentElement);
|
| 226 |
liveuser |
10779 |
|
| 3 |
liveuser |
10780 |
});
|
| 226 |
liveuser |
10781 |
|
|
|
10782 |
//讓 iframe 接收指定內容
|
| 3 |
liveuser |
10783 |
documentInIframe.write(dom.outerHTML);
|
| 226 |
liveuser |
10784 |
|
| 3 |
liveuser |
10785 |
//讓 iframe 結束接收內容
|
|
|
10786 |
documentInIframe.close();
|
| 226 |
liveuser |
10787 |
|
| 3 |
liveuser |
10788 |
});//回傳 Promise end
|
| 226 |
liveuser |
10789 |
|
| 3 |
liveuser |
10790 |
}//window.qbpwcf.slide.loadDom end
|
| 226 |
liveuser |
10791 |
|
|
|
10792 |
//將多個 dom 給 ifrmae 執行完後,回傳其 document 集合
|
| 3 |
liveuser |
10793 |
window.qbpwcf.slide.loadDoms=function(doms){
|
| 226 |
liveuser |
10794 |
|
| 3 |
liveuser |
10795 |
//回傳 Promise
|
|
|
10796 |
return new Promise(resolve => {
|
| 226 |
liveuser |
10797 |
|
| 3 |
liveuser |
10798 |
//初始化儲存 iframe document
|
|
|
10799 |
var iframeDocs=[];
|
| 226 |
liveuser |
10800 |
|
| 3 |
liveuser |
10801 |
//初始化儲存排序過後的 iframe document
|
|
|
10802 |
var tempIframeDocs=[];
|
| 226 |
liveuser |
10803 |
|
| 3 |
liveuser |
10804 |
//針對每個dom
|
|
|
10805 |
doms.forEach(async function(value,key){
|
| 226 |
liveuser |
10806 |
|
| 3 |
liveuser |
10807 |
//取得 iframe document
|
|
|
10808 |
var iframeDoc=await window.qbpwcf.slide.loadDom.call(this,value);
|
| 226 |
liveuser |
10809 |
|
| 3 |
liveuser |
10810 |
//記錄排序順序
|
|
|
10811 |
iframeDoc.order=key;
|
| 226 |
liveuser |
10812 |
|
| 3 |
liveuser |
10813 |
//儲存
|
| 174 |
liveuser |
10814 |
iframeDocs.push(iframeDoc);
|
| 226 |
liveuser |
10815 |
|
| 3 |
liveuser |
10816 |
//如果每個都解析成 dom 了
|
|
|
10817 |
if(iframeDocs.length===doms.length){
|
| 226 |
liveuser |
10818 |
|
| 3 |
liveuser |
10819 |
//初始化要尋找的索引
|
|
|
10820 |
var indexToFind=0;
|
| 226 |
liveuser |
10821 |
|
| 3 |
liveuser |
10822 |
//初始化最後的索引
|
|
|
10823 |
var maxlidex=doms.length-1;
|
| 226 |
liveuser |
10824 |
|
| 3 |
liveuser |
10825 |
//按照 order 重新排序
|
|
|
10826 |
for(var i=0;i<=maxlidex;i++){
|
| 226 |
liveuser |
10827 |
|
| 3 |
liveuser |
10828 |
//如果是要找的索引
|
|
|
10829 |
if(iframeDocs[i].order===indexToFind){
|
| 226 |
liveuser |
10830 |
|
| 3 |
liveuser |
10831 |
//放置iframeDoc
|
|
|
10832 |
tempIframeDocs.push(iframeDocs[i]);
|
| 226 |
liveuser |
10833 |
|
| 3 |
liveuser |
10834 |
//要尋找的索引+1
|
|
|
10835 |
indexToFind++;
|
| 226 |
liveuser |
10836 |
|
| 3 |
liveuser |
10837 |
//重新搜尋
|
|
|
10838 |
i=-1;
|
| 226 |
liveuser |
10839 |
|
| 3 |
liveuser |
10840 |
//繼續迴圈
|
|
|
10841 |
continue;
|
| 226 |
liveuser |
10842 |
|
| 3 |
liveuser |
10843 |
}//if end
|
| 226 |
liveuser |
10844 |
|
| 3 |
liveuser |
10845 |
}//for end
|
| 226 |
liveuser |
10846 |
|
| 3 |
liveuser |
10847 |
//回傳各個 iframe document
|
|
|
10848 |
resolve(tempIframeDocs);
|
| 226 |
liveuser |
10849 |
|
| 3 |
liveuser |
10850 |
}//if end
|
| 226 |
liveuser |
10851 |
|
| 3 |
liveuser |
10852 |
});//forEach end
|
| 226 |
liveuser |
10853 |
|
| 3 |
liveuser |
10854 |
});//回傳 Promise end
|
| 226 |
liveuser |
10855 |
|
| 3 |
liveuser |
10856 |
}//window.qbpwcf.slide.loadDoms end
|
| 226 |
liveuser |
10857 |
|
| 3 |
liveuser |
10858 |
//執行的定義
|
|
|
10859 |
window.qbpwcf.slide.func=async function(){
|
| 226 |
liveuser |
10860 |
|
| 3 |
liveuser |
10861 |
//取得要輪播的元素
|
|
|
10862 |
var eles=window.qbpwcf.slide.eles;
|
| 226 |
liveuser |
10863 |
|
| 3 |
liveuser |
10864 |
//如果沒有要輪播的內容
|
|
|
10865 |
if(eles.length===0){
|
| 226 |
liveuser |
10866 |
|
| 3 |
liveuser |
10867 |
//提示錯誤訊息
|
|
|
10868 |
console.error('Array(window.qbpwcf.slide.eles) should not be empty');
|
| 226 |
liveuser |
10869 |
|
| 3 |
liveuser |
10870 |
//結束執行
|
|
|
10871 |
return false;
|
| 226 |
liveuser |
10872 |
|
| 3 |
liveuser |
10873 |
}//if end
|
| 226 |
liveuser |
10874 |
|
| 3 |
liveuser |
10875 |
//取得放置輪播的div QuerySelectorString
|
|
|
10876 |
var displayDivByQuerySelector=window.qbpwcf.slide.displayDivByQuerySelector;
|
| 226 |
liveuser |
10877 |
|
| 3 |
liveuser |
10878 |
//取得放置輪播的div
|
|
|
10879 |
var displayDiv=document.querySelector(displayDivByQuerySelector);
|
| 226 |
liveuser |
10880 |
|
| 3 |
liveuser |
10881 |
//如果沒有找到放置輪播內容的div
|
|
|
10882 |
if(displayDiv===null){
|
| 226 |
liveuser |
10883 |
|
| 3 |
liveuser |
10884 |
//提示錯誤訊息
|
|
|
10885 |
console.error('result of querySelector by '+displayDivByQuerySelector+' is null');
|
| 226 |
liveuser |
10886 |
|
| 3 |
liveuser |
10887 |
//結束執行
|
|
|
10888 |
return false;
|
| 226 |
liveuser |
10889 |
|
| 3 |
liveuser |
10890 |
}//if end
|
| 226 |
liveuser |
10891 |
|
| 3 |
liveuser |
10892 |
//取得每個slide的最小播放時間
|
|
|
10893 |
var showTime=window.qbpwcf.slide.showTime;
|
| 226 |
liveuser |
10894 |
|
| 3 |
liveuser |
10895 |
//將輪播內容轉換為doms
|
|
|
10896 |
var doms = await window.qbpwcf.slide.toDoms.call(this,eles);
|
| 226 |
liveuser |
10897 |
|
| 3 |
liveuser |
10898 |
//debug
|
|
|
10899 |
//console.log(doms);
|
| 226 |
liveuser |
10900 |
|
| 3 |
liveuser |
10901 |
//取得每個 iframe 的 document
|
|
|
10902 |
var iframeDocs = await window.qbpwcf.slide.loadDoms.call(this,doms);
|
| 226 |
liveuser |
10903 |
|
| 3 |
liveuser |
10904 |
//debug
|
|
|
10905 |
//console.log(iframeDocs);
|
| 226 |
liveuser |
10906 |
|
| 3 |
liveuser |
10907 |
//放置讀取好的投影片
|
|
|
10908 |
for(var i=0;i<iframeDocs.length;i++){
|
| 226 |
liveuser |
10909 |
|
| 3 |
liveuser |
10910 |
//取得容器 div
|
|
|
10911 |
var containerDiv=iframeDocs[i].querySelector('div');
|
| 226 |
liveuser |
10912 |
|
| 3 |
liveuser |
10913 |
//放置要播放的內容
|
|
|
10914 |
displayDiv.appendChild(containerDiv);
|
| 226 |
liveuser |
10915 |
|
| 3 |
liveuser |
10916 |
}//for end
|
| 226 |
liveuser |
10917 |
|
| 3 |
liveuser |
10918 |
//初始化索引為0
|
|
|
10919 |
i=0;
|
| 226 |
liveuser |
10920 |
|
| 3 |
liveuser |
10921 |
//無窮迴圈
|
|
|
10922 |
while(true){
|
| 226 |
liveuser |
10923 |
|
| 3 |
liveuser |
10924 |
//如果目標不存在
|
|
|
10925 |
if(iframeDocs[i]===undefined){
|
| 226 |
liveuser |
10926 |
|
| 3 |
liveuser |
10927 |
//重新計數
|
|
|
10928 |
i=0;
|
| 226 |
liveuser |
10929 |
|
| 3 |
liveuser |
10930 |
//下一輪
|
|
|
10931 |
continue;
|
| 226 |
liveuser |
10932 |
|
| 3 |
liveuser |
10933 |
}//if end
|
| 226 |
liveuser |
10934 |
|
| 3 |
liveuser |
10935 |
//取得所有投影片
|
|
|
10936 |
var slides=displayDiv.querySelectorAll('div#window_qbpwcf_slide');
|
| 226 |
liveuser |
10937 |
|
| 3 |
liveuser |
10938 |
//針對每個投影片
|
|
|
10939 |
for(var j=0;j<slides.length;j++){
|
| 226 |
liveuser |
10940 |
|
| 3 |
liveuser |
10941 |
//設置放在背景
|
|
|
10942 |
slides[j].style.zIndex=-1;
|
| 226 |
liveuser |
10943 |
|
| 3 |
liveuser |
10944 |
//設置為透明
|
|
|
10945 |
slides[j].style.opacity=0;
|
| 226 |
liveuser |
10946 |
|
| 3 |
liveuser |
10947 |
//設置為absolute,不占用空間
|
|
|
10948 |
slides[j].style.position='absolute';
|
| 226 |
liveuser |
10949 |
|
| 3 |
liveuser |
10950 |
}//for end
|
| 226 |
liveuser |
10951 |
|
| 3 |
liveuser |
10952 |
//取得當前播放的內容
|
|
|
10953 |
var prePlayContent=displayDiv.querySelectorAll('div#window_qbpwcf_slide')[i];
|
| 226 |
liveuser |
10954 |
|
| 3 |
liveuser |
10955 |
//當前要播放的內容移到前景
|
|
|
10956 |
prePlayContent.style.zIndex='unset';
|
| 226 |
liveuser |
10957 |
|
| 3 |
liveuser |
10958 |
//顯示當前要播放的內容
|
|
|
10959 |
prePlayContent.style.opacity='unset';
|
| 226 |
liveuser |
10960 |
|
| 3 |
liveuser |
10961 |
//設置為unset,要占用空間
|
|
|
10962 |
prePlayContent.style.position='unset';
|
| 226 |
liveuser |
10963 |
|
| 3 |
liveuser |
10964 |
//如果有子元素
|
|
|
10965 |
if(prePlayContent.children.length>0){
|
| 226 |
liveuser |
10966 |
|
| 3 |
liveuser |
10967 |
//如果是影片
|
|
|
10968 |
if(prePlayContent.children[0].tagName==='VIDEO'){
|
| 226 |
liveuser |
10969 |
|
| 3 |
liveuser |
10970 |
//播放之
|
|
|
10971 |
prePlayContent.children[0].play();
|
| 226 |
liveuser |
10972 |
|
| 3 |
liveuser |
10973 |
}//if end
|
| 226 |
liveuser |
10974 |
|
| 3 |
liveuser |
10975 |
}//if end
|
| 226 |
liveuser |
10976 |
|
| 3 |
liveuser |
10977 |
//播放 showTime 秒
|
|
|
10978 |
await window.qbpwcf.sleep.func(showTime);
|
| 226 |
liveuser |
10979 |
|
| 3 |
liveuser |
10980 |
//如果尚不行置換slide
|
|
|
10981 |
while(prePlayContent.dataset.canChangeNow==='false'){
|
| 226 |
liveuser |
10982 |
|
| 3 |
liveuser |
10983 |
//多播放 1 秒
|
|
|
10984 |
await window.qbpwcf.sleep.func(1);
|
| 226 |
liveuser |
10985 |
|
| 3 |
liveuser |
10986 |
}//while end
|
| 226 |
liveuser |
10987 |
|
| 3 |
liveuser |
10988 |
//如果有子元素
|
|
|
10989 |
if(prePlayContent.children.length>0){
|
| 226 |
liveuser |
10990 |
|
| 3 |
liveuser |
10991 |
//如果是影片
|
|
|
10992 |
if(prePlayContent.children[0].tagName==='VIDEO'){
|
| 226 |
liveuser |
10993 |
|
| 3 |
liveuser |
10994 |
//設置下次要等待影片播放完才能換頁
|
|
|
10995 |
prePlayContent.dataset.canChangeNow=false;
|
| 226 |
liveuser |
10996 |
|
| 3 |
liveuser |
10997 |
}//if end
|
| 226 |
liveuser |
10998 |
|
| 3 |
liveuser |
10999 |
}//if end
|
| 226 |
liveuser |
11000 |
|
| 3 |
liveuser |
11001 |
//執行到這邊代表可以置換slide了
|
| 226 |
liveuser |
11002 |
|
| 3 |
liveuser |
11003 |
//計數增加
|
|
|
11004 |
i++;
|
| 226 |
liveuser |
11005 |
|
| 3 |
liveuser |
11006 |
}//while end
|
| 226 |
liveuser |
11007 |
|
| 3 |
liveuser |
11008 |
}//window.qbpwcf.slide.func end
|
| 226 |
liveuser |
11009 |
|
| 3 |
liveuser |
11010 |
";
|
| 226 |
liveuser |
11011 |
|
| 3 |
liveuser |
11012 |
#js function
|
|
|
11013 |
$conf["javaScript::toScript"]["jsFunciton"][]=
|
|
|
11014 |
"
|
|
|
11015 |
/*
|
|
|
11016 |
說明:
|
|
|
11017 |
取得用戶端的檔案.
|
|
|
11018 |
回傳結果:
|
|
|
11019 |
result.data,取得檔案的 base64 data
|
| 226 |
liveuser |
11020 |
result.mime,取得檔案的 mime
|
| 3 |
liveuser |
11021 |
result.base64,取得檔案的純 base64 部分
|
|
|
11022 |
參考資料:
|
|
|
11023 |
https://developer.mozilla.org/en-US/docs/Web/API/File
|
|
|
11024 |
https://developer.mozilla.org/en-US/docs/Web/API/FileList
|
|
|
11025 |
https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/accept
|
|
|
11026 |
https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL_static
|
|
|
11027 |
https://developer.mozilla.org/en-US/docs/Web/API/FileReader/readAsDataURL
|
|
|
11028 |
*/
|
| 226 |
liveuser |
11029 |
|
| 3 |
liveuser |
11030 |
//初始化
|
|
|
11031 |
window.qbpwcf.clientFile={};
|
| 226 |
liveuser |
11032 |
|
| 3 |
liveuser |
11033 |
//取得用戶端檔案的參數設定
|
|
|
11034 |
window.qbpwcf.clientFile.params={};
|
| 226 |
liveuser |
11035 |
|
| 3 |
liveuser |
11036 |
//初始化multiple參數為false
|
|
|
11037 |
window.qbpwcf.clientFile.params.multiple=false;
|
| 226 |
liveuser |
11038 |
|
| 3 |
liveuser |
11039 |
//初始化accept參數為''
|
|
|
11040 |
window.qbpwcf.clientFile.params.accept='';
|
| 226 |
liveuser |
11041 |
|
| 3 |
liveuser |
11042 |
//設置只接受video
|
|
|
11043 |
window.qbpwcf.clientFile.acceptVideoOnly=function(){
|
| 226 |
liveuser |
11044 |
|
| 3 |
liveuser |
11045 |
//設置accept為'video/*'
|
|
|
11046 |
window.qbpwcf.clientFile.params.accept='video/*';
|
| 226 |
liveuser |
11047 |
|
| 3 |
liveuser |
11048 |
}//function end
|
| 226 |
liveuser |
11049 |
|
| 3 |
liveuser |
11050 |
//設置只接受audio
|
|
|
11051 |
window.qbpwcf.clientFile.acceptAudioOnly=function(){
|
| 226 |
liveuser |
11052 |
|
| 3 |
liveuser |
11053 |
//設置accept為'audio/*'
|
|
|
11054 |
window.qbpwcf.clientFile.params.accept='audio/*';
|
| 226 |
liveuser |
11055 |
|
| 3 |
liveuser |
11056 |
}//function end
|
| 226 |
liveuser |
11057 |
|
| 3 |
liveuser |
11058 |
//設置只接受image
|
|
|
11059 |
window.qbpwcf.clientFile.acceptImageOnly=function(){
|
| 226 |
liveuser |
11060 |
|
| 3 |
liveuser |
11061 |
//設置accept為'image/*'
|
|
|
11062 |
window.qbpwcf.clientFile.params.accept='image/*';
|
| 226 |
liveuser |
11063 |
|
| 3 |
liveuser |
11064 |
}//function end
|
| 226 |
liveuser |
11065 |
|
| 3 |
liveuser |
11066 |
//累加允許的檔案類型
|
|
|
11067 |
window.qbpwcf.clientFile.acceptAppend=function(type){
|
| 226 |
liveuser |
11068 |
|
| 3 |
liveuser |
11069 |
//如果已經有內容
|
|
|
11070 |
if(window.qbpwcf.clientFile.params.accept!=''){
|
| 226 |
liveuser |
11071 |
|
| 3 |
liveuser |
11072 |
//增加允許的類型
|
|
|
11073 |
window.qbpwcf.clientFile.params.accept=window.qbpwcf.clientFile.params.accept+','+type;
|
| 226 |
liveuser |
11074 |
|
| 3 |
liveuser |
11075 |
}//if end
|
| 226 |
liveuser |
11076 |
|
| 3 |
liveuser |
11077 |
//反之尚無設定
|
|
|
11078 |
else{
|
| 226 |
liveuser |
11079 |
|
| 3 |
liveuser |
11080 |
//設置允許的類型
|
|
|
11081 |
window.qbpwcf.clientFile.params.accept=type;
|
| 226 |
liveuser |
11082 |
|
| 3 |
liveuser |
11083 |
}//else end
|
| 226 |
liveuser |
11084 |
|
| 3 |
liveuser |
11085 |
}//function end
|
| 226 |
liveuser |
11086 |
|
| 3 |
liveuser |
11087 |
//觸發選擇檔案的視窗後,若沒有選擇到的檔案,會強制使用者再度選擇,預設為'false'不啟用;反之為'true'要啟用.
|
|
|
11088 |
window.qbpwcf.clientFile.forceSelectFileAfterTrigger='false';
|
| 226 |
liveuser |
11089 |
|
| 3 |
liveuser |
11090 |
//取得用戶端的檔案,使用時前面請加上 await 才能取得回應.
|
|
|
11091 |
window.qbpwcf.clientFile.init=async function(){
|
| 226 |
liveuser |
11092 |
|
| 3 |
liveuser |
11093 |
//建立 input
|
|
|
11094 |
var input=document.createElement('input');
|
| 226 |
liveuser |
11095 |
|
| 3 |
liveuser |
11096 |
//設置 type 為檔案
|
|
|
11097 |
input.type='file';
|
| 226 |
liveuser |
11098 |
|
| 3 |
liveuser |
11099 |
//設置multiple參數
|
|
|
11100 |
input.multiple=window.qbpwcf.clientFile.params.multiple;
|
| 226 |
liveuser |
11101 |
|
| 3 |
liveuser |
11102 |
//設置multiple參數
|
|
|
11103 |
input.accept=window.qbpwcf.clientFile.params.accept;
|
| 226 |
liveuser |
11104 |
|
| 3 |
liveuser |
11105 |
//初始化要回傳的結果物件
|
|
|
11106 |
input.result={};
|
| 226 |
liveuser |
11107 |
|
| 3 |
liveuser |
11108 |
//預設使用者尚未取消選取檔案
|
|
|
11109 |
input.canceled='false';
|
| 226 |
liveuser |
11110 |
|
| 3 |
liveuser |
11111 |
//當選擇的檔案有異動
|
|
|
11112 |
input.onchange=function(){
|
| 226 |
liveuser |
11113 |
|
| 3 |
liveuser |
11114 |
//轉換與取得ObjectURL
|
|
|
11115 |
input.result.url=URL.createObjectURL(input.files[0]);
|
|
|
11116 |
|
|
|
11117 |
//初始化 FileReader
|
|
|
11118 |
var reader = new FileReader();
|
| 226 |
liveuser |
11119 |
|
| 3 |
liveuser |
11120 |
//讀取檔案
|
|
|
11121 |
reader.readAsDataURL(input.files[0]);
|
| 226 |
liveuser |
11122 |
|
| 3 |
liveuser |
11123 |
//當檔案讀取完畢後
|
|
|
11124 |
reader.onload=function(){
|
| 226 |
liveuser |
11125 |
|
| 3 |
liveuser |
11126 |
//取得檔案的 base64 data
|
|
|
11127 |
input.result.data = reader.result;
|
| 226 |
liveuser |
11128 |
|
| 3 |
liveuser |
11129 |
//取得檔案的 mime
|
|
|
11130 |
input.result.mime = input.result.data.split(':')[1].split(';')[0];
|
| 226 |
liveuser |
11131 |
|
| 3 |
liveuser |
11132 |
//取得檔案的純 base64 部分
|
|
|
11133 |
input.result.base64 = input.result.data.split(',')[1];
|
| 226 |
liveuser |
11134 |
|
| 3 |
liveuser |
11135 |
}//function end
|
| 226 |
liveuser |
11136 |
|
| 3 |
liveuser |
11137 |
};//function end
|
| 226 |
liveuser |
11138 |
|
| 3 |
liveuser |
11139 |
//綁定使用按下取消的事件
|
|
|
11140 |
//參考資料:
|
|
|
11141 |
//https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/cancel_event
|
|
|
11142 |
input.addEventListener('cancel',function(event){
|
|
|
11143 |
|
|
|
11144 |
//debug
|
|
|
11145 |
//console.log(event,Object.keys(input.result).length);return false;
|
|
|
11146 |
|
|
|
11147 |
//如果沒有結果
|
|
|
11148 |
if(Object.keys(input.result).length===0){
|
| 226 |
liveuser |
11149 |
|
| 3 |
liveuser |
11150 |
//設置被按下cancel了
|
|
|
11151 |
input.canceled='true';
|
| 226 |
liveuser |
11152 |
|
| 3 |
liveuser |
11153 |
}//if end
|
| 226 |
liveuser |
11154 |
|
| 3 |
liveuser |
11155 |
});
|
| 226 |
liveuser |
11156 |
|
| 3 |
liveuser |
11157 |
//觸發使用者選擇檔案
|
|
|
11158 |
input.click();
|
| 226 |
liveuser |
11159 |
|
| 3 |
liveuser |
11160 |
//無窮迴圈
|
|
|
11161 |
while(true){
|
| 226 |
liveuser |
11162 |
|
| 3 |
liveuser |
11163 |
//如果使用者取消了
|
|
|
11164 |
if(input.canceled==='true'){
|
| 226 |
liveuser |
11165 |
|
| 3 |
liveuser |
11166 |
//回傳結果
|
|
|
11167 |
return input.result;
|
| 226 |
liveuser |
11168 |
|
| 3 |
liveuser |
11169 |
}//if end
|
| 226 |
liveuser |
11170 |
|
| 3 |
liveuser |
11171 |
//休息一秒
|
|
|
11172 |
await window.qbpwcf.sleep.func(1);
|
| 226 |
liveuser |
11173 |
|
| 3 |
liveuser |
11174 |
//debug
|
|
|
11175 |
console.log('wait file selected');
|
| 226 |
liveuser |
11176 |
|
| 3 |
liveuser |
11177 |
//如果有結果
|
|
|
11178 |
if(input.result!={}){
|
| 226 |
liveuser |
11179 |
|
| 3 |
liveuser |
11180 |
//如果
|
|
|
11181 |
if(
|
| 226 |
liveuser |
11182 |
|
| 3 |
liveuser |
11183 |
//url存在
|
| 226 |
liveuser |
11184 |
input.result.url!=undefined
|
|
|
11185 |
|
|
|
11186 |
&&
|
|
|
11187 |
|
| 3 |
liveuser |
11188 |
//data存在
|
| 226 |
liveuser |
11189 |
input.result.data!=undefined
|
|
|
11190 |
|
| 3 |
liveuser |
11191 |
&&
|
| 226 |
liveuser |
11192 |
|
| 3 |
liveuser |
11193 |
//mime存在
|
|
|
11194 |
input.result.mime!=undefined
|
| 226 |
liveuser |
11195 |
|
| 3 |
liveuser |
11196 |
&&
|
| 226 |
liveuser |
11197 |
|
| 3 |
liveuser |
11198 |
//base64存在
|
|
|
11199 |
input.result.base64!=undefined
|
| 226 |
liveuser |
11200 |
|
| 3 |
liveuser |
11201 |
){
|
| 226 |
liveuser |
11202 |
|
| 3 |
liveuser |
11203 |
//執行到這代表資料都有了
|
| 226 |
liveuser |
11204 |
|
| 3 |
liveuser |
11205 |
//結束迴圈
|
|
|
11206 |
break;
|
| 226 |
liveuser |
11207 |
|
| 3 |
liveuser |
11208 |
}//if end
|
| 226 |
liveuser |
11209 |
|
| 3 |
liveuser |
11210 |
}//if end
|
| 226 |
liveuser |
11211 |
|
| 3 |
liveuser |
11212 |
}//while end
|
| 226 |
liveuser |
11213 |
|
| 3 |
liveuser |
11214 |
//回傳結果
|
|
|
11215 |
return input.result;
|
| 226 |
liveuser |
11216 |
|
| 3 |
liveuser |
11217 |
};
|
| 226 |
liveuser |
11218 |
|
| 3 |
liveuser |
11219 |
";
|
| 226 |
liveuser |
11220 |
|
| 3 |
liveuser |
11221 |
#js function
|
|
|
11222 |
$conf["javaScript::toScript"]["jsFunciton"][]=
|
|
|
11223 |
"
|
|
|
11224 |
/*
|
|
|
11225 |
說明:
|
|
|
11226 |
text_editor,編輯文字.
|
|
|
11227 |
*/
|
| 226 |
liveuser |
11228 |
|
| 3 |
liveuser |
11229 |
//初始化
|
|
|
11230 |
window.qbpwcf.text_editor={};
|
| 226 |
liveuser |
11231 |
|
| 3 |
liveuser |
11232 |
//用於取得顯示輸入內容的區塊
|
|
|
11233 |
window.qbpwcf.text_editor.selector='';
|
| 226 |
liveuser |
11234 |
|
| 3 |
liveuser |
11235 |
//執行
|
|
|
11236 |
window.qbpwcf.text_editor.init=function(){
|
| 226 |
liveuser |
11237 |
|
| 3 |
liveuser |
11238 |
//取得用來顯示輸入內容的 selector
|
|
|
11239 |
var displayTag=document.querySelector(window.qbpwcf.text_editor.selector);
|
| 226 |
liveuser |
11240 |
|
| 3 |
liveuser |
11241 |
//取得一開始的內容,用一個div代表一行.
|
|
|
11242 |
var lines=displayTag.children;
|
| 226 |
liveuser |
11243 |
|
| 3 |
liveuser |
11244 |
//關注用來顯示輸入內容的元素後
|
|
|
11245 |
displayTag.addEventListener('focus',function(event){
|
| 226 |
liveuser |
11246 |
|
| 3 |
liveuser |
11247 |
//取得觸發的元素
|
|
|
11248 |
var eTarget=event.target;
|
| 226 |
liveuser |
11249 |
|
| 3 |
liveuser |
11250 |
//debug
|
|
|
11251 |
console.log(eTarget);
|
| 226 |
liveuser |
11252 |
|
| 3 |
liveuser |
11253 |
//建立暫存的textInput
|
|
|
11254 |
var tempInput=document.createElement('input');
|
| 226 |
liveuser |
11255 |
|
| 3 |
liveuser |
11256 |
//設置為單行輸入
|
|
|
11257 |
tempInput.type='text';
|
| 226 |
liveuser |
11258 |
|
| 3 |
liveuser |
11259 |
//break point
|
|
|
11260 |
return;
|
| 226 |
liveuser |
11261 |
|
| 3 |
liveuser |
11262 |
//初始化內容
|
|
|
11263 |
tempInput.value=contentOfTag;
|
| 226 |
liveuser |
11264 |
|
| 3 |
liveuser |
11265 |
//關注之
|
|
|
11266 |
tempInput.focus();
|
| 226 |
liveuser |
11267 |
|
| 3 |
liveuser |
11268 |
//若內容有改變
|
|
|
11269 |
tempInput.addEventListener('change',function(event){
|
| 226 |
liveuser |
11270 |
|
| 3 |
liveuser |
11271 |
//更新用來顯示輸入的內容
|
|
|
11272 |
displayTag.innerText=this.value;
|
| 226 |
liveuser |
11273 |
|
| 3 |
liveuser |
11274 |
});
|
| 226 |
liveuser |
11275 |
|
| 3 |
liveuser |
11276 |
});
|
| 226 |
liveuser |
11277 |
|
| 3 |
liveuser |
11278 |
}
|
|
|
11279 |
";
|
| 226 |
liveuser |
11280 |
|
| 3 |
liveuser |
11281 |
#js function
|
|
|
11282 |
$conf["javaScript::toScript"]["jsFunciton"][]=
|
|
|
11283 |
"
|
| 226 |
liveuser |
11284 |
|
| 3 |
liveuser |
11285 |
/*
|
|
|
11286 |
說明:
|
|
|
11287 |
openWindow,由javaScript開啟可管控的視窗,甚至存取其內容.
|
| 226 |
liveuser |
11288 |
|
| 3 |
liveuser |
11289 |
範例:
|
| 226 |
liveuser |
11290 |
|
| 3 |
liveuser |
11291 |
//第一段
|
|
|
11292 |
var script=document.createElement('script');
|
|
|
11293 |
script.src='https://latest.qbpwcf.org/qbpwcf/javaScript/qbpwcf.php';
|
|
|
11294 |
document.head.appendChild(script);
|
| 226 |
liveuser |
11295 |
|
| 3 |
liveuser |
11296 |
//第二段
|
|
|
11297 |
window.qbpwcf.openWindow.params.url=window.location.href;
|
|
|
11298 |
window.qbpwcf.openWindow.saveSourceAtTheEnd='true';
|
|
|
11299 |
await window.qbpwcf.openWindow.func();
|
| 226 |
liveuser |
11300 |
|
| 3 |
liveuser |
11301 |
參考資料:
|
|
|
11302 |
https://developer.mozilla.org/en-US/docs/Web/API/FileReader/readAsDataURL
|
| 226 |
liveuser |
11303 |
https://developer.mozilla.org/en-US/docs/Web/API/File/File
|
| 3 |
liveuser |
11304 |
*/
|
| 226 |
liveuser |
11305 |
|
| 3 |
liveuser |
11306 |
//初始化物件
|
|
|
11307 |
window.qbpwcf.openWindow={};
|
| 226 |
liveuser |
11308 |
|
| 3 |
liveuser |
11309 |
//初始化參數
|
|
|
11310 |
window.qbpwcf.openWindow.init=function(){
|
| 226 |
liveuser |
11311 |
|
| 3 |
liveuser |
11312 |
//初始化參數物件
|
|
|
11313 |
window.qbpwcf.openWindow.params={};
|
| 226 |
liveuser |
11314 |
|
| 3 |
liveuser |
11315 |
//初始化目標網址
|
|
|
11316 |
window.qbpwcf.openWindow.params.url='https://sourceforge.net/projects/qbpwc/';
|
| 226 |
liveuser |
11317 |
|
| 3 |
liveuser |
11318 |
//初始化要將window.open()儲存到哪個全域變數裡面.
|
|
|
11319 |
window.qbpwcf.openWindow.params.varName='qbpwcf_openWindow_instance';
|
| 226 |
liveuser |
11320 |
|
| 3 |
liveuser |
11321 |
//初始化給予 window.open() 的第三個參數.
|
|
|
11322 |
window.qbpwcf.openWindow.params.windowFeatures='';
|
| 226 |
liveuser |
11323 |
|
| 3 |
liveuser |
11324 |
//初始化window.open()後,其回應的html source
|
|
|
11325 |
window.qbpwcf.openWindow.resSource='';
|
| 226 |
liveuser |
11326 |
|
| 3 |
liveuser |
11327 |
//初始化window.open()後,要執行什麼操作,參數Window為其opened的Window的.
|
|
|
11328 |
window.qbpwcf.openWindow.actionAfterOpen=function(Window){
|
| 226 |
liveuser |
11329 |
|
| 3 |
liveuser |
11330 |
//預設的提示訊息
|
|
|
11331 |
console.log('do something after window.oepn()');
|
| 226 |
liveuser |
11332 |
|
| 3 |
liveuser |
11333 |
}//actionAfterOpen end
|
| 226 |
liveuser |
11334 |
|
| 3 |
liveuser |
11335 |
//預設window.open()後經過處理後結果不要下載下來
|
|
|
11336 |
window.qbpwcf.openWindow.saveSourceAtTheEnd='false';
|
| 226 |
liveuser |
11337 |
|
| 3 |
liveuser |
11338 |
}//funciton end
|
| 226 |
liveuser |
11339 |
|
| 3 |
liveuser |
11340 |
//初始化參數
|
|
|
11341 |
window.qbpwcf.openWindow.init();
|
| 226 |
liveuser |
11342 |
|
| 3 |
liveuser |
11343 |
//window.open
|
|
|
11344 |
window.qbpwcf.openWindow.func=async function(){
|
| 226 |
liveuser |
11345 |
|
| 3 |
liveuser |
11346 |
//window.open()並儲存回傳的結果
|
|
|
11347 |
window[window.qbpwcf.openWindow.params.varName]=await window.open(window.qbpwcf.openWindow.params.url,'_blank',window.qbpwcf.openWindow.params.windowFeatures);
|
| 226 |
liveuser |
11348 |
|
| 3 |
liveuser |
11349 |
//如果執行失敗
|
|
|
11350 |
if(!(window[window.qbpwcf.openWindow.params.varName])){
|
|
|
11351 |
|
|
|
11352 |
//提示錯誤訊息
|
|
|
11353 |
console.error('The window wasn\'t allowed to open. This is likely caused by built-in popup blockers.');
|
|
|
11354 |
|
|
|
11355 |
//結束執行
|
|
|
11356 |
return;
|
|
|
11357 |
|
|
|
11358 |
}//if end
|
| 226 |
liveuser |
11359 |
|
| 3 |
liveuser |
11360 |
//加入load事件
|
|
|
11361 |
window[window.qbpwcf.openWindow.params.varName].addEventListener('load',function(event){
|
| 226 |
liveuser |
11362 |
|
| 3 |
liveuser |
11363 |
//debug
|
|
|
11364 |
//console.log(this);
|
| 226 |
liveuser |
11365 |
|
| 3 |
liveuser |
11366 |
//呼叫開啟後要做度事情
|
|
|
11367 |
window.qbpwcf.openWindow.actionAfterOpen(this);
|
| 226 |
liveuser |
11368 |
|
| 3 |
liveuser |
11369 |
//取得html原始碼
|
|
|
11370 |
window.qbpwcf.openWindow.resSource='<html>'+window[window.qbpwcf.openWindow.params.varName].document.head.outerHTML+window[window.qbpwcf.openWindow.params.varName].document.body.outerHTML+'</html>';
|
| 226 |
liveuser |
11371 |
|
| 3 |
liveuser |
11372 |
//如果要下載內容
|
|
|
11373 |
if(window.qbpwcf.openWindow.saveSourceAtTheEnd=='true'){
|
| 226 |
liveuser |
11374 |
|
| 3 |
liveuser |
11375 |
//建立檔案File
|
|
|
11376 |
var filed2download=new File([window.qbpwcf.openWindow.resSource],'filed2download');
|
| 226 |
liveuser |
11377 |
|
| 3 |
liveuser |
11378 |
//建立用來讀取檔案的FileReader
|
|
|
11379 |
var fileReader=new FileReader();
|
| 226 |
liveuser |
11380 |
|
| 3 |
liveuser |
11381 |
//檔案讀取完畢後
|
|
|
11382 |
fileReader.addEventListener('load',function(event){
|
| 226 |
liveuser |
11383 |
|
| 3 |
liveuser |
11384 |
//取得dataUrl
|
|
|
11385 |
dataUrl=fileReader.result;
|
| 226 |
liveuser |
11386 |
|
| 3 |
liveuser |
11387 |
//建立 a
|
|
|
11388 |
var a=document.createElement('a');
|
| 226 |
liveuser |
11389 |
|
| 3 |
liveuser |
11390 |
//設置連結為dataUrl
|
|
|
11391 |
a.href=dataUrl;
|
|
|
11392 |
|
|
|
11393 |
//點擊開始下載
|
|
|
11394 |
a.click();
|
|
|
11395 |
|
|
|
11396 |
});
|
| 226 |
liveuser |
11397 |
|
| 3 |
liveuser |
11398 |
//讀取檔案為 dataUrl]
|
|
|
11399 |
fileReader.readAsDataURL(filed2download);
|
| 226 |
liveuser |
11400 |
|
| 3 |
liveuser |
11401 |
}//if end
|
| 226 |
liveuser |
11402 |
|
| 3 |
liveuser |
11403 |
});
|
| 226 |
liveuser |
11404 |
|
| 3 |
liveuser |
11405 |
}//function end
|
| 226 |
liveuser |
11406 |
|
| 3 |
liveuser |
11407 |
";
|
| 226 |
liveuser |
11408 |
|
| 3 |
liveuser |
11409 |
#js function
|
|
|
11410 |
$conf["javaScript::toScript"]["jsFunciton"][]=
|
|
|
11411 |
"
|
| 226 |
liveuser |
11412 |
|
| 3 |
liveuser |
11413 |
/*
|
|
|
11414 |
說明:
|
|
|
11415 |
儲存當前頁面的原始碼
|
| 226 |
liveuser |
11416 |
|
| 3 |
liveuser |
11417 |
範例:
|
|
|
11418 |
window.qbpwcf.saveSource();
|
|
|
11419 |
*/
|
| 226 |
liveuser |
11420 |
|
| 3 |
liveuser |
11421 |
//儲存當前頁面原始碼
|
|
|
11422 |
window.qbpwcf.saveSource=async function(){
|
| 226 |
liveuser |
11423 |
|
| 3 |
liveuser |
11424 |
//取得原始碼
|
|
|
11425 |
var sourceStr='<html>'+document.head.outerHTML+document.body.outerHTML+'</html>';
|
| 226 |
liveuser |
11426 |
|
| 3 |
liveuser |
11427 |
//建立File,檔案名稱隨機產生.
|
|
|
11428 |
var file2download=new File([sourceStr],'file2download');
|
| 226 |
liveuser |
11429 |
|
| 3 |
liveuser |
11430 |
//建立用來讀取檔案的FileReader
|
|
|
11431 |
var fileReader=new FileReader();
|
| 226 |
liveuser |
11432 |
|
| 3 |
liveuser |
11433 |
//檔案讀取完畢後
|
|
|
11434 |
fileReader.addEventListener('load',function(event){
|
| 226 |
liveuser |
11435 |
|
| 3 |
liveuser |
11436 |
//取得dataUrl
|
|
|
11437 |
dataUrl=fileReader.result;
|
| 226 |
liveuser |
11438 |
|
| 3 |
liveuser |
11439 |
//建立 a
|
|
|
11440 |
var a=document.createElement('a');
|
| 226 |
liveuser |
11441 |
|
| 3 |
liveuser |
11442 |
//設置連結為dataUrl
|
|
|
11443 |
a.href=dataUrl;
|
|
|
11444 |
|
|
|
11445 |
//點擊開始下載
|
|
|
11446 |
a.click();
|
|
|
11447 |
|
|
|
11448 |
});
|
| 226 |
liveuser |
11449 |
|
| 3 |
liveuser |
11450 |
//讀取檔案為 dataUrl
|
|
|
11451 |
fileReader.readAsDataURL(file2download);
|
| 226 |
liveuser |
11452 |
|
| 3 |
liveuser |
11453 |
}//function end
|
| 226 |
liveuser |
11454 |
|
| 3 |
liveuser |
11455 |
";
|
| 226 |
liveuser |
11456 |
|
| 3 |
liveuser |
11457 |
#js function
|
|
|
11458 |
$conf["javaScript::toScript"]["jsFunciton"][]=
|
|
|
11459 |
"
|
| 226 |
liveuser |
11460 |
|
| 3 |
liveuser |
11461 |
/*
|
|
|
11462 |
說明:
|
|
|
11463 |
將要執行的任務交由 web socket 處理.
|
| 226 |
liveuser |
11464 |
|
| 3 |
liveuser |
11465 |
範例:
|
| 226 |
liveuser |
11466 |
|
| 3 |
liveuser |
11467 |
//初始化參數
|
|
|
11468 |
var params={};
|
| 226 |
liveuser |
11469 |
|
| 3 |
liveuser |
11470 |
//設定websocket位置
|
| 30 |
liveuser |
11471 |
params.url='wss://'+location.hostname+':443/wss';
|
| 226 |
liveuser |
11472 |
|
| 3 |
liveuser |
11473 |
//要傳輸的資料
|
|
|
11474 |
params.data={};
|
| 226 |
liveuser |
11475 |
|
| 3 |
liveuser |
11476 |
//用來識別是所需要資料的id
|
|
|
11477 |
params.data.id=crypto.randomUUID();
|
| 226 |
liveuser |
11478 |
|
| 3 |
liveuser |
11479 |
//取得對應的回應
|
|
|
11480 |
var response=await window.qbpwcf.ws.init(params);
|
| 226 |
liveuser |
11481 |
|
| 3 |
liveuser |
11482 |
*/
|
| 226 |
liveuser |
11483 |
|
| 3 |
liveuser |
11484 |
//該方法的物件
|
|
|
11485 |
window.qbpwcf.ws={};
|
| 226 |
liveuser |
11486 |
|
| 3 |
liveuser |
11487 |
//連線到web socket,並傳輸資料,會回傳promise.亦即要在 async function 中使用,且使用 await 來取得結果.
|
| 59 |
liveuser |
11488 |
//params,參數物件.
|
|
|
11489 |
//params.url,web socket的url,加密的連線為wss://url,預設為當前頁面的 domain name/wss
|
|
|
11490 |
//params.callback,函式,參數為收到的訊息,收到訊息後要怎麼處理.
|
|
|
11491 |
//params.data,要傳輸的資料物件.
|
|
|
11492 |
//params.data.id,用於識別wss連線是屬於誰的id資訊,預設為自動產生.
|
| 3 |
liveuser |
11493 |
window.qbpwcf.ws.init=async function(params){
|
| 226 |
liveuser |
11494 |
|
| 3 |
liveuser |
11495 |
//回傳 Promise
|
|
|
11496 |
return new Promise(function(resolve, reject){
|
| 226 |
liveuser |
11497 |
|
| 3 |
liveuser |
11498 |
//若無參數
|
|
|
11499 |
if(Object.keys(params).length==0){
|
| 226 |
liveuser |
11500 |
|
| 3 |
liveuser |
11501 |
//初始化參數
|
|
|
11502 |
params={};
|
| 226 |
liveuser |
11503 |
|
| 3 |
liveuser |
11504 |
//設定websocket位置
|
|
|
11505 |
params.url='wss://'+location.hostname+':443/';
|
| 226 |
liveuser |
11506 |
|
| 3 |
liveuser |
11507 |
//要傳輸的資料
|
|
|
11508 |
params.data={};
|
| 226 |
liveuser |
11509 |
|
| 3 |
liveuser |
11510 |
//用來識別是所需要資料的id
|
|
|
11511 |
params.data.id=crypto.randomUUID();
|
| 226 |
liveuser |
11512 |
|
| 3 |
liveuser |
11513 |
//收到資料後要做的事情
|
|
|
11514 |
params.callback=function(msg){
|
| 226 |
liveuser |
11515 |
|
| 3 |
liveuser |
11516 |
//debug
|
|
|
11517 |
console.log('run callback');
|
| 226 |
liveuser |
11518 |
|
| 3 |
liveuser |
11519 |
}//function end
|
| 226 |
liveuser |
11520 |
|
| 3 |
liveuser |
11521 |
}//if end
|
| 226 |
liveuser |
11522 |
|
| 59 |
liveuser |
11523 |
//如果沒有 url 參數
|
|
|
11524 |
if(params.url==undefined){
|
| 226 |
liveuser |
11525 |
|
| 59 |
liveuser |
11526 |
//初始化要回傳的結果
|
|
|
11527 |
var result={};
|
| 226 |
liveuser |
11528 |
|
| 59 |
liveuser |
11529 |
//設置錯誤訊息
|
|
|
11530 |
result.error='missing param url';
|
| 226 |
liveuser |
11531 |
|
| 59 |
liveuser |
11532 |
//設置執行失敗
|
|
|
11533 |
result.status='false';
|
| 226 |
liveuser |
11534 |
|
| 59 |
liveuser |
11535 |
//回傳結果, await 可以有結果.
|
|
|
11536 |
reject(result);
|
| 226 |
liveuser |
11537 |
|
| 59 |
liveuser |
11538 |
}//if end
|
| 226 |
liveuser |
11539 |
|
| 66 |
liveuser |
11540 |
//如果無 params.data 參數
|
|
|
11541 |
if(params.data==undefined){
|
| 226 |
liveuser |
11542 |
|
| 59 |
liveuser |
11543 |
//初始化要回傳的結果
|
|
|
11544 |
var result={};
|
| 226 |
liveuser |
11545 |
|
| 59 |
liveuser |
11546 |
//設置錯誤訊息
|
|
|
11547 |
result.error='missing param data';
|
| 226 |
liveuser |
11548 |
|
| 59 |
liveuser |
11549 |
//設置執行失敗
|
|
|
11550 |
result.status='false';
|
| 226 |
liveuser |
11551 |
|
| 59 |
liveuser |
11552 |
//回傳結果, await 可以有結果.
|
|
|
11553 |
reject(result);
|
| 226 |
liveuser |
11554 |
|
| 59 |
liveuser |
11555 |
}//if end
|
| 226 |
liveuser |
11556 |
|
| 3 |
liveuser |
11557 |
//如果沒有儲存所有wss連線的變數存在
|
|
|
11558 |
if(this.qbpwcf.ws.wss==undefined){
|
| 226 |
liveuser |
11559 |
|
| 3 |
liveuser |
11560 |
//初始化為空物件
|
|
|
11561 |
this.qbpwcf.ws.wss={};
|
| 226 |
liveuser |
11562 |
|
| 3 |
liveuser |
11563 |
}//if end
|
| 226 |
liveuser |
11564 |
|
| 3 |
liveuser |
11565 |
//設置 既有的 web socket 實體清單 參考
|
|
|
11566 |
var wsList={
|
| 226 |
liveuser |
11567 |
|
| 3 |
liveuser |
11568 |
//取得本函式的參數參考
|
|
|
11569 |
'params':params,
|
| 226 |
liveuser |
11570 |
|
| 3 |
liveuser |
11571 |
//取得既有的 web socket 實體清單
|
|
|
11572 |
'list':Object.keys(window.qbpwcf.ws.wss),
|
| 226 |
liveuser |
11573 |
|
| 3 |
liveuser |
11574 |
}//wsList end
|
| 226 |
liveuser |
11575 |
|
| 3 |
liveuser |
11576 |
//針對每個實體清單
|
|
|
11577 |
for(key in wsList.list){
|
| 226 |
liveuser |
11578 |
|
| 3 |
liveuser |
11579 |
//如果有同樣目標的連線
|
|
|
11580 |
if(key==params.url){
|
| 226 |
liveuser |
11581 |
|
| 3 |
liveuser |
11582 |
//使用既有的連線
|
|
|
11583 |
var conn=value;
|
| 226 |
liveuser |
11584 |
|
| 3 |
liveuser |
11585 |
//如果有要傳遞資料
|
|
|
11586 |
if(params.data!={}){
|
| 226 |
liveuser |
11587 |
|
| 3 |
liveuser |
11588 |
//傳遞資料
|
|
|
11589 |
conn.send(JONS.toString(params.data));
|
|
|
11590 |
|
|
|
11591 |
//如果更新要識別的id?
|
|
|
11592 |
//...
|
| 226 |
liveuser |
11593 |
|
| 3 |
liveuser |
11594 |
}//if end
|
| 226 |
liveuser |
11595 |
|
| 3 |
liveuser |
11596 |
//結束for
|
|
|
11597 |
break;
|
| 226 |
liveuser |
11598 |
|
| 3 |
liveuser |
11599 |
}//if end
|
| 226 |
liveuser |
11600 |
|
| 3 |
liveuser |
11601 |
}//for end
|
| 226 |
liveuser |
11602 |
|
| 3 |
liveuser |
11603 |
//如果尚無可用的ws連線
|
|
|
11604 |
if(conn==undefined){
|
| 226 |
liveuser |
11605 |
|
| 3 |
liveuser |
11606 |
//設定webSocket的連線目標
|
|
|
11607 |
var conn = new WebSocket(params.url);
|
| 226 |
liveuser |
11608 |
|
| 3 |
liveuser |
11609 |
//設置上層參考
|
|
|
11610 |
conn.mother=this.qbpwcf.ws;
|
|
|
11611 |
|
|
|
11612 |
//設置本函式參數的參考
|
|
|
11613 |
conn.params=params;
|
|
|
11614 |
|
|
|
11615 |
//儲存可以使用的連線
|
|
|
11616 |
window.qbpwcf.ws.wss[params.url]=conn;
|
| 226 |
liveuser |
11617 |
|
| 3 |
liveuser |
11618 |
//當有收到訊息時
|
| 59 |
liveuser |
11619 |
conn.onmessage = async function(e){
|
| 226 |
liveuser |
11620 |
|
| 3 |
liveuser |
11621 |
//debug
|
|
|
11622 |
console.log(e);
|
| 226 |
liveuser |
11623 |
|
| 3 |
liveuser |
11624 |
//解析成json
|
| 66 |
liveuser |
11625 |
var revJson=JSON.parse(e.data);
|
| 226 |
liveuser |
11626 |
|
| 3 |
liveuser |
11627 |
//如果有 id
|
|
|
11628 |
if(revJson.id!=undefined){
|
| 226 |
liveuser |
11629 |
|
| 3 |
liveuser |
11630 |
//如果id符合
|
|
|
11631 |
if(revJson.id==params.data.id){
|
| 226 |
liveuser |
11632 |
|
| 3 |
liveuser |
11633 |
//卸除Object revJson的id屬性
|
|
|
11634 |
delete revJson.id;
|
| 226 |
liveuser |
11635 |
|
| 3 |
liveuser |
11636 |
//resolve, await 可以有結果.
|
|
|
11637 |
resolve(revJson);
|
| 226 |
liveuser |
11638 |
|
| 3 |
liveuser |
11639 |
}//if end
|
| 226 |
liveuser |
11640 |
|
| 3 |
liveuser |
11641 |
}//if end
|
| 226 |
liveuser |
11642 |
|
| 66 |
liveuser |
11643 |
//如果有 callback
|
| 3 |
liveuser |
11644 |
if(this.params.callback!=undefined){
|
| 226 |
liveuser |
11645 |
|
| 66 |
liveuser |
11646 |
//callback,收到資料後要做的事情,參數為收到的訊息.
|
| 3 |
liveuser |
11647 |
this.params.callback(e.data);
|
| 226 |
liveuser |
11648 |
|
| 3 |
liveuser |
11649 |
}//if end
|
| 226 |
liveuser |
11650 |
|
| 66 |
liveuser |
11651 |
//反之
|
|
|
11652 |
else{
|
| 226 |
liveuser |
11653 |
|
| 66 |
liveuser |
11654 |
//直接resolve結果
|
|
|
11655 |
resolve(e.data);
|
| 226 |
liveuser |
11656 |
|
| 66 |
liveuser |
11657 |
}//else end
|
| 226 |
liveuser |
11658 |
|
| 3 |
liveuser |
11659 |
}//function end
|
| 226 |
liveuser |
11660 |
|
| 3 |
liveuser |
11661 |
//當連線斷開後
|
|
|
11662 |
conn.onclose = async function(e){
|
| 226 |
liveuser |
11663 |
|
| 3 |
liveuser |
11664 |
//debug
|
|
|
11665 |
console.log('onclose');
|
| 226 |
liveuser |
11666 |
|
| 3 |
liveuser |
11667 |
//等待1秒
|
|
|
11668 |
await window.qbpwcf.sleep.func(1);
|
| 226 |
liveuser |
11669 |
|
| 3 |
liveuser |
11670 |
//重新嘗試一次.
|
|
|
11671 |
this.mother.init(this.params);
|
| 226 |
liveuser |
11672 |
|
| 3 |
liveuser |
11673 |
}//function end
|
| 226 |
liveuser |
11674 |
|
| 3 |
liveuser |
11675 |
//當遇到錯誤時
|
| 59 |
liveuser |
11676 |
conn.onerror = async function(e){
|
| 226 |
liveuser |
11677 |
|
| 3 |
liveuser |
11678 |
//初始化要回傳的結果
|
|
|
11679 |
var result={};
|
| 226 |
liveuser |
11680 |
|
| 3 |
liveuser |
11681 |
//設置錯誤訊息
|
|
|
11682 |
result.error=e;
|
| 226 |
liveuser |
11683 |
|
| 3 |
liveuser |
11684 |
//設置執行失敗
|
|
|
11685 |
result.status='false';
|
| 226 |
liveuser |
11686 |
|
| 3 |
liveuser |
11687 |
//回傳結果, await 可以有結果.
|
|
|
11688 |
reject(result);
|
| 226 |
liveuser |
11689 |
|
| 3 |
liveuser |
11690 |
}//function end
|
| 226 |
liveuser |
11691 |
|
| 3 |
liveuser |
11692 |
//建立與當連線成功後
|
| 226 |
liveuser |
11693 |
conn.onopen = async function(e){
|
|
|
11694 |
|
| 59 |
liveuser |
11695 |
//如果無要傳遞資料
|
|
|
11696 |
if(params.data==undefined){
|
| 226 |
liveuser |
11697 |
|
| 59 |
liveuser |
11698 |
//結束
|
|
|
11699 |
return;
|
| 226 |
liveuser |
11700 |
|
| 59 |
liveuser |
11701 |
}//if end
|
| 226 |
liveuser |
11702 |
|
| 3 |
liveuser |
11703 |
//如果有要傳遞資料
|
|
|
11704 |
if(params.data!={}){
|
| 226 |
liveuser |
11705 |
|
| 3 |
liveuser |
11706 |
//debug
|
|
|
11707 |
console.log(params.data);
|
| 226 |
liveuser |
11708 |
|
| 3 |
liveuser |
11709 |
//將訊息顯現在console
|
|
|
11710 |
console.log('send:'+JSON.stringify(params.data));
|
| 226 |
liveuser |
11711 |
|
| 3 |
liveuser |
11712 |
//傳遞資料
|
|
|
11713 |
conn.send(JSON.stringify(params.data));
|
| 226 |
liveuser |
11714 |
|
| 3 |
liveuser |
11715 |
}//if end
|
| 226 |
liveuser |
11716 |
|
| 3 |
liveuser |
11717 |
}//function end
|
| 226 |
liveuser |
11718 |
|
| 3 |
liveuser |
11719 |
}//if end
|
| 226 |
liveuser |
11720 |
|
| 59 |
liveuser |
11721 |
//Promise must return something
|
|
|
11722 |
resolve(null);
|
| 226 |
liveuser |
11723 |
|
| 3 |
liveuser |
11724 |
});//Promise end
|
| 226 |
liveuser |
11725 |
|
| 3 |
liveuser |
11726 |
}//function end
|
| 226 |
liveuser |
11727 |
|
| 3 |
liveuser |
11728 |
";
|
| 226 |
liveuser |
11729 |
|
| 3 |
liveuser |
11730 |
#$conf["noScriptTag"],字串,是否不要輸出<script></script>,預設為"false",代表要輸出;反之為"true",代表不要輸出.
|
|
|
11731 |
$conf["javaScript::toScript"]["noScriptTag"]=$conf["noScriptTag"];
|
| 226 |
liveuser |
11732 |
|
| 3 |
liveuser |
11733 |
#參考資料:
|
|
|
11734 |
#http://stackoverflow.com/questions/9899372/pure-javascript-equivalent-to-jquerys-ready-how-to-call-a-function-when-the
|
|
|
11735 |
$toScript=javaScript::toScript($conf["javaScript::toScript"]);
|
|
|
11736 |
unset($conf["javaScript::toScript"]);
|
|
|
11737 |
|
|
|
11738 |
#如果建立script失敗
|
|
|
11739 |
if($toScript["status"]==="false"){
|
|
|
11740 |
|
|
|
11741 |
#設置執行失敗
|
|
|
11742 |
$result["status"]="false";
|
|
|
11743 |
|
|
|
11744 |
#設置錯誤訊息
|
|
|
11745 |
$result["error"]=$toScript;
|
|
|
11746 |
|
|
|
11747 |
#回傳結果
|
|
|
11748 |
return $result;
|
|
|
11749 |
|
|
|
11750 |
}#if end
|
|
|
11751 |
|
|
|
11752 |
#取得建立好的js語法
|
|
|
11753 |
$result["content"]=$toScript["content"];
|
|
|
11754 |
|
|
|
11755 |
#設置執行正常
|
|
|
11756 |
$result["status"]="true";
|
|
|
11757 |
|
|
|
11758 |
#回傳結果
|
|
|
11759 |
return $result;
|
|
|
11760 |
|
|
|
11761 |
}#function qbpwcfJavaScript end
|
|
|
11762 |
|
|
|
11763 |
/*
|
|
|
11764 |
#函式說明:
|
|
|
11765 |
#分段續載檔案
|
|
|
11766 |
#回傳結果:
|
|
|
11767 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
|
|
11768 |
#$result["error"],錯誤訊息.
|
|
|
11769 |
#$result["function"],當前執行的函式名稱.
|
|
|
11770 |
#$result["content"],js語法.
|
|
|
11771 |
#必填參數:
|
|
|
11772 |
#$conf["url"],字串,下載檔案的url.
|
|
|
11773 |
$conf["url"]="";
|
|
|
11774 |
#可省略參數:
|
|
|
11775 |
#$conf["scriptTag"],字串,是否要用<script>標籤包起來,預設為"true"代表要;"false"代表不要.
|
|
|
11776 |
#$conf["scriptTag"]="true";
|
|
|
11777 |
#$conf["partSize"],字串,一次要下載多少bytes,預設為"1024",亦即1kb.
|
|
|
11778 |
#$conf["partSize"]="1024";
|
|
|
11779 |
#$conf["retryIn"],字串,如果下載失敗或不完整,要幾秒後再度嘗試,預設為3.
|
|
|
11780 |
#$conf["retryIn"]="3";
|
|
|
11781 |
#參考資料:
|
|
|
11782 |
#無.
|
|
|
11783 |
#備註:
|
|
|
11784 |
#尚不支援,關閉瀏覽器後再續載.
|
|
|
11785 |
#server 端需要搭配 fileAccess::partDownload 方可運行
|
|
|
11786 |
*/
|
|
|
11787 |
public static function conDownload(&$conf=array()){
|
|
|
11788 |
|
|
|
11789 |
#初始化要回傳的結果
|
|
|
11790 |
$result=array();
|
|
|
11791 |
|
|
|
11792 |
#取得當前執行的函數名稱
|
|
|
11793 |
$result["function"]=__FUNCTION__;
|
|
|
11794 |
|
|
|
11795 |
#如果沒有參數
|
|
|
11796 |
if(func_num_args()==0){
|
|
|
11797 |
|
|
|
11798 |
#設置執行失敗
|
|
|
11799 |
$result["status"]="false";
|
|
|
11800 |
|
|
|
11801 |
#設置執行錯誤訊息
|
|
|
11802 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
11803 |
|
|
|
11804 |
#回傳結果
|
|
|
11805 |
return $result;
|
|
|
11806 |
|
|
|
11807 |
}#if end
|
|
|
11808 |
|
|
|
11809 |
#取得參數
|
|
|
11810 |
$result["argu"]=$conf;
|
|
|
11811 |
|
|
|
11812 |
#如果 $conf 不為陣列
|
|
|
11813 |
if(gettype($conf)!=="array"){
|
|
|
11814 |
|
|
|
11815 |
#設置執行失敗
|
|
|
11816 |
$result["status"]="false";
|
|
|
11817 |
|
|
|
11818 |
#設置執行錯誤訊息
|
|
|
11819 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
11820 |
|
|
|
11821 |
#如果傳入的參數為 null
|
|
|
11822 |
if($conf===null){
|
|
|
11823 |
|
|
|
11824 |
#設置執行錯誤訊息
|
|
|
11825 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
11826 |
|
|
|
11827 |
}#if end
|
|
|
11828 |
|
|
|
11829 |
#回傳結果
|
|
|
11830 |
return $result;
|
|
|
11831 |
|
|
|
11832 |
}#if end
|
|
|
11833 |
|
|
|
11834 |
#檢查參數
|
|
|
11835 |
#函式說明:
|
|
|
11836 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
11837 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
11838 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
11839 |
#$result["function"],當前執行的函式名稱.
|
|
|
11840 |
#$result["argu"],設置給予的參數.
|
|
|
11841 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
11842 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
11843 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
11844 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
11845 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
11846 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
11847 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
11848 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
11849 |
#必填寫的參數:
|
|
|
11850 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
11851 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
11852 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
11853 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
11854 |
#可以省略的參數:
|
|
|
11855 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
11856 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("url");
|
|
|
11857 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
11858 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
11859 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
11860 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
11861 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
11862 |
#$conf["canNotBeEmpty"]=array();
|
|
|
11863 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
11864 |
#$conf["canBeEmpty"]=array();
|
|
|
11865 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
11866 |
$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("scriptTag","partSize","retryIn");
|
|
|
11867 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
11868 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("scriptTag","partSize","retryIn");
|
|
|
11869 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
11870 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
|
|
|
11871 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
11872 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true","1024","3","60");
|
|
|
11873 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
11874 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
11875 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
11876 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
11877 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
11878 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
11879 |
#參考資料來源:
|
|
|
11880 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
11881 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
11882 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
11883 |
|
|
|
11884 |
#如果檢查參數失敗
|
|
|
11885 |
if($checkArguments["status"]==="false"){
|
|
|
11886 |
|
|
|
11887 |
#設置執行失敗
|
|
|
11888 |
$result["status"]="false";
|
|
|
11889 |
|
|
|
11890 |
#設置執行錯誤
|
|
|
11891 |
$result["error"]=$checkArguments;
|
|
|
11892 |
|
|
|
11893 |
#回傳結果
|
|
|
11894 |
return $result;
|
|
|
11895 |
|
|
|
11896 |
}#if end
|
|
|
11897 |
|
|
|
11898 |
#如果檢查參數不通過
|
|
|
11899 |
if($checkArguments["passed"]==="false"){
|
|
|
11900 |
|
|
|
11901 |
#設置執行失敗
|
|
|
11902 |
$result["status"]="false";
|
|
|
11903 |
|
|
|
11904 |
#設置執行錯誤
|
|
|
11905 |
$result["error"]=$checkArguments;
|
|
|
11906 |
|
|
|
11907 |
#回傳結果
|
|
|
11908 |
return $result;
|
|
|
11909 |
|
|
|
11910 |
}#if end
|
|
|
11911 |
|
|
|
11912 |
#續載的js
|
|
|
11913 |
$result["content"]=
|
|
|
11914 |
"
|
|
|
11915 |
var myConDownloadAgent=new conDownloadAgent();
|
|
|
11916 |
myConDownloadAgent.fileUrl='".$conf["url"]."';
|
|
|
11917 |
myConDownloadAgent.partSize='".$conf["partSize"]."';
|
|
|
11918 |
myConDownloadAgent.retryIn=".$conf["retryIn"].";
|
|
|
11919 |
myConDownloadAgent.getPart();
|
|
|
11920 |
";
|
|
|
11921 |
|
|
|
11922 |
#如果要用<script>標籤包起來
|
|
|
11923 |
if($conf["scriptTag"]==="true"){
|
|
|
11924 |
|
|
|
11925 |
#函式說明:
|
|
|
11926 |
#將要執行的script語法透過該函式執行(會在程式外層用<script></script>包起來).
|
|
|
11927 |
#回傳結果:
|
|
|
11928 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
11929 |
#$result["error"],錯誤訊息陣列
|
|
|
11930 |
#$result["function"],當前執行的函數名稱
|
|
|
11931 |
#$result["content"],要執行的javaScript語法
|
|
|
11932 |
#必填參數:
|
|
|
11933 |
#$conf["script"],字串,要執行的javaScript語法.
|
|
|
11934 |
$conf["javaScript::toScript"]["script"]=$result["content"];
|
|
|
11935 |
#可省略參數:
|
|
|
11936 |
#$conf["onReady"],字串,是否要在網頁完全載入後再執行,"false"為不等載入完就先執行,預設為"true"要等載入完再執行.
|
|
|
11937 |
#$conf["javaScript::toScript"]["onReady"]=$conf["onReady"];
|
|
|
11938 |
#$conf["globalJs"],字串陣列,為要放入<script>標籤的js全域變數.
|
|
|
11939 |
#$conf["globalJs"]=array();
|
|
|
11940 |
#$conf["jsFunciton"],字串陣列,為要放入<script>標籤的js函數.
|
|
|
11941 |
#$conf["jsFunciton"]=array();
|
|
|
11942 |
#參考資料:
|
|
|
11943 |
#http://stackoverflow.com/questions/9899372/pure-javascript-equivalent-to-jquerys-ready-how-to-call-a-function-when-the
|
|
|
11944 |
$toScript=javaScript::toScript($conf["javaScript::toScript"]);
|
|
|
11945 |
unset($conf["javaScript::toScript"]);
|
|
|
11946 |
|
|
|
11947 |
#如果轉成script失敗
|
|
|
11948 |
if($toScript["status"]==="false"){
|
|
|
11949 |
|
|
|
11950 |
#設置執行不正常
|
|
|
11951 |
$result["status"]="false";
|
|
|
11952 |
|
|
|
11953 |
#設置執行錯誤訊息
|
|
|
11954 |
$result["error"]=$toScript;
|
|
|
11955 |
|
|
|
11956 |
#回傳結果
|
|
|
11957 |
return $result;
|
|
|
11958 |
|
|
|
11959 |
}#if end
|
|
|
11960 |
|
|
|
11961 |
#取得js語法
|
|
|
11962 |
$result["content"]=$toScript["content"];
|
|
|
11963 |
|
|
|
11964 |
}#if end
|
|
|
11965 |
|
|
|
11966 |
#設置執行正常
|
|
|
11967 |
$result["status"]="true";
|
|
|
11968 |
|
|
|
11969 |
#回傳結果
|
|
|
11970 |
return $result;
|
|
|
11971 |
|
|
|
11972 |
}#function conDownload end
|
| 226 |
liveuser |
11973 |
|
| 3 |
liveuser |
11974 |
/*
|
|
|
11975 |
#函式說明:
|
|
|
11976 |
#建立rwd的置頂menu,橫向span選單遇到寬度不足會變成div選單,其中第一個元素爲Logo.
|
|
|
11977 |
#回傳結果:
|
|
|
11978 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
11979 |
#$result["error"],錯誤訊息.
|
|
|
11980 |
#$result["function"],當前執行的函數名稱.
|
|
|
11981 |
#$result["content"],語法.
|
|
|
11982 |
#必填參數:
|
|
|
11983 |
#$conf["firstEleId"],字串,選單的擡頭元素id.
|
|
|
11984 |
$conf["firstEleId"]="";
|
|
|
11985 |
#$conf["otherEleClass"],字串,除擡頭選單外項目的共同類別名稱.
|
|
|
11986 |
$conf["otherEleClass"]="";
|
| 226 |
liveuser |
11987 |
#可省略參數:
|
| 3 |
liveuser |
11988 |
#$conf["bgColor"],字串,選單的背景顏色,預設爲"#FFFFFF".
|
|
|
11989 |
#$conf["bgColor"]="";
|
|
|
11990 |
#參考資料:
|
|
|
11991 |
#無.
|
|
|
11992 |
#備註:
|
|
|
11993 |
#bgColor尚未實作
|
|
|
11994 |
#固定在頂端或底端的功能未實作
|
|
|
11995 |
*/
|
|
|
11996 |
public static function rwdMenu($conf){
|
| 226 |
liveuser |
11997 |
|
| 3 |
liveuser |
11998 |
return css::rwdMenu($conf);
|
| 226 |
liveuser |
11999 |
|
| 3 |
liveuser |
12000 |
}#function rwdMenu end
|
| 226 |
liveuser |
12001 |
|
| 3 |
liveuser |
12002 |
/*
|
|
|
12003 |
#函式說明:
|
|
|
12004 |
#建立廣告幻燈片,實際上為div的背景會隨着時間變化.
|
|
|
12005 |
#回傳結果:
|
|
|
12006 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
12007 |
#$result["error"],錯誤訊息.
|
|
|
12008 |
#$result["function"],當前執行的函數名稱.
|
|
|
12009 |
#$result["content"],語法.
|
|
|
12010 |
#必填參數:
|
|
|
12011 |
#$conf["divId"],字串,廣告區域的div id.
|
|
|
12012 |
$conf["divId"]="";
|
|
|
12013 |
#$conf["divClass"],字串,廣告區域用於套用動畫效果的div class名稱.
|
|
|
12014 |
$conf["divClass"]="";
|
|
|
12015 |
#$conf["adImg"],字串陣列,廣告圖片的網站陣列.
|
|
|
12016 |
$conf["adImg"]=array();
|
| 226 |
liveuser |
12017 |
#可省略參數:
|
| 3 |
liveuser |
12018 |
#無.
|
|
|
12019 |
#參考資料:
|
|
|
12020 |
#無.
|
|
|
12021 |
#備註:
|
|
|
12022 |
#bgColor尚未實作
|
|
|
12023 |
#固定在頂端或底端的功能未實作
|
|
|
12024 |
*/
|
|
|
12025 |
public static function adImg($conf){
|
| 226 |
liveuser |
12026 |
|
| 3 |
liveuser |
12027 |
#初始化要回傳的結果
|
|
|
12028 |
$result=array();
|
|
|
12029 |
|
|
|
12030 |
#取得當前執行的函數名稱
|
|
|
12031 |
$result["function"]=__FUNCTION__;
|
|
|
12032 |
|
|
|
12033 |
#如果沒有參數
|
|
|
12034 |
if(func_num_args()==0){
|
|
|
12035 |
|
|
|
12036 |
#設置執行失敗
|
|
|
12037 |
$result["status"]="false";
|
|
|
12038 |
|
|
|
12039 |
#設置執行錯誤訊息
|
|
|
12040 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
12041 |
|
|
|
12042 |
#回傳結果
|
|
|
12043 |
return $result;
|
|
|
12044 |
|
|
|
12045 |
}#if end
|
|
|
12046 |
|
|
|
12047 |
#取得參數
|
|
|
12048 |
$result["argu"]=$conf;
|
|
|
12049 |
|
|
|
12050 |
#如果 $conf 不為陣列
|
|
|
12051 |
if(gettype($conf)!=="array"){
|
|
|
12052 |
|
|
|
12053 |
#設置執行失敗
|
|
|
12054 |
$result["status"]="false";
|
|
|
12055 |
|
|
|
12056 |
#設置執行錯誤訊息
|
|
|
12057 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
12058 |
|
|
|
12059 |
#如果傳入的參數為 null
|
|
|
12060 |
if($conf===null){
|
|
|
12061 |
|
|
|
12062 |
#設置執行錯誤訊息
|
|
|
12063 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
12064 |
|
|
|
12065 |
}#if end
|
|
|
12066 |
|
|
|
12067 |
#回傳結果
|
|
|
12068 |
return $result;
|
|
|
12069 |
|
|
|
12070 |
}#if end
|
|
|
12071 |
|
|
|
12072 |
#檢查參數
|
|
|
12073 |
#函式說明:
|
|
|
12074 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
12075 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
12076 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
12077 |
#$result["function"],當前執行的函式名稱.
|
|
|
12078 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
12079 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
12080 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
12081 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
12082 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
12083 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
12084 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
12085 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
12086 |
#必填參數:
|
|
|
12087 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
12088 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
12089 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
12090 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("divId","divClass","adImg");
|
|
|
12091 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
12092 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","array");
|
|
|
12093 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
12094 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
12095 |
#可以省略的參數:
|
|
|
12096 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
12097 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
12098 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
12099 |
#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("bgColor");
|
|
|
12100 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
12101 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("bgColor");
|
|
|
12102 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
12103 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
12104 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
12105 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("#FFFFFF");
|
|
|
12106 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
12107 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("headOrTail","target","styleAttr","styleVal","content");
|
|
|
12108 |
#參考資料來源:
|
|
|
12109 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
12110 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
12111 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
12112 |
|
|
|
12113 |
#如果檢查參數失敗
|
|
|
12114 |
if($checkArguments["status"]==="false"){
|
|
|
12115 |
|
|
|
12116 |
#設置執行不正常
|
|
|
12117 |
$result["status"]="false";
|
|
|
12118 |
|
|
|
12119 |
#設置執行錯誤
|
|
|
12120 |
$result["error"]=$checkArguments;
|
|
|
12121 |
|
|
|
12122 |
#回傳結果
|
|
|
12123 |
return $result;
|
|
|
12124 |
|
|
|
12125 |
}#if end
|
|
|
12126 |
|
|
|
12127 |
#如果檢查參數不通過
|
|
|
12128 |
if($checkArguments["passed"]==="false"){
|
|
|
12129 |
|
|
|
12130 |
#設置執行不正常
|
|
|
12131 |
$result["status"]="false";
|
|
|
12132 |
|
|
|
12133 |
#設置執行錯誤
|
|
|
12134 |
$result["error"]=$checkArguments;
|
|
|
12135 |
|
|
|
12136 |
#回傳結果
|
|
|
12137 |
return $result;
|
|
|
12138 |
|
|
|
12139 |
}#if end
|
| 226 |
liveuser |
12140 |
|
| 3 |
liveuser |
12141 |
#初始化要回傳的語法
|
|
|
12142 |
$result["content"]="";
|
| 226 |
liveuser |
12143 |
|
| 3 |
liveuser |
12144 |
#ad bar
|
|
|
12145 |
#函式說明:
|
|
|
12146 |
#<div>區塊,裡面可以指定css的class樣式,可以指定提示文字.
|
|
|
12147 |
#$result["status"],字串,執行否正常,"true"代表正常,"false"代表不正常.
|
|
|
12148 |
#$result["functin"],字串,當前函數的名稱.
|
|
|
12149 |
#$result["error"],陣列,錯訊訊息.
|
|
|
12150 |
#$result["content"],字串,含有<div>標籤的內容.
|
|
|
12151 |
#必填參數:
|
|
|
12152 |
#$conf["contentArray"],字串陣列,要放入的內容陣列.
|
|
|
12153 |
$conf["css::divSection"]["contentArray"]=array("");
|
|
|
12154 |
#可省略參數
|
|
|
12155 |
#$conf["id"],字串,div區塊的id.
|
|
|
12156 |
$conf["css::divSection"]["id"]=$conf["divId"];
|
|
|
12157 |
#$conf["styleAttr"],字串陣列,給div區段要套用的style樣式屬性.
|
|
|
12158 |
$conf["css::divSection"]["styleAttr"]=array("width","height","background-size");
|
|
|
12159 |
#$conf["styleVal"],字串陣列,給div區段要套用的style樣式數值.
|
|
|
12160 |
$conf["css::divSection"]["styleVal"]=array("100vw","100vh","cover");
|
|
|
12161 |
#$conf["class"],字串,div區段要套用的css樣式.
|
|
|
12162 |
$conf["css::divSection"]["class"]=$conf["divClass"];
|
|
|
12163 |
#$conf["title"],陣列,滑鼠移到上面時要顯示的內容,每個元素代表一列內容.
|
|
|
12164 |
#$conf["title"]=array();
|
|
|
12165 |
#$conf["oneScreenSize"],字串,div區塊是否要占一個螢幕的大小,預設為"false"不設定,"true"為設定成一個螢幕的大小.
|
|
|
12166 |
#$conf["oneScreenSize"]="false";
|
|
|
12167 |
#$conf["textAlignCenter"],字串,div區塊是否要置中,預設為$conf["oneScreenSize"]的值,"false"為不置中,"true"代表要置中.
|
|
|
12168 |
$conf["css::divSection"]["textAlignCenter"]="true";
|
|
|
12169 |
#$conf["data"],字串陣列,每個要設置的屬性data內容,例如array("option1"=>"A","option2"=>"B"),預設不使用.
|
|
|
12170 |
#$conf["data"]=array();
|
|
|
12171 |
$divSection=css::divSection($conf["css::divSection"]);
|
|
|
12172 |
unset($conf["css::divSection"]);
|
|
|
12173 |
|
|
|
12174 |
#如果建立div區塊失敗
|
|
|
12175 |
if($divSection["status"]==="false"){
|
| 226 |
liveuser |
12176 |
|
| 3 |
liveuser |
12177 |
#設置執行失敗
|
|
|
12178 |
$result["status"]="false";
|
| 226 |
liveuser |
12179 |
|
| 3 |
liveuser |
12180 |
#設置錯誤訊息
|
|
|
12181 |
$result["error"]=$divSection;
|
| 226 |
liveuser |
12182 |
|
| 3 |
liveuser |
12183 |
#回傳結果
|
|
|
12184 |
return $result;
|
| 226 |
liveuser |
12185 |
|
| 3 |
liveuser |
12186 |
}#if end
|
|
|
12187 |
|
|
|
12188 |
#儲存內容
|
|
|
12189 |
$result["content"]=$result["content"].$divSection["content"];
|
| 226 |
liveuser |
12190 |
|
| 3 |
liveuser |
12191 |
#儲存廣告圖片的計數
|
|
|
12192 |
$adImgCount=count($conf["adImg"]);
|
| 226 |
liveuser |
12193 |
|
| 3 |
liveuser |
12194 |
#函式說明:
|
|
|
12195 |
#製作針對 css class 的動畫,請套用在div上,才會有效果
|
|
|
12196 |
#回傳結果:
|
|
|
12197 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
12198 |
#$result["content"],css動畫設定的語法
|
|
|
12199 |
#$result["function"],當前執行的函數
|
|
|
12200 |
#$result["error"],涵式錯誤訊息陣列
|
|
|
12201 |
#$result["warning"],警告訊息陣列
|
|
|
12202 |
#必填參數:
|
|
|
12203 |
#$conf["name"],字串,css動畫的名稱.
|
|
|
12204 |
$conf["css::animation"]["name"]=$conf["divClass"];
|
|
|
12205 |
#$conf["durationTime"],字串,整個動畫需要幾秒完成,例如"5s".
|
|
|
12206 |
$durationTime=$adImgCount*5;
|
|
|
12207 |
$durationTime=$durationTime."s";
|
|
|
12208 |
$conf["css::animation"]["durationTime"]=$durationTime;
|
|
|
12209 |
#$conf["iteration"],字串,整個動畫要重複幾次,"infinite"代表不斷地重複,"0"代表不重複執行.
|
|
|
12210 |
$conf["css::animation"]["iteration"]="infinite";
|
|
|
12211 |
#$conf["direction"],字串,動畫要怎麼樣重複,"alternate"代表來回執行,"normal"代表正常執行.
|
|
|
12212 |
$conf["css::animation"]["direction"]="alternate";
|
|
|
12213 |
#$conf["delay"],字串,動畫要延遲幾秒開始,例如"0s".
|
|
|
12214 |
$conf["css::animation"]["delay"]="0s";
|
|
|
12215 |
#$conf["speedMode"],字串,動畫執行過程的速度要用什麼模式來執行,"linear"代表等速,"ease"代表起始跟結尾是靜止的,中間是最快的.
|
|
|
12216 |
$conf["css::animation"]["speedMode"]="linear";
|
|
|
12217 |
#可省略參數:
|
| 226 |
liveuser |
12218 |
|
| 3 |
liveuser |
12219 |
#每個廣告圖片的依存時間百分比.
|
|
|
12220 |
$perImgPercentage=(int)(100/$adImgCount/2);
|
| 226 |
liveuser |
12221 |
|
| 3 |
liveuser |
12222 |
#$conf["keyFrameStartPoint"],字串陣列,各個動畫單位開始的時間百分比,"0%"與"from"代表一開始,"100%"與"to"代表時間結束.
|
|
|
12223 |
#$conf["css::animation"]["keyFrameStartPoint"]=array("0%","10%","30%","70%","90%","100%");
|
| 226 |
liveuser |
12224 |
|
| 3 |
liveuser |
12225 |
#針對每個廣告圖片
|
|
|
12226 |
for($i=1;$i<=$adImgCount*2;$i=$i+2){
|
| 226 |
liveuser |
12227 |
|
| 3 |
liveuser |
12228 |
#如果是第一個
|
|
|
12229 |
if($i===1){
|
| 226 |
liveuser |
12230 |
|
| 3 |
liveuser |
12231 |
#起始點
|
| 226 |
liveuser |
12232 |
$conf["css::animation"]["keyFrameStartPoint"][]="0%";
|
| 3 |
liveuser |
12233 |
$conf["css::animation"]["keyFrameStartPoint"][]=$perImgPercentage*$i."%";
|
| 226 |
liveuser |
12234 |
|
| 3 |
liveuser |
12235 |
}#if end
|
| 226 |
liveuser |
12236 |
|
| 3 |
liveuser |
12237 |
#反之如果是最後一個
|
|
|
12238 |
else if($i===$adImgCount*2-1){
|
| 226 |
liveuser |
12239 |
|
| 3 |
liveuser |
12240 |
#最後一點
|
|
|
12241 |
$conf["css::animation"]["keyFrameStartPoint"][]=$perImgPercentage*($i)."%";
|
|
|
12242 |
$conf["css::animation"]["keyFrameStartPoint"][]="100%";
|
| 226 |
liveuser |
12243 |
|
| 3 |
liveuser |
12244 |
}#if end
|
| 226 |
liveuser |
12245 |
|
| 3 |
liveuser |
12246 |
#其他狀況
|
|
|
12247 |
else{
|
|
|
12248 |
#擺兩個點,在區間內呈現
|
|
|
12249 |
$conf["css::animation"]["keyFrameStartPoint"][]=$perImgPercentage*($i-1)."%";
|
| 226 |
liveuser |
12250 |
|
| 3 |
liveuser |
12251 |
#$i多加1
|
|
|
12252 |
$conf["css::animation"]["keyFrameStartPoint"][]=$perImgPercentage*($i+1)."%";
|
| 226 |
liveuser |
12253 |
|
| 3 |
liveuser |
12254 |
}#else end
|
| 226 |
liveuser |
12255 |
|
| 3 |
liveuser |
12256 |
}#for end
|
| 226 |
liveuser |
12257 |
|
| 3 |
liveuser |
12258 |
#debug
|
|
|
12259 |
#var_dump($conf["css::animation"]["keyFrameStartPoint"]);
|
| 226 |
liveuser |
12260 |
|
| 3 |
liveuser |
12261 |
#$conf["keyFrameCssMoveAttribute"],二維字串陣列,各個動畫影格子的與動畫相關的css屬性.
|
|
|
12262 |
#$conf["keyFrameCssMoveAttribute"][]=array();
|
|
|
12263 |
#$conf["keyFrameCssMoveValue"],二維字串陣列,各個動畫影格子的與動畫相關的css屬性.
|
|
|
12264 |
#$conf["keyFrameCssMoveValue"][]=array();
|
| 226 |
liveuser |
12265 |
|
| 3 |
liveuser |
12266 |
#$conf["keyFrameCssAttribute"],二維字串陣列,各個動畫影格子的一般非動畫的css屬性.
|
| 226 |
liveuser |
12267 |
|
| 3 |
liveuser |
12268 |
#跑 $adImgCount*2 的次數
|
|
|
12269 |
for($i=0;$i<$adImgCount*2;$i++){
|
| 226 |
liveuser |
12270 |
|
| 3 |
liveuser |
12271 |
$conf["css::animation"]["keyFrameCssAttribute"][]=array("background-image");
|
| 226 |
liveuser |
12272 |
|
| 3 |
liveuser |
12273 |
}#for end
|
| 226 |
liveuser |
12274 |
|
| 3 |
liveuser |
12275 |
#$conf["keyFrameCssValue"],二維字串陣列,各個動畫格子的css屬性數值.
|
| 226 |
liveuser |
12276 |
|
| 3 |
liveuser |
12277 |
#跑 $adImgCount 的次數
|
|
|
12278 |
for($i=0;$i<$adImgCount;$i++){
|
| 226 |
liveuser |
12279 |
|
| 3 |
liveuser |
12280 |
#兩個點的圖片要一致
|
|
|
12281 |
$conf["css::animation"]["keyFrameCssValue"][]=array("url('".$conf["adImg"][$i]."')");
|
|
|
12282 |
$conf["css::animation"]["keyFrameCssValue"][]=array("url('".$conf["adImg"][$i]."')");
|
| 226 |
liveuser |
12283 |
|
| 3 |
liveuser |
12284 |
}#for end
|
| 226 |
liveuser |
12285 |
|
| 3 |
liveuser |
12286 |
#參考資料:
|
|
|
12287 |
#css動畫,http://blogger.gtwang.org/2013/12/using-css3-animation.html
|
|
|
12288 |
#w3c的animation-keyframes,http://www.w3schools.com/cssref/css3_pr_animation-keyframes.asp
|
|
|
12289 |
$animation=css::animation($conf["css::animation"]);
|
|
|
12290 |
unset($conf["css::animation"]);
|
| 226 |
liveuser |
12291 |
|
| 3 |
liveuser |
12292 |
#如果建立動畫失敗
|
|
|
12293 |
if($animation["status"]==="false"){
|
| 226 |
liveuser |
12294 |
|
| 3 |
liveuser |
12295 |
#設置執行失敗
|
|
|
12296 |
$result["status"]="false";
|
| 226 |
liveuser |
12297 |
|
| 3 |
liveuser |
12298 |
#設置錯誤訊息
|
|
|
12299 |
$result["error"]=$animation;
|
| 226 |
liveuser |
12300 |
|
| 3 |
liveuser |
12301 |
#回傳結果
|
|
|
12302 |
return $result;
|
| 226 |
liveuser |
12303 |
|
| 3 |
liveuser |
12304 |
}#if end
|
|
|
12305 |
|
|
|
12306 |
#儲存內容
|
|
|
12307 |
$result["content"]=$result["content"].$animation["content"];
|
| 226 |
liveuser |
12308 |
|
| 3 |
liveuser |
12309 |
#函式說明:
|
|
|
12310 |
#將要執行的script語法透過該函式執行(會在程式外層用<script></script>包起來).
|
|
|
12311 |
#回傳結果:
|
|
|
12312 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
12313 |
#$result["error"],錯誤訊息陣列
|
|
|
12314 |
#$result["function"],當前執行的函數名稱
|
|
|
12315 |
#$result["content"],要執行的javaScript語法
|
|
|
12316 |
#必填參數:
|
|
|
12317 |
#$conf["script"],字串,要執行的javaScript語法.
|
|
|
12318 |
$conf["javaScript::toScript"]["script"]=
|
|
|
12319 |
"
|
|
|
12320 |
//debug
|
|
|
12321 |
console.log('loaded');
|
| 226 |
liveuser |
12322 |
|
| 3 |
liveuser |
12323 |
//get scroll div
|
|
|
12324 |
var scrollDiv=document.getElementById('".$conf["divId"]."');
|
| 226 |
liveuser |
12325 |
|
| 3 |
liveuser |
12326 |
//set click one to 0
|
| 226 |
liveuser |
12327 |
scrollDiv.dataset.clickOnce=0;
|
|
|
12328 |
|
| 3 |
liveuser |
12329 |
//scrolliv click event
|
|
|
12330 |
scrollDiv.addEventListener('click',function(e){
|
| 226 |
liveuser |
12331 |
|
| 3 |
liveuser |
12332 |
//set scroll div id
|
|
|
12333 |
var scrollDivId='".$conf["divId"]."';
|
| 226 |
liveuser |
12334 |
|
| 3 |
liveuser |
12335 |
//get scroll div
|
|
|
12336 |
var scrollDiv=document.getElementById(scrollDivId);
|
| 226 |
liveuser |
12337 |
|
| 3 |
liveuser |
12338 |
//如果已經點擊過一次了
|
|
|
12339 |
if(scrollDiv.dataset.clickOnce==='1'){
|
|
|
12340 |
|
|
|
12341 |
//結束事件
|
|
|
12342 |
return true;
|
| 226 |
liveuser |
12343 |
|
|
|
12344 |
}//if end
|
|
|
12345 |
|
| 3 |
liveuser |
12346 |
//觸發者非div
|
|
|
12347 |
if(e.target.id!==scrollDivId){
|
| 226 |
liveuser |
12348 |
|
| 3 |
liveuser |
12349 |
//debug
|
|
|
12350 |
console.log(e.target.id+'!=='+scrollDivId);
|
| 226 |
liveuser |
12351 |
|
| 3 |
liveuser |
12352 |
//debug
|
|
|
12353 |
console.log(e.target);
|
| 226 |
liveuser |
12354 |
|
| 3 |
liveuser |
12355 |
//end function
|
|
|
12356 |
return false;
|
| 226 |
liveuser |
12357 |
|
| 3 |
liveuser |
12358 |
}//if end
|
| 226 |
liveuser |
12359 |
|
| 3 |
liveuser |
12360 |
//debug
|
|
|
12361 |
console.log(e.target);
|
| 226 |
liveuser |
12362 |
|
| 3 |
liveuser |
12363 |
//get target computed style
|
|
|
12364 |
var tcs=window.getComputedStyle(e.target,null);
|
| 226 |
liveuser |
12365 |
|
| 3 |
liveuser |
12366 |
//debug
|
|
|
12367 |
console.log(tcs);
|
| 226 |
liveuser |
12368 |
|
| 3 |
liveuser |
12369 |
//get style background image url
|
|
|
12370 |
var tcsBg=tcs.backgroundImage;
|
| 226 |
liveuser |
12371 |
|
| 3 |
liveuser |
12372 |
//debug
|
|
|
12373 |
console.log(tcsBg);
|
| 226 |
liveuser |
12374 |
|
| 3 |
liveuser |
12375 |
//split by '/'
|
|
|
12376 |
var splitedStr=tcsBg.split('/');
|
| 226 |
liveuser |
12377 |
|
|
|
12378 |
//debug
|
| 3 |
liveuser |
12379 |
for(i=0;i<splitedStr.length;i++){
|
| 226 |
liveuser |
12380 |
|
| 3 |
liveuser |
12381 |
//show each section str
|
|
|
12382 |
console.log(splitedStr[i]);
|
| 226 |
liveuser |
12383 |
|
| 3 |
liveuser |
12384 |
}//for end
|
| 226 |
liveuser |
12385 |
|
| 3 |
liveuser |
12386 |
//get clicked image file name
|
| 226 |
liveuser |
12387 |
var clickedImgName=splitedStr[splitedStr.length-1].split('\")')[0];
|
|
|
12388 |
|
| 3 |
liveuser |
12389 |
//debug
|
|
|
12390 |
console.log(clickedImgName);
|
| 226 |
liveuser |
12391 |
|
| 3 |
liveuser |
12392 |
//split by '\"'
|
|
|
12393 |
var splitedStr=tcsBg.split('\"');
|
| 226 |
liveuser |
12394 |
|
| 3 |
liveuser |
12395 |
//get clickedImgUrl
|
| 226 |
liveuser |
12396 |
var clickedImgUrl=splitedStr[1];
|
|
|
12397 |
|
| 3 |
liveuser |
12398 |
//debug
|
| 226 |
liveuser |
12399 |
console.log(clickedImgUrl);
|
|
|
12400 |
|
| 3 |
liveuser |
12401 |
//delete applied class
|
|
|
12402 |
scrollDiv.classList={};
|
| 226 |
liveuser |
12403 |
|
| 3 |
liveuser |
12404 |
//set clicked image
|
|
|
12405 |
scrollDiv.style.backgroundImage='url('+clickedImgUrl+')';
|
| 226 |
liveuser |
12406 |
|
| 3 |
liveuser |
12407 |
//設置點擊過一次了
|
|
|
12408 |
scrollDiv.dataset.clickOnce='1';
|
|
|
12409 |
|
|
|
12410 |
//scrolliv click event
|
|
|
12411 |
scrollDiv.addEventListener('click',function(e){
|
| 226 |
liveuser |
12412 |
|
| 3 |
liveuser |
12413 |
//set scroll div id
|
|
|
12414 |
var scrollDivId='".$conf["divId"]."';
|
| 226 |
liveuser |
12415 |
|
| 3 |
liveuser |
12416 |
//get scroll div
|
|
|
12417 |
var scrollDiv=document.getElementById(scrollDivId);
|
| 226 |
liveuser |
12418 |
|
| 3 |
liveuser |
12419 |
//如果已經點擊過一次了
|
|
|
12420 |
if(scrollDiv.dataset.clickOnce!=='1'){
|
|
|
12421 |
|
|
|
12422 |
//結束執行
|
|
|
12423 |
return true;
|
| 226 |
liveuser |
12424 |
|
| 3 |
liveuser |
12425 |
}//if end
|
| 226 |
liveuser |
12426 |
|
| 3 |
liveuser |
12427 |
//debug
|
|
|
12428 |
console.log('should change to next pic');
|
| 226 |
liveuser |
12429 |
|
| 3 |
liveuser |
12430 |
//debug
|
|
|
12431 |
console.log(e.target);
|
| 226 |
liveuser |
12432 |
|
| 3 |
liveuser |
12433 |
//get target computed style
|
|
|
12434 |
var tcs=window.getComputedStyle(e.target,null);
|
| 226 |
liveuser |
12435 |
|
| 3 |
liveuser |
12436 |
//debug
|
|
|
12437 |
console.log(tcs);
|
| 226 |
liveuser |
12438 |
|
| 3 |
liveuser |
12439 |
//get style background image url
|
|
|
12440 |
var tcsBg=tcs.backgroundImage;
|
| 226 |
liveuser |
12441 |
|
| 3 |
liveuser |
12442 |
//debug
|
|
|
12443 |
console.log(tcsBg);
|
| 226 |
liveuser |
12444 |
|
| 3 |
liveuser |
12445 |
//split by '/'
|
|
|
12446 |
var splitedStr=tcsBg.split('/');
|
| 226 |
liveuser |
12447 |
|
|
|
12448 |
//debug
|
| 3 |
liveuser |
12449 |
for(i=0;i<splitedStr.length;i++){
|
| 226 |
liveuser |
12450 |
|
| 3 |
liveuser |
12451 |
//show each section str
|
|
|
12452 |
console.log(splitedStr[i]);
|
| 226 |
liveuser |
12453 |
|
| 3 |
liveuser |
12454 |
}//for end
|
| 226 |
liveuser |
12455 |
|
| 3 |
liveuser |
12456 |
//get clicked image file name
|
| 226 |
liveuser |
12457 |
var clickedImgName=splitedStr[splitedStr.length-1].split('\")')[0];
|
|
|
12458 |
|
| 3 |
liveuser |
12459 |
//debug
|
|
|
12460 |
console.log(clickedImgName);
|
| 226 |
liveuser |
12461 |
|
| 3 |
liveuser |
12462 |
//split by '\"'
|
|
|
12463 |
var splitedStr=tcsBg.split('\"');
|
| 226 |
liveuser |
12464 |
|
| 3 |
liveuser |
12465 |
//get clickedImgUrl
|
| 226 |
liveuser |
12466 |
var clickedImgUrl=splitedStr[1];
|
|
|
12467 |
|
| 3 |
liveuser |
12468 |
//debug
|
| 226 |
liveuser |
12469 |
console.log(clickedImgUrl);
|
|
|
12470 |
|
| 3 |
liveuser |
12471 |
//set img array
|
|
|
12472 |
var imgArray=".json_encode($conf["adImg"]).";
|
| 226 |
liveuser |
12473 |
|
| 3 |
liveuser |
12474 |
//無窮迴圈
|
|
|
12475 |
for(i=0;i<".$adImgCount.";i++){
|
| 226 |
liveuser |
12476 |
|
| 3 |
liveuser |
12477 |
//如果找到點擊的圖片
|
|
|
12478 |
if(clickedImgUrl.includes(imgArray[i])){
|
| 226 |
liveuser |
12479 |
|
| 3 |
liveuser |
12480 |
//debug
|
|
|
12481 |
console.log(i+'<".$adImgCount."');
|
| 226 |
liveuser |
12482 |
|
| 3 |
liveuser |
12483 |
//如果是最後一張圖片
|
|
|
12484 |
if(i===".$adImgCount."-1){
|
| 226 |
liveuser |
12485 |
|
| 3 |
liveuser |
12486 |
//設置為第一張圖片
|
|
|
12487 |
i=0;
|
| 226 |
liveuser |
12488 |
|
| 3 |
liveuser |
12489 |
}
|
| 226 |
liveuser |
12490 |
|
| 3 |
liveuser |
12491 |
//反之+1
|
|
|
12492 |
else{
|
| 226 |
liveuser |
12493 |
|
| 3 |
liveuser |
12494 |
i++;
|
| 226 |
liveuser |
12495 |
|
| 3 |
liveuser |
12496 |
}//else end
|
| 226 |
liveuser |
12497 |
|
| 3 |
liveuser |
12498 |
//debug
|
|
|
12499 |
console.log('set img to '+imgArray[i]);
|
| 226 |
liveuser |
12500 |
|
| 3 |
liveuser |
12501 |
//set clicked image
|
|
|
12502 |
scrollDiv.style.backgroundImage='url('+imgArray[i]+')';
|
| 226 |
liveuser |
12503 |
|
| 3 |
liveuser |
12504 |
//debug
|
|
|
12505 |
console.log('end for');
|
| 226 |
liveuser |
12506 |
|
| 3 |
liveuser |
12507 |
//end for
|
|
|
12508 |
break;
|
| 226 |
liveuser |
12509 |
|
| 3 |
liveuser |
12510 |
}//if end
|
| 226 |
liveuser |
12511 |
|
| 3 |
liveuser |
12512 |
}//for end
|
| 226 |
liveuser |
12513 |
|
| 3 |
liveuser |
12514 |
});//scrollDiv addEventListener end
|
| 226 |
liveuser |
12515 |
|
| 3 |
liveuser |
12516 |
});//scrollDiv click event end
|
|
|
12517 |
";
|
|
|
12518 |
#可省略參數:
|
|
|
12519 |
#$conf["onReady"],字串,是否要在網頁完全載入後再執行,"false"為不等載入完就先執行,預設為"true"要等載入完再執行.
|
|
|
12520 |
#$conf["onReady"]="true";
|
|
|
12521 |
#$conf["globalJs"],字串陣列,為要放入<script>標籤的js全域變數.
|
|
|
12522 |
#$conf["globalJs"]=array();
|
|
|
12523 |
#$conf["jsFunciton"],字串陣列,為要放入<script>標籤的js函數.
|
|
|
12524 |
#$conf["jsFunciton"]=array();
|
|
|
12525 |
#參考資料:
|
|
|
12526 |
#http://stackoverflow.com/questions/9899372/pure-javascript-equivalent-to-jquerys-ready-how-to-call-a-function-when-the
|
|
|
12527 |
$toScript=javaScript::toScript($conf["javaScript::toScript"]);
|
|
|
12528 |
unset($conf["javaScript::toScript"]);
|
| 226 |
liveuser |
12529 |
|
| 3 |
liveuser |
12530 |
#如果建立 script 語法失敗
|
|
|
12531 |
if($toScript["status"]==="false"){
|
| 226 |
liveuser |
12532 |
|
| 3 |
liveuser |
12533 |
#設置執行失敗
|
|
|
12534 |
$result["status"]="false";
|
| 226 |
liveuser |
12535 |
|
| 3 |
liveuser |
12536 |
#設置錯誤訊息
|
|
|
12537 |
$result["error"]=$toScript;
|
| 226 |
liveuser |
12538 |
|
| 3 |
liveuser |
12539 |
#回傳結果
|
|
|
12540 |
return $result;
|
| 226 |
liveuser |
12541 |
|
| 3 |
liveuser |
12542 |
}#if end
|
| 226 |
liveuser |
12543 |
|
| 3 |
liveuser |
12544 |
#儲存內容
|
|
|
12545 |
$result["content"]=$result["content"].$toScript["content"];
|
| 226 |
liveuser |
12546 |
|
| 3 |
liveuser |
12547 |
#設置執行正常
|
|
|
12548 |
$result["status"]="true";
|
| 226 |
liveuser |
12549 |
|
| 3 |
liveuser |
12550 |
#回傳結果
|
| 226 |
liveuser |
12551 |
return $result;
|
|
|
12552 |
|
| 3 |
liveuser |
12553 |
}//function adImg end
|
| 226 |
liveuser |
12554 |
|
| 3 |
liveuser |
12555 |
/*
|
|
|
12556 |
#函式說明:
|
|
|
12557 |
#區塊輪播的效果
|
|
|
12558 |
#回傳結果:
|
|
|
12559 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
12560 |
#$result["error"],錯誤訊息.
|
|
|
12561 |
#$result["function"],當前執行的函數名稱.
|
|
|
12562 |
#$result["content"],語法.
|
|
|
12563 |
#必填參數:
|
|
|
12564 |
#$conf["place"],字串,輪播區塊要在哪個元素裡面呈現,其區塊特徵為何?(請參閱javascript的querySelector函式).
|
|
|
12565 |
$conf["place"]="";
|
|
|
12566 |
#$conf["slideDiv"],字串陣列,每個投影片的div區塊特徵(請參閱javascript的querySelector函式).
|
|
|
12567 |
$conf["slideDiv"]=array("");
|
| 226 |
liveuser |
12568 |
#可省略參數:
|
| 3 |
liveuser |
12569 |
#$conf["sec"],字串,過幾秒就要置換成下一張投影片,預設為"5",代表每5秒就換一張投影片.
|
|
|
12570 |
#$conf["sec"]="5";
|
|
|
12571 |
#參考資料:
|
|
|
12572 |
#無.
|
|
|
12573 |
#備註:
|
|
|
12574 |
#無.
|
|
|
12575 |
*/
|
|
|
12576 |
public static function slideDiv(&$conf){
|
|
|
12577 |
|
|
|
12578 |
#初始化要回傳的結果
|
|
|
12579 |
$result=array();
|
|
|
12580 |
|
|
|
12581 |
#取得當前執行的函數名稱
|
|
|
12582 |
$result["function"]=__FUNCTION__;
|
|
|
12583 |
|
|
|
12584 |
#如果沒有參數
|
|
|
12585 |
if(func_num_args()==0){
|
|
|
12586 |
|
|
|
12587 |
#設置執行失敗
|
|
|
12588 |
$result["status"]="false";
|
|
|
12589 |
|
|
|
12590 |
#設置執行錯誤訊息
|
|
|
12591 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
12592 |
|
|
|
12593 |
#回傳結果
|
|
|
12594 |
return $result;
|
|
|
12595 |
|
|
|
12596 |
}#if end
|
|
|
12597 |
|
|
|
12598 |
#取得參數
|
|
|
12599 |
$result["argu"]=$conf;
|
|
|
12600 |
|
|
|
12601 |
#如果 $conf 不為陣列
|
|
|
12602 |
if(gettype($conf)!=="array"){
|
|
|
12603 |
|
|
|
12604 |
#設置執行失敗
|
|
|
12605 |
$result["status"]="false";
|
|
|
12606 |
|
|
|
12607 |
#設置執行錯誤訊息
|
|
|
12608 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
12609 |
|
|
|
12610 |
#如果傳入的參數為 null
|
|
|
12611 |
if($conf===null){
|
|
|
12612 |
|
|
|
12613 |
#設置執行錯誤訊息
|
|
|
12614 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
12615 |
|
|
|
12616 |
}#if end
|
|
|
12617 |
|
|
|
12618 |
#回傳結果
|
|
|
12619 |
return $result;
|
|
|
12620 |
|
|
|
12621 |
}#if end
|
|
|
12622 |
|
|
|
12623 |
#檢查參數
|
|
|
12624 |
#函式說明:
|
|
|
12625 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
12626 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
12627 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
12628 |
#$result["function"],當前執行的函式名稱.
|
|
|
12629 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
12630 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
12631 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
12632 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
12633 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
12634 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
12635 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
12636 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
12637 |
#必填參數:
|
|
|
12638 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
12639 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
12640 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
12641 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("place","slideDiv");
|
|
|
12642 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
12643 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","array");
|
|
|
12644 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
12645 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
12646 |
#可以省略的參數:
|
|
|
12647 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
12648 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
12649 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
12650 |
$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("sec");
|
|
|
12651 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
12652 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("sec");
|
|
|
12653 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
12654 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
12655 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
12656 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("5");
|
|
|
12657 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
12658 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("headOrTail","target","styleAttr","styleVal","content");
|
|
|
12659 |
#參考資料來源:
|
|
|
12660 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
12661 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
12662 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
12663 |
|
|
|
12664 |
#如果檢查參數失敗
|
|
|
12665 |
if($checkArguments["status"]==="false"){
|
|
|
12666 |
|
|
|
12667 |
#設置執行不正常
|
|
|
12668 |
$result["status"]="false";
|
|
|
12669 |
|
|
|
12670 |
#設置執行錯誤
|
|
|
12671 |
$result["error"]=$checkArguments;
|
|
|
12672 |
|
|
|
12673 |
#回傳結果
|
|
|
12674 |
return $result;
|
|
|
12675 |
|
|
|
12676 |
}#if end
|
|
|
12677 |
|
|
|
12678 |
#如果檢查參數不通過
|
|
|
12679 |
if($checkArguments["passed"]==="false"){
|
|
|
12680 |
|
|
|
12681 |
#設置執行不正常
|
|
|
12682 |
$result["status"]="false";
|
|
|
12683 |
|
|
|
12684 |
#設置執行錯誤
|
|
|
12685 |
$result["error"]=$checkArguments;
|
|
|
12686 |
|
|
|
12687 |
#回傳結果
|
|
|
12688 |
return $result;
|
|
|
12689 |
|
|
|
12690 |
}#if end
|
| 226 |
liveuser |
12691 |
|
| 3 |
liveuser |
12692 |
#初始化要回傳的語法
|
|
|
12693 |
$result["content"]="";
|
| 226 |
liveuser |
12694 |
|
| 3 |
liveuser |
12695 |
#函式說明:
|
|
|
12696 |
#將要執行的script語法透過該函式執行(會在程式外層用<script></script>包起來).
|
|
|
12697 |
#回傳結果:
|
|
|
12698 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
12699 |
#$result["error"],錯誤訊息陣列
|
|
|
12700 |
#$result["function"],當前執行的函數名稱
|
|
|
12701 |
#$result["content"],要執行的javaScript語法
|
|
|
12702 |
#必填參數:
|
|
|
12703 |
#$conf["script"],字串,要執行的javaScript語法.
|
|
|
12704 |
$conf["javaScript::toScript"]["script"]=
|
|
|
12705 |
"
|
|
|
12706 |
//取得內部要放置投影片內容的區塊
|
|
|
12707 |
var displayArea=document.querySelector('".$conf["place"]."');
|
| 226 |
liveuser |
12708 |
|
| 3 |
liveuser |
12709 |
//get left value
|
|
|
12710 |
var leftP=displayArea.offsetLeft+'px';
|
| 226 |
liveuser |
12711 |
|
| 3 |
liveuser |
12712 |
//get top value
|
|
|
12713 |
var topP=displayArea.offsetTop+'px';
|
| 226 |
liveuser |
12714 |
|
| 3 |
liveuser |
12715 |
//get width value
|
| 226 |
liveuser |
12716 |
var widthP=displayArea.clientWidth;
|
|
|
12717 |
|
| 3 |
liveuser |
12718 |
//get height value
|
| 226 |
liveuser |
12719 |
var heightP=displayArea.clientHeight;
|
|
|
12720 |
|
| 3 |
liveuser |
12721 |
//不顯示原始內容
|
|
|
12722 |
displayArea.style.opacity=0;
|
|
|
12723 |
displayArea.style.zIndex=-1;
|
| 226 |
liveuser |
12724 |
|
| 3 |
liveuser |
12725 |
//取得投影片的數量
|
|
|
12726 |
var slideCount=".count($conf["slideDiv"])."
|
| 226 |
liveuser |
12727 |
|
| 3 |
liveuser |
12728 |
//宣告儲存投影片陣列的變數
|
|
|
12729 |
var slide=[];
|
| 226 |
liveuser |
12730 |
|
| 3 |
liveuser |
12731 |
";
|
| 226 |
liveuser |
12732 |
|
| 3 |
liveuser |
12733 |
#針對每個投影片
|
|
|
12734 |
foreach($conf["slideDiv"] as $index=>$slide)
|
|
|
12735 |
{
|
|
|
12736 |
#串接js內容
|
|
|
12737 |
$conf["javaScript::toScript"]["script"]=$conf["javaScript::toScript"]["script"].
|
|
|
12738 |
"
|
|
|
12739 |
//取得投影片的區塊元素
|
|
|
12740 |
var content=document.querySelector('".$slide."');
|
| 226 |
liveuser |
12741 |
|
| 3 |
liveuser |
12742 |
//強制設定其位置為看不到的地方
|
|
|
12743 |
content.style.position='absolute';
|
|
|
12744 |
content.style.left='-100vw';
|
|
|
12745 |
content.style.top='-100vh';
|
| 226 |
liveuser |
12746 |
|
| 3 |
liveuser |
12747 |
//設置投影片的資訊
|
|
|
12748 |
var info={};
|
| 226 |
liveuser |
12749 |
|
| 3 |
liveuser |
12750 |
//設置投影片的left資訊
|
|
|
12751 |
info.left=getComputedStyle(content).left;
|
| 226 |
liveuser |
12752 |
|
| 3 |
liveuser |
12753 |
//設置投影片的top資訊
|
|
|
12754 |
info.top=getComputedStyle(content).top;
|
| 226 |
liveuser |
12755 |
|
| 3 |
liveuser |
12756 |
//初始化儲存單一投影片的結構
|
|
|
12757 |
var slideObject={};
|
| 226 |
liveuser |
12758 |
|
| 3 |
liveuser |
12759 |
//設置投影片的內容
|
|
|
12760 |
slideObject.content=content;
|
| 226 |
liveuser |
12761 |
|
| 3 |
liveuser |
12762 |
//設置投影片的資訊
|
|
|
12763 |
slideObject.info=info;
|
| 226 |
liveuser |
12764 |
|
| 3 |
liveuser |
12765 |
//儲存投影片到陣列
|
|
|
12766 |
slide.push(slideObject);
|
| 226 |
liveuser |
12767 |
|
| 3 |
liveuser |
12768 |
";
|
|
|
12769 |
}
|
| 226 |
liveuser |
12770 |
|
| 3 |
liveuser |
12771 |
#串接js的內容.
|
|
|
12772 |
$conf["javaScript::toScript"]["script"]=$conf["javaScript::toScript"]["script"].
|
|
|
12773 |
"
|
| 226 |
liveuser |
12774 |
|
| 3 |
liveuser |
12775 |
//debug
|
|
|
12776 |
//console.log(slide);
|
| 226 |
liveuser |
12777 |
|
| 3 |
liveuser |
12778 |
//設置投影片置換的等待秒數
|
|
|
12779 |
var sec=".$conf["sec"].";
|
| 226 |
liveuser |
12780 |
|
| 3 |
liveuser |
12781 |
//設置等待時間的函式
|
|
|
12782 |
var timeout=function(sec)
|
|
|
12783 |
{
|
| 226 |
liveuser |
12784 |
return new Promise(resolve =>
|
| 3 |
liveuser |
12785 |
{
|
| 226 |
liveuser |
12786 |
setTimeout(() =>
|
| 3 |
liveuser |
12787 |
{
|
|
|
12788 |
resolve(sec);
|
|
|
12789 |
}, sec*1000);
|
|
|
12790 |
});
|
|
|
12791 |
}
|
| 226 |
liveuser |
12792 |
|
| 3 |
liveuser |
12793 |
//建立與執行隨着畫面大小改變而更新播放區域資訊的函式
|
|
|
12794 |
var updateDisplayInfo=window.addEventListener('resize',function()
|
|
|
12795 |
{
|
|
|
12796 |
//更新投影區域資訊
|
|
|
12797 |
leftP=displayArea.offsetLeft+'px';
|
|
|
12798 |
topP=displayArea.offsetTop+'px';
|
| 226 |
liveuser |
12799 |
widthP=displayArea.clientWidth+'px';
|
|
|
12800 |
heightP=displayArea.clientHeight+'px';
|
|
|
12801 |
|
| 3 |
liveuser |
12802 |
//初始化要更新的投影片索引為-1
|
|
|
12803 |
var showedSlideIndex=-1;
|
| 226 |
liveuser |
12804 |
|
| 3 |
liveuser |
12805 |
//針對每個投影片
|
|
|
12806 |
for(var i=0;i<slideCount;i++)
|
|
|
12807 |
{
|
|
|
12808 |
//如果是正在顯示的投影片
|
|
|
12809 |
if(slide[i].content.dataset.show==='true')
|
|
|
12810 |
{
|
|
|
12811 |
//取得當前播放的投影片索引
|
|
|
12812 |
showedSlideIndex=i;
|
|
|
12813 |
}
|
|
|
12814 |
}
|
| 226 |
liveuser |
12815 |
|
| 3 |
liveuser |
12816 |
//如果有抓取到正在播放的投影片索引
|
|
|
12817 |
if(showedSlideIndex!==-1)
|
|
|
12818 |
{
|
| 226 |
liveuser |
12819 |
|
| 3 |
liveuser |
12820 |
//更新正在投影的投影片
|
|
|
12821 |
slide[showedSlideIndex].content.style.top=topP;
|
|
|
12822 |
slide[showedSlideIndex].content.style.left=leftP;
|
|
|
12823 |
slide[showedSlideIndex].content.style.width=widthP;
|
|
|
12824 |
slide[showedSlideIndex].content.style.height=heightP;
|
|
|
12825 |
}
|
|
|
12826 |
});
|
| 226 |
liveuser |
12827 |
|
| 3 |
liveuser |
12828 |
//宣告置換投影片的函式
|
|
|
12829 |
var changeSlide=async function(page)
|
|
|
12830 |
{
|
|
|
12831 |
//debug
|
|
|
12832 |
//console.log('start chaneg slide');
|
| 226 |
liveuser |
12833 |
|
| 3 |
liveuser |
12834 |
//如果要顯示的投影片編號超出範圍
|
|
|
12835 |
if(page > slideCount - 1)
|
|
|
12836 |
{
|
|
|
12837 |
//代表是要顯示第一張投影片
|
|
|
12838 |
page=0;
|
|
|
12839 |
}
|
| 226 |
liveuser |
12840 |
|
| 3 |
liveuser |
12841 |
//取得要隱藏的投影片編號
|
|
|
12842 |
var lastSlideNo=page-1;
|
| 226 |
liveuser |
12843 |
|
| 3 |
liveuser |
12844 |
//如果要隱藏的投影片編號是負的
|
|
|
12845 |
if(lastSlideNo < 0)
|
|
|
12846 |
{
|
|
|
12847 |
//代表要隱藏的投影片編號最後一張
|
|
|
12848 |
lastSlideNo = slideCount - 1;
|
|
|
12849 |
}
|
| 226 |
liveuser |
12850 |
|
| 3 |
liveuser |
12851 |
//隱藏上一張投影片
|
|
|
12852 |
slide[lastSlideNo].content.style.top=slide[lastSlideNo].info.top;
|
|
|
12853 |
slide[lastSlideNo].content.style.left=slide[lastSlideNo].info.left;
|
|
|
12854 |
slide[lastSlideNo].content.dataset.show='false';
|
| 226 |
liveuser |
12855 |
|
| 3 |
liveuser |
12856 |
//顯示下一張投影片
|
|
|
12857 |
slide[page].content.style.top=topP;
|
|
|
12858 |
slide[page].content.style.left=leftP;
|
|
|
12859 |
slide[page].content.style.width=widthP;
|
|
|
12860 |
slide[page].content.style.height=heightP;
|
|
|
12861 |
slide[page].content.dataset.show='true';
|
| 226 |
liveuser |
12862 |
|
| 3 |
liveuser |
12863 |
//等待時間
|
|
|
12864 |
await timeout.call(this,sec);
|
| 226 |
liveuser |
12865 |
|
| 3 |
liveuser |
12866 |
//呼叫自己
|
|
|
12867 |
changeSlide.call(this,page+1);
|
|
|
12868 |
}
|
| 226 |
liveuser |
12869 |
|
| 3 |
liveuser |
12870 |
//每過了 sec 秒後就置換投影片
|
|
|
12871 |
changeSlide.call(this,0);
|
| 226 |
liveuser |
12872 |
|
| 3 |
liveuser |
12873 |
";
|
| 226 |
liveuser |
12874 |
|
| 3 |
liveuser |
12875 |
#可省略參數:
|
|
|
12876 |
#$conf["onReady"],字串,是否要在網頁完全載入後再執行,"false"為不等載入完就先執行,預設為"true"要等載入完再執行.
|
|
|
12877 |
#$conf["onReady"]="true";
|
|
|
12878 |
#$conf["globalJs"],字串陣列,為要放入<script>標籤的js全域變數.
|
|
|
12879 |
#$conf["globalJs"]=array();
|
|
|
12880 |
#$conf["jsFunciton"],字串陣列,為要放入<script>標籤的js函數.
|
|
|
12881 |
#$conf["jsFunciton"]=array();
|
|
|
12882 |
#參考資料:
|
|
|
12883 |
#http://stackoverflow.com/questions/9899372/pure-javascript-equivalent-to-jquerys-ready-how-to-call-a-function-when-the
|
|
|
12884 |
#備註:
|
|
|
12885 |
#無.
|
|
|
12886 |
$toScript=javaScript::toScript($conf["javaScript::toScript"]);
|
|
|
12887 |
unset($conf["javaScript::toScript"]);
|
| 226 |
liveuser |
12888 |
|
| 3 |
liveuser |
12889 |
#如果建立 script 語法失敗
|
|
|
12890 |
if($toScript["status"]==="false"){
|
| 226 |
liveuser |
12891 |
|
| 3 |
liveuser |
12892 |
#設置執行失敗
|
|
|
12893 |
$result["status"]="false";
|
| 226 |
liveuser |
12894 |
|
| 3 |
liveuser |
12895 |
#設置錯誤訊息
|
|
|
12896 |
$result["error"]=$toScript;
|
| 226 |
liveuser |
12897 |
|
| 3 |
liveuser |
12898 |
#回傳結果
|
|
|
12899 |
return $result;
|
| 226 |
liveuser |
12900 |
|
| 3 |
liveuser |
12901 |
}#if end
|
| 226 |
liveuser |
12902 |
|
| 3 |
liveuser |
12903 |
#儲存內容
|
|
|
12904 |
$result["content"]=$result["content"].$toScript["content"];
|
| 226 |
liveuser |
12905 |
|
| 3 |
liveuser |
12906 |
#設置執行正常
|
|
|
12907 |
$result["status"]="true";
|
| 226 |
liveuser |
12908 |
|
| 3 |
liveuser |
12909 |
#回傳結果
|
| 226 |
liveuser |
12910 |
return $result;
|
|
|
12911 |
|
| 3 |
liveuser |
12912 |
}#function slideDiv end
|
| 226 |
liveuser |
12913 |
|
| 3 |
liveuser |
12914 |
/*
|
|
|
12915 |
#函式說明:
|
|
|
12916 |
#簡易版區塊輪播的效果,要輪播的內容為$conf["place"]特徵區塊的children元素.
|
|
|
12917 |
#回傳結果:
|
|
|
12918 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
12919 |
#$result["error"],錯誤訊息.
|
|
|
12920 |
#$result["function"],當前執行的函數名稱.
|
|
|
12921 |
#$result["content"],語法.
|
|
|
12922 |
#必填參數:
|
|
|
12923 |
#$conf["place"],字串,輪播區塊要在哪個元素裡面呈現,其區塊特徵為何?(請參閱javascript的querySelector函式).
|
|
|
12924 |
$conf["place"]="";
|
| 226 |
liveuser |
12925 |
#可省略參數:
|
| 3 |
liveuser |
12926 |
#$conf["sec"],字串,過幾秒就要置換成下一張投影片,預設為"5",代表每5秒就換一張投影片.
|
|
|
12927 |
#$conf["sec"]="5";
|
|
|
12928 |
#參考資料:
|
|
|
12929 |
#無.
|
|
|
12930 |
#備註:
|
|
|
12931 |
#無.
|
|
|
12932 |
*/
|
|
|
12933 |
public static function slideDivSimple(&$conf){
|
|
|
12934 |
|
|
|
12935 |
#初始化要回傳的結果
|
|
|
12936 |
$result=array();
|
|
|
12937 |
|
|
|
12938 |
#取得當前執行的函數名稱
|
|
|
12939 |
$result["function"]=__FUNCTION__;
|
|
|
12940 |
|
|
|
12941 |
#如果沒有參數
|
|
|
12942 |
if(func_num_args()==0){
|
|
|
12943 |
|
|
|
12944 |
#設置執行失敗
|
|
|
12945 |
$result["status"]="false";
|
|
|
12946 |
|
|
|
12947 |
#設置執行錯誤訊息
|
|
|
12948 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
12949 |
|
|
|
12950 |
#回傳結果
|
|
|
12951 |
return $result;
|
|
|
12952 |
|
|
|
12953 |
}#if end
|
|
|
12954 |
|
|
|
12955 |
#取得參數
|
|
|
12956 |
$result["argu"]=$conf;
|
|
|
12957 |
|
|
|
12958 |
#如果 $conf 不為陣列
|
|
|
12959 |
if(gettype($conf)!=="array"){
|
|
|
12960 |
|
|
|
12961 |
#設置執行失敗
|
|
|
12962 |
$result["status"]="false";
|
|
|
12963 |
|
|
|
12964 |
#設置執行錯誤訊息
|
|
|
12965 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
12966 |
|
|
|
12967 |
#如果傳入的參數為 null
|
|
|
12968 |
if($conf===null){
|
|
|
12969 |
|
|
|
12970 |
#設置執行錯誤訊息
|
|
|
12971 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
12972 |
|
|
|
12973 |
}#if end
|
|
|
12974 |
|
|
|
12975 |
#回傳結果
|
|
|
12976 |
return $result;
|
|
|
12977 |
|
|
|
12978 |
}#if end
|
|
|
12979 |
|
|
|
12980 |
#檢查參數
|
|
|
12981 |
#函式說明:
|
|
|
12982 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
12983 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
12984 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
12985 |
#$result["function"],當前執行的函式名稱.
|
|
|
12986 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
12987 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
12988 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
12989 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
12990 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
12991 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
12992 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
12993 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
12994 |
#必填參數:
|
|
|
12995 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
12996 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
12997 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
12998 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("place");
|
|
|
12999 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
13000 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
13001 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
13002 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
13003 |
#可以省略的參數:
|
|
|
13004 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
13005 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
13006 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
13007 |
$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("sec");
|
|
|
13008 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
13009 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("sec");
|
|
|
13010 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
13011 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
13012 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
13013 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("5");
|
|
|
13014 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
13015 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("headOrTail","target","styleAttr","styleVal","content");
|
|
|
13016 |
#參考資料來源:
|
|
|
13017 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
13018 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
13019 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
13020 |
|
|
|
13021 |
#如果檢查參數失敗
|
|
|
13022 |
if($checkArguments["status"]==="false"){
|
|
|
13023 |
|
|
|
13024 |
#設置執行不正常
|
|
|
13025 |
$result["status"]="false";
|
|
|
13026 |
|
|
|
13027 |
#設置執行錯誤
|
|
|
13028 |
$result["error"]=$checkArguments;
|
|
|
13029 |
|
|
|
13030 |
#回傳結果
|
|
|
13031 |
return $result;
|
|
|
13032 |
|
|
|
13033 |
}#if end
|
|
|
13034 |
|
|
|
13035 |
#如果檢查參數不通過
|
|
|
13036 |
if($checkArguments["passed"]==="false"){
|
|
|
13037 |
|
|
|
13038 |
#設置執行不正常
|
|
|
13039 |
$result["status"]="false";
|
|
|
13040 |
|
|
|
13041 |
#設置執行錯誤
|
|
|
13042 |
$result["error"]=$checkArguments;
|
|
|
13043 |
|
|
|
13044 |
#回傳結果
|
|
|
13045 |
return $result;
|
|
|
13046 |
|
|
|
13047 |
}#if end
|
| 226 |
liveuser |
13048 |
|
| 3 |
liveuser |
13049 |
#初始化要回傳的語法
|
|
|
13050 |
$result["content"]="";
|
| 226 |
liveuser |
13051 |
|
| 3 |
liveuser |
13052 |
#函式說明:
|
|
|
13053 |
#將要執行的script語法透過該函式執行(會在程式外層用<script></script>包起來).
|
|
|
13054 |
#回傳結果:
|
|
|
13055 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
13056 |
#$result["error"],錯誤訊息陣列
|
|
|
13057 |
#$result["function"],當前執行的函數名稱
|
|
|
13058 |
#$result["content"],要執行的javaScript語法
|
|
|
13059 |
#必填參數:
|
|
|
13060 |
#$conf["script"],字串,要執行的javaScript語法.
|
|
|
13061 |
$conf["javaScript::toScript"]["script"]=
|
|
|
13062 |
"
|
|
|
13063 |
//取得要放置投影片內容的區塊
|
|
|
13064 |
var displayArea=document.querySelector('".$conf["place"]."');
|
| 226 |
liveuser |
13065 |
|
| 3 |
liveuser |
13066 |
//如果無投影片的內容存在
|
|
|
13067 |
if(displayArea.children.length<1){
|
| 226 |
liveuser |
13068 |
|
| 3 |
liveuser |
13069 |
//提示錯誤
|
|
|
13070 |
console.error('無投影片內容');
|
| 226 |
liveuser |
13071 |
|
| 3 |
liveuser |
13072 |
//結束執行
|
|
|
13073 |
return;
|
| 226 |
liveuser |
13074 |
|
| 3 |
liveuser |
13075 |
}//if end
|
| 226 |
liveuser |
13076 |
|
| 3 |
liveuser |
13077 |
//設置投影片的數量
|
|
|
13078 |
var slideCount=displayArea.children.length;
|
| 226 |
liveuser |
13079 |
|
| 3 |
liveuser |
13080 |
//設置投影片置換的等待秒數
|
|
|
13081 |
var sec=".$conf["sec"].";
|
| 226 |
liveuser |
13082 |
|
| 3 |
liveuser |
13083 |
//設置等待時間的函式
|
|
|
13084 |
var timeout=function(sec)
|
|
|
13085 |
{
|
| 226 |
liveuser |
13086 |
return new Promise(resolve =>
|
| 3 |
liveuser |
13087 |
{
|
| 226 |
liveuser |
13088 |
setTimeout(() =>
|
| 3 |
liveuser |
13089 |
{
|
|
|
13090 |
resolve(sec);
|
|
|
13091 |
}, sec*1000);
|
|
|
13092 |
});
|
|
|
13093 |
}
|
| 226 |
liveuser |
13094 |
|
| 3 |
liveuser |
13095 |
//宣告置換投影片的函式
|
|
|
13096 |
var changeSlide=async function(page)
|
|
|
13097 |
{
|
|
|
13098 |
//隱藏所有投影片
|
|
|
13099 |
for(var i=0;i<slideCount;i++)
|
|
|
13100 |
{
|
|
|
13101 |
//隱藏投影片
|
|
|
13102 |
displayArea.children[i].style.display='none';
|
| 226 |
liveuser |
13103 |
|
| 3 |
liveuser |
13104 |
}//for end
|
| 226 |
liveuser |
13105 |
|
| 3 |
liveuser |
13106 |
//如果page超過上限
|
|
|
13107 |
if(page===slideCount)
|
|
|
13108 |
{
|
|
|
13109 |
//設置為第1個投影片
|
|
|
13110 |
page=0;
|
|
|
13111 |
}
|
| 226 |
liveuser |
13112 |
|
| 3 |
liveuser |
13113 |
//顯示投影片
|
|
|
13114 |
displayArea.children[page].style.display='inline-block';
|
| 226 |
liveuser |
13115 |
|
| 3 |
liveuser |
13116 |
//等待時間
|
|
|
13117 |
await timeout.call(this,sec);
|
| 226 |
liveuser |
13118 |
|
| 3 |
liveuser |
13119 |
//呼叫自己
|
|
|
13120 |
changeSlide.call(this,page+1);
|
|
|
13121 |
}
|
| 226 |
liveuser |
13122 |
|
| 3 |
liveuser |
13123 |
//每過了 sec 秒後就置換投影片
|
|
|
13124 |
changeSlide.call(this,0);
|
| 226 |
liveuser |
13125 |
|
| 3 |
liveuser |
13126 |
";
|
|
|
13127 |
#可省略參數:
|
|
|
13128 |
#$conf["onReady"],字串,是否要在網頁完全載入後再執行,"false"為不等載入完就先執行,預設為"true"要等載入完再執行.
|
|
|
13129 |
#$conf["onReady"]="true";
|
|
|
13130 |
#$conf["globalJs"],字串陣列,為要放入<script>標籤的js全域變數.
|
|
|
13131 |
#$conf["globalJs"]=array();
|
|
|
13132 |
#$conf["jsFunciton"],字串陣列,為要放入<script>標籤的js函數.
|
|
|
13133 |
#$conf["jsFunciton"]=array();
|
|
|
13134 |
#參考資料:
|
|
|
13135 |
#http://stackoverflow.com/questions/9899372/pure-javascript-equivalent-to-jquerys-ready-how-to-call-a-function-when-the
|
|
|
13136 |
#備註:
|
|
|
13137 |
#無.
|
|
|
13138 |
$toScript=javaScript::toScript($conf["javaScript::toScript"]);
|
|
|
13139 |
unset($conf["javaScript::toScript"]);
|
| 226 |
liveuser |
13140 |
|
| 3 |
liveuser |
13141 |
#如果建立 script 語法失敗
|
|
|
13142 |
if($toScript["status"]==="false"){
|
| 226 |
liveuser |
13143 |
|
| 3 |
liveuser |
13144 |
#設置執行失敗
|
|
|
13145 |
$result["status"]="false";
|
| 226 |
liveuser |
13146 |
|
| 3 |
liveuser |
13147 |
#設置錯誤訊息
|
|
|
13148 |
$result["error"]=$toScript;
|
| 226 |
liveuser |
13149 |
|
| 3 |
liveuser |
13150 |
#回傳結果
|
|
|
13151 |
return $result;
|
| 226 |
liveuser |
13152 |
|
| 3 |
liveuser |
13153 |
}#if end
|
| 226 |
liveuser |
13154 |
|
| 3 |
liveuser |
13155 |
#儲存內容
|
|
|
13156 |
$result["content"]=$result["content"].$toScript["content"];
|
| 226 |
liveuser |
13157 |
|
| 3 |
liveuser |
13158 |
#設置執行正常
|
|
|
13159 |
$result["status"]="true";
|
| 226 |
liveuser |
13160 |
|
| 3 |
liveuser |
13161 |
#回傳結果
|
| 226 |
liveuser |
13162 |
return $result;
|
| 3 |
liveuser |
13163 |
}
|
| 226 |
liveuser |
13164 |
|
| 3 |
liveuser |
13165 |
/*
|
|
|
13166 |
#函式說明:
|
|
|
13167 |
#建立點擊後會移到最頂端的 span icon,位於頂端時則會隱藏.
|
|
|
13168 |
#回傳結果:
|
|
|
13169 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
13170 |
#$result["error"],錯誤訊息.
|
|
|
13171 |
#$result["function"],當前執行的函數名稱.
|
|
|
13172 |
#$result["content"],語法.
|
|
|
13173 |
#必填參數:
|
|
|
13174 |
#$conf["id"],字串,廣告區域的span id.
|
|
|
13175 |
$conf["id"]="";
|
| 226 |
liveuser |
13176 |
#可省略參數:
|
| 3 |
liveuser |
13177 |
#$conf["img"],字串,gotop的icon位置與名稱,預設爲base64加密svg圖檔.
|
|
|
13178 |
#$conf["img"]="";
|
|
|
13179 |
#$conf["mimeType"],字串,圖檔的mime type,預設爲image/*.
|
|
|
13180 |
#$conf["mimeType"]="image/*";
|
|
|
13181 |
#$conf["fileArgu"],字串, __FILE__ 的內容,若有設置img參數,則也要設置該參數.
|
|
|
13182 |
#$conf["fileArgu"]=__FILE__;
|
|
|
13183 |
#$conf["bottom"],字串,icon距離底部的位置.
|
|
|
13184 |
$conf["bottom"]="";
|
|
|
13185 |
#$conf["right"],字串,icon距離右部的位置.
|
|
|
13186 |
$conf["right"]="";
|
|
|
13187 |
#參考資料:
|
|
|
13188 |
#無.
|
|
|
13189 |
#備註:
|
|
|
13190 |
#bgColor尚未實作
|
|
|
13191 |
#固定在頂端或底端的功能未實作
|
|
|
13192 |
*/
|
|
|
13193 |
public static function goTopIcon(&$conf){
|
| 226 |
liveuser |
13194 |
|
| 3 |
liveuser |
13195 |
#初始化要回傳的結果
|
|
|
13196 |
$result=array();
|
|
|
13197 |
|
|
|
13198 |
#取得當前執行的函數名稱
|
|
|
13199 |
$result["function"]=__FUNCTION__;
|
|
|
13200 |
|
|
|
13201 |
#如果沒有參數
|
|
|
13202 |
if(func_num_args()==0){
|
|
|
13203 |
|
|
|
13204 |
#設置執行失敗
|
|
|
13205 |
$result["status"]="false";
|
|
|
13206 |
|
|
|
13207 |
#設置執行錯誤訊息
|
|
|
13208 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
13209 |
|
|
|
13210 |
#回傳結果
|
|
|
13211 |
return $result;
|
|
|
13212 |
|
|
|
13213 |
}#if end
|
|
|
13214 |
|
|
|
13215 |
#取得參數
|
|
|
13216 |
$result["argu"]=$conf;
|
|
|
13217 |
|
|
|
13218 |
#如果 $conf 不為陣列
|
|
|
13219 |
if(gettype($conf)!=="array"){
|
|
|
13220 |
|
|
|
13221 |
#設置執行失敗
|
|
|
13222 |
$result["status"]="false";
|
|
|
13223 |
|
|
|
13224 |
#設置執行錯誤訊息
|
|
|
13225 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
13226 |
|
|
|
13227 |
#如果傳入的參數為 null
|
|
|
13228 |
if($conf===null){
|
|
|
13229 |
|
|
|
13230 |
#設置執行錯誤訊息
|
|
|
13231 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
13232 |
|
|
|
13233 |
}#if end
|
|
|
13234 |
|
|
|
13235 |
#回傳結果
|
|
|
13236 |
return $result;
|
|
|
13237 |
|
|
|
13238 |
}#if end
|
|
|
13239 |
|
|
|
13240 |
#初始化內容
|
|
|
13241 |
$result["content"]="";
|
|
|
13242 |
|
|
|
13243 |
#檢查參數
|
|
|
13244 |
#函式說明:
|
|
|
13245 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
13246 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
13247 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
13248 |
#$result["function"],當前執行的函式名稱.
|
|
|
13249 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
13250 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
13251 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
13252 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
13253 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
13254 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
13255 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
13256 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
13257 |
#必填參數:
|
|
|
13258 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
13259 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
13260 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
13261 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
|
|
|
13262 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
13263 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
13264 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
13265 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
13266 |
#可以省略的參數:
|
|
|
13267 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
13268 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
13269 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
13270 |
#$conf["canNotBeEmpty"]=array();
|
|
|
13271 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
13272 |
#$conf["canBeEmpty"]=array();
|
|
|
13273 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
13274 |
$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("img","bottom","right","fileArgu","mimeType");
|
|
|
13275 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
13276 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("img","bottom","right","fileArgu","mimeType");
|
|
|
13277 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
13278 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string");
|
|
|
13279 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
13280 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"30px","30px",null,null);
|
|
|
13281 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
13282 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
13283 |
#參考資料來源:
|
|
|
13284 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
13285 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
13286 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
13287 |
|
|
|
13288 |
#如果檢查參數失敗
|
|
|
13289 |
if($checkArguments["status"]==="false"){
|
|
|
13290 |
|
|
|
13291 |
#設置執行失敗
|
|
|
13292 |
$result["status"]="false";
|
|
|
13293 |
|
|
|
13294 |
#設置執行錯誤訊息
|
|
|
13295 |
$result["error"]=$checkArguments;
|
|
|
13296 |
|
|
|
13297 |
#回傳結果
|
|
|
13298 |
return $result;
|
|
|
13299 |
|
|
|
13300 |
}#if end
|
|
|
13301 |
|
|
|
13302 |
#如果參數檢查不通過
|
|
|
13303 |
if($checkArguments["passed"]==="false"){
|
|
|
13304 |
|
|
|
13305 |
#設置執行失敗
|
|
|
13306 |
$result["status"]="false";
|
|
|
13307 |
|
|
|
13308 |
#設置執行錯誤訊息
|
|
|
13309 |
$result["error"]=$checkArguments;
|
|
|
13310 |
|
|
|
13311 |
#回傳結果
|
|
|
13312 |
return $result;
|
|
|
13313 |
|
|
|
13314 |
}#if end
|
| 226 |
liveuser |
13315 |
|
| 3 |
liveuser |
13316 |
#如果有設置 $conf["img"] 跟 $conf["fileArgu"]
|
|
|
13317 |
if( isset($conf["img"]) && isset($conf["fileArgu"]) ){
|
| 226 |
liveuser |
13318 |
|
| 3 |
liveuser |
13319 |
#移到最上面的icon
|
|
|
13320 |
#函式說明:
|
|
|
13321 |
#用data:mimeType;base64,imgVar的形式來提供圖片的連結,亦即圖片儲存在變數裡面,本函式包含顯示圖片的語法.
|
|
|
13322 |
#回傳結果:
|
|
|
13323 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
13324 |
#$result["error"],錯誤訊息
|
|
|
13325 |
#$result["content"],圖片的連結資訊
|
| 226 |
liveuser |
13326 |
#$result["function"],當前執行的函數名稱
|
| 3 |
liveuser |
13327 |
#必填參數:
|
|
|
13328 |
#$conf["imgPosition"],要轉存成2元碼的圖片檔案位置與名稱
|
|
|
13329 |
$conf["img::data"]["imgPosition"]=$conf["img"];
|
|
|
13330 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
|
|
|
13331 |
$conf["img::data"]["fileArgu"]=$conf["fileArgu"];
|
|
|
13332 |
#可省略參數:
|
|
|
13333 |
#$conf["alt"],若沒有圖片要用什麼文字顯示。
|
|
|
13334 |
#$conf["alt"]="";
|
|
|
13335 |
#$conf["style"],字串陣列,要使用的style,key為樣式名稱,value為樣式值.
|
|
|
13336 |
#$conf["style"]=array();
|
|
|
13337 |
#$conf["class"],圖片要套用的css樣式名稱.
|
|
|
13338 |
#$conf["class"]="";
|
| 226 |
liveuser |
13339 |
|
| 3 |
liveuser |
13340 |
#如果有設置 $conf["mimeType"]
|
|
|
13341 |
if(isset($conf["mimeType"])){
|
| 226 |
liveuser |
13342 |
|
| 3 |
liveuser |
13343 |
#$conf["mimeType"],2元碼的內容是什麼,預設為"image/*".
|
|
|
13344 |
$conf["img::data"]["mimeType"]=$conf["mimeType"];
|
| 226 |
liveuser |
13345 |
|
|
|
13346 |
}#if end
|
|
|
13347 |
|
| 3 |
liveuser |
13348 |
#$conf["compressType"],2元碼壓縮的方式,預設為"base64".
|
|
|
13349 |
#$conf["compressType"]="base64";
|
|
|
13350 |
#$conf["delImg"],讀取完圖片檔案後,要移除圖片嗎?"true"代表要移除,"false"代表不要移除,預設為"false".
|
|
|
13351 |
#$conf["delImg"]="false";
|
|
|
13352 |
#參考資料:
|
|
|
13353 |
#將檔案用字串變數儲存起來=>http://php.net/manual/en/function.file-get-contents.php
|
|
|
13354 |
#壓縮2元碼=>http://php.net/manual/en/function.base64-encode.php
|
|
|
13355 |
$data=img::data($conf["img::data"]);
|
|
|
13356 |
unset($conf["img::data"]);
|
|
|
13357 |
|
|
|
13358 |
#如果建立 span section 失敗
|
|
|
13359 |
if($data["status"]==="false"){
|
| 226 |
liveuser |
13360 |
|
| 3 |
liveuser |
13361 |
#設置執行失敗
|
|
|
13362 |
$result["status"]="false";
|
|
|
13363 |
|
|
|
13364 |
#設置執行錯誤訊息
|
|
|
13365 |
$result["error"]=$data;
|
|
|
13366 |
|
|
|
13367 |
#回傳結果
|
|
|
13368 |
return $result;
|
| 226 |
liveuser |
13369 |
|
| 3 |
liveuser |
13370 |
}#if end
|
| 226 |
liveuser |
13371 |
|
|
|
13372 |
}#if end
|
|
|
13373 |
|
| 3 |
liveuser |
13374 |
#反之設置爲
|
|
|
13375 |
else{
|
| 226 |
liveuser |
13376 |
|
| 3 |
liveuser |
13377 |
#預設的 go top svg base64 encode
|
|
|
13378 |
$data["content"]="<img src=\"data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjwhLS0gQ3JlYXRlZCB3aXRoIElua3NjYXBlIChodHRwOi8vd3d3Lmlua3NjYXBlLm9yZy8pIC0tPgoKPHN2ZwogICB4bWxuczpkYz0iaHR0cDovL3B1cmwub3JnL2RjL2VsZW1lbnRzLzEuMS8iCiAgIHhtbG5zOmNjPSJodHRwOi8vY3JlYXRpdmVjb21tb25zLm9yZy9ucyMiCiAgIHhtbG5zOnJkZj0iaHR0cDovL3d3dy53My5vcmcvMTk5OS8wMi8yMi1yZGYtc3ludGF4LW5zIyIKICAgeG1sbnM6c3ZnPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIKICAgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIgogICB4bWxuczpzb2RpcG9kaT0iaHR0cDovL3NvZGlwb2RpLnNvdXJjZWZvcmdlLm5ldC9EVEQvc29kaXBvZGktMC5kdGQiCiAgIHhtbG5zOmlua3NjYXBlPSJodHRwOi8vd3d3Lmlua3NjYXBlLm9yZy9uYW1lc3BhY2VzL2lua3NjYXBlIgogICB3aWR0aD0iOTAiCiAgIGhlaWdodD0iOTAiCiAgIHZpZXdCb3g9IjAgMCA4OS45OTk5OSA4OS45OTk5OTkiCiAgIGlkPSJzdmcyIgogICB2ZXJzaW9uPSIxLjEiCiAgIGlua3NjYXBlOnZlcnNpb249IjAuOTEgcjEzNzI1IgogICBzb2RpcG9kaTpkb2NuYW1lPSJ0b3Auc3ZnIgogICBpbmtzY2FwZTpleHBvcnQtZmlsZW5hbWU9Ii9ob21lL2xpdmV1c2VyL3B1YmxpY19odG1sL3NhbXBsZVBhZ2UvZmFjdG9yeS9pbWcvdG9wLnN2Zy5wbmciCiAgIGlua3NjYXBlOmV4cG9ydC14ZHBpPSI5MCIKICAgaW5rc2NhcGU6ZXhwb3J0LXlkcGk9IjkwIj4KICA8ZGVmcwogICAgIGlkPSJkZWZzNCIgLz4KICA8c29kaXBvZGk6bmFtZWR2aWV3CiAgICAgaWQ9ImJhc2UiCiAgICAgcGFnZWNvbG9yPSIjZmZmZmZmIgogICAgIGJvcmRlcmNvbG9yPSIjNjY2NjY2IgogICAgIGJvcmRlcm9wYWNpdHk9IjEuMCIKICAgICBpbmtzY2FwZTpwYWdlb3BhY2l0eT0iMC4wIgogICAgIGlua3NjYXBlOnBhZ2VzaGFkb3c9IjIiCiAgICAgaW5rc2NhcGU6em9vbT0iMS40IgogICAgIGlua3NjYXBlOmN4PSI0NS4xMDA5NjYiCiAgICAgaW5rc2NhcGU6Y3k9IjEzMS45NjQ5MiIKICAgICBpbmtzY2FwZTpkb2N1bWVudC11bml0cz0ibW0iCiAgICAgaW5rc2NhcGU6Y3VycmVudC1sYXllcj0iZzMzNTkiCiAgICAgc2hvd2dyaWQ9InRydWUiCiAgICAgc2hvd2d1aWRlcz0iZmFsc2UiCiAgICAgaW5rc2NhcGU6d2luZG93LXdpZHRoPSIxOTIwIgogICAgIGlua3NjYXBlOndpbmRvdy1oZWlnaHQ9IjEwMjMiCiAgICAgaW5rc2NhcGU6d2luZG93LXg9IjAiCiAgICAgaW5rc2NhcGU6d2luZG93LXk9IjMxIgogICAgIGlua3NjYXBlOndpbmRvdy1tYXhpbWl6ZWQ9IjEiCiAgICAgaW5rc2NhcGU6c2hvd3BhZ2VzaGFkb3c9ImZhbHNlIgogICAgIHNob3dib3JkZXI9InRydWUiCiAgICAgdW5pdHM9InB4Ij4KICAgIDxpbmtzY2FwZTpncmlkCiAgICAgICB0eXBlPSJ4eWdyaWQiCiAgICAgICBpZD0iZ3JpZDMzNjQiIC8+CiAgPC9zb2RpcG9kaTpuYW1lZHZpZXc+CiAgPG1ldGFkYXRhCiAgICAgaWQ9Im1ldGFkYXRhNyI+CiAgICA8cmRmOlJERj4KICAgICAgPGNjOldvcmsKICAgICAgICAgcmRmOmFib3V0PSIiPgogICAgICAgIDxkYzpmb3JtYXQ+aW1hZ2Uvc3ZnK3htbDwvZGM6Zm9ybWF0PgogICAgICAgIDxkYzp0eXBlCiAgICAgICAgICAgcmRmOnJlc291cmNlPSJodHRwOi8vcHVybC5vcmcvZGMvZGNtaXR5cGUvU3RpbGxJbWFnZSIgLz4KICAgICAgICA8ZGM6dGl0bGUgLz4KICAgICAgPC9jYzpXb3JrPgogICAgPC9yZGY6UkRGPgogIDwvbWV0YWRhdGE+CiAgPGcKICAgICBpbmtzY2FwZTpsYWJlbD0iTGF5ZXIgMSIKICAgICBpbmtzY2FwZTpncm91cG1vZGU9ImxheWVyIgogICAgIGlkPSJsYXllcjEiCiAgICAgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoMCwtOTYyLjM2MjIyKSI+CiAgICA8ZwogICAgICAgaWQ9ImczMzU5IgogICAgICAgdHJhbnNmb3JtPSJtYXRyaXgoMC45OTkzNzg1OCwwLDAsMS4wNDIxOTk3LC0zMTIuODc2ODUsNzkwLjE2OTMxKSI+CiAgICAgIDxnCiAgICAgICAgIGlkPSJnMzMzOCIKICAgICAgICAgdHJhbnNmb3JtPSJtYXRyaXgoMC45OTE2NDk1LDAsMCwxLjAyNDkzNTQsMi42MzA5MTk2LC01LjU1NTczMDYpIj4KICAgICAgICA8cmVjdAogICAgICAgICAgIHN0eWxlPSJmaWxsOiNmZmZmZmY7c3Ryb2tlOiMwMDAwMDA7c3Ryb2tlLXdpZHRoOjIuNjY5MTU5NjUiCiAgICAgICAgICAgaWQ9InJlY3QzMzQ1IgogICAgICAgICAgIHdpZHRoPSI4OC4zMzA4NDEiCiAgICAgICAgICAgaGVpZ2h0PSI4MS41NTk4NDUiCiAgICAgICAgICAgeD0iMzEzLjY5MTI1IgogICAgICAgICAgIHk9IjE2OC4yODE3NyIKICAgICAgICAgICByeT0iNDEuNjY1NDA1IgogICAgICAgICAgIHJ4PSI0NC4xNjU0MjEiIC8+CiAgICAgICAgPHRleHQKICAgICAgICAgICB4bWw6c3BhY2U9InByZXNlcnZlIgogICAgICAgICAgIHN0eWxlPSJmb250LXN0eWxlOm5vcm1hbDtmb250LXdlaWdodDpub3JtYWw7Zm9udC1zaXplOjQwcHg7bGluZS1oZWlnaHQ6MTI1JTtmb250LWZhbWlseTpzYW5zLXNlcmlmO2xldHRlci1zcGFjaW5nOjBweDt3b3JkLXNwYWNpbmc6MHB4O2ZpbGw6IzAwMDAwMDtmaWxsLW9wYWNpdHk6MTtzdHJva2U6bm9uZTtzdHJva2Utd2lkdGg6MXB4O3N0cm9rZS1saW5lY2FwOmJ1dHQ7c3Ryb2tlLWxpbmVqb2luOm1pdGVyO3N0cm9rZS1vcGFjaXR5OjEiCiAgICAgICAgICAgeD0iMzI1LjcxNDI5IgogICAgICAgICAgIHk9IjIyMi4zNjIyIgogICAgICAgICAgIGlkPSJ0ZXh0MzM0NyIKICAgICAgICAgICBzb2RpcG9kaTpsaW5lc3BhY2luZz0iMTI1JSI+PHRzcGFuCiAgICAgICAgICAgICBzb2RpcG9kaTpyb2xlPSJsaW5lIgogICAgICAgICAgICAgaWQ9InRzcGFuMzM0OSIKICAgICAgICAgICAgIHg9IjMyNS43MTQyOSIKICAgICAgICAgICAgIHk9IjIyMi4zNjIyIj5Ub3A8L3RzcGFuPjwvdGV4dD4KICAgICAgPC9nPgogICAgPC9nPgogIDwvZz4KPC9zdmc+Cg==\">";
|
| 226 |
liveuser |
13379 |
|
| 3 |
liveuser |
13380 |
}#else end
|
|
|
13381 |
|
|
|
13382 |
#移到最上面的icon div
|
|
|
13383 |
#函式說明:
|
|
|
13384 |
#<span>區塊,裡面可以指定css的class樣式,可以指定提示文字,若要使用移動的css樣式,請改用divSection函數.
|
|
|
13385 |
#$result["status"],字串,執行否正常,"true"代表正常,"false"代表不正常.
|
|
|
13386 |
#$result["functin"],字串,當前函數的名稱.
|
|
|
13387 |
#$result["error"],陣列,錯訊訊息.
|
|
|
13388 |
#$result["content"],字串,含有<span>標籤的內容.
|
|
|
13389 |
#必填參數:
|
|
|
13390 |
#$conf["contentArray"],字串陣列,要放入的內容陣列.
|
|
|
13391 |
$conf["css::spanSection"]["contentArray"]=array($data["content"]);
|
|
|
13392 |
#可省略參數
|
|
|
13393 |
#$conf["id"],字串,span元素的id.
|
|
|
13394 |
$conf["css::spanSection"]["id"]=$conf["id"];
|
|
|
13395 |
#$conf["styleAttr"],字串陣列,給div區段要套用的style樣式屬性.
|
|
|
13396 |
$conf["css::spanSection"]["styleAttr"]=array("position","bottom","right","display");
|
|
|
13397 |
#$conf["styleVal"],字串陣列,給div區段要套用的style樣式數值.
|
|
|
13398 |
$conf["css::spanSection"]["styleVal"]=array("fixed",$conf["bottom"],$conf["right"],"none");
|
|
|
13399 |
#$conf["class"],字串,span區段要套用的css樣式.
|
|
|
13400 |
#$conf["class"]="";
|
|
|
13401 |
#$conf["title"],陣列,滑鼠移到上面時要顯示的內容,每個元素代表一列內容
|
|
|
13402 |
#$conf["title"]=array();
|
|
|
13403 |
#$conf["data"],字串陣列,每個data屬性名稱為數值內容,例如array("a"=>"A","b"=>"B")
|
|
|
13404 |
#$conf["data"]=array();
|
|
|
13405 |
$spanSection=css::spanSection($conf["css::spanSection"]);
|
|
|
13406 |
unset($conf["css::spanSection"]);
|
|
|
13407 |
|
|
|
13408 |
#如果建立 span section 失敗
|
|
|
13409 |
if($spanSection["status"]==="false"){
|
| 226 |
liveuser |
13410 |
|
| 3 |
liveuser |
13411 |
#設置執行失敗
|
|
|
13412 |
$result["status"]="false";
|
|
|
13413 |
|
|
|
13414 |
#設置執行錯誤訊息
|
|
|
13415 |
$result["error"]=$spanSection;
|
|
|
13416 |
|
|
|
13417 |
#回傳結果
|
|
|
13418 |
return $result;
|
| 226 |
liveuser |
13419 |
|
| 3 |
liveuser |
13420 |
}#if end
|
|
|
13421 |
|
|
|
13422 |
#儲存 top span
|
|
|
13423 |
$result["content"]=$result["content"].$spanSection["content"];
|
| 226 |
liveuser |
13424 |
|
| 3 |
liveuser |
13425 |
#函式說明:
|
|
|
13426 |
#將要執行的script語法透過該函式執行(會在程式外層用<script></script>包起來).
|
|
|
13427 |
#回傳結果:
|
|
|
13428 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
13429 |
#$result["error"],錯誤訊息陣列
|
|
|
13430 |
#$result["function"],當前執行的函數名稱
|
|
|
13431 |
#$result["content"],要執行的javaScript語法
|
|
|
13432 |
#必填參數:
|
|
|
13433 |
#$conf["script"],字串,要執行的javaScript語法.
|
|
|
13434 |
$conf["javaScript::toScript"]["script"]="
|
|
|
13435 |
//get topspan
|
|
|
13436 |
var topSpan=document.getElementById('".$conf["id"]."');
|
| 226 |
liveuser |
13437 |
|
| 3 |
liveuser |
13438 |
//scrolliv click event
|
| 226 |
liveuser |
13439 |
topSpan.addEventListener('click',function(e){
|
|
|
13440 |
|
| 3 |
liveuser |
13441 |
//滑到頂端
|
| 226 |
liveuser |
13442 |
document.scrollingElement.scrollTop=0;
|
|
|
13443 |
|
| 3 |
liveuser |
13444 |
});//topSpan addEventListener end
|
| 226 |
liveuser |
13445 |
|
| 3 |
liveuser |
13446 |
//當滾軸滾動時觸發
|
|
|
13447 |
window.addEventListener('scroll', function(e){
|
| 226 |
liveuser |
13448 |
|
| 3 |
liveuser |
13449 |
//get last scroll y
|
|
|
13450 |
var last_known_scroll_position = window.scrollY;
|
| 226 |
liveuser |
13451 |
|
| 3 |
liveuser |
13452 |
//get topspan
|
|
|
13453 |
var topSpan=document.getElementById('".$conf["id"]."');
|
| 226 |
liveuser |
13454 |
|
| 3 |
liveuser |
13455 |
//如果是在網頁頂端
|
|
|
13456 |
if(last_known_scroll_position===0){
|
| 226 |
liveuser |
13457 |
|
| 3 |
liveuser |
13458 |
//隱藏往頂端的圖示
|
|
|
13459 |
topSpan.style.display='none';
|
| 226 |
liveuser |
13460 |
|
| 3 |
liveuser |
13461 |
}//if end
|
| 226 |
liveuser |
13462 |
|
| 3 |
liveuser |
13463 |
//反之
|
|
|
13464 |
else{
|
| 226 |
liveuser |
13465 |
|
| 3 |
liveuser |
13466 |
//get topspan to show
|
|
|
13467 |
topSpan.style.display='inline';
|
| 226 |
liveuser |
13468 |
|
| 3 |
liveuser |
13469 |
}//else end
|
| 226 |
liveuser |
13470 |
|
| 3 |
liveuser |
13471 |
});//window scroll event end
|
|
|
13472 |
";
|
|
|
13473 |
#可省略參數:
|
|
|
13474 |
#$conf["onReady"],字串,是否要在網頁完全載入後再執行,"false"為不等載入完就先執行,預設為"true"要等載入完再執行.
|
|
|
13475 |
#$conf["onReady"]="true";
|
|
|
13476 |
#$conf["globalJs"],字串陣列,為要放入<script>標籤的js全域變數.
|
|
|
13477 |
#$conf["globalJs"]=array();
|
|
|
13478 |
#$conf["jsFunciton"],字串陣列,為要放入<script>標籤的js函數.
|
|
|
13479 |
#$conf["jsFunciton"]=array();
|
|
|
13480 |
#參考資料:
|
|
|
13481 |
#http://stackoverflow.com/questions/9899372/pure-javascript-equivalent-to-jquerys-ready-how-to-call-a-function-when-the
|
|
|
13482 |
$toScript=javaScript::toScript($conf["javaScript::toScript"]);
|
|
|
13483 |
unset($conf["javaScript::toScript"]);
|
| 226 |
liveuser |
13484 |
|
| 3 |
liveuser |
13485 |
#如果建立js失敗
|
|
|
13486 |
if($toScript["status"]==="false"){
|
| 226 |
liveuser |
13487 |
|
| 3 |
liveuser |
13488 |
#設置執行失敗
|
|
|
13489 |
$result["status"]="false";
|
|
|
13490 |
|
|
|
13491 |
#設置執行錯誤訊息
|
|
|
13492 |
$result["error"]=$toScript;
|
|
|
13493 |
|
|
|
13494 |
#回傳結果
|
|
|
13495 |
return $result;
|
| 226 |
liveuser |
13496 |
|
| 3 |
liveuser |
13497 |
}#if end
|
| 226 |
liveuser |
13498 |
|
| 3 |
liveuser |
13499 |
#儲存 top span
|
|
|
13500 |
$result["content"]=$result["content"].$toScript["content"];
|
| 226 |
liveuser |
13501 |
|
| 3 |
liveuser |
13502 |
#設置執行正常
|
|
|
13503 |
$result["status"]="true";
|
| 226 |
liveuser |
13504 |
|
| 3 |
liveuser |
13505 |
#回傳結果
|
|
|
13506 |
return $result;
|
|
|
13507 |
|
| 226 |
liveuser |
13508 |
}#funcion goTopIcon end
|
|
|
13509 |
|
| 3 |
liveuser |
13510 |
/*
|
|
|
13511 |
#函式說明:
|
|
|
13512 |
#透過ajax遞迴取得檔案的內容,類似tail指令的效果.
|
|
|
13513 |
#回傳結果:
|
|
|
13514 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
13515 |
#$result["error"],錯誤訊息.
|
|
|
13516 |
#$result["function"],當前執行的函數名稱.
|
|
|
13517 |
#$result["argu"],使用的參數.
|
|
|
13518 |
#$result["content"],語法.
|
|
|
13519 |
#必填參數:
|
|
|
13520 |
#$conf["url"],字串,提供tail ajax的網址.
|
|
|
13521 |
$conf["url"]="";
|
| 226 |
liveuser |
13522 |
#可省略參數:
|
| 3 |
liveuser |
13523 |
#$conf["rootDivId"],字串,root div的id,預設為"tailRootDiv".
|
|
|
13524 |
#$conf["rootDivId"]="tailRootDiv";
|
|
|
13525 |
#參考資料:
|
|
|
13526 |
#無.
|
|
|
13527 |
#備註:
|
|
|
13528 |
#請跟fileAccess類別的tail函式搭配使用.
|
|
|
13529 |
*/
|
|
|
13530 |
public static function tail(&$conf){
|
|
|
13531 |
|
|
|
13532 |
#初始化要回傳的結果
|
|
|
13533 |
$result=array();
|
|
|
13534 |
|
|
|
13535 |
#取得當前執行的函數名稱
|
|
|
13536 |
$result["function"]=__FUNCTION__;
|
|
|
13537 |
|
|
|
13538 |
#如果沒有參數
|
|
|
13539 |
if(func_num_args()==0){
|
|
|
13540 |
|
|
|
13541 |
#設置執行失敗
|
|
|
13542 |
$result["status"]="false";
|
|
|
13543 |
|
|
|
13544 |
#設置執行錯誤訊息
|
|
|
13545 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
13546 |
|
|
|
13547 |
#回傳結果
|
|
|
13548 |
return $result;
|
|
|
13549 |
|
|
|
13550 |
}#if end
|
|
|
13551 |
|
|
|
13552 |
#取得參數
|
|
|
13553 |
$result["argu"]=$conf;
|
|
|
13554 |
|
|
|
13555 |
#如果 $conf 不為陣列
|
|
|
13556 |
if(gettype($conf)!=="array"){
|
|
|
13557 |
|
|
|
13558 |
#設置執行失敗
|
|
|
13559 |
$result["status"]="false";
|
|
|
13560 |
|
|
|
13561 |
#設置執行錯誤訊息
|
|
|
13562 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
13563 |
|
|
|
13564 |
#如果傳入的參數為 null
|
|
|
13565 |
if($conf===null){
|
|
|
13566 |
|
|
|
13567 |
#設置執行錯誤訊息
|
|
|
13568 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
13569 |
|
|
|
13570 |
}#if end
|
|
|
13571 |
|
|
|
13572 |
#回傳結果
|
|
|
13573 |
return $result;
|
|
|
13574 |
|
|
|
13575 |
}#if end
|
|
|
13576 |
|
|
|
13577 |
#初始化內容
|
| 226 |
liveuser |
13578 |
$result["content"]="";
|
| 3 |
liveuser |
13579 |
|
|
|
13580 |
#檢查參數
|
|
|
13581 |
#函式說明:
|
|
|
13582 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
13583 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
13584 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
13585 |
#$result["function"],當前執行的函式名稱.
|
|
|
13586 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
13587 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
13588 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
13589 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
13590 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
13591 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
13592 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
13593 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
13594 |
#必填參數:
|
|
|
13595 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
13596 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
13597 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
13598 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("url");
|
|
|
13599 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
13600 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
13601 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
13602 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
13603 |
#可以省略的參數:
|
|
|
13604 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
13605 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
13606 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
13607 |
#$conf["canNotBeEmpty"]=array();
|
|
|
13608 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
13609 |
#$conf["canBeEmpty"]=array();
|
|
|
13610 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
13611 |
$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("rootDivId");
|
|
|
13612 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
13613 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("rootDivId");
|
|
|
13614 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
13615 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
13616 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
13617 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("tailRootDiv");
|
|
|
13618 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
13619 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
13620 |
#參考資料來源:
|
|
|
13621 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
13622 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
13623 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
13624 |
|
|
|
13625 |
#如果檢查參數失敗
|
|
|
13626 |
if($checkArguments["status"]==="false"){
|
|
|
13627 |
|
|
|
13628 |
#設置執行失敗
|
|
|
13629 |
$result["status"]="false";
|
|
|
13630 |
|
|
|
13631 |
#設置執行錯誤訊息
|
|
|
13632 |
$result["error"]=$checkArguments;
|
|
|
13633 |
|
|
|
13634 |
#回傳結果
|
|
|
13635 |
return $result;
|
|
|
13636 |
|
|
|
13637 |
}#if end
|
|
|
13638 |
|
|
|
13639 |
#如果參數檢查不通過
|
|
|
13640 |
if($checkArguments["passed"]==="false"){
|
|
|
13641 |
|
|
|
13642 |
#設置執行失敗
|
|
|
13643 |
$result["status"]="false";
|
|
|
13644 |
|
|
|
13645 |
#設置執行錯誤訊息
|
|
|
13646 |
$result["error"]=$checkArguments;
|
|
|
13647 |
|
|
|
13648 |
#回傳結果
|
|
|
13649 |
return $result;
|
|
|
13650 |
|
|
|
13651 |
}#if end
|
|
|
13652 |
|
|
|
13653 |
#函式說明:
|
|
|
13654 |
#將要執行的script語法透過該函式執行(會在程式外層用<script></script>包起來).
|
|
|
13655 |
#回傳結果:
|
|
|
13656 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
13657 |
#$result["error"],錯誤訊息陣列
|
|
|
13658 |
#$result["function"],當前執行的函數名稱
|
|
|
13659 |
#$result["content"],要執行的javaScript語法
|
|
|
13660 |
#必填參數:
|
|
|
13661 |
#$conf["script"],字串,要執行的javaScript語法.
|
|
|
13662 |
$conf["javaScript::toScript"]["script"]="
|
| 226 |
liveuser |
13663 |
|
| 3 |
liveuser |
13664 |
//initial window.tail
|
|
|
13665 |
if(window.tail===undefined){
|
|
|
13666 |
|
|
|
13667 |
//初始化 window.tail
|
|
|
13668 |
window.tail={};
|
|
|
13669 |
|
|
|
13670 |
//初始化繼續執行
|
|
|
13671 |
window.tail.continue=true;
|
|
|
13672 |
|
|
|
13673 |
}//if end
|
| 226 |
liveuser |
13674 |
|
| 3 |
liveuser |
13675 |
//create root div
|
| 226 |
liveuser |
13676 |
window.tail.rootDiv = document.createElement('div');
|
| 3 |
liveuser |
13677 |
window.tail.rootDiv.id = '".$conf["rootDivId"]."';
|
|
|
13678 |
document.body.appendChild(window.tail.rootDiv);
|
|
|
13679 |
|
|
|
13680 |
//set tail url
|
|
|
13681 |
window.tailUrl='".$conf["url"]."';
|
| 226 |
liveuser |
13682 |
|
| 3 |
liveuser |
13683 |
//設置周期執行的涵式
|
|
|
13684 |
window.tail.ajax = function(line2start){
|
| 226 |
liveuser |
13685 |
|
| 3 |
liveuser |
13686 |
xmlhttp=new XMLHttpRequest();
|
|
|
13687 |
xmlhttp.responseType='json';
|
|
|
13688 |
xmlhttp.timeout=60000;
|
|
|
13689 |
xmlhttp.open('POST',window.tailUrl,true);
|
|
|
13690 |
xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
|
|
|
13691 |
xmlhttp.setRequestHeader('X-Requested-With','XMLHttpRequest');
|
|
|
13692 |
xmlhttp.onreadystatechange=function(){
|
|
|
13693 |
|
|
|
13694 |
//如果狀態為4且response code為200
|
|
|
13695 |
if(xmlhttp.readyState===4 && xmlhttp.status===200){
|
|
|
13696 |
|
| 226 |
liveuser |
13697 |
//get response
|
| 3 |
liveuser |
13698 |
res=xmlhttp.response;
|
| 226 |
liveuser |
13699 |
|
| 3 |
liveuser |
13700 |
//debug
|
|
|
13701 |
console.log(res);
|
| 226 |
liveuser |
13702 |
|
| 3 |
liveuser |
13703 |
//針對每個輸出的行
|
|
|
13704 |
for(var i=0;i<xmlhttp.response.lines;i++){
|
| 226 |
liveuser |
13705 |
|
| 3 |
liveuser |
13706 |
//set output line
|
|
|
13707 |
var div=document.createElement('div');
|
|
|
13708 |
var text=document.createTextNode(xmlhttp.response.content[i]);
|
|
|
13709 |
div.appendChild(text);
|
| 226 |
liveuser |
13710 |
|
| 3 |
liveuser |
13711 |
//debug
|
| 226 |
liveuser |
13712 |
console.log(div);
|
|
|
13713 |
|
| 3 |
liveuser |
13714 |
//如果內容為空
|
|
|
13715 |
if(xmlhttp.response.content[i]==='')
|
|
|
13716 |
{
|
|
|
13717 |
//建立<br>
|
|
|
13718 |
var br=document.createElement('br');
|
| 226 |
liveuser |
13719 |
|
| 3 |
liveuser |
13720 |
//遷入<br>
|
|
|
13721 |
div.appendChild(br);
|
|
|
13722 |
}
|
| 226 |
liveuser |
13723 |
|
| 3 |
liveuser |
13724 |
//show output line
|
|
|
13725 |
var rootDiv=document.getElementById(window.tail.rootDiv.id);
|
|
|
13726 |
rootDiv.prepend(div);
|
|
|
13727 |
|
| 226 |
liveuser |
13728 |
}//for end
|
|
|
13729 |
|
| 3 |
liveuser |
13730 |
//遞迴
|
|
|
13731 |
window.tail.ajax.call(this,(res.lineNum)+1);
|
|
|
13732 |
|
|
|
13733 |
}//if end
|
|
|
13734 |
|
|
|
13735 |
}//function end
|
| 226 |
liveuser |
13736 |
|
|
|
13737 |
//如果要繼續
|
| 3 |
liveuser |
13738 |
if(window.tail.continue){
|
|
|
13739 |
|
|
|
13740 |
//繼續
|
|
|
13741 |
xmlhttp.send('line2start='+line2start);
|
|
|
13742 |
|
|
|
13743 |
}//if end
|
| 226 |
liveuser |
13744 |
|
| 3 |
liveuser |
13745 |
//反之要暫停
|
|
|
13746 |
else{
|
| 226 |
liveuser |
13747 |
|
| 3 |
liveuser |
13748 |
//設置無限等待
|
|
|
13749 |
var intervalTail = window.setInterval(function(){
|
| 226 |
liveuser |
13750 |
|
| 3 |
liveuser |
13751 |
//提示已經暫停
|
|
|
13752 |
console.log('paused');
|
| 226 |
liveuser |
13753 |
|
| 3 |
liveuser |
13754 |
//如果要繼續了
|
|
|
13755 |
if(window.tail.continue){
|
| 226 |
liveuser |
13756 |
|
| 3 |
liveuser |
13757 |
//清除無限等待
|
|
|
13758 |
clearInterval(intervalTail);
|
| 226 |
liveuser |
13759 |
|
| 3 |
liveuser |
13760 |
//繼續
|
|
|
13761 |
xmlhttp.send('line2start='+line2start);
|
| 226 |
liveuser |
13762 |
|
| 3 |
liveuser |
13763 |
}//if end
|
| 226 |
liveuser |
13764 |
|
| 3 |
liveuser |
13765 |
},1000);
|
| 226 |
liveuser |
13766 |
|
| 3 |
liveuser |
13767 |
}//else end
|
|
|
13768 |
|
|
|
13769 |
}//function end
|
|
|
13770 |
|
|
|
13771 |
//call tail ajax
|
|
|
13772 |
window.tail.ajax.call(this,-1);
|
|
|
13773 |
";
|
|
|
13774 |
#可省略參數:
|
|
|
13775 |
#$conf["onReady"],字串,是否要在網頁完全載入後再執行,"false"為不等載入完就先執行,預設為"true"要等載入完再執行.
|
|
|
13776 |
#$conf["onReady"]="true";
|
|
|
13777 |
#$conf["globalJs"],字串陣列,為要放入<script>標籤的js全域變數.
|
|
|
13778 |
#$conf["globalJs"]=array();
|
|
|
13779 |
#$conf["jsFunciton"],字串陣列,為要放入<script>標籤的js函數.
|
|
|
13780 |
#$conf["jsFunciton"]=array();
|
|
|
13781 |
#參考資料:
|
|
|
13782 |
#http://stackoverflow.com/questions/9899372/pure-javascript-equivalent-to-jquerys-ready-how-to-call-a-function-when-the
|
|
|
13783 |
$toScript=javaScript::toScript($conf["javaScript::toScript"]);
|
|
|
13784 |
unset($conf["javaScript::toScript"]);
|
| 226 |
liveuser |
13785 |
|
| 3 |
liveuser |
13786 |
#如果建立js失敗
|
|
|
13787 |
if($toScript["status"]==="false"){
|
| 226 |
liveuser |
13788 |
|
| 3 |
liveuser |
13789 |
#設置執行失敗
|
|
|
13790 |
$result["status"]="false";
|
|
|
13791 |
|
|
|
13792 |
#設置執行錯誤訊息
|
|
|
13793 |
$result["error"]=$toScript;
|
|
|
13794 |
|
|
|
13795 |
#回傳結果
|
|
|
13796 |
return $result;
|
| 226 |
liveuser |
13797 |
|
| 3 |
liveuser |
13798 |
}#if end
|
| 226 |
liveuser |
13799 |
|
| 3 |
liveuser |
13800 |
#儲存 top span
|
|
|
13801 |
$result["content"]=$result["content"].$toScript["content"];
|
| 226 |
liveuser |
13802 |
|
| 3 |
liveuser |
13803 |
#設置執行正常
|
|
|
13804 |
$result["status"]="true";
|
| 226 |
liveuser |
13805 |
|
| 3 |
liveuser |
13806 |
#回傳結果
|
|
|
13807 |
return $result;
|
|
|
13808 |
|
|
|
13809 |
}#function tail end
|
|
|
13810 |
|
|
|
13811 |
/*
|
|
|
13812 |
#函式說明:
|
|
|
13813 |
#透過ajax產生亂數驗證碼,驗證亂數驗證碼與傳送表單
|
|
|
13814 |
#回傳結果:
|
|
|
13815 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
13816 |
#$result["error"],錯誤訊息.
|
|
|
13817 |
#$result["argu"],使用的參數.
|
|
|
13818 |
#$result["function"],當前執行的函數名稱.
|
|
|
13819 |
#$result["content"],json.
|
|
|
13820 |
#必填參數:
|
|
|
13821 |
#$conf["url"],字串,提供random code的網址.
|
|
|
13822 |
$conf["url"]="";
|
|
|
13823 |
#$conf["callBackUrls"],字串陣列,用來處理表單資訊的網址們,會傳送 obj 物件的 post 內容到第一個 callback url,之後都會將 json 回應傳送給下一個 callback url. 如果進行第2個含以上的 callback urls 時有回應含有 formObj 元素的 json 則會改傳送之.每次傳送給 callback url 的表單變數均為 $conf["sendedName"].
|
|
|
13824 |
$conf["callBackUrls"]=array();
|
| 226 |
liveuser |
13825 |
#可省略參數:
|
| 3 |
liveuser |
13826 |
#$conf["resDivId"],字串,輸入驗證碼的表單id,預設為"randomCode".
|
|
|
13827 |
#$conf["resDivId"]="randomCode";
|
|
|
13828 |
#$conf["names"],字串陣列,需要傳送的表單變數.
|
|
|
13829 |
#$conf["names"]=array();
|
|
|
13830 |
#$conf["sendedName"],字串,傳送的post變數名稱,預設的爲"formData".
|
|
|
13831 |
#$conf["sendedName"]="";
|
|
|
13832 |
#備註:
|
|
|
13833 |
#請跟 authenticate 類別的 verifyCodeAndFormData 函式搭配.
|
|
|
13834 |
#每次呼叫 callBackUrl 應該要驗證其所 post 的驗證碼是否正確,其對應的 post 變數為元素 id 為 $conf["resDivId"] 的 name 屬性數值;對應的session變數名稱則為 "authenticate.verifyCodeAndFormData.".元素 id 為 $conf["resDivId"] 的 name 屬性數值.例如 $_SESSION["authenticate.verifyCodeAndFormData.randomCode"]===$post->randomCode .
|
|
|
13835 |
#從 $conf["callBackUrls"] 取得的 json 回應,若有 msg 屬性,且 status 屬性爲 'true', 則會顯示提示訊息.
|
|
|
13836 |
#從 $conf["callBackUrls"] 取得的 json 回應,若有 error 屬性,且 status 屬性爲 'false', 則會顯示錯誤訊息.
|
|
|
13837 |
#從 $conf["callBackUrls"] 中的最後一個 callback url 取得的 json 回應,若有 href 屬性,則會轉址.
|
|
|
13838 |
#從 $conf["callBackUrls"] 中的最後一個 callback url 取得的 json 回應,若有 refresh 屬性,且爲 'true' 則會重新整理頁面.
|
|
|
13839 |
#參考資料:
|
|
|
13840 |
#無.
|
|
|
13841 |
#備註:
|
|
|
13842 |
#提示訊息的呈現改用 text area;
|
|
|
13843 |
#驗證失敗原因呈現改用 text area;
|
|
|
13844 |
*/
|
|
|
13845 |
public static function randomCode(&$conf){
|
| 226 |
liveuser |
13846 |
|
| 3 |
liveuser |
13847 |
#初始化要回傳的結果
|
|
|
13848 |
$result=array();
|
|
|
13849 |
|
|
|
13850 |
#取得當前執行的函數名稱
|
|
|
13851 |
$result["function"]=__FUNCTION__;
|
|
|
13852 |
|
|
|
13853 |
#如果沒有參數
|
|
|
13854 |
if(func_num_args()==0){
|
|
|
13855 |
|
|
|
13856 |
#設置執行失敗
|
|
|
13857 |
$result["status"]="false";
|
|
|
13858 |
|
|
|
13859 |
#設置執行錯誤訊息
|
|
|
13860 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
13861 |
|
|
|
13862 |
#回傳結果
|
|
|
13863 |
return $result;
|
|
|
13864 |
|
|
|
13865 |
}#if end
|
|
|
13866 |
|
|
|
13867 |
#取得參數
|
|
|
13868 |
$result["argu"]=$conf;
|
|
|
13869 |
|
|
|
13870 |
#如果 $conf 不為陣列
|
|
|
13871 |
if(gettype($conf)!=="array"){
|
|
|
13872 |
|
|
|
13873 |
#設置執行失敗
|
|
|
13874 |
$result["status"]="false";
|
|
|
13875 |
|
|
|
13876 |
#設置執行錯誤訊息
|
|
|
13877 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
13878 |
|
|
|
13879 |
#如果傳入的參數為 null
|
|
|
13880 |
if($conf===null){
|
|
|
13881 |
|
|
|
13882 |
#設置執行錯誤訊息
|
|
|
13883 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
13884 |
|
|
|
13885 |
}#if end
|
|
|
13886 |
|
|
|
13887 |
#回傳結果
|
|
|
13888 |
return $result;
|
|
|
13889 |
|
|
|
13890 |
}#if end
|
|
|
13891 |
|
|
|
13892 |
#初始化內容
|
| 226 |
liveuser |
13893 |
$result["content"]="";
|
| 3 |
liveuser |
13894 |
|
|
|
13895 |
#檢查參數
|
|
|
13896 |
#函式說明:
|
|
|
13897 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
13898 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
13899 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
13900 |
#$result["function"],當前執行的函式名稱.
|
|
|
13901 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
13902 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
13903 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
13904 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
13905 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
13906 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
13907 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
13908 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
13909 |
#必填參數:
|
|
|
13910 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
13911 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
13912 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
13913 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("url","callBackUrls");
|
|
|
13914 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
13915 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","array");
|
|
|
13916 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
13917 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
13918 |
#可以省略的參數:
|
|
|
13919 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
13920 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
13921 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
13922 |
#$conf["canNotBeEmpty"]=array();
|
|
|
13923 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
13924 |
#$conf["canBeEmpty"]=array();
|
|
|
13925 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
13926 |
$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("resDivId","names","sendedName");
|
|
|
13927 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
13928 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("resDivId","names","sendedName");
|
|
|
13929 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
13930 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","array","string");
|
|
|
13931 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
13932 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("randomCode",null,"formData");
|
|
|
13933 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
13934 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
13935 |
#參考資料來源:
|
|
|
13936 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
13937 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
13938 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
13939 |
|
|
|
13940 |
#如果檢查參數失敗
|
|
|
13941 |
if($checkArguments["status"]==="false"){
|
|
|
13942 |
|
|
|
13943 |
#設置執行失敗
|
|
|
13944 |
$result["status"]="false";
|
|
|
13945 |
|
|
|
13946 |
#設置執行錯誤訊息
|
|
|
13947 |
$result["error"]=$checkArguments;
|
|
|
13948 |
|
|
|
13949 |
#回傳結果
|
|
|
13950 |
return $result;
|
|
|
13951 |
|
|
|
13952 |
}#if end
|
|
|
13953 |
|
|
|
13954 |
#如果參數檢查不通過
|
|
|
13955 |
if($checkArguments["passed"]==="false"){
|
|
|
13956 |
|
|
|
13957 |
#設置執行失敗
|
|
|
13958 |
$result["status"]="false";
|
|
|
13959 |
|
|
|
13960 |
#設置執行錯誤訊息
|
|
|
13961 |
$result["error"]=$checkArguments;
|
|
|
13962 |
|
|
|
13963 |
#回傳結果
|
|
|
13964 |
return $result;
|
|
|
13965 |
|
|
|
13966 |
}#if end
|
| 226 |
liveuser |
13967 |
|
| 3 |
liveuser |
13968 |
#如果未設置 $conf["names"]
|
|
|
13969 |
if(!isset($conf["names"])){
|
|
|
13970 |
|
|
|
13971 |
#設置爲空
|
|
|
13972 |
$conf["names"]=array();
|
|
|
13973 |
|
|
|
13974 |
}#if end
|
|
|
13975 |
|
|
|
13976 |
#函式說明:
|
|
|
13977 |
#將要執行的script語法透過該函式執行(會在程式外層用<script></script>包起來).
|
|
|
13978 |
#回傳結果:
|
|
|
13979 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
13980 |
#$result["error"],錯誤訊息陣列
|
|
|
13981 |
#$result["function"],當前執行的函數名稱
|
|
|
13982 |
#$result["content"],要執行的javaScript語法
|
|
|
13983 |
#必填參數:
|
|
|
13984 |
#$conf["script"],字串,要執行的javaScript語法.
|
|
|
13985 |
$conf["javaScript::toScript"]["script"]="
|
| 226 |
liveuser |
13986 |
|
| 3 |
liveuser |
13987 |
//initial window.qbpwcf
|
|
|
13988 |
if(window.qbpwcf===undefined){
|
|
|
13989 |
|
|
|
13990 |
window.qbpwcf={};
|
|
|
13991 |
|
|
|
13992 |
}//if end
|
| 226 |
liveuser |
13993 |
|
| 3 |
liveuser |
13994 |
//initial window.randomCode
|
|
|
13995 |
if(window.qbpwcf.randomCode===undefined){
|
|
|
13996 |
|
|
|
13997 |
window.qbpwcf.randomCode={};
|
|
|
13998 |
|
|
|
13999 |
}//if end
|
|
|
14000 |
|
|
|
14001 |
//set random code generate url
|
|
|
14002 |
window.qbpwcf.randomCode.randomCodeUrl='".$conf["url"]."';
|
| 226 |
liveuser |
14003 |
|
| 3 |
liveuser |
14004 |
//set 表單ID 陣列
|
|
|
14005 |
window.qbpwcf.randomCode.formDataIDs=".json_encode($conf["names"])."
|
| 226 |
liveuser |
14006 |
|
| 3 |
liveuser |
14007 |
//設置傳送表單的涵式
|
|
|
14008 |
window.qbpwcf.randomCodeAjax = function(formObj){
|
| 226 |
liveuser |
14009 |
|
| 3 |
liveuser |
14010 |
xmlhttp=new XMLHttpRequest();
|
|
|
14011 |
xmlhttp.responseType='json';
|
|
|
14012 |
xmlhttp.timeout=60000;
|
|
|
14013 |
xmlhttp.open('POST',window.qbpwcf.randomCode.randomCodeUrl,true);
|
|
|
14014 |
xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
|
|
|
14015 |
xmlhttp.setRequestHeader('X-Requested-With','XMLHttpRequest');
|
|
|
14016 |
xmlhttp.onreadystatechange=function(){
|
|
|
14017 |
|
|
|
14018 |
//如果狀態為4且response code為200
|
|
|
14019 |
if(xmlhttp.readyState===4 && xmlhttp.status===200){
|
|
|
14020 |
|
| 226 |
liveuser |
14021 |
//get response
|
| 3 |
liveuser |
14022 |
res=xmlhttp.response;
|
| 226 |
liveuser |
14023 |
|
| 3 |
liveuser |
14024 |
//debug
|
|
|
14025 |
console.log(res);
|
| 226 |
liveuser |
14026 |
|
| 3 |
liveuser |
14027 |
//debug
|
|
|
14028 |
console.log(res.status);
|
| 226 |
liveuser |
14029 |
|
| 3 |
liveuser |
14030 |
//if error occur
|
|
|
14031 |
if(res.status==='false'){
|
| 226 |
liveuser |
14032 |
|
| 3 |
liveuser |
14033 |
//debug
|
|
|
14034 |
console.log(res.error);
|
| 226 |
liveuser |
14035 |
|
| 3 |
liveuser |
14036 |
//if no data
|
|
|
14037 |
if(res.error==='no data'){
|
| 226 |
liveuser |
14038 |
|
| 3 |
liveuser |
14039 |
//get random code base64 encoded string
|
|
|
14040 |
var randomCodeSrc=res.content.randomCodeSrc;
|
| 226 |
liveuser |
14041 |
|
| 3 |
liveuser |
14042 |
//debug
|
| 226 |
liveuser |
14043 |
console.log(randomCodeSrc);
|
|
|
14044 |
|
| 3 |
liveuser |
14045 |
//get random code length
|
|
|
14046 |
window.qbpwcf.randomCode.codeLength=res.content.randomCodeLength;
|
| 226 |
liveuser |
14047 |
|
| 3 |
liveuser |
14048 |
//debug
|
|
|
14049 |
console.log(window.qbpwcf.randomCode.codeLength);
|
|
|
14050 |
|
|
|
14051 |
//get code input element
|
|
|
14052 |
var codeInput=document.getElementById('".$conf["resDivId"]."');
|
| 226 |
liveuser |
14053 |
|
| 3 |
liveuser |
14054 |
//create img element
|
|
|
14055 |
var img=document.createElement('img');
|
| 226 |
liveuser |
14056 |
|
| 3 |
liveuser |
14057 |
//put src code
|
|
|
14058 |
img.src=randomCodeSrc;
|
| 226 |
liveuser |
14059 |
|
| 3 |
liveuser |
14060 |
//create random code img id
|
|
|
14061 |
var imgId='".$conf["resDivId"]."'+'Img';
|
| 226 |
liveuser |
14062 |
|
| 3 |
liveuser |
14063 |
//若存在舊的驗證碼
|
|
|
14064 |
if(document.getElementById(imgId)!==null){
|
| 226 |
liveuser |
14065 |
|
| 3 |
liveuser |
14066 |
//移除舊的驗證碼
|
|
|
14067 |
document.getElementById(imgId).remove();
|
| 226 |
liveuser |
14068 |
|
| 3 |
liveuser |
14069 |
}//if end
|
| 226 |
liveuser |
14070 |
|
| 3 |
liveuser |
14071 |
//set img id
|
|
|
14072 |
img.id=imgId;
|
| 226 |
liveuser |
14073 |
|
| 3 |
liveuser |
14074 |
//設置寬度
|
|
|
14075 |
img.width='200';
|
|
|
14076 |
|
|
|
14077 |
//debug
|
|
|
14078 |
console.log(img);
|
| 226 |
liveuser |
14079 |
|
| 3 |
liveuser |
14080 |
//place random code img
|
|
|
14081 |
codeInput.parentElement.prepend(img);
|
| 226 |
liveuser |
14082 |
|
| 3 |
liveuser |
14083 |
}//if end
|
|
|
14084 |
|
|
|
14085 |
//反之有其他錯誤
|
|
|
14086 |
else{
|
| 226 |
liveuser |
14087 |
|
| 3 |
liveuser |
14088 |
//debug
|
|
|
14089 |
console.log(res.error);
|
|
|
14090 |
|
|
|
14091 |
//alert
|
|
|
14092 |
alert(res.error);
|
| 226 |
liveuser |
14093 |
|
| 3 |
liveuser |
14094 |
}//else end
|
| 226 |
liveuser |
14095 |
|
| 3 |
liveuser |
14096 |
}//if end
|
| 226 |
liveuser |
14097 |
|
| 3 |
liveuser |
14098 |
//如果驗證失敗
|
|
|
14099 |
if(res.passed==='false'){
|
|
|
14100 |
|
|
|
14101 |
//debug
|
|
|
14102 |
console.log(res.error);
|
|
|
14103 |
|
|
|
14104 |
//alert
|
|
|
14105 |
alert(res.error);
|
|
|
14106 |
|
|
|
14107 |
}//if end
|
| 226 |
liveuser |
14108 |
|
| 3 |
liveuser |
14109 |
//反之通過驗證
|
|
|
14110 |
else if(res.passed==='true'){
|
|
|
14111 |
|
|
|
14112 |
//debug
|
|
|
14113 |
console.log(res.msg);
|
|
|
14114 |
|
|
|
14115 |
//alert
|
|
|
14116 |
//alert(res.msg);
|
| 226 |
liveuser |
14117 |
|
| 3 |
liveuser |
14118 |
//set callback urls
|
|
|
14119 |
window.qbpwcf.randomCode.callBackUrls=".json_encode($conf["callBackUrls"]).";
|
| 226 |
liveuser |
14120 |
|
| 3 |
liveuser |
14121 |
//nested call callback urls
|
|
|
14122 |
window.qbpwcf.randomCode.callBackFunc.call(this,formObj,window.qbpwcf.randomCode.callBackUrls);
|
|
|
14123 |
|
|
|
14124 |
}//else end
|
| 226 |
liveuser |
14125 |
|
| 3 |
liveuser |
14126 |
}//if end
|
|
|
14127 |
|
|
|
14128 |
}//function end
|
| 226 |
liveuser |
14129 |
|
|
|
14130 |
//加密傳送資料
|
| 3 |
liveuser |
14131 |
xmlhttp.send('".$conf["sendedName"]."='+btoa(encodeURIComponent(JSON.stringify(formObj))));
|
| 226 |
liveuser |
14132 |
|
| 3 |
liveuser |
14133 |
}//end window.qbpwcf.randomCodeAjax
|
|
|
14134 |
|
|
|
14135 |
//initial call random code ajax
|
|
|
14136 |
window.qbpwcf.randomCodeAjax({});
|
| 226 |
liveuser |
14137 |
|
| 3 |
liveuser |
14138 |
//設置遞迴傳送表單的涵式
|
| 226 |
liveuser |
14139 |
window.qbpwcf.randomCode.callBackFunc = function(formObj,urls){
|
|
|
14140 |
|
| 3 |
liveuser |
14141 |
xmlhttp=new XMLHttpRequest();
|
|
|
14142 |
xmlhttp.responseType='json';
|
|
|
14143 |
xmlhttp.timeout=60000;
|
|
|
14144 |
xmlhttp.open('POST',urls[0],true);
|
|
|
14145 |
xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
|
|
|
14146 |
xmlhttp.setRequestHeader('X-Requested-With','XMLHttpRequest');
|
|
|
14147 |
xmlhttp.onreadystatechange=function(){
|
|
|
14148 |
|
|
|
14149 |
//如果狀態為4且response code為200
|
|
|
14150 |
if(xmlhttp.readyState===4 && xmlhttp.status===200){
|
|
|
14151 |
|
| 226 |
liveuser |
14152 |
//get response
|
| 3 |
liveuser |
14153 |
res=xmlhttp.response;
|
| 226 |
liveuser |
14154 |
|
| 3 |
liveuser |
14155 |
//如果沒有定義 res.status
|
|
|
14156 |
if(res===null){
|
|
|
14157 |
|
|
|
14158 |
//debug
|
|
|
14159 |
console.log('callback to '+urls[0]+' fails!');
|
| 226 |
liveuser |
14160 |
|
| 3 |
liveuser |
14161 |
//show error
|
|
|
14162 |
alert('callback to '+urls[0]+' fails!');
|
| 226 |
liveuser |
14163 |
|
| 3 |
liveuser |
14164 |
//return & end process.
|
|
|
14165 |
return false;
|
|
|
14166 |
|
|
|
14167 |
|
|
|
14168 |
}//if end
|
|
|
14169 |
|
|
|
14170 |
//debug
|
|
|
14171 |
console.log(res);
|
| 226 |
liveuser |
14172 |
|
| 3 |
liveuser |
14173 |
//如果沒有定義 res.status
|
|
|
14174 |
if(res.status===undefined){
|
|
|
14175 |
|
|
|
14176 |
//debug
|
|
|
14177 |
console.log('callback to '+urls[0]+' fails!');
|
| 226 |
liveuser |
14178 |
|
| 3 |
liveuser |
14179 |
//show error
|
|
|
14180 |
alert('callback to '+urls[0]+' fails!');
|
| 226 |
liveuser |
14181 |
|
| 3 |
liveuser |
14182 |
//return & end process.
|
|
|
14183 |
return false;
|
|
|
14184 |
|
|
|
14185 |
}//if end
|
|
|
14186 |
|
|
|
14187 |
//debug
|
|
|
14188 |
console.log(res.status);
|
| 226 |
liveuser |
14189 |
|
| 3 |
liveuser |
14190 |
//如果執行不正常
|
|
|
14191 |
if(res.status!=='true'){
|
| 226 |
liveuser |
14192 |
|
| 3 |
liveuser |
14193 |
//debug
|
|
|
14194 |
console.log('callback to '+urls[0]+' fails!');
|
| 226 |
liveuser |
14195 |
|
| 3 |
liveuser |
14196 |
//show error
|
|
|
14197 |
alert(res.error);
|
| 226 |
liveuser |
14198 |
|
| 3 |
liveuser |
14199 |
//return & end process.
|
|
|
14200 |
return false;
|
| 226 |
liveuser |
14201 |
|
| 3 |
liveuser |
14202 |
}//if end
|
| 226 |
liveuser |
14203 |
|
| 3 |
liveuser |
14204 |
//執行正常
|
|
|
14205 |
|
|
|
14206 |
//如果有訊息
|
|
|
14207 |
if(res.msg!==undefined){
|
|
|
14208 |
|
|
|
14209 |
//顯示訊息
|
|
|
14210 |
alert(res.msg);
|
|
|
14211 |
|
|
|
14212 |
}//if end
|
| 226 |
liveuser |
14213 |
|
| 3 |
liveuser |
14214 |
//新的表單變數存在
|
|
|
14215 |
if(res.formObj!==undefined){
|
| 226 |
liveuser |
14216 |
|
|
|
14217 |
//取代要傳送的表單變數
|
| 3 |
liveuser |
14218 |
res=res.formObj;
|
| 226 |
liveuser |
14219 |
|
|
|
14220 |
}//else end
|
|
|
14221 |
|
| 3 |
liveuser |
14222 |
//移除第一個已經callback的url
|
|
|
14223 |
urls.splice(0, 1);
|
| 226 |
liveuser |
14224 |
|
| 3 |
liveuser |
14225 |
//如果還有 callback urls
|
|
|
14226 |
if(urls.length>0){
|
| 226 |
liveuser |
14227 |
|
| 3 |
liveuser |
14228 |
//debug
|
| 226 |
liveuser |
14229 |
console.log('callback to:'+urls[0]);
|
|
|
14230 |
|
| 3 |
liveuser |
14231 |
//nested call callback urls
|
|
|
14232 |
window.qbpwcf.randomCode.callBackFunc.call(this,res,urls);
|
| 226 |
liveuser |
14233 |
|
| 3 |
liveuser |
14234 |
}//if end
|
| 226 |
liveuser |
14235 |
|
| 3 |
liveuser |
14236 |
//反之
|
|
|
14237 |
else{
|
|
|
14238 |
|
|
|
14239 |
//如果有 href 設定
|
|
|
14240 |
if(res.href!==undefined){
|
| 226 |
liveuser |
14241 |
|
| 3 |
liveuser |
14242 |
//到指定頁面
|
|
|
14243 |
window.location.href=res.href;
|
|
|
14244 |
|
|
|
14245 |
//結束執行
|
|
|
14246 |
return true;
|
|
|
14247 |
|
|
|
14248 |
}//if end
|
|
|
14249 |
|
|
|
14250 |
//如果有 refresh 設定
|
|
|
14251 |
if(res.refresh!==undefined){
|
|
|
14252 |
|
|
|
14253 |
//如果要 refresh
|
|
|
14254 |
if(res.refresh==='true'){
|
|
|
14255 |
|
|
|
14256 |
//重新整理頁面
|
|
|
14257 |
window.location.href=document.baseURI;
|
| 226 |
liveuser |
14258 |
|
| 3 |
liveuser |
14259 |
//結束執行
|
|
|
14260 |
return true;
|
|
|
14261 |
|
|
|
14262 |
}//if end
|
| 226 |
liveuser |
14263 |
|
| 3 |
liveuser |
14264 |
}//if end
|
|
|
14265 |
|
|
|
14266 |
}//else end
|
| 226 |
liveuser |
14267 |
|
| 3 |
liveuser |
14268 |
}//if end
|
|
|
14269 |
|
|
|
14270 |
}//function end
|
| 226 |
liveuser |
14271 |
|
|
|
14272 |
//加密傳送資料
|
| 3 |
liveuser |
14273 |
xmlhttp.send('".$conf["sendedName"]."='+btoa(encodeURIComponent(JSON.stringify(formObj))));
|
| 226 |
liveuser |
14274 |
|
| 3 |
liveuser |
14275 |
}//function end
|
| 226 |
liveuser |
14276 |
|
| 3 |
liveuser |
14277 |
//get code input element
|
|
|
14278 |
var codeInput=document.getElementById('".$conf["resDivId"]."');
|
| 226 |
liveuser |
14279 |
|
| 3 |
liveuser |
14280 |
//如果存在輸入驗證碼的表單
|
|
|
14281 |
if(codeInput!==null){
|
|
|
14282 |
|
|
|
14283 |
//當輸入的驗證碼長度變化時、有按鍵放開時.
|
|
|
14284 |
codeInput.addEventListener('keyup',function(e){
|
| 226 |
liveuser |
14285 |
|
| 3 |
liveuser |
14286 |
//debug
|
|
|
14287 |
console.log('keyup event occur');
|
|
|
14288 |
|
|
|
14289 |
//debug
|
|
|
14290 |
console.log('放開的Key爲'+e.key);
|
|
|
14291 |
|
|
|
14292 |
//expected 'Enter' Key
|
|
|
14293 |
if( e.key!=='Enter' )
|
|
|
14294 |
{
|
|
|
14295 |
//debug
|
|
|
14296 |
console.log('ignore '+e.key);
|
|
|
14297 |
|
|
|
14298 |
return false;
|
|
|
14299 |
|
|
|
14300 |
}//if end
|
|
|
14301 |
|
|
|
14302 |
//如果長度不一致
|
|
|
14303 |
if(codeInput.value.length!==window.qbpwcf.randomCode.codeLength){
|
| 226 |
liveuser |
14304 |
|
| 3 |
liveuser |
14305 |
//結束執行
|
|
|
14306 |
return false;
|
| 226 |
liveuser |
14307 |
|
| 3 |
liveuser |
14308 |
}//if end
|
| 226 |
liveuser |
14309 |
|
| 3 |
liveuser |
14310 |
//長度一致
|
| 226 |
liveuser |
14311 |
|
| 3 |
liveuser |
14312 |
//初始化 form Obj
|
|
|
14313 |
formObj={};
|
| 226 |
liveuser |
14314 |
|
| 3 |
liveuser |
14315 |
//依照每個表單
|
|
|
14316 |
for(var i=0;i<window.qbpwcf.randomCode.formDataIDs.length;i++){
|
| 226 |
liveuser |
14317 |
|
| 3 |
liveuser |
14318 |
//構成表單變數名稱
|
| 226 |
liveuser |
14319 |
var formName=window.qbpwcf.randomCode.formDataIDs[i];
|
| 3 |
liveuser |
14320 |
|
|
|
14321 |
//debug
|
|
|
14322 |
console.log(formName);
|
|
|
14323 |
|
|
|
14324 |
//取得表單內容
|
|
|
14325 |
formObj.formName=document.getElementById(window.qbpwcf.randomCode.formDataIDs[i]).value;
|
| 226 |
liveuser |
14326 |
|
| 3 |
liveuser |
14327 |
}//for end
|
| 226 |
liveuser |
14328 |
|
| 3 |
liveuser |
14329 |
//加入驗證碼表單內容
|
|
|
14330 |
formObj.".$conf["resDivId"]."=document.getElementById('".$conf["resDivId"]."').value;
|
| 226 |
liveuser |
14331 |
|
| 3 |
liveuser |
14332 |
//傳送表單
|
|
|
14333 |
window.qbpwcf.randomCodeAjax.call(this,formObj);
|
| 226 |
liveuser |
14334 |
|
| 3 |
liveuser |
14335 |
});//function end
|
|
|
14336 |
|
|
|
14337 |
}//if end
|
|
|
14338 |
";
|
|
|
14339 |
#可省略參數:
|
|
|
14340 |
#$conf["onReady"],字串,是否要在網頁完全載入後再執行,"false"為不等載入完就先執行,預設為"true"要等載入完再執行.
|
|
|
14341 |
#$conf["onReady"]="true";
|
|
|
14342 |
#$conf["globalJs"],字串陣列,為要放入<script>標籤的js全域變數.
|
|
|
14343 |
#$conf["globalJs"]=array();
|
|
|
14344 |
#$conf["jsFunciton"],字串陣列,為要放入<script>標籤的js函數.
|
|
|
14345 |
#$conf["jsFunciton"]=array();
|
|
|
14346 |
#參考資料:
|
|
|
14347 |
#http://stackoverflow.com/questions/9899372/pure-javascript-equivalent-to-jquerys-ready-how-to-call-a-function-when-the
|
|
|
14348 |
$toScript=javaScript::toScript($conf["javaScript::toScript"]);
|
|
|
14349 |
unset($conf["javaScript::toScript"]);
|
| 226 |
liveuser |
14350 |
|
| 3 |
liveuser |
14351 |
#如果建立js失敗
|
|
|
14352 |
if($toScript["status"]==="false"){
|
| 226 |
liveuser |
14353 |
|
| 3 |
liveuser |
14354 |
#設置執行失敗
|
|
|
14355 |
$result["status"]="false";
|
|
|
14356 |
|
|
|
14357 |
#設置執行錯誤訊息
|
|
|
14358 |
$result["error"]=$toScript;
|
|
|
14359 |
|
|
|
14360 |
#回傳結果
|
|
|
14361 |
return $result;
|
| 226 |
liveuser |
14362 |
|
| 3 |
liveuser |
14363 |
}#if end
|
| 226 |
liveuser |
14364 |
|
| 3 |
liveuser |
14365 |
#儲存 js 語法
|
|
|
14366 |
$result["content"]=$result["content"].$toScript["content"];
|
| 226 |
liveuser |
14367 |
|
| 3 |
liveuser |
14368 |
#設置執行正常
|
|
|
14369 |
$result["status"]="true";
|
| 226 |
liveuser |
14370 |
|
| 3 |
liveuser |
14371 |
#回傳結果
|
| 226 |
liveuser |
14372 |
return $result;
|
|
|
14373 |
|
| 3 |
liveuser |
14374 |
}#function randomCode end
|
|
|
14375 |
|
|
|
14376 |
/*
|
|
|
14377 |
#函式說明:
|
|
|
14378 |
#$conf["countdownSec"]n秒後轉址
|
|
|
14379 |
#回傳結果:
|
|
|
14380 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
|
|
14381 |
#$result["error"],錯誤訊息.
|
|
|
14382 |
#$result["function"],當前執行的函式名稱.
|
|
|
14383 |
#$result["content"],js語法.
|
|
|
14384 |
#必填參數:
|
|
|
14385 |
#$conf["url"],字串,要導頁到哪邊.
|
|
|
14386 |
$conf["url"]="";
|
|
|
14387 |
#可省略參數:
|
|
|
14388 |
#$conf["countdownSec"],字串,幾秒後要導頁,預設不指定.
|
|
|
14389 |
#$conf["countdownSec"]="";
|
|
|
14390 |
#參考資料:
|
|
|
14391 |
#無.
|
|
|
14392 |
#備註:
|
|
|
14393 |
#無.
|
|
|
14394 |
*/
|
|
|
14395 |
public static function redirectUrl(&$conf){
|
|
|
14396 |
|
|
|
14397 |
#初始化要回傳的結果
|
|
|
14398 |
$result=array();
|
|
|
14399 |
|
|
|
14400 |
#取得當前執行的函數名稱
|
|
|
14401 |
$result["function"]=__FUNCTION__;
|
|
|
14402 |
|
|
|
14403 |
#如果沒有參數
|
|
|
14404 |
if(func_num_args()==0){
|
|
|
14405 |
|
|
|
14406 |
#設置執行失敗
|
|
|
14407 |
$result["status"]="false";
|
|
|
14408 |
|
|
|
14409 |
#設置執行錯誤訊息
|
|
|
14410 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
14411 |
|
|
|
14412 |
#回傳結果
|
|
|
14413 |
return $result;
|
|
|
14414 |
|
|
|
14415 |
}#if end
|
|
|
14416 |
|
|
|
14417 |
#取得參數
|
|
|
14418 |
$result["argu"]=$conf;
|
|
|
14419 |
|
|
|
14420 |
#如果 $conf 不為陣列
|
|
|
14421 |
if(gettype($conf)!=="array"){
|
|
|
14422 |
|
|
|
14423 |
#設置執行失敗
|
|
|
14424 |
$result["status"]="false";
|
|
|
14425 |
|
|
|
14426 |
#設置執行錯誤訊息
|
|
|
14427 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
14428 |
|
|
|
14429 |
#如果傳入的參數為 null
|
|
|
14430 |
if($conf===null){
|
|
|
14431 |
|
|
|
14432 |
#設置執行錯誤訊息
|
|
|
14433 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
14434 |
|
|
|
14435 |
}#if end
|
|
|
14436 |
|
|
|
14437 |
#回傳結果
|
|
|
14438 |
return $result;
|
|
|
14439 |
|
|
|
14440 |
}#if end
|
|
|
14441 |
|
|
|
14442 |
#初始化內容
|
| 226 |
liveuser |
14443 |
$result["content"]="";
|
| 3 |
liveuser |
14444 |
|
|
|
14445 |
#檢查參數
|
|
|
14446 |
#函式說明:
|
|
|
14447 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
14448 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
14449 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
14450 |
#$result["function"],當前執行的函式名稱.
|
|
|
14451 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
14452 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
14453 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
14454 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
14455 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
14456 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
14457 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
14458 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
14459 |
#必填參數:
|
|
|
14460 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
14461 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
14462 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
14463 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("url");
|
|
|
14464 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
14465 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
14466 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
14467 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
14468 |
#可以省略的參數:
|
|
|
14469 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
14470 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
14471 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
14472 |
#$conf["canNotBeEmpty"]=array();
|
|
|
14473 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
14474 |
#$conf["canBeEmpty"]=array();
|
|
|
14475 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
14476 |
$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("countdownSec");
|
|
|
14477 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
14478 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("countdownSec");
|
|
|
14479 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
14480 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
14481 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
14482 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
|
|
|
14483 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
14484 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
14485 |
#參考資料來源:
|
|
|
14486 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
14487 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
14488 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
14489 |
|
|
|
14490 |
#如果檢查參數失敗
|
|
|
14491 |
if($checkArguments["status"]==="false"){
|
|
|
14492 |
|
|
|
14493 |
#設置執行失敗
|
|
|
14494 |
$result["status"]="false";
|
|
|
14495 |
|
|
|
14496 |
#設置執行錯誤訊息
|
|
|
14497 |
$result["error"]=$checkArguments;
|
|
|
14498 |
|
|
|
14499 |
#回傳結果
|
|
|
14500 |
return $result;
|
|
|
14501 |
|
|
|
14502 |
}#if end
|
|
|
14503 |
|
|
|
14504 |
#如果參數檢查不通過
|
|
|
14505 |
if($checkArguments["passed"]==="false"){
|
|
|
14506 |
|
|
|
14507 |
#設置執行失敗
|
|
|
14508 |
$result["status"]="false";
|
|
|
14509 |
|
|
|
14510 |
#設置執行錯誤訊息
|
|
|
14511 |
$result["error"]=$checkArguments;
|
|
|
14512 |
|
|
|
14513 |
#回傳結果
|
|
|
14514 |
return $result;
|
|
|
14515 |
|
|
|
14516 |
}#if end
|
|
|
14517 |
|
|
|
14518 |
#初始化不指定要幾秒後導頁
|
|
|
14519 |
$countdownSec="";
|
|
|
14520 |
|
|
|
14521 |
#如果有設置 countdownSec
|
|
|
14522 |
if(isset($conf["countdownSec"])){
|
|
|
14523 |
|
|
|
14524 |
#設置要幾秒後才導頁
|
|
|
14525 |
$countdownSec="params.countdownSec=".$conf["countdownSec"].";";
|
|
|
14526 |
|
|
|
14527 |
}#if end
|
|
|
14528 |
|
|
|
14529 |
#函式說明:
|
|
|
14530 |
#將要執行的script語法透過該函式執行(會在程式外層用<script></script>包起來).
|
|
|
14531 |
#回傳結果:
|
|
|
14532 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
14533 |
#$result["error"],錯誤訊息陣列
|
|
|
14534 |
#$result["function"],當前執行的函數名稱
|
|
|
14535 |
#$result["content"],要執行的javaScript語法
|
|
|
14536 |
#必填參數:
|
|
|
14537 |
#$conf["script"],字串,要執行的javaScript語法.
|
|
|
14538 |
$conf["javaScript::toScript"]["script"]=
|
|
|
14539 |
"
|
|
|
14540 |
params={};
|
|
|
14541 |
params.url='".$conf["url"]."';
|
|
|
14542 |
".$countdownSec."
|
| 174 |
liveuser |
14543 |
window.qbpwcf.redirectURL.call(this,params);
|
| 3 |
liveuser |
14544 |
";
|
|
|
14545 |
#可省略參數:
|
|
|
14546 |
#$conf["onReady"],字串,是否要在網頁完全載入後再執行,"false"為不等載入完就先執行,預設為"true"要等載入完再執行.
|
|
|
14547 |
#$conf["onReady"]="true";
|
|
|
14548 |
#$conf["globalJs"],字串陣列,為要放入<script>標籤的js全域變數.
|
|
|
14549 |
#$conf["globalJs"]=array();
|
|
|
14550 |
#$conf["jsFunciton"],字串陣列,為要放入<script>標籤的js函數.
|
|
|
14551 |
#$conf["jsFunciton"]=array();
|
|
|
14552 |
#參考資料:
|
|
|
14553 |
#http://stackoverflow.com/questions/9899372/pure-javascript-equivalent-to-jquerys-ready-how-to-call-a-function-when-the
|
|
|
14554 |
$toScript=javaScript::toScript($conf["javaScript::toScript"]);
|
|
|
14555 |
unset($conf["javaScript::toScript"]);
|
|
|
14556 |
|
|
|
14557 |
#如果執行失敗
|
|
|
14558 |
if($toScript["status"]==="false"){
|
|
|
14559 |
|
|
|
14560 |
#設置執行失敗
|
|
|
14561 |
$result["status"]="false";
|
|
|
14562 |
|
|
|
14563 |
#設置執行錯誤訊息
|
|
|
14564 |
$result["error"]=$toScript;
|
|
|
14565 |
|
|
|
14566 |
#回傳結果
|
|
|
14567 |
return $result;
|
|
|
14568 |
|
|
|
14569 |
}#if end
|
| 226 |
liveuser |
14570 |
|
| 3 |
liveuser |
14571 |
#取得js語法
|
|
|
14572 |
$result["content"]=$toScript["content"];
|
|
|
14573 |
|
|
|
14574 |
#設置執行正常
|
|
|
14575 |
$result["status"]="true";
|
|
|
14576 |
|
|
|
14577 |
#回傳結果
|
|
|
14578 |
return $result;
|
|
|
14579 |
|
|
|
14580 |
}#function redirectUrl end
|
|
|
14581 |
|
|
|
14582 |
/*
|
|
|
14583 |
#函式說明:
|
|
|
14584 |
#傳遞識別數字進而取得連續的資料
|
|
|
14585 |
#回傳結果:
|
|
|
14586 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
|
|
14587 |
#$result["error"],錯誤訊息.
|
|
|
14588 |
#$result["function"],當前執行的函式名稱.
|
|
|
14589 |
#$result["content"],js語法.
|
|
|
14590 |
#必填參數:
|
|
|
14591 |
#$conf["params"],參數陣列,要傳遞的識別參數.
|
|
|
14592 |
$conf["params"]=array();
|
|
|
14593 |
#$conf["url"],字串,要從哪個頁面要求連續的資料.
|
|
|
14594 |
$conf["url"]="";
|
|
|
14595 |
#可省略參數:
|
|
|
14596 |
#$conf["method"],字串,資料傳輸的方式,有POST跟GET
|
|
|
14597 |
#$conf["method"]="";
|
|
|
14598 |
#$conf["responseDivId"],字串,放置取得資料div的id.
|
|
|
14599 |
#$conf["responseDivId"]="";
|
|
|
14600 |
#參考資料:
|
|
|
14601 |
#無.
|
|
|
14602 |
#備註:
|
|
|
14603 |
#無.
|
|
|
14604 |
*/
|
|
|
14605 |
public static function tailAny(&$conf){
|
| 226 |
liveuser |
14606 |
|
| 3 |
liveuser |
14607 |
#初始化要回傳的結果
|
|
|
14608 |
$result=array();
|
|
|
14609 |
|
|
|
14610 |
#取得當前執行的函數名稱
|
|
|
14611 |
$result["function"]=__FUNCTION__;
|
|
|
14612 |
|
|
|
14613 |
#如果沒有參數
|
|
|
14614 |
if(func_num_args()==0){
|
|
|
14615 |
|
|
|
14616 |
#設置執行失敗
|
|
|
14617 |
$result["status"]="false";
|
|
|
14618 |
|
|
|
14619 |
#設置執行錯誤訊息
|
|
|
14620 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
14621 |
|
|
|
14622 |
#回傳結果
|
|
|
14623 |
return $result;
|
|
|
14624 |
|
|
|
14625 |
}#if end
|
|
|
14626 |
|
|
|
14627 |
#取得參數
|
|
|
14628 |
$result["argu"]=$conf;
|
|
|
14629 |
|
|
|
14630 |
#如果 $conf 不為陣列
|
|
|
14631 |
if(gettype($conf)!=="array"){
|
|
|
14632 |
|
|
|
14633 |
#設置執行失敗
|
|
|
14634 |
$result["status"]="false";
|
|
|
14635 |
|
|
|
14636 |
#設置執行錯誤訊息
|
|
|
14637 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
14638 |
|
|
|
14639 |
#如果傳入的參數為 null
|
|
|
14640 |
if($conf===null){
|
|
|
14641 |
|
|
|
14642 |
#設置執行錯誤訊息
|
|
|
14643 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
14644 |
|
|
|
14645 |
}#if end
|
|
|
14646 |
|
|
|
14647 |
#回傳結果
|
|
|
14648 |
return $result;
|
|
|
14649 |
|
|
|
14650 |
}#if end
|
|
|
14651 |
|
|
|
14652 |
#初始化內容
|
| 226 |
liveuser |
14653 |
$result["content"]="";
|
| 3 |
liveuser |
14654 |
|
|
|
14655 |
#檢查參數
|
|
|
14656 |
#函式說明:
|
|
|
14657 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
14658 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
14659 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
14660 |
#$result["function"],當前執行的函式名稱.
|
|
|
14661 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
14662 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
14663 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
14664 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
14665 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
14666 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
14667 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
14668 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
14669 |
#必填參數:
|
|
|
14670 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
14671 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
14672 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
14673 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("params","url");
|
|
|
14674 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
14675 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string");
|
|
|
14676 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
14677 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
14678 |
#可以省略的參數:
|
|
|
14679 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
14680 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
14681 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
14682 |
#$conf["canNotBeEmpty"]=array();
|
|
|
14683 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
14684 |
#$conf["canBeEmpty"]=array();
|
|
|
14685 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
14686 |
$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("method","responseDivId");
|
|
|
14687 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
14688 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("method","responseDivId");
|
|
|
14689 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
14690 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
|
|
|
14691 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
14692 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("POST","rootDiv");
|
|
|
14693 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
14694 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
14695 |
#參考資料來源:
|
|
|
14696 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
14697 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
14698 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
14699 |
|
|
|
14700 |
#如果檢查參數失敗
|
|
|
14701 |
if($checkArguments["status"]==="false"){
|
|
|
14702 |
|
|
|
14703 |
#設置執行失敗
|
|
|
14704 |
$result["status"]="false";
|
|
|
14705 |
|
|
|
14706 |
#設置執行錯誤訊息
|
|
|
14707 |
$result["error"]=$checkArguments;
|
|
|
14708 |
|
|
|
14709 |
#回傳結果
|
|
|
14710 |
return $result;
|
|
|
14711 |
|
|
|
14712 |
}#if end
|
|
|
14713 |
|
|
|
14714 |
#如果參數檢查不通過
|
|
|
14715 |
if($checkArguments["passed"]==="false"){
|
|
|
14716 |
|
|
|
14717 |
#設置執行失敗
|
|
|
14718 |
$result["status"]="false";
|
|
|
14719 |
|
|
|
14720 |
#設置執行錯誤訊息
|
|
|
14721 |
$result["error"]=$checkArguments;
|
|
|
14722 |
|
|
|
14723 |
#回傳結果
|
|
|
14724 |
return $result;
|
|
|
14725 |
|
|
|
14726 |
}#if end
|
|
|
14727 |
|
|
|
14728 |
#函式說明:
|
|
|
14729 |
#將要執行的script語法透過該函式執行(會在程式外層用<script></script>包起來).
|
|
|
14730 |
#回傳結果:
|
|
|
14731 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
14732 |
#$result["error"],錯誤訊息陣列
|
|
|
14733 |
#$result["function"],當前執行的函數名稱
|
|
|
14734 |
#$result["content"],要執行的javaScript語法
|
|
|
14735 |
#必填參數:
|
|
|
14736 |
#$conf["script"],字串,要執行的javaScript語法.
|
|
|
14737 |
$conf["javaScript::toScript"]["script"]=
|
|
|
14738 |
"
|
|
|
14739 |
params=".json_encode($conf["params"])."
|
|
|
14740 |
var tailAny=new window.qbpwcf.tailAny.func(params,'".$conf["url"]."','".$conf["method"]."','".$conf["responseDivId"]."');
|
|
|
14741 |
";
|
|
|
14742 |
#可省略參數:
|
|
|
14743 |
#$conf["onReady"],字串,是否要在網頁完全載入後再執行,"false"為不等載入完就先執行,預設為"true"要等載入完再執行.
|
|
|
14744 |
#$conf["onReady"]="true";
|
|
|
14745 |
#$conf["globalJs"],字串陣列,為要放入<script>標籤的js全域變數.
|
|
|
14746 |
#$conf["globalJs"]=array();
|
|
|
14747 |
#$conf["jsFunciton"],字串陣列,為要放入<script>標籤的js函數.
|
|
|
14748 |
#$conf["jsFunciton"]=array();
|
|
|
14749 |
#參考資料:
|
|
|
14750 |
#http://stackoverflow.com/questions/9899372/pure-javascript-equivalent-to-jquerys-ready-how-to-call-a-function-when-the
|
|
|
14751 |
$toScript=javaScript::toScript($conf["javaScript::toScript"]);
|
|
|
14752 |
unset($conf["javaScript::toScript"]);
|
|
|
14753 |
|
|
|
14754 |
#如果執行失敗
|
|
|
14755 |
if($toScript["status"]==="false"){
|
|
|
14756 |
|
|
|
14757 |
#設置執行失敗
|
|
|
14758 |
$result["status"]="false";
|
|
|
14759 |
|
|
|
14760 |
#設置執行錯誤訊息
|
|
|
14761 |
$result["error"]=$toScript;
|
|
|
14762 |
|
|
|
14763 |
#回傳結果
|
|
|
14764 |
return $result;
|
|
|
14765 |
|
|
|
14766 |
}#if end
|
| 226 |
liveuser |
14767 |
|
| 3 |
liveuser |
14768 |
#取得js語法
|
|
|
14769 |
$result["content"]=$toScript["content"];
|
|
|
14770 |
|
|
|
14771 |
#設置執行正常
|
|
|
14772 |
$result["status"]="true";
|
|
|
14773 |
|
|
|
14774 |
#回傳結果
|
|
|
14775 |
return $result;
|
|
|
14776 |
|
|
|
14777 |
}#funtion tailAny end
|
|
|
14778 |
|
|
|
14779 |
/*
|
|
|
14780 |
#函式說明:
|
|
|
14781 |
#設置點擊元素後會傳遞data屬性為名稱與其數值為表單數值給特定url,進而取得連續的資料
|
|
|
14782 |
#回傳結果:
|
|
|
14783 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
|
|
14784 |
#$result["error"],錯誤訊息.
|
|
|
14785 |
#$result["function"],當前執行的函式名稱.
|
|
|
14786 |
#$result["content"],js語法.
|
|
|
14787 |
#必填參數:
|
|
|
14788 |
#$conf["elementJS"],字串,要用什麼js語法抓取要綁定事件的元素
|
|
|
14789 |
$conf["elementJS"]=""
|
|
|
14790 |
#$conf["url"],字串,要將表單資訊傳遞的哪個url.
|
|
|
14791 |
$conf["url"]="";
|
|
|
14792 |
#可省略參數:
|
|
|
14793 |
#$conf["method"],字串,資料傳輸的方式,有POST跟GET,預設為"POST".
|
|
|
14794 |
#$conf["method"]="";
|
|
|
14795 |
#$conf["resDiv"],字串,放置回應的div之id,預設為"rootDiv".
|
|
|
14796 |
#$conf["resDiv"]="";
|
|
|
14797 |
#參考資料:
|
|
|
14798 |
#無.
|
|
|
14799 |
#備註:
|
|
|
14800 |
#無.
|
| 174 |
liveuser |
14801 |
*/
|
| 3 |
liveuser |
14802 |
public static function postDataAttr(&$conf){
|
|
|
14803 |
|
|
|
14804 |
#初始化要回傳的結果
|
|
|
14805 |
$result=array();
|
|
|
14806 |
|
|
|
14807 |
#取得當前執行的函數名稱
|
|
|
14808 |
$result["function"]=__FUNCTION__;
|
|
|
14809 |
|
|
|
14810 |
#如果沒有參數
|
|
|
14811 |
if(func_num_args()==0){
|
|
|
14812 |
|
|
|
14813 |
#設置執行失敗
|
|
|
14814 |
$result["status"]="false";
|
|
|
14815 |
|
|
|
14816 |
#設置執行錯誤訊息
|
|
|
14817 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
14818 |
|
|
|
14819 |
#回傳結果
|
|
|
14820 |
return $result;
|
|
|
14821 |
|
|
|
14822 |
}#if end
|
|
|
14823 |
|
|
|
14824 |
#取得參數
|
|
|
14825 |
$result["argu"]=$conf;
|
|
|
14826 |
|
|
|
14827 |
#如果 $conf 不為陣列
|
|
|
14828 |
if(gettype($conf)!=="array"){
|
|
|
14829 |
|
|
|
14830 |
#設置執行失敗
|
|
|
14831 |
$result["status"]="false";
|
|
|
14832 |
|
|
|
14833 |
#設置執行錯誤訊息
|
|
|
14834 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
14835 |
|
|
|
14836 |
#如果傳入的參數為 null
|
|
|
14837 |
if($conf===null){
|
|
|
14838 |
|
|
|
14839 |
#設置執行錯誤訊息
|
|
|
14840 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
14841 |
|
|
|
14842 |
}#if end
|
|
|
14843 |
|
|
|
14844 |
#回傳結果
|
|
|
14845 |
return $result;
|
|
|
14846 |
|
|
|
14847 |
}#if end
|
|
|
14848 |
|
|
|
14849 |
#初始化內容
|
| 226 |
liveuser |
14850 |
$result["content"]="";
|
| 3 |
liveuser |
14851 |
|
|
|
14852 |
#檢查參數
|
|
|
14853 |
#函式說明:
|
|
|
14854 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
14855 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
14856 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
14857 |
#$result["function"],當前執行的函式名稱.
|
|
|
14858 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
14859 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
14860 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
14861 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
14862 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
14863 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
14864 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
14865 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
14866 |
#必填參數:
|
|
|
14867 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
14868 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
14869 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
14870 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("elementJS","url");
|
|
|
14871 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
14872 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
14873 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
14874 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
14875 |
#可以省略的參數:
|
|
|
14876 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
14877 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
14878 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
14879 |
#$conf["canNotBeEmpty"]=array();
|
|
|
14880 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
14881 |
#$conf["canBeEmpty"]=array();
|
|
|
14882 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
14883 |
$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("method","resDiv");
|
|
|
14884 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
14885 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("method","resDiv");
|
|
|
14886 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
14887 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
|
|
|
14888 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
14889 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("POST","rootDiv");
|
|
|
14890 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
14891 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
14892 |
#參考資料來源:
|
|
|
14893 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
14894 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
14895 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
14896 |
|
|
|
14897 |
#如果檢查參數失敗
|
|
|
14898 |
if($checkArguments["status"]==="false"){
|
|
|
14899 |
|
|
|
14900 |
#設置執行失敗
|
|
|
14901 |
$result["status"]="false";
|
|
|
14902 |
|
|
|
14903 |
#設置執行錯誤訊息
|
|
|
14904 |
$result["error"]=$checkArguments;
|
|
|
14905 |
|
|
|
14906 |
#回傳結果
|
|
|
14907 |
return $result;
|
|
|
14908 |
|
|
|
14909 |
}#if end
|
|
|
14910 |
|
|
|
14911 |
#如果參數檢查不通過
|
|
|
14912 |
if($checkArguments["passed"]==="false"){
|
|
|
14913 |
|
|
|
14914 |
#設置執行失敗
|
|
|
14915 |
$result["status"]="false";
|
|
|
14916 |
|
|
|
14917 |
#設置執行錯誤訊息
|
|
|
14918 |
$result["error"]=$checkArguments;
|
|
|
14919 |
|
|
|
14920 |
#回傳結果
|
|
|
14921 |
return $result;
|
|
|
14922 |
|
|
|
14923 |
}#if end
|
|
|
14924 |
|
|
|
14925 |
#函式說明:
|
|
|
14926 |
#將要執行的script語法透過該函式執行(會在程式外層用<script></script>包起來).
|
|
|
14927 |
#回傳結果:
|
|
|
14928 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
14929 |
#$result["error"],錯誤訊息陣列
|
|
|
14930 |
#$result["function"],當前執行的函數名稱
|
|
|
14931 |
#$result["content"],要執行的javaScript語法
|
|
|
14932 |
#必填參數:
|
|
|
14933 |
#$conf["script"],字串,要執行的javaScript語法.
|
|
|
14934 |
$conf["javaScript::toScript"]["script"]=
|
|
|
14935 |
"
|
|
|
14936 |
element=".$conf["elementJS"]."
|
|
|
14937 |
window.qbpwcf.postDataAttr.func.call(this,element,'".$conf["url"]."','".$conf["method"]."','".$conf["resDiv"]."');
|
|
|
14938 |
";
|
|
|
14939 |
#可省略參數:
|
|
|
14940 |
#$conf["onReady"],字串,是否要在網頁完全載入後再執行,"false"為不等載入完就先執行,預設為"true"要等載入完再執行.
|
|
|
14941 |
#$conf["onReady"]="true";
|
|
|
14942 |
#$conf["globalJs"],字串陣列,為要放入<script>標籤的js全域變數.
|
|
|
14943 |
#$conf["globalJs"]=array();
|
|
|
14944 |
#$conf["jsFunciton"],字串陣列,為要放入<script>標籤的js函數.
|
|
|
14945 |
#$conf["jsFunciton"]=array();
|
|
|
14946 |
#參考資料:
|
|
|
14947 |
#http://stackoverflow.com/questions/9899372/pure-javascript-equivalent-to-jquerys-ready-how-to-call-a-function-when-the
|
|
|
14948 |
$toScript=javaScript::toScript($conf["javaScript::toScript"]);
|
|
|
14949 |
unset($conf["javaScript::toScript"]);
|
|
|
14950 |
|
|
|
14951 |
#如果執行失敗
|
|
|
14952 |
if($toScript["status"]==="false"){
|
|
|
14953 |
|
|
|
14954 |
#設置執行失敗
|
|
|
14955 |
$result["status"]="false";
|
|
|
14956 |
|
|
|
14957 |
#設置執行錯誤訊息
|
|
|
14958 |
$result["error"]=$toScript;
|
|
|
14959 |
|
|
|
14960 |
#回傳結果
|
|
|
14961 |
return $result;
|
|
|
14962 |
|
|
|
14963 |
}#if end
|
| 226 |
liveuser |
14964 |
|
| 3 |
liveuser |
14965 |
#取得js語法
|
|
|
14966 |
$result["content"]=$toScript["content"];
|
|
|
14967 |
|
|
|
14968 |
#設置執行正常
|
|
|
14969 |
$result["status"]="true";
|
|
|
14970 |
|
|
|
14971 |
#回傳結果
|
|
|
14972 |
return $result;
|
|
|
14973 |
|
|
|
14974 |
}#function postDataAttr end
|
|
|
14975 |
|
|
|
14976 |
/*
|
|
|
14977 |
#函式說明:
|
|
|
14978 |
#設置指定元素的數值長度為特定條件時,會傳遞data屬性為名稱與其數值為表單數值給特定url,進而取得連續的資料
|
|
|
14979 |
#回傳結果:
|
|
|
14980 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
|
|
14981 |
#$result["error"],錯誤訊息.
|
|
|
14982 |
#$result["function"],當前執行的函式名稱.
|
|
|
14983 |
#$result["content"],js語法.
|
|
|
14984 |
#必填參數:
|
|
|
14985 |
#$conf["elementJS"],字串,要用什麼js語法抓取要綁定事件的元素
|
|
|
14986 |
$conf["elementJS"]=""
|
|
|
14987 |
#$conf["length"],字串,數值長度為多少才傳送要求.
|
|
|
14988 |
$conf["length"]="";
|
|
|
14989 |
#$conf["paramsJS"],字串陣列要使用的js參數物件
|
|
|
14990 |
$conf["paramsJS"]="";
|
|
|
14991 |
#$conf["url"],字串,要將表單資訊傳遞的哪個url.
|
|
|
14992 |
$conf["url"]="";
|
|
|
14993 |
#可省略參數:
|
|
|
14994 |
#$conf["method"],字串,資料傳輸的方式,有POST跟GET,預設為"POST".
|
|
|
14995 |
#$conf["method"]="";
|
|
|
14996 |
#$conf["resDiv"],字串,放置回應的div之id,預設為"rootDiv".
|
|
|
14997 |
#$conf["resDiv"]="";
|
|
|
14998 |
#$conf["outFunc"],字串,重新定義用來將資料放到畫面上的函式,參數有兩個,第一個是得到的json回應,第二個為放置回應的div之id.
|
|
|
14999 |
#$conf["outFunc"]="function(res,id){console.log(res,id);}";
|
|
|
15000 |
#參考資料:
|
|
|
15001 |
#無.
|
|
|
15002 |
#備註:
|
|
|
15003 |
#無.
|
|
|
15004 |
*/
|
|
|
15005 |
public static function gatDataDynamic(&$conf){
|
|
|
15006 |
|
|
|
15007 |
#初始化要回傳的結果
|
|
|
15008 |
$result=array();
|
|
|
15009 |
|
|
|
15010 |
#取得當前執行的函數名稱
|
|
|
15011 |
$result["function"]=__FUNCTION__;
|
|
|
15012 |
|
|
|
15013 |
#如果沒有參數
|
|
|
15014 |
if(func_num_args()==0){
|
|
|
15015 |
|
|
|
15016 |
#設置執行失敗
|
|
|
15017 |
$result["status"]="false";
|
|
|
15018 |
|
|
|
15019 |
#設置執行錯誤訊息
|
|
|
15020 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
15021 |
|
|
|
15022 |
#回傳結果
|
|
|
15023 |
return $result;
|
|
|
15024 |
|
|
|
15025 |
}#if end
|
|
|
15026 |
|
|
|
15027 |
#取得參數
|
|
|
15028 |
$result["argu"]=$conf;
|
|
|
15029 |
|
|
|
15030 |
#如果 $conf 不為陣列
|
|
|
15031 |
if(gettype($conf)!=="array"){
|
|
|
15032 |
|
|
|
15033 |
#設置執行失敗
|
|
|
15034 |
$result["status"]="false";
|
|
|
15035 |
|
|
|
15036 |
#設置執行錯誤訊息
|
|
|
15037 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
15038 |
|
|
|
15039 |
#如果傳入的參數為 null
|
|
|
15040 |
if($conf===null){
|
|
|
15041 |
|
|
|
15042 |
#設置執行錯誤訊息
|
|
|
15043 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
15044 |
|
|
|
15045 |
}#if end
|
|
|
15046 |
|
|
|
15047 |
#回傳結果
|
|
|
15048 |
return $result;
|
|
|
15049 |
|
|
|
15050 |
}#if end
|
|
|
15051 |
|
|
|
15052 |
#初始化內容
|
| 226 |
liveuser |
15053 |
$result["content"]="";
|
| 3 |
liveuser |
15054 |
|
|
|
15055 |
#檢查參數
|
|
|
15056 |
#函式說明:
|
|
|
15057 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
15058 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
15059 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
15060 |
#$result["function"],當前執行的函式名稱.
|
|
|
15061 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
15062 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
15063 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
15064 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
15065 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
15066 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
15067 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
15068 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
15069 |
#必填參數:
|
|
|
15070 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
15071 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
15072 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
15073 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("elementJS","length","paramsJS","url");
|
|
|
15074 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
15075 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string","string");
|
|
|
15076 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
15077 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
15078 |
#可以省略的參數:
|
|
|
15079 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
15080 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
15081 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
15082 |
#$conf["canNotBeEmpty"]=array();
|
|
|
15083 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
15084 |
#$conf["canBeEmpty"]=array();
|
|
|
15085 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
15086 |
$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("method","resDiv");
|
|
|
15087 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
15088 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("method","resDiv","outFunc");
|
|
|
15089 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
15090 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
|
|
|
15091 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
15092 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("POST","rootDiv",null);
|
|
|
15093 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
15094 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
15095 |
#參考資料來源:
|
|
|
15096 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
15097 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
15098 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
15099 |
|
|
|
15100 |
#如果檢查參數失敗
|
|
|
15101 |
if($checkArguments["status"]==="false"){
|
|
|
15102 |
|
|
|
15103 |
#設置執行失敗
|
|
|
15104 |
$result["status"]="false";
|
|
|
15105 |
|
|
|
15106 |
#設置執行錯誤訊息
|
|
|
15107 |
$result["error"]=$checkArguments;
|
|
|
15108 |
|
|
|
15109 |
#回傳結果
|
|
|
15110 |
return $result;
|
|
|
15111 |
|
|
|
15112 |
}#if end
|
|
|
15113 |
|
|
|
15114 |
#如果參數檢查不通過
|
|
|
15115 |
if($checkArguments["passed"]==="false"){
|
|
|
15116 |
|
|
|
15117 |
#設置執行失敗
|
|
|
15118 |
$result["status"]="false";
|
|
|
15119 |
|
|
|
15120 |
#設置執行錯誤訊息
|
|
|
15121 |
$result["error"]=$checkArguments;
|
|
|
15122 |
|
|
|
15123 |
#回傳結果
|
|
|
15124 |
return $result;
|
|
|
15125 |
|
|
|
15126 |
}#if end
|
|
|
15127 |
|
|
|
15128 |
#函式說明:
|
|
|
15129 |
#將要執行的script語法透過該函式執行(會在程式外層用<script></script>包起來).
|
|
|
15130 |
#回傳結果:
|
|
|
15131 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
15132 |
#$result["error"],錯誤訊息陣列
|
|
|
15133 |
#$result["function"],當前執行的函數名稱
|
|
|
15134 |
#$result["content"],要執行的javaScript語法
|
|
|
15135 |
#必填參數:
|
|
|
15136 |
#$conf["script"],字串,要執行的javaScript語法.
|
|
|
15137 |
$conf["javaScript::toScript"]["script"]=
|
|
|
15138 |
"
|
|
|
15139 |
var element=".$conf["elementJS"]."
|
|
|
15140 |
var params=".$conf["paramsJS"];
|
| 226 |
liveuser |
15141 |
|
| 3 |
liveuser |
15142 |
#如果有設置 $conf["outFunc"]
|
|
|
15143 |
if(isset($conf["outFunc"]))
|
|
|
15144 |
{
|
|
|
15145 |
#串接客制化的輸出函式
|
|
|
15146 |
$conf["javaScript::toScript"]["script"]=$conf["javaScript::toScript"]["script"]."
|
|
|
15147 |
window.qbpwcf.tailAny.outputFunc=".$conf["outFunc"];
|
| 226 |
liveuser |
15148 |
|
|
|
15149 |
}#if end
|
|
|
15150 |
|
| 3 |
liveuser |
15151 |
//呼叫涵式
|
|
|
15152 |
$conf["javaScript::toScript"]["script"]=$conf["javaScript::toScript"]["script"]."
|
|
|
15153 |
window.qbpwcf.gatDataDynamic.func.call(this,element,".$conf["length"].",params,'".$conf["url"]."','".$conf["method"]."','".$conf["resDiv"]."');
|
|
|
15154 |
";
|
|
|
15155 |
#可省略參數:
|
|
|
15156 |
#$conf["onReady"],字串,是否要在網頁完全載入後再執行,"false"為不等載入完就先執行,預設為"true"要等載入完再執行.
|
|
|
15157 |
#$conf["onReady"]="true";
|
|
|
15158 |
#$conf["globalJs"],字串陣列,為要放入<script>標籤的js全域變數.
|
|
|
15159 |
#$conf["globalJs"]=array();
|
|
|
15160 |
#$conf["jsFunciton"],字串陣列,為要放入<script>標籤的js函數.
|
|
|
15161 |
#$conf["jsFunciton"]=array();
|
|
|
15162 |
#參考資料:
|
|
|
15163 |
#http://stackoverflow.com/questions/9899372/pure-javascript-equivalent-to-jquerys-ready-how-to-call-a-function-when-the
|
|
|
15164 |
$toScript=javaScript::toScript($conf["javaScript::toScript"]);
|
|
|
15165 |
unset($conf["javaScript::toScript"]);
|
|
|
15166 |
|
|
|
15167 |
#如果執行失敗
|
|
|
15168 |
if($toScript["status"]==="false"){
|
|
|
15169 |
|
|
|
15170 |
#設置執行失敗
|
|
|
15171 |
$result["status"]="false";
|
|
|
15172 |
|
|
|
15173 |
#設置執行錯誤訊息
|
|
|
15174 |
$result["error"]=$toScript;
|
|
|
15175 |
|
|
|
15176 |
#回傳結果
|
|
|
15177 |
return $result;
|
|
|
15178 |
|
|
|
15179 |
}#if end
|
| 226 |
liveuser |
15180 |
|
| 3 |
liveuser |
15181 |
#取得js語法
|
|
|
15182 |
$result["content"]=$toScript["content"];
|
|
|
15183 |
|
|
|
15184 |
#設置執行正常
|
|
|
15185 |
$result["status"]="true";
|
|
|
15186 |
|
|
|
15187 |
#回傳結果
|
|
|
15188 |
return $result;
|
|
|
15189 |
|
|
|
15190 |
}#function end
|
|
|
15191 |
|
|
|
15192 |
/*
|
|
|
15193 |
#函式說明:
|
|
|
15194 |
#設置點擊元素後會傳遞data屬性為名稱與其數值為表單數值給特定url,進而取得連續的資料
|
|
|
15195 |
#回傳結果:
|
|
|
15196 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
|
|
15197 |
#$result["error"],錯誤訊息.
|
|
|
15198 |
#$result["function"],當前執行的函式名稱.
|
|
|
15199 |
#$result["content"],js語法.
|
|
|
15200 |
#必填參數:
|
|
|
15201 |
#$conf["url"],字串,要將表單資訊傳遞的哪個url.
|
|
|
15202 |
$conf["url"]="";
|
|
|
15203 |
#$conf["name"],字串,變數名稱.
|
|
|
15204 |
$conf["name"]="";
|
|
|
15205 |
#$conf["callback"],陣列字串,要呼叫的涵式$conf["callback"]["name"]與參數$conf["callback"]["params"].
|
|
|
15206 |
$conf["callback"]=array();
|
|
|
15207 |
#可省略參數:
|
|
|
15208 |
#無
|
|
|
15209 |
#參考資料:
|
|
|
15210 |
#無.
|
|
|
15211 |
#備註:
|
|
|
15212 |
#無.
|
|
|
15213 |
*/
|
|
|
15214 |
public static function sequenceQuery(&$conf){
|
| 226 |
liveuser |
15215 |
|
| 3 |
liveuser |
15216 |
#初始化要回傳的結果
|
|
|
15217 |
$result=array();
|
|
|
15218 |
|
|
|
15219 |
#取得當前執行的函數名稱
|
|
|
15220 |
$result["function"]=__FUNCTION__;
|
|
|
15221 |
|
|
|
15222 |
#如果沒有參數
|
|
|
15223 |
if(func_num_args()==0){
|
|
|
15224 |
|
|
|
15225 |
#設置執行失敗
|
|
|
15226 |
$result["status"]="false";
|
|
|
15227 |
|
|
|
15228 |
#設置執行錯誤訊息
|
|
|
15229 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
15230 |
|
|
|
15231 |
#回傳結果
|
|
|
15232 |
return $result;
|
|
|
15233 |
|
|
|
15234 |
}#if end
|
|
|
15235 |
|
|
|
15236 |
#取得參數
|
|
|
15237 |
$result["argu"]=$conf;
|
|
|
15238 |
|
|
|
15239 |
#如果 $conf 不為陣列
|
|
|
15240 |
if(gettype($conf)!=="array"){
|
|
|
15241 |
|
|
|
15242 |
#設置執行失敗
|
|
|
15243 |
$result["status"]="false";
|
|
|
15244 |
|
|
|
15245 |
#設置執行錯誤訊息
|
|
|
15246 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
15247 |
|
|
|
15248 |
#如果傳入的參數為 null
|
|
|
15249 |
if($conf===null){
|
|
|
15250 |
|
|
|
15251 |
#設置執行錯誤訊息
|
|
|
15252 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
15253 |
|
|
|
15254 |
}#if end
|
|
|
15255 |
|
|
|
15256 |
#回傳結果
|
|
|
15257 |
return $result;
|
|
|
15258 |
|
|
|
15259 |
}#if end
|
|
|
15260 |
|
|
|
15261 |
#初始化內容
|
| 226 |
liveuser |
15262 |
$result["content"]="";
|
| 3 |
liveuser |
15263 |
|
|
|
15264 |
#檢查參數
|
|
|
15265 |
#函式說明:
|
|
|
15266 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
15267 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
15268 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
15269 |
#$result["function"],當前執行的函式名稱.
|
|
|
15270 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
15271 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
15272 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
15273 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
15274 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
15275 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
15276 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
15277 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
15278 |
#必填參數:
|
|
|
15279 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
15280 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
15281 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
15282 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("url","name","callback");
|
|
|
15283 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
15284 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","array");
|
|
|
15285 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
15286 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
15287 |
#可以省略的參數:
|
|
|
15288 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
15289 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
15290 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
15291 |
#$conf["canNotBeEmpty"]=array();
|
|
|
15292 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
15293 |
#$conf["canBeEmpty"]=array();
|
|
|
15294 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
15295 |
#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("method","resDiv");
|
|
|
15296 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
15297 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("method","resDiv");
|
|
|
15298 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
15299 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
|
|
|
15300 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
15301 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("POST","rootDiv");
|
|
|
15302 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
15303 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
15304 |
#參考資料來源:
|
|
|
15305 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
15306 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
15307 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
15308 |
|
|
|
15309 |
#如果檢查參數失敗
|
|
|
15310 |
if($checkArguments["status"]==="false"){
|
|
|
15311 |
|
|
|
15312 |
#設置執行失敗
|
|
|
15313 |
$result["status"]="false";
|
|
|
15314 |
|
|
|
15315 |
#設置執行錯誤訊息
|
|
|
15316 |
$result["error"]=$checkArguments;
|
|
|
15317 |
|
|
|
15318 |
#回傳結果
|
|
|
15319 |
return $result;
|
|
|
15320 |
|
|
|
15321 |
}#if end
|
|
|
15322 |
|
|
|
15323 |
#如果參數檢查不通過
|
|
|
15324 |
if($checkArguments["passed"]==="false"){
|
|
|
15325 |
|
|
|
15326 |
#設置執行失敗
|
|
|
15327 |
$result["status"]="false";
|
|
|
15328 |
|
|
|
15329 |
#設置執行錯誤訊息
|
|
|
15330 |
$result["error"]=$checkArguments;
|
|
|
15331 |
|
|
|
15332 |
#回傳結果
|
|
|
15333 |
return $result;
|
|
|
15334 |
|
|
|
15335 |
}#if end
|
| 226 |
liveuser |
15336 |
|
| 3 |
liveuser |
15337 |
#函式說明:
|
|
|
15338 |
#將要執行的script語法透過該函式執行(會在程式外層用<script></script>包起來).
|
|
|
15339 |
#回傳結果:
|
|
|
15340 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
15341 |
#$result["error"],錯誤訊息陣列
|
|
|
15342 |
#$result["function"],當前執行的函數名稱
|
|
|
15343 |
#$result["content"],要執行的javaScript語法
|
|
|
15344 |
#必填參數:
|
|
|
15345 |
#$conf["script"],字串,要執行的javaScript語法.
|
|
|
15346 |
$conf["javaScript::toScript"]["script"]=
|
|
|
15347 |
"
|
|
|
15348 |
url='".$conf["url"]."';
|
|
|
15349 |
name='".$conf["name"]."';
|
|
|
15350 |
queue=[];
|
|
|
15351 |
callback=".json_encode($conf["callback"]).";
|
|
|
15352 |
window.qbpwcf.sequenceQuery.func.call(this,url,name,queue,callback);
|
|
|
15353 |
";
|
|
|
15354 |
#可省略參數:
|
|
|
15355 |
#$conf["onReady"],字串,是否要在網頁完全載入後再執行,"false"為不等載入完就先執行,預設為"true"要等載入完再執行.
|
|
|
15356 |
#$conf["onReady"]="true";
|
|
|
15357 |
#$conf["globalJs"],字串陣列,為要放入<script>標籤的js全域變數.
|
|
|
15358 |
#$conf["globalJs"]=array();
|
|
|
15359 |
#$conf["jsFunciton"],字串陣列,為要放入<script>標籤的js函數.
|
|
|
15360 |
#$conf["jsFunciton"]=array();
|
|
|
15361 |
#參考資料:
|
|
|
15362 |
#http://stackoverflow.com/questions/9899372/pure-javascript-equivalent-to-jquerys-ready-how-to-call-a-function-when-the
|
|
|
15363 |
$toScript=javaScript::toScript($conf["javaScript::toScript"]);
|
|
|
15364 |
unset($conf["javaScript::toScript"]);
|
|
|
15365 |
|
|
|
15366 |
#如果執行失敗
|
|
|
15367 |
if($toScript["status"]==="false"){
|
|
|
15368 |
|
|
|
15369 |
#設置執行失敗
|
|
|
15370 |
$result["status"]="false";
|
|
|
15371 |
|
|
|
15372 |
#設置執行錯誤訊息
|
|
|
15373 |
$result["error"]=$toScript;
|
|
|
15374 |
|
|
|
15375 |
#回傳結果
|
|
|
15376 |
return $result;
|
|
|
15377 |
|
|
|
15378 |
}#if end
|
| 226 |
liveuser |
15379 |
|
| 3 |
liveuser |
15380 |
#取得js語法
|
|
|
15381 |
$result["content"]=$toScript["content"];
|
|
|
15382 |
|
|
|
15383 |
#設置執行正常
|
|
|
15384 |
$result["status"]="true";
|
|
|
15385 |
|
|
|
15386 |
#回傳結果
|
|
|
15387 |
return $result;
|
| 226 |
liveuser |
15388 |
|
| 3 |
liveuser |
15389 |
}#function sequenceQuery end
|
|
|
15390 |
|
|
|
15391 |
/*
|
|
|
15392 |
#函數說明
|
|
|
15393 |
#讓js變數確實存在.
|
|
|
15394 |
#回傳的結果
|
|
|
15395 |
#$result["status"],執行正常與否.
|
|
|
15396 |
#$result["content"],js語法.
|
|
|
15397 |
#$result[argu],使用的參數.
|
|
|
15398 |
#必填參數:
|
|
|
15399 |
#$conf["name"],js變數的名稱.
|
| 226 |
liveuser |
15400 |
$conf["name"]="";
|
| 3 |
liveuser |
15401 |
#可省略參數:
|
|
|
15402 |
#無
|
|
|
15403 |
#參考資料:
|
|
|
15404 |
#無.
|
|
|
15405 |
#備註:
|
|
|
15406 |
#無.
|
|
|
15407 |
*/
|
|
|
15408 |
public static function makeVarExist(&$conf=array()){
|
| 226 |
liveuser |
15409 |
|
| 3 |
liveuser |
15410 |
#初始化要回傳的結果
|
|
|
15411 |
$result=array();
|
|
|
15412 |
|
|
|
15413 |
#取得當前執行的函數名稱
|
|
|
15414 |
$result["function"]=__FUNCTION__;
|
|
|
15415 |
|
|
|
15416 |
#如果沒有參數
|
|
|
15417 |
if(func_num_args()==0){
|
|
|
15418 |
|
|
|
15419 |
#設置執行失敗
|
|
|
15420 |
$result["status"]="false";
|
|
|
15421 |
|
|
|
15422 |
#設置執行錯誤訊息
|
|
|
15423 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
15424 |
|
|
|
15425 |
#回傳結果
|
|
|
15426 |
return $result;
|
|
|
15427 |
|
|
|
15428 |
}#if end
|
|
|
15429 |
|
|
|
15430 |
#取得參數
|
|
|
15431 |
$result["argu"]=$conf;
|
|
|
15432 |
|
|
|
15433 |
#如果 $conf 不為陣列
|
|
|
15434 |
if(gettype($conf)!=="array"){
|
|
|
15435 |
|
|
|
15436 |
#設置執行失敗
|
|
|
15437 |
$result["status"]="false";
|
|
|
15438 |
|
|
|
15439 |
#設置執行錯誤訊息
|
|
|
15440 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
15441 |
|
|
|
15442 |
#如果傳入的參數為 null
|
|
|
15443 |
if($conf===null){
|
|
|
15444 |
|
|
|
15445 |
#設置執行錯誤訊息
|
|
|
15446 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
15447 |
|
|
|
15448 |
}#if end
|
|
|
15449 |
|
|
|
15450 |
#回傳結果
|
|
|
15451 |
return $result;
|
|
|
15452 |
|
|
|
15453 |
}#if end
|
|
|
15454 |
|
|
|
15455 |
#檢查參數
|
|
|
15456 |
#函式說明:
|
|
|
15457 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
15458 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
15459 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
15460 |
#$result["function"],當前執行的函式名稱.
|
|
|
15461 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
15462 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
15463 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
15464 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
15465 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
15466 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
15467 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
15468 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
15469 |
#必填參數:
|
|
|
15470 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
15471 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
15472 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
15473 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("name",);
|
|
|
15474 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
15475 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
15476 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
15477 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
15478 |
#可以省略的參數:
|
|
|
15479 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
15480 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
15481 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
15482 |
#$conf["canNotBeEmpty"]=array();
|
|
|
15483 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
15484 |
#$conf["canBeEmpty"]=array();
|
|
|
15485 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
15486 |
#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("method","resDiv");
|
|
|
15487 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
15488 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("var","storeInArray","action");
|
|
|
15489 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
15490 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","array");
|
|
|
15491 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
15492 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("window.qbpwcf.readTable","true",null);
|
|
|
15493 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
15494 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
15495 |
#參考資料來源:
|
|
|
15496 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
15497 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
15498 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
15499 |
|
|
|
15500 |
#如果檢查參數失敗
|
|
|
15501 |
if($checkArguments["status"]==="false"){
|
|
|
15502 |
|
|
|
15503 |
#設置執行失敗
|
|
|
15504 |
$result["status"]="false";
|
|
|
15505 |
|
|
|
15506 |
#設置執行錯誤訊息
|
|
|
15507 |
$result["error"]=$checkArguments;
|
|
|
15508 |
|
|
|
15509 |
#回傳結果
|
|
|
15510 |
return $result;
|
|
|
15511 |
|
|
|
15512 |
}#if end
|
|
|
15513 |
|
|
|
15514 |
#如果參數檢查不通過
|
|
|
15515 |
if($checkArguments["passed"]==="false"){
|
|
|
15516 |
|
|
|
15517 |
#設置執行失敗
|
|
|
15518 |
$result["status"]="false";
|
|
|
15519 |
|
|
|
15520 |
#設置執行錯誤訊息
|
|
|
15521 |
$result["error"]=$checkArguments;
|
|
|
15522 |
|
|
|
15523 |
#回傳結果
|
|
|
15524 |
return $result;
|
|
|
15525 |
|
|
|
15526 |
}#if end
|
|
|
15527 |
|
|
|
15528 |
#初始化內容
|
| 226 |
liveuser |
15529 |
$result["content"]="";
|
|
|
15530 |
|
| 3 |
liveuser |
15531 |
#用 "." 分割 $conf["var"]
|
|
|
15532 |
#函式說明:
|
|
|
15533 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
15534 |
#回傳結果:
|
|
|
15535 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
15536 |
#$result["error"],錯誤訊息陣列
|
|
|
15537 |
#$result["function"],當前執行的函數名稱.
|
|
|
15538 |
#$result["argu"],使用的參數.
|
|
|
15539 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
15540 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
15541 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
15542 |
#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
|
|
|
15543 |
#必填參數:
|
|
|
15544 |
$conf["stringProcess::spiltString"]["stringIn"]=$conf["name"];#要處理的字串。
|
|
|
15545 |
$conf["stringProcess::spiltString"]["spiltSymbol"]=".";#爲以哪個符號作爲分割
|
|
|
15546 |
#可省略參數:
|
|
|
15547 |
#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
|
|
|
15548 |
$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
|
|
|
15549 |
$spiltString=$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
|
|
|
15550 |
unset($conf["stringProcess::spiltString"]);
|
| 226 |
liveuser |
15551 |
|
| 3 |
liveuser |
15552 |
#如果檢查參數失敗
|
|
|
15553 |
if($spiltString["status"]==="false"){
|
|
|
15554 |
|
|
|
15555 |
#設置執行失敗
|
|
|
15556 |
$result["status"]="false";
|
|
|
15557 |
|
|
|
15558 |
#設置執行錯誤訊息
|
|
|
15559 |
$result["error"]=$spiltString;
|
|
|
15560 |
|
|
|
15561 |
#回傳結果
|
|
|
15562 |
return $result;
|
|
|
15563 |
|
|
|
15564 |
}#if end
|
| 226 |
liveuser |
15565 |
|
| 3 |
liveuser |
15566 |
#函式說明:
|
|
|
15567 |
#將要執行的script語法透過該函式執行(會在程式外層用<script></script>包起來).
|
|
|
15568 |
#回傳結果:
|
|
|
15569 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
15570 |
#$result["error"],錯誤訊息陣列
|
|
|
15571 |
#$result["function"],當前執行的函數名稱
|
|
|
15572 |
#$result["content"],要執行的javaScript語法
|
| 226 |
liveuser |
15573 |
#必填參數:
|
| 3 |
liveuser |
15574 |
#$conf["script"],字串,要執行的javaScript語法.
|
|
|
15575 |
$conf["javaScript::toScript"]["script"]="";
|
| 226 |
liveuser |
15576 |
|
| 3 |
liveuser |
15577 |
#初始化 js 變數
|
|
|
15578 |
$jsVar="";
|
| 226 |
liveuser |
15579 |
|
| 3 |
liveuser |
15580 |
#針對每個 js 變數的階層
|
|
|
15581 |
for($i=0;$i<$spiltString["dataCounts"];$i++){
|
| 226 |
liveuser |
15582 |
|
| 3 |
liveuser |
15583 |
#取得片段 js 變數名稱
|
|
|
15584 |
$jsVarPart=$spiltString["dataArray"][$i];
|
| 226 |
liveuser |
15585 |
|
| 3 |
liveuser |
15586 |
#如果不是第一層變數
|
|
|
15587 |
if($i!==0){
|
| 226 |
liveuser |
15588 |
|
| 3 |
liveuser |
15589 |
#串接 js 變數名稱
|
|
|
15590 |
$jsVar=$jsVar.".".$jsVarPart;
|
| 226 |
liveuser |
15591 |
|
| 3 |
liveuser |
15592 |
}#if end
|
| 226 |
liveuser |
15593 |
|
| 3 |
liveuser |
15594 |
#反之
|
|
|
15595 |
else{
|
| 226 |
liveuser |
15596 |
|
| 3 |
liveuser |
15597 |
#串接 js 變數名稱
|
|
|
15598 |
$jsVar=$jsVar.$jsVarPart;
|
| 226 |
liveuser |
15599 |
|
| 3 |
liveuser |
15600 |
}#else end
|
| 226 |
liveuser |
15601 |
|
| 3 |
liveuser |
15602 |
#串接 js 語法
|
|
|
15603 |
$conf["javaScript::toScript"]["script"]=$conf["javaScript::toScript"]["script"].
|
|
|
15604 |
"
|
|
|
15605 |
//如果該階段變數不存在
|
|
|
15606 |
if(".$jsVar."===undefined){
|
| 226 |
liveuser |
15607 |
|
| 3 |
liveuser |
15608 |
//初始化為空物件
|
|
|
15609 |
".$jsVar."={};
|
| 226 |
liveuser |
15610 |
|
| 3 |
liveuser |
15611 |
}//if end
|
|
|
15612 |
";
|
| 226 |
liveuser |
15613 |
|
| 3 |
liveuser |
15614 |
}#foreach end
|
| 226 |
liveuser |
15615 |
|
| 3 |
liveuser |
15616 |
#可省略參數:
|
|
|
15617 |
#$conf["onReady"],字串,是否要在網頁完全載入後再執行,"false"為不等載入完就先執行,預設為"true"要等載入完再執行.
|
|
|
15618 |
#$conf["onReady"]="true";
|
|
|
15619 |
#$conf["globalJs"],字串陣列,為要放入<script>標籤的js全域變數.
|
|
|
15620 |
#$conf["globalJs"]=array();
|
|
|
15621 |
#$conf["jsFunciton"],字串陣列,為要放入<script>標籤的js函數.
|
|
|
15622 |
#$conf["jsFunciton"]=array();
|
|
|
15623 |
#參考資料:
|
|
|
15624 |
#http://stackoverflow.com/questions/9899372/pure-javascript-equivalent-to-jquerys-ready-how-to-call-a-function-when-the
|
|
|
15625 |
$toScript=javaScript::toScript($conf["javaScript::toScript"]);
|
| 226 |
liveuser |
15626 |
unset($conf["javaScript::toScript"]);
|
|
|
15627 |
|
| 3 |
liveuser |
15628 |
#如果檢查參數失敗
|
|
|
15629 |
if($toScript["status"]==="false"){
|
|
|
15630 |
|
|
|
15631 |
#設置執行失敗
|
|
|
15632 |
$result["status"]="false";
|
|
|
15633 |
|
|
|
15634 |
#設置執行錯誤訊息
|
|
|
15635 |
$result["error"]=$toScript;
|
|
|
15636 |
|
|
|
15637 |
#回傳結果
|
|
|
15638 |
return $result;
|
|
|
15639 |
|
|
|
15640 |
}#if end
|
| 226 |
liveuser |
15641 |
|
| 3 |
liveuser |
15642 |
#取得 js 語法
|
| 226 |
liveuser |
15643 |
$result["content"]=$toScript["content"];
|
|
|
15644 |
|
| 3 |
liveuser |
15645 |
#設置執行正常
|
|
|
15646 |
$result["status"]="true";
|
| 226 |
liveuser |
15647 |
|
| 3 |
liveuser |
15648 |
#回傳結果
|
|
|
15649 |
return $result;
|
| 226 |
liveuser |
15650 |
|
| 3 |
liveuser |
15651 |
}#fucntion makeVarExist end
|
|
|
15652 |
|
|
|
15653 |
/*
|
|
|
15654 |
#函數說明
|
|
|
15655 |
#讀取由table::div建立的資料表,依照欄位內容做不同的事情.
|
|
|
15656 |
#回傳的結果
|
|
|
15657 |
#$result["status"],執行正常與否.
|
|
|
15658 |
#$result["content"],js語法.
|
|
|
15659 |
#$result[argu],使用的參數.
|
|
|
15660 |
#必填參數:
|
|
|
15661 |
#$conf["table"],取得table的js.
|
| 226 |
liveuser |
15662 |
$conf["table"]="";
|
| 3 |
liveuser |
15663 |
#可省略參數:
|
|
|
15664 |
#$conf["var"],表格的資訊要儲在哪個js變數,預設為"window.qbpwcf.readTable"
|
|
|
15665 |
#$conf["var"]="window.qbpwcf.readTable";
|
|
|
15666 |
#$conf["storeInArray"],預設為儲存成陣列"true",反之儲存成單一變數"false".
|
|
|
15667 |
#$conf["storeInArray"]="true";
|
|
|
15668 |
#$conf["action"],字串陣列,讀到每個欄位要做什麼事情,預設選項為"save":僅儲存;"call,function name":呼叫call js funcion,欄位內容作為參數.
|
|
|
15669 |
#$conf["action"]=array();
|
|
|
15670 |
#參考資料:
|
|
|
15671 |
#無.
|
|
|
15672 |
#備註:
|
|
|
15673 |
#無.
|
|
|
15674 |
*/
|
|
|
15675 |
public static function readTable(&$conf=array()){
|
| 226 |
liveuser |
15676 |
|
| 3 |
liveuser |
15677 |
#初始化要回傳的結果
|
|
|
15678 |
$result=array();
|
|
|
15679 |
|
|
|
15680 |
#取得當前執行的函數名稱
|
|
|
15681 |
$result["function"]=__FUNCTION__;
|
|
|
15682 |
|
|
|
15683 |
#如果沒有參數
|
|
|
15684 |
if(func_num_args()==0){
|
|
|
15685 |
|
|
|
15686 |
#設置執行失敗
|
|
|
15687 |
$result["status"]="false";
|
|
|
15688 |
|
|
|
15689 |
#設置執行錯誤訊息
|
|
|
15690 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
15691 |
|
|
|
15692 |
#回傳結果
|
|
|
15693 |
return $result;
|
|
|
15694 |
|
|
|
15695 |
}#if end
|
|
|
15696 |
|
|
|
15697 |
#取得參數
|
|
|
15698 |
$result["argu"]=$conf;
|
|
|
15699 |
|
|
|
15700 |
#如果 $conf 不為陣列
|
|
|
15701 |
if(gettype($conf)!=="array"){
|
|
|
15702 |
|
|
|
15703 |
#設置執行失敗
|
|
|
15704 |
$result["status"]="false";
|
|
|
15705 |
|
|
|
15706 |
#設置執行錯誤訊息
|
|
|
15707 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
15708 |
|
|
|
15709 |
#如果傳入的參數為 null
|
|
|
15710 |
if($conf===null){
|
|
|
15711 |
|
|
|
15712 |
#設置執行錯誤訊息
|
|
|
15713 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
15714 |
|
|
|
15715 |
}#if end
|
|
|
15716 |
|
|
|
15717 |
#回傳結果
|
|
|
15718 |
return $result;
|
|
|
15719 |
|
|
|
15720 |
}#if end
|
|
|
15721 |
|
|
|
15722 |
#檢查參數
|
|
|
15723 |
#函式說明:
|
|
|
15724 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
15725 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
15726 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
15727 |
#$result["function"],當前執行的函式名稱.
|
|
|
15728 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
15729 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
15730 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
15731 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
15732 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
15733 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
15734 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
15735 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
15736 |
#必填參數:
|
|
|
15737 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
15738 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
15739 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
15740 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("table",);
|
|
|
15741 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
15742 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
15743 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
15744 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
15745 |
#可以省略的參數:
|
|
|
15746 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
15747 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
15748 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
15749 |
#$conf["canNotBeEmpty"]=array();
|
|
|
15750 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
15751 |
#$conf["canBeEmpty"]=array();
|
|
|
15752 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
15753 |
#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("method","resDiv");
|
|
|
15754 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
15755 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("var","storeInArray","action");
|
|
|
15756 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
15757 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","array");
|
|
|
15758 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
15759 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("window.qbpwcf.readTable","true",null);
|
|
|
15760 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
15761 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
15762 |
#參考資料來源:
|
|
|
15763 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
15764 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
15765 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
15766 |
|
|
|
15767 |
#如果檢查參數失敗
|
|
|
15768 |
if($checkArguments["status"]==="false"){
|
|
|
15769 |
|
|
|
15770 |
#設置執行失敗
|
|
|
15771 |
$result["status"]="false";
|
|
|
15772 |
|
|
|
15773 |
#設置執行錯誤訊息
|
|
|
15774 |
$result["error"]=$checkArguments;
|
|
|
15775 |
|
|
|
15776 |
#回傳結果
|
|
|
15777 |
return $result;
|
|
|
15778 |
|
|
|
15779 |
}#if end
|
|
|
15780 |
|
|
|
15781 |
#如果參數檢查不通過
|
|
|
15782 |
if($checkArguments["passed"]==="false"){
|
|
|
15783 |
|
|
|
15784 |
#設置執行失敗
|
|
|
15785 |
$result["status"]="false";
|
|
|
15786 |
|
|
|
15787 |
#設置執行錯誤訊息
|
|
|
15788 |
$result["error"]=$checkArguments;
|
|
|
15789 |
|
|
|
15790 |
#回傳結果
|
|
|
15791 |
return $result;
|
|
|
15792 |
|
|
|
15793 |
}#if end
|
|
|
15794 |
|
|
|
15795 |
#初始化內容
|
| 226 |
liveuser |
15796 |
$result["content"]="";
|
|
|
15797 |
|
| 3 |
liveuser |
15798 |
#函數說明
|
|
|
15799 |
#讓js變數確實存在.
|
|
|
15800 |
#回傳的結果
|
|
|
15801 |
#$result["status"],執行正常與否.
|
|
|
15802 |
#$result["content"],js語法.
|
|
|
15803 |
#$result[argu],使用的參數.
|
|
|
15804 |
#必填參數:
|
|
|
15805 |
#$conf["name"],js變數的名稱.
|
| 226 |
liveuser |
15806 |
$conf["javaScript::makeVarExist"]["name"]=$conf["var"];
|
| 3 |
liveuser |
15807 |
#可省略參數:
|
|
|
15808 |
#無
|
|
|
15809 |
$makeVarExist=javaScript::makeVarExist($conf["javaScript::makeVarExist"]);
|
|
|
15810 |
unset($conf["javaScript::makeVarExist"]);
|
|
|
15811 |
|
|
|
15812 |
#如果執行失敗
|
|
|
15813 |
if($makeVarExist["status"]==="false"){
|
|
|
15814 |
|
|
|
15815 |
#設置執行失敗
|
|
|
15816 |
$result["status"]="false";
|
|
|
15817 |
|
|
|
15818 |
#設置執行錯誤訊息
|
|
|
15819 |
$result["error"]=$makeVarExist;
|
|
|
15820 |
|
|
|
15821 |
#回傳結果
|
|
|
15822 |
return $result;
|
|
|
15823 |
|
|
|
15824 |
}#if end
|
| 226 |
liveuser |
15825 |
|
| 3 |
liveuser |
15826 |
#串接js語法
|
| 226 |
liveuser |
15827 |
$result["content"]=$result["content"].$makeVarExist["content"];
|
|
|
15828 |
|
| 3 |
liveuser |
15829 |
#函式說明:
|
|
|
15830 |
#將要執行的script語法透過該函式執行(會在程式外層用<script></script>包起來).
|
|
|
15831 |
#回傳結果:
|
|
|
15832 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
15833 |
#$result["error"],錯誤訊息陣列
|
|
|
15834 |
#$result["function"],當前執行的函數名稱
|
|
|
15835 |
#$result["content"],要執行的javaScript語法
|
| 226 |
liveuser |
15836 |
#必填參數:
|
| 3 |
liveuser |
15837 |
#$conf["script"],字串,要執行的javaScript語法.
|
|
|
15838 |
$conf["javaScript::toScript"]["script"]=
|
|
|
15839 |
"
|
|
|
15840 |
//set debug mode
|
|
|
15841 |
window.debug=true;
|
| 226 |
liveuser |
15842 |
|
| 3 |
liveuser |
15843 |
//set params
|
|
|
15844 |
params=".json_encode($conf).";
|
| 226 |
liveuser |
15845 |
|
| 3 |
liveuser |
15846 |
//初始化變數存在
|
| 226 |
liveuser |
15847 |
noExist=true;
|
|
|
15848 |
|
|
|
15849 |
//確認變數是否存在
|
| 3 |
liveuser |
15850 |
eval(noExist=('+params.var+'===undefined));
|
| 226 |
liveuser |
15851 |
|
| 3 |
liveuser |
15852 |
//如果變數不存在
|
|
|
15853 |
if(noExist===false){
|
| 226 |
liveuser |
15854 |
|
| 3 |
liveuser |
15855 |
//如果要儲存成陣列
|
|
|
15856 |
if(params.storeInArray==='true'){
|
| 226 |
liveuser |
15857 |
|
| 3 |
liveuser |
15858 |
//初始化為空陣列
|
|
|
15859 |
eval(params.var+'=[]');
|
| 226 |
liveuser |
15860 |
|
|
|
15861 |
}//if end
|
|
|
15862 |
|
| 3 |
liveuser |
15863 |
//反之
|
|
|
15864 |
else{
|
| 226 |
liveuser |
15865 |
|
| 3 |
liveuser |
15866 |
//初始化為空陣列
|
|
|
15867 |
eval(params.var+'={}');
|
| 226 |
liveuser |
15868 |
|
|
|
15869 |
}//else end
|
|
|
15870 |
|
| 3 |
liveuser |
15871 |
}//if end
|
| 226 |
liveuser |
15872 |
|
| 3 |
liveuser |
15873 |
//initial empty table object
|
| 226 |
liveuser |
15874 |
thisTable={};
|
|
|
15875 |
|
| 3 |
liveuser |
15876 |
//get latest table
|
|
|
15877 |
thisTable.target=".$conf["table"].";
|
| 226 |
liveuser |
15878 |
|
| 3 |
liveuser |
15879 |
//如果有 thead,tbody
|
|
|
15880 |
if(thisTable.target.children.length>1){
|
| 226 |
liveuser |
15881 |
|
| 3 |
liveuser |
15882 |
//get thead
|
|
|
15883 |
thisTable.thead=thisTable.target.children[0];
|
| 226 |
liveuser |
15884 |
|
| 3 |
liveuser |
15885 |
//get tbody
|
|
|
15886 |
thisTable.tbody=thisTable.target.children[1];
|
| 226 |
liveuser |
15887 |
|
| 3 |
liveuser |
15888 |
}//if end
|
| 226 |
liveuser |
15889 |
|
| 3 |
liveuser |
15890 |
//反之只有 tbody
|
|
|
15891 |
else{
|
| 226 |
liveuser |
15892 |
|
| 3 |
liveuser |
15893 |
//empty thead
|
|
|
15894 |
thisTable.thead={};
|
| 226 |
liveuser |
15895 |
|
| 3 |
liveuser |
15896 |
//get tbody
|
|
|
15897 |
thisTable.tbody=thisTable.target.children[1];
|
| 226 |
liveuser |
15898 |
|
| 3 |
liveuser |
15899 |
}//if end
|
| 226 |
liveuser |
15900 |
|
| 3 |
liveuser |
15901 |
//列數
|
|
|
15902 |
thisTable.rowsCount=thisTable.tbody.children.length;
|
| 226 |
liveuser |
15903 |
|
| 3 |
liveuser |
15904 |
//欄數
|
|
|
15905 |
thisTable.colsCount=thisTable.tbody.children[1].children.length;
|
| 226 |
liveuser |
15906 |
|
| 3 |
liveuser |
15907 |
//如果有標題欄位
|
|
|
15908 |
if(thisTable.thead!=={}){
|
| 226 |
liveuser |
15909 |
|
| 3 |
liveuser |
15910 |
//debug
|
|
|
15911 |
if(window.debug){
|
| 226 |
liveuser |
15912 |
|
| 3 |
liveuser |
15913 |
//提示有欄位標題
|
|
|
15914 |
console.log('There is title.');
|
| 226 |
liveuser |
15915 |
|
| 3 |
liveuser |
15916 |
}//if end
|
| 226 |
liveuser |
15917 |
|
| 3 |
liveuser |
15918 |
//取得每個欄位的標題
|
|
|
15919 |
thisTable.title=[];
|
| 226 |
liveuser |
15920 |
|
| 3 |
liveuser |
15921 |
//debug
|
|
|
15922 |
if(window.debug){
|
| 226 |
liveuser |
15923 |
|
| 3 |
liveuser |
15924 |
//提示欄位數目
|
|
|
15925 |
console.log('thisTable.colsCount='+thisTable.colsCount);
|
| 226 |
liveuser |
15926 |
|
| 3 |
liveuser |
15927 |
}//if end
|
| 226 |
liveuser |
15928 |
|
| 3 |
liveuser |
15929 |
//針對每個
|
|
|
15930 |
for(i=0;i<thisTable.colsCount;i++){
|
| 226 |
liveuser |
15931 |
|
| 3 |
liveuser |
15932 |
//debug
|
|
|
15933 |
if(window.debug){
|
| 226 |
liveuser |
15934 |
|
| 3 |
liveuser |
15935 |
//提示當前是第幾個欄位(從0開始)
|
|
|
15936 |
console.log('i='+i);
|
| 226 |
liveuser |
15937 |
|
| 3 |
liveuser |
15938 |
}//if end
|
| 226 |
liveuser |
15939 |
|
|
|
15940 |
//如果欄位存在
|
| 3 |
liveuser |
15941 |
if(thisTable.thead.children[0].children[i]!==undefined){
|
| 226 |
liveuser |
15942 |
|
| 3 |
liveuser |
15943 |
//取得欄位標題
|
|
|
15944 |
thisTable.title.push(thisTable.thead.children[0].children[i].innerText);
|
| 226 |
liveuser |
15945 |
|
| 3 |
liveuser |
15946 |
//debug
|
|
|
15947 |
if(window.debug){
|
| 226 |
liveuser |
15948 |
|
| 3 |
liveuser |
15949 |
console.log('column title - start');
|
|
|
15950 |
console.log(thisTable.thead.children[0].children[i].innerText);
|
|
|
15951 |
console.log('column title - end');
|
| 226 |
liveuser |
15952 |
|
| 3 |
liveuser |
15953 |
}//if end
|
| 226 |
liveuser |
15954 |
|
| 3 |
liveuser |
15955 |
}//if end
|
| 226 |
liveuser |
15956 |
|
| 3 |
liveuser |
15957 |
}//for end
|
| 226 |
liveuser |
15958 |
|
| 3 |
liveuser |
15959 |
}//if end
|
| 226 |
liveuser |
15960 |
|
| 3 |
liveuser |
15961 |
//反之
|
|
|
15962 |
else{
|
| 226 |
liveuser |
15963 |
|
| 3 |
liveuser |
15964 |
//預設欄位標題為 A,B,C....Z
|
|
|
15965 |
console.log('尚未實作');
|
|
|
15966 |
exit;
|
| 226 |
liveuser |
15967 |
|
| 3 |
liveuser |
15968 |
}//else end
|
| 226 |
liveuser |
15969 |
|
|
|
15970 |
|
| 3 |
liveuser |
15971 |
//暫存欄位的資料
|
|
|
15972 |
rowData=[];
|
| 226 |
liveuser |
15973 |
|
| 3 |
liveuser |
15974 |
//debug
|
|
|
15975 |
if(window.debug){
|
| 226 |
liveuser |
15976 |
|
| 3 |
liveuser |
15977 |
//提示資料筆數
|
|
|
15978 |
console.log('thisTable.rowsCount='+thisTable.rowsCount);
|
| 226 |
liveuser |
15979 |
|
| 3 |
liveuser |
15980 |
}//if end
|
| 226 |
liveuser |
15981 |
|
| 3 |
liveuser |
15982 |
//針對每筆資料
|
|
|
15983 |
for(i=1;i<thisTable.rowsCount;i++){
|
| 226 |
liveuser |
15984 |
|
| 3 |
liveuser |
15985 |
//debug
|
|
|
15986 |
if(window.debug){
|
| 226 |
liveuser |
15987 |
|
| 3 |
liveuser |
15988 |
//提示第幾筆資料
|
|
|
15989 |
console.log('i='+i);
|
| 226 |
liveuser |
15990 |
|
| 3 |
liveuser |
15991 |
}//if end
|
| 226 |
liveuser |
15992 |
|
| 3 |
liveuser |
15993 |
//取得列
|
|
|
15994 |
tr=thisTable.tbody.children[i];
|
| 226 |
liveuser |
15995 |
|
| 3 |
liveuser |
15996 |
//debug
|
|
|
15997 |
if(window.debug){
|
| 226 |
liveuser |
15998 |
|
| 3 |
liveuser |
15999 |
//提示第幾筆資料
|
|
|
16000 |
console.log('tr - start');
|
|
|
16001 |
console.log(tr);
|
|
|
16002 |
console.log('tr - end');
|
| 226 |
liveuser |
16003 |
|
| 3 |
liveuser |
16004 |
}//if end
|
| 226 |
liveuser |
16005 |
|
| 3 |
liveuser |
16006 |
//暫存欄位資料
|
|
|
16007 |
colData={};
|
| 226 |
liveuser |
16008 |
|
| 3 |
liveuser |
16009 |
//debug
|
|
|
16010 |
if(window.debug){
|
| 226 |
liveuser |
16011 |
|
| 3 |
liveuser |
16012 |
//提示欄位數量
|
|
|
16013 |
console.log('thisTable.rowsCount='+thisTable.rowsCount);
|
| 226 |
liveuser |
16014 |
|
| 3 |
liveuser |
16015 |
}//if end
|
| 226 |
liveuser |
16016 |
|
| 3 |
liveuser |
16017 |
//針對每個欄位
|
|
|
16018 |
for(j=0;j<thisTable.colsCount;j++){
|
| 226 |
liveuser |
16019 |
|
| 3 |
liveuser |
16020 |
//debug
|
|
|
16021 |
if(window.debug){
|
| 226 |
liveuser |
16022 |
|
| 3 |
liveuser |
16023 |
//提示欄位編號
|
|
|
16024 |
console.log('j='+j);
|
| 226 |
liveuser |
16025 |
|
| 3 |
liveuser |
16026 |
}//if end
|
| 226 |
liveuser |
16027 |
|
| 3 |
liveuser |
16028 |
//取得欄位內容
|
|
|
16029 |
td=tr.children[j].innerHTML;
|
| 226 |
liveuser |
16030 |
|
| 3 |
liveuser |
16031 |
//debug
|
|
|
16032 |
if(window.debug){
|
| 226 |
liveuser |
16033 |
|
| 3 |
liveuser |
16034 |
//提示欄位內容
|
|
|
16035 |
console.log('td='+td);
|
| 226 |
liveuser |
16036 |
|
| 3 |
liveuser |
16037 |
}//if end
|
| 226 |
liveuser |
16038 |
|
| 3 |
liveuser |
16039 |
//debug
|
|
|
16040 |
if(window.debug){
|
| 226 |
liveuser |
16041 |
|
| 3 |
liveuser |
16042 |
//提示欄位原始名稱
|
|
|
16043 |
console.log('thisTable.title['+j+']='+thisTable.title[j]);
|
| 226 |
liveuser |
16044 |
|
| 3 |
liveuser |
16045 |
}//if end
|
| 226 |
liveuser |
16046 |
|
| 3 |
liveuser |
16047 |
//set temp title,replace ' ' to '_'.
|
|
|
16048 |
tempTitle=thisTable.title[j].replace(/ /i, '_');
|
| 226 |
liveuser |
16049 |
|
| 3 |
liveuser |
16050 |
//debug
|
|
|
16051 |
if(window.debug){
|
| 226 |
liveuser |
16052 |
|
| 3 |
liveuser |
16053 |
//提示欄位新名稱
|
|
|
16054 |
console.log('tempTitle='+tempTitle);
|
| 226 |
liveuser |
16055 |
|
| 3 |
liveuser |
16056 |
}//if end
|
| 226 |
liveuser |
16057 |
|
| 3 |
liveuser |
16058 |
//用欄位標題儲存欄位內容
|
|
|
16059 |
eval('colData.'+tempTitle+'=td');
|
| 226 |
liveuser |
16060 |
|
| 3 |
liveuser |
16061 |
//如果有 action 參數
|
|
|
16062 |
if(params.action!==undefined){
|
| 226 |
liveuser |
16063 |
|
| 3 |
liveuser |
16064 |
//如果 action 參數對應的欄位存在數值
|
|
|
16065 |
if(params.action[j]!==undefined){
|
|
|
16066 |
|
|
|
16067 |
//get action
|
|
|
16068 |
action=params.action[j];
|
|
|
16069 |
|
|
|
16070 |
//debug
|
|
|
16071 |
if(window.debug){
|
| 226 |
liveuser |
16072 |
|
| 3 |
liveuser |
16073 |
//提示欄位新名稱
|
|
|
16074 |
console.log('action='+action);
|
| 226 |
liveuser |
16075 |
|
| 3 |
liveuser |
16076 |
}//if end
|
|
|
16077 |
|
|
|
16078 |
//如果動作不是 'save'
|
|
|
16079 |
if(action!=='save'){
|
| 226 |
liveuser |
16080 |
|
| 3 |
liveuser |
16081 |
//debug
|
|
|
16082 |
if(window.debug){
|
| 226 |
liveuser |
16083 |
|
| 3 |
liveuser |
16084 |
console.log('not only save, need extra action.');
|
| 226 |
liveuser |
16085 |
|
| 3 |
liveuser |
16086 |
}//if end
|
| 226 |
liveuser |
16087 |
|
| 3 |
liveuser |
16088 |
//用 ',' 分割 action 字串
|
|
|
16089 |
splitedStr=action.split(',');
|
| 226 |
liveuser |
16090 |
|
| 3 |
liveuser |
16091 |
//debug
|
|
|
16092 |
if(window.debug){
|
| 226 |
liveuser |
16093 |
|
| 3 |
liveuser |
16094 |
console.log('call '+splitedStr[1]+' function with param('+td+')');
|
| 226 |
liveuser |
16095 |
|
| 3 |
liveuser |
16096 |
//call functino with params
|
|
|
16097 |
eval(splitedStr[1]+'.call(this,td)');
|
| 226 |
liveuser |
16098 |
|
| 3 |
liveuser |
16099 |
}//if end
|
| 226 |
liveuser |
16100 |
|
| 3 |
liveuser |
16101 |
}//if end
|
| 226 |
liveuser |
16102 |
|
| 3 |
liveuser |
16103 |
}//fie nd
|
| 226 |
liveuser |
16104 |
|
| 3 |
liveuser |
16105 |
}//if end
|
| 226 |
liveuser |
16106 |
|
| 3 |
liveuser |
16107 |
}//if end
|
| 226 |
liveuser |
16108 |
|
| 3 |
liveuser |
16109 |
//儲存該筆資料的欄位資料
|
|
|
16110 |
rowData.push(colData);
|
| 226 |
liveuser |
16111 |
|
| 3 |
liveuser |
16112 |
}//for end
|
| 226 |
liveuser |
16113 |
|
| 3 |
liveuser |
16114 |
//儲存每筆資料的欄位資料
|
|
|
16115 |
thisTable.rowData=rowData;
|
| 226 |
liveuser |
16116 |
|
| 3 |
liveuser |
16117 |
//如果要儲存成陣列
|
|
|
16118 |
if(params.storeInArray==='true'){
|
| 226 |
liveuser |
16119 |
|
| 3 |
liveuser |
16120 |
//put table in array
|
| 226 |
liveuser |
16121 |
eval(params.var+'.push(thisTable)');
|
|
|
16122 |
|
|
|
16123 |
}//if end
|
|
|
16124 |
|
| 3 |
liveuser |
16125 |
//反之
|
|
|
16126 |
else{
|
| 226 |
liveuser |
16127 |
|
|
|
16128 |
//put table in var
|
|
|
16129 |
eval(params.var+'.=thisTable');
|
|
|
16130 |
|
|
|
16131 |
}//else end
|
|
|
16132 |
|
| 3 |
liveuser |
16133 |
";
|
|
|
16134 |
#可省略參數:
|
|
|
16135 |
#$conf["onReady"],字串,是否要在網頁完全載入後再執行,"false"為不等載入完就先執行,預設為"true"要等載入完再執行.
|
|
|
16136 |
#$conf["onReady"]="true";
|
|
|
16137 |
#$conf["globalJs"],字串陣列,為要放入<script>標籤的js全域變數.
|
|
|
16138 |
#$conf["globalJs"]=array();
|
|
|
16139 |
#$conf["jsFunciton"],字串陣列,為要放入<script>標籤的js函數.
|
|
|
16140 |
#$conf["jsFunciton"]=array();
|
|
|
16141 |
#參考資料:
|
|
|
16142 |
#http://stackoverflow.com/questions/9899372/pure-javascript-equivalent-to-jquerys-ready-how-to-call-a-function-when-the
|
|
|
16143 |
$toScript=javaScript::toScript($conf["javaScript::toScript"]);
|
| 226 |
liveuser |
16144 |
unset($conf["javaScript::toScript"]);
|
|
|
16145 |
|
| 3 |
liveuser |
16146 |
#如果檢查參數失敗
|
|
|
16147 |
if($toScript["status"]==="false"){
|
|
|
16148 |
|
|
|
16149 |
#設置執行失敗
|
|
|
16150 |
$result["status"]="false";
|
|
|
16151 |
|
|
|
16152 |
#設置執行錯誤訊息
|
|
|
16153 |
$result["error"]=$toScript;
|
|
|
16154 |
|
|
|
16155 |
#回傳結果
|
|
|
16156 |
return $result;
|
|
|
16157 |
|
|
|
16158 |
}#if end
|
| 226 |
liveuser |
16159 |
|
| 3 |
liveuser |
16160 |
#取得 js 語法
|
| 226 |
liveuser |
16161 |
$result["content"]=$result["content"].$toScript["content"];
|
|
|
16162 |
|
| 3 |
liveuser |
16163 |
#設置執行正常
|
|
|
16164 |
$result["status"]="true";
|
| 226 |
liveuser |
16165 |
|
| 3 |
liveuser |
16166 |
#回傳結果
|
|
|
16167 |
return $result;
|
| 226 |
liveuser |
16168 |
|
| 3 |
liveuser |
16169 |
}#funtion readTable end
|
|
|
16170 |
|
|
|
16171 |
/*
|
|
|
16172 |
#函式說明:
|
|
|
16173 |
#提供tab頁簽,點選頁簽後顯示對應的內容.套用的element結構如下:
|
|
|
16174 |
#<div>
|
|
|
16175 |
# <!-- data-tab-name 為頁籤要顯示名稱 -->
|
|
|
16176 |
# <div data-tab-name="tab1" style="display:none;">
|
|
|
16177 |
# <!-- 頁籤對應的內容 -->
|
|
|
16178 |
# tab1 content...
|
|
|
16179 |
# </div>
|
|
|
16180 |
# <div data-tab-name="tab2" style="display:none;">
|
|
|
16181 |
# tab2 content...
|
|
|
16182 |
# </div>
|
|
|
16183 |
# <div data-tab-name="tab3" style="display:none;">
|
| 226 |
liveuser |
16184 |
# tab3 content...
|
| 3 |
liveuser |
16185 |
# </div>
|
|
|
16186 |
#</div>
|
|
|
16187 |
#回傳結果:
|
|
|
16188 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
16189 |
#$result["error"],錯誤訊息.
|
|
|
16190 |
#$result["function"],當前執行的函數名稱.
|
|
|
16191 |
#$result["content"],語法.
|
|
|
16192 |
#必填參數:
|
|
|
16193 |
#$conf["place"],字串,該功能區塊要在哪個元素裡面呈現,其區塊特徵為何?(請參閱javascript的querySelector函式).
|
|
|
16194 |
$conf["place"]="";
|
| 226 |
liveuser |
16195 |
#可省略參數:
|
| 3 |
liveuser |
16196 |
#$conf["height"],字串,tab選單+內容的高度,單位為px..
|
|
|
16197 |
#$conf["height"]="291";
|
|
|
16198 |
#參考資料:
|
|
|
16199 |
#無.
|
|
|
16200 |
#備註:
|
|
|
16201 |
#無.
|
|
|
16202 |
*/
|
|
|
16203 |
public static function tab(&$conf){
|
| 226 |
liveuser |
16204 |
|
| 3 |
liveuser |
16205 |
#初始化要回傳的結果
|
|
|
16206 |
$result=array();
|
|
|
16207 |
|
|
|
16208 |
#取得當前執行的函數名稱
|
|
|
16209 |
$result["function"]=__FUNCTION__;
|
|
|
16210 |
|
|
|
16211 |
#如果沒有參數
|
|
|
16212 |
if(func_num_args()==0){
|
|
|
16213 |
|
|
|
16214 |
#設置執行失敗
|
|
|
16215 |
$result["status"]="false";
|
|
|
16216 |
|
|
|
16217 |
#設置執行錯誤訊息
|
|
|
16218 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
16219 |
|
|
|
16220 |
#回傳結果
|
|
|
16221 |
return $result;
|
|
|
16222 |
|
|
|
16223 |
}#if end
|
|
|
16224 |
|
|
|
16225 |
#取得參數
|
|
|
16226 |
$result["argu"]=$conf;
|
|
|
16227 |
|
|
|
16228 |
#如果 $conf 不為陣列
|
|
|
16229 |
if(gettype($conf)!=="array"){
|
|
|
16230 |
|
|
|
16231 |
#設置執行失敗
|
|
|
16232 |
$result["status"]="false";
|
|
|
16233 |
|
|
|
16234 |
#設置執行錯誤訊息
|
|
|
16235 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
16236 |
|
|
|
16237 |
#如果傳入的參數為 null
|
|
|
16238 |
if($conf===null){
|
|
|
16239 |
|
|
|
16240 |
#設置執行錯誤訊息
|
|
|
16241 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
16242 |
|
|
|
16243 |
}#if end
|
|
|
16244 |
|
|
|
16245 |
#回傳結果
|
|
|
16246 |
return $result;
|
|
|
16247 |
|
|
|
16248 |
}#if end
|
|
|
16249 |
|
|
|
16250 |
#檢查參數
|
|
|
16251 |
#函式說明:
|
|
|
16252 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
16253 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
16254 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
16255 |
#$result["function"],當前執行的函式名稱.
|
|
|
16256 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
16257 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
16258 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
16259 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
16260 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
16261 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
16262 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
16263 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
16264 |
#必填參數:
|
|
|
16265 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
16266 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
16267 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
16268 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("place");
|
|
|
16269 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
16270 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
16271 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
16272 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
16273 |
#可以省略的參數:
|
|
|
16274 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
16275 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
16276 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
16277 |
#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("sec");
|
|
|
16278 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
16279 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("height");
|
|
|
16280 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
16281 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
16282 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
16283 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
|
|
|
16284 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
16285 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("tabsDisplayValue","tabsContent");
|
|
|
16286 |
#參考資料來源:
|
|
|
16287 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
16288 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
16289 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
16290 |
|
|
|
16291 |
#如果檢查參數失敗
|
|
|
16292 |
if($checkArguments["status"]==="false"){
|
|
|
16293 |
|
|
|
16294 |
#設置執行不正常
|
|
|
16295 |
$result["status"]="false";
|
|
|
16296 |
|
|
|
16297 |
#設置執行錯誤
|
|
|
16298 |
$result["error"]=$checkArguments;
|
|
|
16299 |
|
|
|
16300 |
#回傳結果
|
|
|
16301 |
return $result;
|
|
|
16302 |
|
|
|
16303 |
}#if end
|
|
|
16304 |
|
|
|
16305 |
#如果檢查參數不通過
|
|
|
16306 |
if($checkArguments["passed"]==="false"){
|
|
|
16307 |
|
|
|
16308 |
#設置執行不正常
|
|
|
16309 |
$result["status"]="false";
|
|
|
16310 |
|
|
|
16311 |
#設置執行錯誤
|
|
|
16312 |
$result["error"]=$checkArguments;
|
|
|
16313 |
|
|
|
16314 |
#回傳結果
|
|
|
16315 |
return $result;
|
|
|
16316 |
|
|
|
16317 |
}#if end
|
| 226 |
liveuser |
16318 |
|
| 3 |
liveuser |
16319 |
#初始化要回傳的語法
|
|
|
16320 |
$result["content"]="";
|
| 226 |
liveuser |
16321 |
|
| 3 |
liveuser |
16322 |
#函式說明:
|
|
|
16323 |
#將要執行的script語法透過該函式執行(會在程式外層用<script></script>包起來).
|
|
|
16324 |
#回傳結果:
|
|
|
16325 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
16326 |
#$result["error"],錯誤訊息陣列
|
|
|
16327 |
#$result["function"],當前執行的函數名稱
|
|
|
16328 |
#$result["content"],要執行的javaScript語法
|
|
|
16329 |
#必填參數:
|
|
|
16330 |
#$conf["script"],字串,要執行的javaScript語法.
|
|
|
16331 |
$conf["javaScript::toScript"]["script"]=
|
|
|
16332 |
"
|
|
|
16333 |
//取得要放置投影片內容的區塊
|
|
|
16334 |
var displayArea=document.querySelector('".$conf["place"]."');
|
| 226 |
liveuser |
16335 |
|
| 3 |
liveuser |
16336 |
//儲存頁籤的數量
|
|
|
16337 |
var tabsCount=displayArea.children.length;
|
| 226 |
liveuser |
16338 |
|
| 3 |
liveuser |
16339 |
//初始化儲存頁籤的名稱
|
|
|
16340 |
var tabsName=[];
|
| 226 |
liveuser |
16341 |
|
| 3 |
liveuser |
16342 |
//針對每個頁簽
|
|
|
16343 |
for(var i=0;i<tabsCount;i++){
|
| 226 |
liveuser |
16344 |
|
| 3 |
liveuser |
16345 |
//隱藏頁籤
|
|
|
16346 |
displayArea.children[i].style.display='none';
|
| 226 |
liveuser |
16347 |
|
| 3 |
liveuser |
16348 |
//初始化頁籤名稱
|
|
|
16349 |
var tabName='tab'+i;
|
| 226 |
liveuser |
16350 |
|
| 3 |
liveuser |
16351 |
//如果有設置頁籤的名稱
|
|
|
16352 |
if(displayArea.children[i].dataset.tabName!==undefined){
|
| 226 |
liveuser |
16353 |
|
| 3 |
liveuser |
16354 |
//更新頁籤名稱
|
|
|
16355 |
tabName=displayArea.children[i].dataset.tabName
|
| 226 |
liveuser |
16356 |
|
| 3 |
liveuser |
16357 |
}//if end
|
| 226 |
liveuser |
16358 |
|
| 3 |
liveuser |
16359 |
//儲存頁籤名稱
|
|
|
16360 |
tabsName.push(tabName);
|
| 226 |
liveuser |
16361 |
|
| 3 |
liveuser |
16362 |
}//for end
|
| 226 |
liveuser |
16363 |
|
| 3 |
liveuser |
16364 |
//建立存放頁籤選單的div
|
|
|
16365 |
var tabsDiv=document.createElement('div');
|
| 226 |
liveuser |
16366 |
|
| 3 |
liveuser |
16367 |
//針對每個頁簽
|
|
|
16368 |
for(var i=0;i<tabsCount;i++){
|
| 226 |
liveuser |
16369 |
|
| 3 |
liveuser |
16370 |
//建立頁籤的div
|
|
|
16371 |
var div=document.createElement('div');
|
| 226 |
liveuser |
16372 |
|
| 3 |
liveuser |
16373 |
//設置儘量不換行
|
|
|
16374 |
div.style.display='inline-block';
|
| 226 |
liveuser |
16375 |
|
| 3 |
liveuser |
16376 |
//設置間隔避免無法識別
|
|
|
16377 |
div.style.marginLeft='5px';
|
|
|
16378 |
div.style.marginRight='5px';
|
| 226 |
liveuser |
16379 |
|
| 3 |
liveuser |
16380 |
//設置index
|
|
|
16381 |
div.dataset.index=i+1;
|
| 226 |
liveuser |
16382 |
|
| 3 |
liveuser |
16383 |
//放置頁籤的名稱
|
|
|
16384 |
div.appendChild(document.createTextNode(tabsName[i]));
|
| 226 |
liveuser |
16385 |
|
| 3 |
liveuser |
16386 |
//放置頁籤
|
|
|
16387 |
tabsDiv.appendChild(div);
|
| 226 |
liveuser |
16388 |
|
| 3 |
liveuser |
16389 |
//新增該頁籤的點擊事件
|
|
|
16390 |
div.addEventListener('click',function(event){
|
| 226 |
liveuser |
16391 |
|
| 3 |
liveuser |
16392 |
//針對每個頁簽
|
|
|
16393 |
for(var j=1;j<tabsDiv.children.length+1;j++){
|
| 226 |
liveuser |
16394 |
|
| 3 |
liveuser |
16395 |
//隱藏頁籤標題
|
|
|
16396 |
displayArea.children[0].children[j-1].style.borderBottom='unset';
|
| 226 |
liveuser |
16397 |
|
| 3 |
liveuser |
16398 |
//隱藏頁籤與礦線
|
|
|
16399 |
displayArea.children[j].style.display='none';
|
| 226 |
liveuser |
16400 |
|
| 3 |
liveuser |
16401 |
}//for end
|
| 226 |
liveuser |
16402 |
|
| 3 |
liveuser |
16403 |
";
|
| 226 |
liveuser |
16404 |
|
| 3 |
liveuser |
16405 |
#如果有設置高度
|
|
|
16406 |
if(isset($conf["height"]))
|
|
|
16407 |
{
|
|
|
16408 |
#串接高度的設定
|
|
|
16409 |
$conf["javaScript::toScript"]["script"]=$conf["javaScript::toScript"]["script"].
|
|
|
16410 |
"
|
|
|
16411 |
//設定tab內容區塊的高度
|
|
|
16412 |
displayArea.children[this.dataset.index].children[0].style.height=".$conf["height"]."-parseInt(getComputedStyle(displayArea.children[0]).height)+'px';
|
|
|
16413 |
";
|
| 226 |
liveuser |
16414 |
|
| 3 |
liveuser |
16415 |
}#if end
|
| 226 |
liveuser |
16416 |
|
| 3 |
liveuser |
16417 |
$conf["javaScript::toScript"]["script"]=$conf["javaScript::toScript"]["script"].
|
|
|
16418 |
"
|
| 226 |
liveuser |
16419 |
|
| 3 |
liveuser |
16420 |
//顯示目標頁籤內容
|
|
|
16421 |
displayArea.children[this.dataset.index].style.display='inline-block';
|
| 226 |
liveuser |
16422 |
|
| 3 |
liveuser |
16423 |
//提示當前選擇的頁籤
|
|
|
16424 |
displayArea.children[0].children[this.dataset.index-1].style.borderBottom='solid blue';
|
| 226 |
liveuser |
16425 |
|
| 3 |
liveuser |
16426 |
});
|
| 226 |
liveuser |
16427 |
|
| 3 |
liveuser |
16428 |
}//for end
|
| 226 |
liveuser |
16429 |
|
| 3 |
liveuser |
16430 |
//放置標籤選單
|
|
|
16431 |
displayArea.prepend(tabsDiv);
|
| 226 |
liveuser |
16432 |
|
| 3 |
liveuser |
16433 |
//預設顯示第一個頁簽
|
|
|
16434 |
displayArea.children[0].children[0].click();
|
| 226 |
liveuser |
16435 |
|
| 3 |
liveuser |
16436 |
";
|
|
|
16437 |
#可省略參數:
|
|
|
16438 |
#$conf["onReady"],字串,是否要在網頁完全載入後再執行,"false"為不等載入完就先執行,預設為"true"要等載入完再執行.
|
|
|
16439 |
#$conf["onReady"]="true";
|
|
|
16440 |
#$conf["globalJs"],字串陣列,為要放入<script>標籤的js全域變數.
|
|
|
16441 |
#$conf["globalJs"]=array();
|
|
|
16442 |
#$conf["jsFunciton"],字串陣列,為要放入<script>標籤的js函數.
|
|
|
16443 |
#$conf["jsFunciton"]=array();
|
|
|
16444 |
#參考資料:
|
|
|
16445 |
#http://stackoverflow.com/questions/9899372/pure-javascript-equivalent-to-jquerys-ready-how-to-call-a-function-when-the
|
|
|
16446 |
#備註:
|
|
|
16447 |
#無.
|
|
|
16448 |
$toScript=javaScript::toScript($conf["javaScript::toScript"]);
|
|
|
16449 |
unset($conf["javaScript::toScript"]);
|
| 226 |
liveuser |
16450 |
|
| 3 |
liveuser |
16451 |
#如果建立 script 語法失敗
|
|
|
16452 |
if($toScript["status"]==="false"){
|
| 226 |
liveuser |
16453 |
|
| 3 |
liveuser |
16454 |
#設置執行失敗
|
|
|
16455 |
$result["status"]="false";
|
| 226 |
liveuser |
16456 |
|
| 3 |
liveuser |
16457 |
#設置錯誤訊息
|
|
|
16458 |
$result["error"]=$toScript;
|
| 226 |
liveuser |
16459 |
|
| 3 |
liveuser |
16460 |
#回傳結果
|
|
|
16461 |
return $result;
|
| 226 |
liveuser |
16462 |
|
| 3 |
liveuser |
16463 |
}#if end
|
| 226 |
liveuser |
16464 |
|
| 3 |
liveuser |
16465 |
#儲存內容
|
|
|
16466 |
$result["content"]=$result["content"].$toScript["content"];
|
| 226 |
liveuser |
16467 |
|
| 3 |
liveuser |
16468 |
#設置執行正常
|
|
|
16469 |
$result["status"]="true";
|
| 226 |
liveuser |
16470 |
|
| 3 |
liveuser |
16471 |
#回傳結果
|
|
|
16472 |
return $result;
|
| 226 |
liveuser |
16473 |
|
| 3 |
liveuser |
16474 |
}#function tab end
|
|
|
16475 |
|
|
|
16476 |
/*
|
|
|
16477 |
#函式說明:
|
|
|
16478 |
#區塊輪播的效果,輪播內容支援影片播放結束後再換下一張.
|
|
|
16479 |
#回傳結果:
|
|
|
16480 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
16481 |
#$result["error"],錯誤訊息.
|
|
|
16482 |
#$result["function"],當前執行的函數名稱.
|
|
|
16483 |
#$result["content"],語法.
|
|
|
16484 |
#必填參數:
|
|
|
16485 |
#$conf["place"],字串,輪播區塊要在哪個元素裡面呈現,其區塊特徵為何?(請參閱javascript的querySelector函式).
|
|
|
16486 |
$conf["place"]="";
|
|
|
16487 |
#$conf["slideHtml"],字串陣列,每個投影片的html語法,其生成結構必須為 html > body > div > anyTag(content to show).
|
|
|
16488 |
$conf["slideHtml"]=array("");
|
| 226 |
liveuser |
16489 |
#可省略參數:
|
| 3 |
liveuser |
16490 |
#$conf["sec"],字串,過幾秒就要置換成下一張投影片,預設為"3",代表每3秒就換一張投影片.
|
|
|
16491 |
#$conf["sec"]="3";
|
|
|
16492 |
#參考資料:
|
|
|
16493 |
#無.
|
|
|
16494 |
#備註:
|
|
|
16495 |
#無.
|
|
|
16496 |
*/
|
|
|
16497 |
public static function slideDivPlus(&$conf){
|
| 226 |
liveuser |
16498 |
|
| 3 |
liveuser |
16499 |
#初始化要回傳的結果
|
|
|
16500 |
$result=array();
|
|
|
16501 |
|
|
|
16502 |
#取得當前執行的函數名稱
|
|
|
16503 |
$result["function"]=__FUNCTION__;
|
|
|
16504 |
|
|
|
16505 |
#如果沒有參數
|
|
|
16506 |
if(func_num_args()==0){
|
|
|
16507 |
|
|
|
16508 |
#設置執行失敗
|
|
|
16509 |
$result["status"]="false";
|
|
|
16510 |
|
|
|
16511 |
#設置執行錯誤訊息
|
|
|
16512 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
16513 |
|
|
|
16514 |
#回傳結果
|
|
|
16515 |
return $result;
|
|
|
16516 |
|
|
|
16517 |
}#if end
|
|
|
16518 |
|
|
|
16519 |
#取得參數
|
|
|
16520 |
$result["argu"]=$conf;
|
|
|
16521 |
|
|
|
16522 |
#如果 $conf 不為陣列
|
|
|
16523 |
if(gettype($conf)!=="array"){
|
|
|
16524 |
|
|
|
16525 |
#設置執行失敗
|
|
|
16526 |
$result["status"]="false";
|
|
|
16527 |
|
|
|
16528 |
#設置執行錯誤訊息
|
|
|
16529 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
16530 |
|
|
|
16531 |
#如果傳入的參數為 null
|
|
|
16532 |
if($conf===null){
|
|
|
16533 |
|
|
|
16534 |
#設置執行錯誤訊息
|
|
|
16535 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
16536 |
|
|
|
16537 |
}#if end
|
|
|
16538 |
|
|
|
16539 |
#回傳結果
|
|
|
16540 |
return $result;
|
|
|
16541 |
|
|
|
16542 |
}#if end
|
|
|
16543 |
|
|
|
16544 |
#檢查參數
|
|
|
16545 |
#函式說明:
|
|
|
16546 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
16547 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
16548 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
16549 |
#$result["function"],當前執行的函式名稱.
|
|
|
16550 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
16551 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
16552 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
16553 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
16554 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
16555 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
16556 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
16557 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
16558 |
#必填參數:
|
|
|
16559 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
16560 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
16561 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
16562 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("place","slideHtml");
|
|
|
16563 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
16564 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","array");
|
|
|
16565 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
16566 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
16567 |
#可以省略的參數:
|
|
|
16568 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
16569 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
16570 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
16571 |
#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("sec");
|
|
|
16572 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
16573 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("sec");
|
|
|
16574 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
16575 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
16576 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
16577 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("3");
|
|
|
16578 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
16579 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("tabsDisplayValue","tabsContent");
|
|
|
16580 |
#參考資料來源:
|
|
|
16581 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
16582 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
16583 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
16584 |
|
|
|
16585 |
#如果檢查參數失敗
|
|
|
16586 |
if($checkArguments["status"]==="false"){
|
|
|
16587 |
|
|
|
16588 |
#設置執行不正常
|
|
|
16589 |
$result["status"]="false";
|
|
|
16590 |
|
|
|
16591 |
#設置執行錯誤
|
|
|
16592 |
$result["error"]=$checkArguments;
|
|
|
16593 |
|
|
|
16594 |
#回傳結果
|
|
|
16595 |
return $result;
|
|
|
16596 |
|
|
|
16597 |
}#if end
|
|
|
16598 |
|
|
|
16599 |
#如果檢查參數不通過
|
|
|
16600 |
if($checkArguments["passed"]==="false"){
|
|
|
16601 |
|
|
|
16602 |
#設置執行不正常
|
|
|
16603 |
$result["status"]="false";
|
|
|
16604 |
|
|
|
16605 |
#設置執行錯誤
|
|
|
16606 |
$result["error"]=$checkArguments;
|
|
|
16607 |
|
|
|
16608 |
#回傳結果
|
|
|
16609 |
return $result;
|
|
|
16610 |
|
|
|
16611 |
}#if end
|
| 226 |
liveuser |
16612 |
|
| 3 |
liveuser |
16613 |
#初始化要回傳的語法
|
|
|
16614 |
$result["content"]="";
|
| 226 |
liveuser |
16615 |
|
| 3 |
liveuser |
16616 |
#函式說明:
|
|
|
16617 |
#將要執行的script語法透過該函式執行(會在程式外層用<script></script>包起來).
|
|
|
16618 |
#回傳結果:
|
|
|
16619 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
16620 |
#$result["error"],錯誤訊息陣列
|
|
|
16621 |
#$result["function"],當前執行的函數名稱
|
|
|
16622 |
#$result["content"],要執行的javaScript語法
|
|
|
16623 |
#必填參數:
|
|
|
16624 |
#$conf["script"],字串,要執行的javaScript語法.
|
|
|
16625 |
$conf["javaScript::toScript"]["script"]=
|
|
|
16626 |
"
|
|
|
16627 |
//設置要使用的投影片
|
|
|
16628 |
window.qbpwcf.slide.eles=".json_encode($conf["slideHtml"]).";
|
| 226 |
liveuser |
16629 |
|
| 3 |
liveuser |
16630 |
//設置放置投影片的區塊特徵
|
|
|
16631 |
window.qbpwcf.slide.displayDivByQuerySelector='".$conf["place"]."';
|
| 226 |
liveuser |
16632 |
|
| 3 |
liveuser |
16633 |
//初始化投影片的滯留時間,預設為3秒,時間到就換下一個投影片.
|
|
|
16634 |
window.qbpwcf.slide.showTime=".$conf["sec"].";
|
| 226 |
liveuser |
16635 |
|
| 3 |
liveuser |
16636 |
//呈現投影片
|
|
|
16637 |
window.qbpwcf.slide.func();
|
|
|
16638 |
";
|
|
|
16639 |
#可省略參數:
|
|
|
16640 |
#$conf["onReady"],字串,是否要在網頁完全載入後再執行,"false"為不等載入完就先執行,預設為"true"要等載入完再執行.
|
|
|
16641 |
#$conf["onReady"]="true";
|
|
|
16642 |
#$conf["globalJs"],字串陣列,為要放入<script>標籤的js全域變數.
|
|
|
16643 |
#$conf["globalJs"]=array();
|
|
|
16644 |
#$conf["jsFunciton"],字串陣列,為要放入<script>標籤的js函數.
|
|
|
16645 |
#$conf["jsFunciton"]=array();
|
|
|
16646 |
#參考資料:
|
|
|
16647 |
#http://stackoverflow.com/questions/9899372/pure-javascript-equivalent-to-jquerys-ready-how-to-call-a-function-when-the
|
|
|
16648 |
#備註:
|
|
|
16649 |
#無.
|
|
|
16650 |
$toScript=javaScript::toScript($conf["javaScript::toScript"]);
|
|
|
16651 |
unset($conf["javaScript::toScript"]);
|
|
|
16652 |
|
|
|
16653 |
#如果建立 script 語法失敗
|
|
|
16654 |
if($toScript["status"]==="false"){
|
| 226 |
liveuser |
16655 |
|
| 3 |
liveuser |
16656 |
#設置執行失敗
|
|
|
16657 |
$result["status"]="false";
|
| 226 |
liveuser |
16658 |
|
| 3 |
liveuser |
16659 |
#設置錯誤訊息
|
|
|
16660 |
$result["error"]=$toScript;
|
| 226 |
liveuser |
16661 |
|
| 3 |
liveuser |
16662 |
#回傳結果
|
|
|
16663 |
return $result;
|
| 226 |
liveuser |
16664 |
|
| 3 |
liveuser |
16665 |
}#if end
|
| 226 |
liveuser |
16666 |
|
| 3 |
liveuser |
16667 |
#儲存內容
|
|
|
16668 |
$result["content"]=$result["content"].$toScript["content"];
|
| 226 |
liveuser |
16669 |
|
| 3 |
liveuser |
16670 |
#設置執行正常
|
|
|
16671 |
$result["status"]="true";
|
| 226 |
liveuser |
16672 |
|
| 3 |
liveuser |
16673 |
#回傳結果
|
|
|
16674 |
return $result;
|
| 226 |
liveuser |
16675 |
|
| 3 |
liveuser |
16676 |
}#functino slideDivPlus end
|
|
|
16677 |
|
| 207 |
liveuser |
16678 |
/*
|
|
|
16679 |
#函式說明:
|
|
|
16680 |
#將指定的字形套用在body上.
|
|
|
16681 |
#回傳結果:
|
|
|
16682 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
16683 |
#$result["error"],錯誤訊息.
|
|
|
16684 |
#$result["function"],當前執行的函數名稱.
|
|
|
16685 |
#$result["content"],語法.
|
|
|
16686 |
#必填參數:
|
|
|
16687 |
#無.
|
|
|
16688 |
#可省略參數:
|
|
|
16689 |
#$conf["fontPath"],字串,字形檔案的位置,預設為"liberation-mono/LiberationMono-Regular.ttf".
|
|
|
16690 |
$conf["fontPath"]="";
|
|
|
16691 |
#參考資料:
|
|
|
16692 |
#無.
|
|
|
16693 |
#備註:
|
|
|
16694 |
#無.
|
|
|
16695 |
*/
|
|
|
16696 |
public static function setBodyFont(&$conf){
|
| 226 |
liveuser |
16697 |
|
| 207 |
liveuser |
16698 |
#初始化要回傳的結果
|
|
|
16699 |
$result=array();
|
|
|
16700 |
|
|
|
16701 |
#取得當前執行的函數名稱
|
|
|
16702 |
$result["function"]=__FUNCTION__;
|
|
|
16703 |
|
|
|
16704 |
#取得參數
|
|
|
16705 |
$result["argu"]=$conf;
|
|
|
16706 |
|
|
|
16707 |
#如果 $conf 不為陣列
|
|
|
16708 |
if(gettype($conf)!="array"){
|
|
|
16709 |
|
|
|
16710 |
#設置執行失敗
|
|
|
16711 |
$result["status"]="false";
|
|
|
16712 |
|
|
|
16713 |
#設置執行錯誤訊息
|
|
|
16714 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
16715 |
|
|
|
16716 |
#如果傳入的參數為 null
|
|
|
16717 |
if(is_null($conf)){
|
|
|
16718 |
|
|
|
16719 |
#設置執行錯誤訊息
|
|
|
16720 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
16721 |
|
|
|
16722 |
}#if end
|
|
|
16723 |
|
|
|
16724 |
#回傳結果
|
|
|
16725 |
return $result;
|
|
|
16726 |
|
|
|
16727 |
}#if end
|
| 226 |
liveuser |
16728 |
|
| 207 |
liveuser |
16729 |
#函式說明:
|
|
|
16730 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
|
|
|
16731 |
#回傳結果:
|
|
|
16732 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
16733 |
#$result["error"],執行不正常結束的錯訊息陣列.
|
|
|
16734 |
#$result["simpleError"],簡單表示的錯誤訊息.
|
|
|
16735 |
#$result["function"],當前執行的函式名稱.
|
|
|
16736 |
#$result["argu"],設置給予的參數.
|
|
|
16737 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
16738 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
16739 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
16740 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
16741 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
16742 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
16743 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
16744 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
16745 |
#必填參數:
|
|
|
16746 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
16747 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
16748 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
16749 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
16750 |
#可省略參數:
|
|
|
16751 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
16752 |
#$conf["mustBeFilledVariableName"]=array();
|
|
|
16753 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
|
|
|
16754 |
#$conf["mustBeFilledVariableType"]=array();
|
|
|
16755 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
16756 |
#$conf["canBeEmptyString"]="false";
|
|
|
16757 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
16758 |
#$conf["canNotBeEmpty"]=array();
|
|
|
16759 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
16760 |
#$conf["canBeEmpty"]=array();
|
|
|
16761 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
16762 |
$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("fontPath","outsideFontUrl");
|
|
|
16763 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
16764 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fontPath","outsideFontUrl");
|
|
|
16765 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
16766 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
|
|
|
16767 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
16768 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("liberation-mono-fonts/LiberationMono-Regular.ttf",null);
|
|
|
16769 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
16770 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
16771 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
16772 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
16773 |
#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
|
|
|
16774 |
#$conf["disallowAllSkipableVarNotExist"]="";
|
|
|
16775 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
16776 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
16777 |
#參考資料:
|
|
|
16778 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
16779 |
#備註:
|
|
|
16780 |
#無.
|
|
|
16781 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
16782 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
16783 |
|
| 207 |
liveuser |
16784 |
#如果執行失敗
|
|
|
16785 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
16786 |
|
| 207 |
liveuser |
16787 |
#設置執行異常
|
|
|
16788 |
$result["status"]="false";
|
| 226 |
liveuser |
16789 |
|
| 207 |
liveuser |
16790 |
#設置執行錯誤訊息
|
|
|
16791 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
16792 |
|
| 207 |
liveuser |
16793 |
#回傳結果
|
|
|
16794 |
return $result;
|
| 226 |
liveuser |
16795 |
|
| 207 |
liveuser |
16796 |
}#if end
|
| 226 |
liveuser |
16797 |
|
| 207 |
liveuser |
16798 |
#如果參數檢查不通過
|
|
|
16799 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
16800 |
|
| 207 |
liveuser |
16801 |
#設置執行異常
|
|
|
16802 |
$result["status"]="false";
|
| 226 |
liveuser |
16803 |
|
| 207 |
liveuser |
16804 |
#設置執行錯誤訊息
|
|
|
16805 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
16806 |
|
| 207 |
liveuser |
16807 |
#回傳結果
|
|
|
16808 |
return $result;
|
| 226 |
liveuser |
16809 |
|
| 207 |
liveuser |
16810 |
}#if end
|
| 226 |
liveuser |
16811 |
|
| 207 |
liveuser |
16812 |
#如果有設置 outsideFontUrl
|
|
|
16813 |
if(isset($conf["outsideFontUrl"])){
|
| 226 |
liveuser |
16814 |
|
| 207 |
liveuser |
16815 |
#設置字形是從 url 取得
|
|
|
16816 |
$isWeb="true";
|
| 226 |
liveuser |
16817 |
|
| 207 |
liveuser |
16818 |
#設置字形url
|
|
|
16819 |
$fontsPath=$conf["outsideFontUrl"];
|
| 226 |
liveuser |
16820 |
|
| 207 |
liveuser |
16821 |
}#if end
|
| 226 |
liveuser |
16822 |
|
| 207 |
liveuser |
16823 |
#反之
|
|
|
16824 |
else{
|
| 226 |
liveuser |
16825 |
|
| 207 |
liveuser |
16826 |
#設置字形是從本地取得
|
|
|
16827 |
$isWeb="false";
|
| 226 |
liveuser |
16828 |
|
| 207 |
liveuser |
16829 |
#取得存在字形的根目錄
|
|
|
16830 |
$fontsPath=pathinfo(__FILE__)["dirname"]."/fonts/".$conf["fontPath"];
|
| 226 |
liveuser |
16831 |
|
| 207 |
liveuser |
16832 |
}#else end
|
|
|
16833 |
|
|
|
16834 |
#取得font檔案內容
|
|
|
16835 |
#函式說明:
|
|
|
16836 |
#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
|
|
|
16837 |
#回傳的變數說明:
|
|
|
16838 |
#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
|
|
|
16839 |
#$result["error"],錯誤訊息提示.
|
|
|
16840 |
#$result["warning"],警告訊息.
|
|
|
16841 |
#$result["function"],當前執行的函數名稱.
|
|
|
16842 |
#$result["fileContent"],爲檔案的內容陣列.
|
|
|
16843 |
#$result["lineCount"],爲檔案內容總共的行數.
|
|
|
16844 |
#$result["fullContent"],為檔案的完整內容.
|
|
|
16845 |
#$result["base64dataOnly"],檔案的base64data.
|
|
|
16846 |
#$result["base64data"],為在網頁上給予src參數的數值.
|
|
|
16847 |
#$result["mimeType"],為檔案的mime type.
|
|
|
16848 |
#必填參數:
|
|
|
16849 |
#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
|
|
|
16850 |
$conf["fileAccess::getFileContent"]["filePositionAndName"]=$fontsPath;
|
|
|
16851 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
16852 |
$conf["fileAccess::getFileContent"]["fileArgu"]=__FILE__;
|
|
|
16853 |
#可省略參數:
|
|
|
16854 |
#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
|
|
|
16855 |
$conf["fileAccess::getFileContent"]["web"]=$isWeb;
|
|
|
16856 |
#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
|
|
|
16857 |
#$conf["createIfnotExist"]="false";
|
|
|
16858 |
#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
|
|
|
16859 |
#$conf["autoDeleteSpaceOnEachLineStart"]="false";
|
|
|
16860 |
#參考資料:
|
|
|
16861 |
#file(),取得檔案內容的行數.
|
|
|
16862 |
#file=>http:#php.net/manual/en/function.file.php
|
|
|
16863 |
#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
|
|
|
16864 |
#filesize=>http://php.net/manual/en/function.filesize.php
|
|
|
16865 |
#參考資料:
|
|
|
16866 |
#無.
|
|
|
16867 |
#備註:
|
|
|
16868 |
#無.
|
|
|
16869 |
$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
|
|
|
16870 |
unset($conf["fileAccess::getFileContent"]);
|
| 226 |
liveuser |
16871 |
|
| 207 |
liveuser |
16872 |
#如果執行異常
|
|
|
16873 |
if($getFileContent["status"]==="false"){
|
| 226 |
liveuser |
16874 |
|
| 207 |
liveuser |
16875 |
#設置執行異常
|
|
|
16876 |
$result["status"]="false";
|
| 226 |
liveuser |
16877 |
|
| 207 |
liveuser |
16878 |
#設置執行錯誤訊息
|
|
|
16879 |
$result["error"]=$getFileContent;
|
| 226 |
liveuser |
16880 |
|
| 207 |
liveuser |
16881 |
#回傳結果
|
|
|
16882 |
return $result;
|
| 226 |
liveuser |
16883 |
|
| 207 |
liveuser |
16884 |
}#if end
|
| 226 |
liveuser |
16885 |
|
| 207 |
liveuser |
16886 |
#set custom font path
|
|
|
16887 |
$setFontPart=
|
|
|
16888 |
"
|
|
|
16889 |
//store font file in base64 encode string
|
|
|
16890 |
window.qbpwcf.fonts.base64='".$getFileContent["base64dataOnly"]."';
|
| 226 |
liveuser |
16891 |
|
|
|
16892 |
//store font file in bufferArray
|
| 207 |
liveuser |
16893 |
window.qbpwcf.fonts.bufferArray=Uint8Array.fromBase64(window.qbpwcf.fonts.base64).buffer;
|
| 226 |
liveuser |
16894 |
|
| 207 |
liveuser |
16895 |
";
|
| 226 |
liveuser |
16896 |
|
| 207 |
liveuser |
16897 |
#函式說明:
|
|
|
16898 |
#將要執行的script語法透過該函式執行(會在程式外層用<script></script>包起來).
|
|
|
16899 |
#回傳結果:
|
|
|
16900 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
16901 |
#$result["error"],錯誤訊息陣列
|
|
|
16902 |
#$result["function"],當前執行的函數名稱
|
|
|
16903 |
#$result["content"],要執行的javaScript語法
|
|
|
16904 |
#必填參數:
|
|
|
16905 |
#$conf["script"],字串,要執行的javaScript語法.
|
|
|
16906 |
$conf["javaScript::toScript"]["script"]=$setFontPart.
|
|
|
16907 |
"
|
|
|
16908 |
//load font function
|
|
|
16909 |
await window.qbpwcf.fonts.load();
|
|
|
16910 |
";
|
|
|
16911 |
#可省略參數:
|
|
|
16912 |
#$conf["onReady"],字串,是否要在網頁完全載入後再執行,"false"為不等載入完就先執行,預設為"true"要等載入完再執行.
|
|
|
16913 |
#$conf["onReady"]="true";
|
|
|
16914 |
#$conf["globalJs"],字串陣列,為要放入<script>標籤的js全域變數.
|
|
|
16915 |
#$conf["globalJs"]=array();
|
|
|
16916 |
#$conf["jsFunciton"],字串陣列,為要放入<script>標籤的js函數.
|
|
|
16917 |
#$conf["jsFunciton"]=array();
|
|
|
16918 |
#$conf["noScriptTag"],字串,是否不要輸出<script></script>,預設為"false",代表要輸出;反之為"true",代表不要輸出.
|
|
|
16919 |
#$conf["noScriptTag"]="false";
|
|
|
16920 |
#參考資料:
|
|
|
16921 |
#http://stackoverflow.com/questions/9899372/pure-javascript-equivalent-to-jquerys-ready-how-to-call-a-function-when-the
|
|
|
16922 |
#備註:
|
|
|
16923 |
#無.
|
|
|
16924 |
$toScript=javaScript::toScript($conf["javaScript::toScript"]);
|
|
|
16925 |
unset($conf["javaScript::toScript"]);
|
| 226 |
liveuser |
16926 |
|
| 207 |
liveuser |
16927 |
#儲存html(javascript)語法
|
|
|
16928 |
$result["content"]=$toScript["content"];
|
| 226 |
liveuser |
16929 |
|
| 207 |
liveuser |
16930 |
#設置執行正常
|
|
|
16931 |
$result["status"]="true";
|
| 226 |
liveuser |
16932 |
|
| 207 |
liveuser |
16933 |
#回傳結果
|
|
|
16934 |
return $result;
|
| 226 |
liveuser |
16935 |
|
| 207 |
liveuser |
16936 |
}#function setBodyFont end
|
|
|
16937 |
|
| 3 |
liveuser |
16938 |
}#class javaScript end
|
|
|
16939 |
|
|
|
16940 |
/*
|
|
|
16941 |
|
|
|
16942 |
宣告變數 - start
|
|
|
16943 |
|
|
|
16944 |
宣告變數請用var,若宣告在函式外面,則會變成全域變數.
|
|
|
16945 |
若不用var來宣告變數,則會被時為全域變數.函式多用會導致被最後一此呼叫的變數所覆蓋.
|
|
|
16946 |
var variable;
|
|
|
16947 |
|
|
|
16948 |
參考資料:
|
|
|
16949 |
https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Statements/var
|
|
|
16950 |
|
|
|
16951 |
宣告變數 - end
|
|
|
16952 |
|
|
|
16953 |
//直接將選擇好的圖片檔案直接用來使用 - start
|
|
|
16954 |
input=document.createElement('input');
|
|
|
16955 |
input.type='file';
|
|
|
16956 |
input.id='file';
|
|
|
16957 |
input.accept="image/*";
|
|
|
16958 |
input.style.display='none';
|
|
|
16959 |
input.addEventListener('change',function(event)
|
|
|
16960 |
{
|
|
|
16961 |
event.preventDefault();
|
|
|
16962 |
event.stopPropagation();
|
|
|
16963 |
|
|
|
16964 |
//置換成選取的照片
|
|
|
16965 |
document.getElementById('img').src=URL.createObjectURL(event.target.files[0]);
|
|
|
16966 |
|
|
|
16967 |
//get selected file content
|
|
|
16968 |
reader=new FileReader();
|
|
|
16969 |
reader.readAsBinaryString(event.target.files[0]);
|
| 226 |
liveuser |
16970 |
reader.onload=function(event)
|
| 3 |
liveuser |
16971 |
{
|
|
|
16972 |
//base64 encode
|
|
|
16973 |
newVal=btoa(event.target.result);
|
| 226 |
liveuser |
16974 |
|
| 3 |
liveuser |
16975 |
//obj to save
|
|
|
16976 |
newValObj=
|
|
|
16977 |
{
|
|
|
16978 |
where:
|
|
|
16979 |
{
|
|
|
16980 |
id:'id', //識別要更新到哪一筆資料
|
|
|
16981 |
},
|
|
|
16982 |
col:'logo', //要儲存到資料表欄位
|
|
|
16983 |
val:newVal, //圖片的base64 encode
|
| 207 |
liveuser |
16984 |
}
|
| 3 |
liveuser |
16985 |
|
|
|
16986 |
//encode post value
|
|
|
16987 |
params=btoa(encodeURIComponent(JSON.stringify(newValObj)));
|
|
|
16988 |
|
|
|
16989 |
//如果服務端有回傳完成的狀態
|
|
|
16990 |
xmlhttp=new XMLHttpRequest();
|
|
|
16991 |
xmlhttp.temp={}; //要依照ajax的回應來編輯的內容請設置在此,透過window變數來修改是無效的.
|
|
|
16992 |
//xmlhttp.responseType='json';
|
|
|
16993 |
//xmlhttp.timeout=60000;
|
|
|
16994 |
xmlhttp.open('POST','update',false);
|
|
|
16995 |
xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
|
|
|
16996 |
xmlhttp.setRequestHeader('X-Requested-With','XMLHttpRequest');
|
|
|
16997 |
xmlhttp.onreadystatechange=function(){}//function end
|
|
|
16998 |
xmlhttp.send('params='+params); //如果是post則要將參數加在這邊 'key1=encodeURIComponent(val1)&key2=encodeURIComponent(val2)';
|
| 226 |
liveuser |
16999 |
};
|
|
|
17000 |
});
|
| 3 |
liveuser |
17001 |
input.click(); //觸發事件
|
|
|
17002 |
// 直接將選擇好的圖片檔案直接用來使用 - end
|
|
|
17003 |
|
|
|
17004 |
//get new value
|
|
|
17005 |
reader=new FileReader();
|
|
|
17006 |
reader.readAsBinaryString(event.target.files[0]);
|
|
|
17007 |
|
|
|
17008 |
取得id為'bottom'的元素的上一層元素,將其儲存到變數bottomDiv裡面。
|
|
|
17009 |
var bottomDiv=document.getElementById('bottom').parentElement;
|
|
|
17010 |
|
|
|
17011 |
取得id為'target'的元素可見高度
|
|
|
17012 |
document.getElementById('target').clientHeight;
|
|
|
17013 |
|
|
|
17014 |
取得id為'bottom'的元素高度(含滾軸)
|
|
|
17015 |
document.getElementById('bottom').scrollHeight;
|
|
|
17016 |
|
|
|
17017 |
#視窗的高度(含滾軸)
|
|
|
17018 |
document.scrollingElement.scrollHeight
|
|
|
17019 |
|
|
|
17020 |
#視窗的高度拉到頂
|
|
|
17021 |
document.scrollingElement.scrollTop=0;
|
|
|
17022 |
|
|
|
17023 |
#取得id為"ID"的元素位置與寬高
|
|
|
17024 |
var element = document.getElementById('ID');
|
|
|
17025 |
var domRect = element.getBoundingClientRect();
|
|
|
17026 |
output example => DOMRect { x: 404, y: 20, width: 155, height: 45, top: 20, right: 559, bottom: 65, left: 404 }
|
|
|
17027 |
|
|
|
17028 |
#當視窗大小改變,要觸發myFunction,只會跑一次
|
|
|
17029 |
window.addEventListener("resize", myFunction);
|
|
|
17030 |
|
|
|
17031 |
#當視窗大小改變,要觸發function
|
|
|
17032 |
window.addEventListener("resize" function(){
|
|
|
17033 |
...
|
|
|
17034 |
});
|
|
|
17035 |
|
|
|
17036 |
#當滾軸移動時觸發的事件
|
| 226 |
liveuser |
17037 |
window.addEventListener('scroll', function(e){
|
| 3 |
liveuser |
17038 |
//get last scroll y, 0 means top.
|
|
|
17039 |
var last_known_scroll_position = window.scrollY;
|
|
|
17040 |
});
|
|
|
17041 |
|
|
|
17042 |
#建立物件函數,並透過addEventListener指定執行
|
|
|
17043 |
var someEvent=function(){
|
|
|
17044 |
...
|
|
|
17045 |
};
|
|
|
17046 |
window.addEventListener("resize",someEvent);
|
|
|
17047 |
|
|
|
17048 |
//在 load event 之前的狀態與事件綁定
|
|
|
17049 |
//https://developer.mozilla.org/zh-TW/docs/Web/API/Document/readyState
|
|
|
17050 |
document.onreadystatechange = function () {
|
|
|
17051 |
|
|
|
17052 |
// alternative to DOMContentLoaded event
|
|
|
17053 |
//文件已經完成讀取和解析,但是其他的子資源,如「圖片樣式層次表」,仍然在讀取。這個狀態表示 DOMContentLoaded 事件已經被觸發。
|
|
|
17054 |
//可以開始使用 DOM 元素。
|
|
|
17055 |
if (document.readyState == "interactive"){
|
|
|
17056 |
initApplication();
|
|
|
17057 |
}
|
|
|
17058 |
|
|
|
17059 |
// alternative to load event
|
|
|
17060 |
//文件及子資源都完成讀取。這個狀態表示 load 事件即將被觸發。
|
|
|
17061 |
else if (document.readyState == "complete"){
|
|
|
17062 |
initApplication();
|
|
|
17063 |
}
|
|
|
17064 |
}
|
|
|
17065 |
|
|
|
17066 |
//所有內容跑完之後再執行的事件
|
|
|
17067 |
window.addEventListener('load',function(){
|
|
|
17068 |
...
|
|
|
17069 |
});
|
|
|
17070 |
|
|
|
17071 |
//取消事件的預設效果
|
|
|
17072 |
document.getElementById("myCheckbox").addEventListener("click", function(event){
|
|
|
17073 |
|
|
|
17074 |
event.preventDefault()
|
|
|
17075 |
|
|
|
17076 |
});
|
|
|
17077 |
|
|
|
17078 |
//將下拉式選單綁定'mousedown'事件,並取消預設的效果
|
|
|
17079 |
document.getElementById("myInputSelect").addEventListener("mousedown",function(event){
|
|
|
17080 |
|
|
|
17081 |
//取消預設按下滑鼠的效果
|
|
|
17082 |
event.preventDefault();
|
|
|
17083 |
|
|
|
17084 |
});
|
|
|
17085 |
|
|
|
17086 |
//取消事件的預設效果與傳播
|
|
|
17087 |
document.getElementById("myCheckbox").addEventListener("click", function(event){
|
|
|
17088 |
|
|
|
17089 |
//取消事件的預設效果
|
|
|
17090 |
event.preventDefault();
|
|
|
17091 |
|
|
|
17092 |
//取消事件的傳播
|
|
|
17093 |
event.stopPropagation();
|
|
|
17094 |
|
|
|
17095 |
});
|
|
|
17096 |
|
|
|
17097 |
//參考資料
|
|
|
17098 |
//https://developer.mozilla.org/zh-TW/docs/Web/API/Event/stopPropagation
|
|
|
17099 |
|
|
|
17100 |
//將事件解除綁定
|
|
|
17101 |
var x = document.getElementById("myDIV");
|
|
|
17102 |
if (x.removeEventListener) { // For all major browsers, except IE 8 and earlier
|
|
|
17103 |
x.removeEventListener("mousemove", myFunction);
|
|
|
17104 |
} else if (x.detachEvent) { // For IE 8 and earlier versions
|
|
|
17105 |
x.detachEvent("onmousemove", myFunction);
|
|
|
17106 |
}
|
|
|
17107 |
|
|
|
17108 |
#使用Date物件
|
|
|
17109 |
var myDate = new Date();
|
|
|
17110 |
#取得unixtime
|
|
|
17111 |
myDate.getTime();
|
|
|
17112 |
#不宣告Dare物件也可取得unixtime
|
|
|
17113 |
Date.parse(Date());
|
|
|
17114 |
#參考資料:
|
|
|
17115 |
#https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse
|
|
|
17116 |
|
|
|
17117 |
#取得網頁body原始碼
|
|
|
17118 |
document.body.innerHTML;
|
|
|
17119 |
|
|
|
17120 |
#取得網頁head原始碼
|
|
|
17121 |
document.head.innerHTML;
|
|
|
17122 |
|
|
|
17123 |
#取得id為'bottom'的元素css style
|
|
|
17124 |
var bottomDiv=document.getElementById('bottom')
|
|
|
17125 |
window.getComputedStyle(bottomDiv,null);
|
|
|
17126 |
|
|
|
17127 |
#取得id為'bottom'的元素css的height數值.
|
|
|
17128 |
var bottomDiv=document.getElementById('bottom');
|
|
|
17129 |
var bottomDivStyle=window.getComputedStyle(bottomDiv,null);
|
|
|
17130 |
var bottomDivH=bottomDivStyle['height'];
|
|
|
17131 |
|
|
|
17132 |
#設置id為'bottom'的元素css的height數值為100px
|
|
|
17133 |
var bottomDiv=document.getElementById('bottom');
|
|
|
17134 |
bottomDiv.style.height='100px';
|
|
|
17135 |
|
|
|
17136 |
#取得iframe內id為"run"的元素.
|
|
|
17137 |
var if1= document.getElementById('run');
|
|
|
17138 |
if1.contentDocument.getElementById('run');
|
|
|
17139 |
|
|
|
17140 |
#設置過了3秒中後要做的事情.
|
|
|
17141 |
setTimeout(function()
|
|
|
17142 |
{
|
| 174 |
liveuser |
17143 |
do something
|
| 3 |
liveuser |
17144 |
},3000);
|
|
|
17145 |
|
|
|
17146 |
#新增網頁元素
|
|
|
17147 |
var node = document.createElement('li'); // Create a <li> node
|
|
|
17148 |
var textnode = document.createTextNode('Water'); // Create a text node
|
|
|
17149 |
node.appendChild(textnode); // Append the text to <li>
|
|
|
17150 |
document.getElementById("myList").appendChild(node); // Append <li> to <ul> with id="myList"
|
|
|
17151 |
|
|
|
17152 |
#取得第一個子元素
|
|
|
17153 |
element=document.getElementById('target');
|
|
|
17154 |
element.firstChild;
|
|
|
17155 |
|
|
|
17156 |
#取得下拉式選單的內容
|
|
|
17157 |
var inputSelect=下拉式選單元素;
|
|
|
17158 |
inputSelect.options.length; //取得選項數目
|
|
|
17159 |
inputSelect.options[0].value; //第1個選項傳送的數值
|
|
|
17160 |
inputSelect.options[0].innerHTML; //第1個選項的顯示內容
|
|
|
17161 |
|
|
|
17162 |
#設置元素的類別
|
|
|
17163 |
var a=目標元素;
|
|
|
17164 |
a.className='className1 className2 ...'
|
|
|
17165 |
|
|
|
17166 |
#取得所有含有 'className' 類別的元素
|
|
|
17167 |
var allOptions=document.getElementsByClassName('className');
|
|
|
17168 |
|
|
|
17169 |
#取得id為targetDiv的div標籤的data-val屬性數值
|
|
|
17170 |
document.getElementById("targetDiv").attributes['data-val'].value;
|
|
|
17171 |
|
|
|
17172 |
#移除id為targetDiv的div元素
|
|
|
17173 |
document.getElementById("targetDiv").remove();
|
|
|
17174 |
|
|
|
17175 |
#移除id為targetDiv的div標籤的data-val屬性
|
|
|
17176 |
document.getElementById("targetDiv").removeAttribute('data-val');
|
|
|
17177 |
|
|
|
17178 |
#若存在 scrollingListMiddleEvent 物件,則呼叫之.
|
|
|
17179 |
if(window.scrollingListMiddleEvent!==undefined){
|
|
|
17180 |
|
|
|
17181 |
//debug
|
|
|
17182 |
//console.log('scrollingListMiddleEvent()');
|
|
|
17183 |
|
|
|
17184 |
//方法1
|
|
|
17185 |
window.scrollingListMiddleEvent();
|
|
|
17186 |
|
|
|
17187 |
//方法2,call()裡面可以覆寫物件.
|
|
|
17188 |
//參考資料:https://www.w3schools.com/js/js_function_call.asp
|
|
|
17189 |
window.scrollingListMiddleEvent.call();
|
|
|
17190 |
|
|
|
17191 |
}
|
|
|
17192 |
|
|
|
17193 |
#下拉式選單於Browser上選擇新的數值之後,所要取得新的數值與所選擇的選項應以<select></select>的value來判斷,而非透過<option></option>是否有selected屬性來判斷。
|
|
|
17194 |
var select=document.getElementById('selectID');
|
|
|
17195 |
var selectVal=document.getElementById('selectID').value;
|
|
|
17196 |
for(var i=0;i<select.options.length;i++){
|
|
|
17197 |
var opval=select.options[i].attributes['value'].value;
|
|
|
17198 |
if(opval===selectVal){
|
|
|
17199 |
var opName=select.options[i].innerHTML;
|
|
|
17200 |
}
|
|
|
17201 |
}
|
| 226 |
liveuser |
17202 |
|
| 3 |
liveuser |
17203 |
#下拉式選單選擇了哪個options;
|
|
|
17204 |
var select=document.getElementById('selectID');
|
|
|
17205 |
var optionIndex=select.options.selectedIndex; //選擇的選項是第幾個
|
|
|
17206 |
var selectedOptions=select.options[select.options..selectedIndex]; 選擇的選項元素.
|
|
|
17207 |
|
|
|
17208 |
#若用jquery取得元素,但想要透過原生js去存取,則其第一個元素就是接口.
|
|
|
17209 |
var nativeEleObject=$('#eleId')[0];
|
|
|
17210 |
|
|
|
17211 |
#元素用"onClick"會停止event bubbling,點擊內部元素不會傳導到外部元素.
|
|
|
17212 |
<tag onClick="do something">
|
|
|
17213 |
|
|
|
17214 |
#對元素進行變更,然後強迫瀏覽器刷新
|
|
|
17215 |
#change something
|
|
|
17216 |
var btn=document.getElementById('top_up_submit');
|
|
|
17217 |
btn.setAttribute('data-lock',0);
|
|
|
17218 |
btn.removeAttribute('disabled');
|
|
|
17219 |
btn.innerHTML='Applying';
|
|
|
17220 |
|
|
|
17221 |
#強迫刷新(不見得有效)
|
|
|
17222 |
var temp=document.createTextNode('');
|
|
|
17223 |
btn.appendChild(temp);
|
|
|
17224 |
var os=btn.style.display;
|
|
|
17225 |
btn.style.display='none';
|
|
|
17226 |
btn.style.display=os;
|
|
|
17227 |
btn.removeChild(temp);
|
|
|
17228 |
|
|
|
17229 |
#如果要讓使用者輸入的數值或選擇的選項能夠反應到dom上則必須透過屬性設置的方式才能取得.
|
|
|
17230 |
#亦即透過 setAttribute 方法來設置這些內容
|
|
|
17231 |
element.setAttribute('attr','value');
|
|
|
17232 |
|
|
|
17233 |
#取得所使用的html header
|
|
|
17234 |
document.head.innerHTML;
|
|
|
17235 |
|
|
|
17236 |
#取得所使用的hmtl body
|
|
|
17237 |
document.body.innerHTML;
|
|
|
17238 |
|
|
|
17239 |
#取得html所有dom物件
|
|
|
17240 |
document.all
|
|
|
17241 |
|
|
|
17242 |
#this的應用
|
|
|
17243 |
window.qbpwcf.lib.init=function(){
|
| 226 |
liveuser |
17244 |
|
| 3 |
liveuser |
17245 |
//等同印出 window,以及this指的是等號左邊的最上層變數.
|
|
|
17246 |
console.log(this);
|
| 226 |
liveuser |
17247 |
|
| 3 |
liveuser |
17248 |
}
|
|
|
17249 |
|
|
|
17250 |
#判斷不是數字
|
|
|
17251 |
var oriVal=parseInt($(this).val());
|
|
|
17252 |
//如果不是數字
|
|
|
17253 |
if(oriVal.toString()==='NaN'){
|
|
|
17254 |
//do something
|
|
|
17255 |
}
|
|
|
17256 |
|
|
|
17257 |
//複製元素
|
|
|
17258 |
var copiedEle=element.cloneNode(true);
|
|
|
17259 |
//參考資料
|
|
|
17260 |
//https://developer.mozilla.org/zh-TW/docs/Web/API/Node/cloneNode
|
|
|
17261 |
|
|
|
17262 |
//複製物件
|
|
|
17263 |
var obj = { a: 1 };
|
|
|
17264 |
var copy = Object.assign({}, obj);
|
|
|
17265 |
console.log(copy); // { a: 1 }
|
|
|
17266 |
//參考資料
|
|
|
17267 |
//https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
|
|
|
17268 |
|
|
|
17269 |
//深層複製物件
|
|
|
17270 |
var a = { b: {c:4} , d: { e: {f:1}} }
|
|
|
17271 |
var g = Object.assign({},a) // 淺層
|
|
|
17272 |
var h = JSON.parse(JSON.stringify(a)); // 深層
|
|
|
17273 |
//參考資料
|
|
|
17274 |
https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
|
|
|
17275 |
|
|
|
17276 |
//json to string
|
|
|
17277 |
//參考資料:
|
|
|
17278 |
//https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
|
|
|
17279 |
JSON.stringify(json);
|
|
|
17280 |
|
|
|
17281 |
//jons string to json
|
|
|
17282 |
JSON.parse(jsonString);
|
|
|
17283 |
|
|
|
17284 |
#設置周期執行的涵式
|
|
|
17285 |
var myVar = setInterval(function()
|
|
|
17286 |
{
|
|
|
17287 |
do something...
|
|
|
17288 |
}, 3000);
|
|
|
17289 |
#停止周期執行的程式
|
|
|
17290 |
clearInterval(myVar);
|
|
|
17291 |
|
|
|
17292 |
#加解密中文
|
|
|
17293 |
var str='中文';
|
|
|
17294 |
var encodeStr=btoa(encodeURIComponent(str));
|
|
|
17295 |
var decodeStr=decodeURIComponent(atob(encodeStr));
|
|
|
17296 |
console.log(encodeStr);
|
|
|
17297 |
console.log(decodeStr);
|
|
|
17298 |
|
|
|
17299 |
#呼叫由儲存在變數裡面的函數,可以藉此產生callback func
|
|
|
17300 |
var getPart=function(){
|
|
|
17301 |
console.log('test');
|
|
|
17302 |
}
|
|
|
17303 |
getPart.call(this);
|
|
|
17304 |
|
|
|
17305 |
#設置 XMLHttpRequest 的回應為何種類型
|
|
|
17306 |
xmlhttp=new XMLHttpRequest();
|
|
|
17307 |
XMLHttpRequest.responseType='blob'; //設置為2元碼
|
|
|
17308 |
XMLHttpRequest.responseType='arraybuffer'; //針對2元碼內容,存成陣列,適合各別byte處理的需要.
|
|
|
17309 |
XMLHttpRequest.responseType='json'; //設置為json
|
|
|
17310 |
XMLHttpRequest.responseType='text'; //設為文字,此為default
|
|
|
17311 |
XMLHttpRequest.responseType='document'; //html, do not set to document when send a not async request
|
|
|
17312 |
https://developer.mozilla.org/zh-TW/docs/Web/API/XMLHttpRequest/responseType
|
|
|
17313 |
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Sending_and_Receiving_Binary_Data
|
|
|
17314 |
|
|
|
17315 |
#取得 XMLHttpRequest 回應的內容(可以非dom)
|
|
|
17316 |
xmlhttp=new XMLHttpRequest();
|
|
|
17317 |
xmlhttp.responseType='blob';
|
|
|
17318 |
//false 代表要同步,亦即會等待ajax完成後再執行.
|
|
|
17319 |
xmlhttp.open('GET','fileAccessT.php',false);
|
|
|
17320 |
xmlhttp.response;
|
|
|
17321 |
|
|
|
17322 |
//如果服務端有回傳完成的狀態
|
|
|
17323 |
xmlhttp=new XMLHttpRequest();
|
|
|
17324 |
xmlhttp.temp={}; //要依照ajax的回應來編輯的內容請設置在此,透過window變數來修改是無效的.
|
|
|
17325 |
xmlhttp.responseType='json';
|
|
|
17326 |
xmlhttp.timeout=60000;
|
|
|
17327 |
xmlhttp.open('GET','fileAccessT.php',true);
|
|
|
17328 |
xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
|
|
|
17329 |
xmlhttp.setRequestHeader('X-Requested-With','XMLHttpRequest');
|
|
|
17330 |
xmlhttp.onreadystatechange=function(){
|
|
|
17331 |
|
|
|
17332 |
//如果狀態為4且response code為200
|
|
|
17333 |
if(xmlhttp.readyState==4 && xmlhttp.status==200){
|
|
|
17334 |
|
|
|
17335 |
//將回應進行處理
|
|
|
17336 |
xmlhttp.response;
|
| 226 |
liveuser |
17337 |
|
| 3 |
liveuser |
17338 |
//取得回應的內容
|
|
|
17339 |
res=xmlhttp.response;
|
|
|
17340 |
|
|
|
17341 |
//取得回應的html並取代當前的內容,當xmlhttp.responseType='document'時 - start;
|
|
|
17342 |
|
|
|
17343 |
//開新文件,要寫的內容類型為 'text/html' 繼承前頁面的資訊
|
|
|
17344 |
document.open('text/html',true);
|
|
|
17345 |
|
|
|
17346 |
//清空文件,寫入取得的完整回應
|
|
|
17347 |
document.write(res.all[0].outerHTML);
|
|
|
17348 |
|
|
|
17349 |
//結束輸出
|
|
|
17350 |
document.close();
|
| 226 |
liveuser |
17351 |
|
| 3 |
liveuser |
17352 |
//取得回應的html並取代當前的內容,當xmlhttp.responseType='document'時 - end;
|
|
|
17353 |
|
|
|
17354 |
}//if end
|
|
|
17355 |
|
|
|
17356 |
}//function end
|
|
|
17357 |
|
|
|
17358 |
//參數跟數值內容要用encodeURIComponent才不會有編碼的錯誤產生
|
|
|
17359 |
xmlhttp.send(); //如果是post則要將參數加在這邊 'encodeURIComponent(key1)=encodeURIComponent(val1)&encodeURIComponent(key2)=encodeURIComponent(val2)';
|
|
|
17360 |
|
| 226 |
liveuser |
17361 |
//如果要在迴圈裏面執行異步的ajax,由於js是傳參考的語言,因此建議將每個ajax個別儲存在陣列裏面。 - start
|
| 3 |
liveuser |
17362 |
|
| 207 |
liveuser |
17363 |
//初始化儲存xmlhttp的陣列
|
| 3 |
liveuser |
17364 |
xmlhttp=[];
|
|
|
17365 |
|
|
|
17366 |
//針對每列
|
|
|
17367 |
for(i=0;i<rowCount;i++)
|
|
|
17368 |
{
|
|
|
17369 |
//取得列
|
|
|
17370 |
tr=tbody.children[i];
|
|
|
17371 |
|
| 207 |
liveuser |
17372 |
//取得燈狀態
|
|
|
17373 |
lightSta=tr.children[1].children[0];
|
| 226 |
liveuser |
17374 |
|
| 3 |
liveuser |
17375 |
//取得gw id
|
|
|
17376 |
gwId=tr.children[0].innerText;
|
|
|
17377 |
|
|
|
17378 |
url='area/device/getDeviceInfoInJSON/'+gwId;
|
|
|
17379 |
xmlhttp[i]=new XMLHttpRequest();
|
|
|
17380 |
xmlhttp[i].temp={}; //用於儲存額外的資訊給ajax function - start
|
|
|
17381 |
xmlhttp[i].temp.gwId=gwId;
|
|
|
17382 |
xmlhttp[i].temp.lightSta=lightSta; //用於儲存額外的資訊給ajax function - end
|
|
|
17383 |
xmlhttp[i].open('POST',url,true);
|
|
|
17384 |
xmlhttp[i].setRequestHeader('Content-type','application/x-www-form-urlencoded; charset=UTF-8');
|
|
|
17385 |
xmlhttp[i].setRequestHeader('X-Requested-With','XMLHttpRequest');
|
|
|
17386 |
xmlhttp[i].onreadystatechange=function(e)
|
| 226 |
liveuser |
17387 |
{
|
|
|
17388 |
//debug
|
| 3 |
liveuser |
17389 |
if(window.debug)
|
|
|
17390 |
{
|
|
|
17391 |
console.log('e - start');
|
|
|
17392 |
console.log(e);
|
|
|
17393 |
console.log(e.target); //xmlhttp[i] 自己
|
|
|
17394 |
console.log(e.target.response); //xmlhttp[i] 的回應
|
|
|
17395 |
console.log('e - end');
|
| 207 |
liveuser |
17396 |
}
|
| 226 |
liveuser |
17397 |
|
| 3 |
liveuser |
17398 |
//get gw id
|
| 207 |
liveuser |
17399 |
gwId=e.target.temp.gwId;
|
| 3 |
liveuser |
17400 |
|
|
|
17401 |
//response ok
|
|
|
17402 |
if(e.target.readyState===4 && e.target.status===200)
|
|
|
17403 |
{
|
|
|
17404 |
//do something,,,
|
|
|
17405 |
}
|
|
|
17406 |
}
|
|
|
17407 |
xmlhttp[i].send(null);
|
|
|
17408 |
|
|
|
17409 |
}//for end
|
|
|
17410 |
|
|
|
17411 |
//如果要在迴圈裏面執行異步的ajax,由於js是傳參考的語言,因此建議將每個ajax個別儲存在陣列裏面。 - end
|
|
|
17412 |
|
|
|
17413 |
//所有內容跑完之後再執行的事件
|
|
|
17414 |
window.addEventListener('load',function(){
|
|
|
17415 |
|
|
|
17416 |
//一段時間後再執行
|
|
|
17417 |
setTimeout(function(){
|
| 226 |
liveuser |
17418 |
|
| 3 |
liveuser |
17419 |
//get div
|
|
|
17420 |
var div=document.getElementById('test');
|
| 226 |
liveuser |
17421 |
|
| 3 |
liveuser |
17422 |
//set div content
|
|
|
17423 |
div.innerText='Loading...';
|
| 226 |
liveuser |
17424 |
|
| 3 |
liveuser |
17425 |
xmlhttp=new XMLHttpRequest();
|
|
|
17426 |
xmlhttp.responseType='document';// do not set to document when send a not async request
|
|
|
17427 |
xmlhttp.open('GET','javaScriptT/hang.php',true);
|
|
|
17428 |
xmlhttp.response;
|
|
|
17429 |
xmlhttp.onreadystatechange=function(){
|
|
|
17430 |
|
|
|
17431 |
//如果狀態為4且response code為200
|
|
|
17432 |
if(xmlhttp.readyState==4 && xmlhttp.status==200){
|
|
|
17433 |
|
|
|
17434 |
div.innerText='finish!';
|
|
|
17435 |
|
|
|
17436 |
}//if end
|
|
|
17437 |
|
|
|
17438 |
}//function end
|
| 226 |
liveuser |
17439 |
|
| 3 |
liveuser |
17440 |
xmlhttp.send();
|
| 226 |
liveuser |
17441 |
|
| 3 |
liveuser |
17442 |
//debug
|
|
|
17443 |
console.log(xmlhttp.response);
|
| 226 |
liveuser |
17444 |
|
| 3 |
liveuser |
17445 |
//3 秒後再執行
|
|
|
17446 |
},3000)
|
|
|
17447 |
});
|
|
|
17448 |
|
|
|
17449 |
//設定要求的屬性、目的、是否要異步
|
|
|
17450 |
//建議要異步,火狐以外的瀏覽器才會正常呈現 loading 效果
|
|
|
17451 |
xmlhttp.open('POST','".$conf["receivePage"]."',true);
|
|
|
17452 |
|
|
|
17453 |
//設定 header
|
|
|
17454 |
xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
|
|
|
17455 |
|
|
|
17456 |
//設定 要求為ajax 的 header
|
|
|
17457 |
xmlhttp.setRequestHeader('X-Requested-With','XMLHttpRequest');
|
|
|
17458 |
|
|
|
17459 |
#設置XMLHttpRequest等待回應的時間上限(毫秒)
|
|
|
17460 |
XMLHttpRequest.timeout=60000;
|
|
|
17461 |
|
|
|
17462 |
//如果XMLHttpRequest等待回應逾時
|
|
|
17463 |
xmlhttp=new XMLHttpRequest();
|
|
|
17464 |
xmlhttp.addEventListener('timeout',function(){
|
|
|
17465 |
do something...
|
|
|
17466 |
}):
|
|
|
17467 |
|
|
|
17468 |
//如果XMLHttpRequest等待回應逾時
|
|
|
17469 |
xmlhttp=new XMLHttpRequest();
|
|
|
17470 |
xmlhttp.ontimeout=function(){
|
|
|
17471 |
do something...
|
|
|
17472 |
};
|
|
|
17473 |
|
|
|
17474 |
#建立與傳送表單物件 - start
|
|
|
17475 |
|
|
|
17476 |
//建立表單物件
|
|
|
17477 |
var formData = new FormData();
|
|
|
17478 |
|
|
|
17479 |
//新增表單的名稱與對應的數值
|
|
|
17480 |
formData.append('username', 'Chris');
|
|
|
17481 |
|
|
|
17482 |
//建立 XMLHttpRequest 物件
|
|
|
17483 |
xmlhttp=new XMLHttpRequest();
|
|
|
17484 |
|
|
|
17485 |
//設置回傳的形態為 html
|
|
|
17486 |
xmlhttp.responseType='document';
|
|
|
17487 |
|
|
|
17488 |
//設置 timeout 為 60 秒
|
|
|
17489 |
xmlhttp.timeout=60000;
|
|
|
17490 |
|
|
|
17491 |
//設定 header
|
|
|
17492 |
xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
|
|
|
17493 |
|
|
|
17494 |
//設定 要求為ajax 的 header
|
|
|
17495 |
xmlhttp.setRequestHeader('X-Requested-With','XMLHttpRequest');
|
|
|
17496 |
|
|
|
17497 |
//設置使用POST傳送到reveived page
|
|
|
17498 |
request.open("POST", "received page");
|
|
|
17499 |
|
|
|
17500 |
//傳送表單
|
|
|
17501 |
request.send(formData);
|
|
|
17502 |
|
|
|
17503 |
參考資料
|
|
|
17504 |
https://developer.mozilla.org/en-US/docs/Web/API/FormData
|
|
|
17505 |
https://developer.mozilla.org/en-US/docs/Web/API/FormData/FormData
|
|
|
17506 |
https://developer.mozilla.org/en-US/docs/Web/API/FormData/Using_FormData_Objects
|
|
|
17507 |
|
|
|
17508 |
#建立與傳送表單物件 - end
|
|
|
17509 |
|
|
|
17510 |
#用\r\n'分割字串'abc\r\nABC'為陣列
|
|
|
17511 |
var testStr='abc\r\nABC';
|
|
|
17512 |
var splitedStr=testStr.split('\r\n');
|
|
|
17513 |
https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Global_Objects/String/split
|
|
|
17514 |
|
|
|
17515 |
#字串轉成數字
|
|
|
17516 |
var stringInt='111';
|
|
|
17517 |
parseInt(stringInt);
|
|
|
17518 |
|
|
|
17519 |
#透過 prototype 實做 append blob data 的 function
|
|
|
17520 |
#https://stackoverflow.com/questions/15970729/appending-blob-data
|
|
|
17521 |
|
|
|
17522 |
//宣告 MyBlobBuilder 建構子
|
|
|
17523 |
var MyBlobBuilder = function() {
|
|
|
17524 |
this.parts = []; //建立屬性
|
|
|
17525 |
}
|
|
|
17526 |
|
|
|
17527 |
//新增 MyBlobBuilder 的 append 方法
|
|
|
17528 |
MyBlobBuilder.prototype.append = function(part) {
|
|
|
17529 |
this.parts.push(part);
|
|
|
17530 |
this.blob = undefined; // Invalidate the blob
|
|
|
17531 |
};
|
|
|
17532 |
|
|
|
17533 |
//新增 MyBlobBuilder 的 getBlob 方法
|
|
|
17534 |
MyBlobBuilder.prototype.getBlob = function(mimeType) {
|
|
|
17535 |
if(mimeType===''){
|
|
|
17536 |
mimeType="text/plain";
|
|
|
17537 |
}
|
|
|
17538 |
if (!this.blob) {
|
|
|
17539 |
this.blob = new Blob(this.parts, { type: mimeType });
|
|
|
17540 |
}
|
|
|
17541 |
return this.blob;
|
|
|
17542 |
};
|
|
|
17543 |
var myBlobBuilder = new MyBlobBuilder(); //實做物件 MyBlobBuilder
|
|
|
17544 |
myBlobBuilder.append("Hello world, 2"); //append 內容
|
|
|
17545 |
myBlobBuilder.append(",another data"); //append 內容
|
|
|
17546 |
var bb = myBlobBuilder.getBlob('application/zip'); //取得 append 完的內容,並設置 mimeType
|
|
|
17547 |
|
|
|
17548 |
用FileReader讀取blob內容
|
|
|
17549 |
https://developer.mozilla.org/zh-TW/docs/Web/API/Blob
|
|
|
17550 |
https://developer.mozilla.org/zh-TW/docs/Web/API/FileReader
|
|
|
17551 |
var reader = new FileReader(); //實做FileReader
|
|
|
17552 |
reader.addEventListener("loadend", function() { //當讀取檔案結束後
|
|
|
17553 |
reader.result; //base64字串
|
|
|
17554 |
}
|
|
|
17555 |
reader.readAsDataURL(blob); //讀取blob物件
|
|
|
17556 |
|
|
|
17557 |
要設定元素的class請用classList
|
|
|
17558 |
element.classList=["classA classB ..."];
|
|
|
17559 |
|
|
|
17560 |
新增元素的class,例如增加hide類別.
|
|
|
17561 |
element.classList.value=element.classList.value+' hide';
|
|
|
17562 |
|
|
|
17563 |
新增元素的class,例如增加strong類別
|
|
|
17564 |
element.classList.add('strong');
|
|
|
17565 |
|
|
|
17566 |
移除元素的class,例如移除strong類別
|
|
|
17567 |
element.classList.remove('strong');
|
|
|
17568 |
|
|
|
17569 |
針對每個陣列元素做事情,不需要中斷.
|
|
|
17570 |
var testArray=[a,b,c,d,e];
|
|
|
17571 |
testArrayforEach.forEach(function(value,key)
|
|
|
17572 |
{
|
|
|
17573 |
console.log('key:'+key+' val:'+value);
|
|
|
17574 |
});
|
|
|
17575 |
|
|
|
17576 |
//參考資料:
|
|
|
17577 |
//https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach
|
|
|
17578 |
|
|
|
17579 |
針對每個陣列元素做事情,需要中斷.
|
|
|
17580 |
var testArray=['a','b','c','d','e'];
|
|
|
17581 |
testArray.find(function(key,value) // 回傳符合條件的數值內容
|
|
|
17582 |
{
|
|
|
17583 |
console.log('key:'+key+' val:'+value);
|
|
|
17584 |
if(key==='c')
|
|
|
17585 |
{
|
|
|
17586 |
return true;
|
|
|
17587 |
}
|
|
|
17588 |
});
|
|
|
17589 |
|
|
|
17590 |
//參考資料:
|
|
|
17591 |
//https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Global_Objects/Array/find
|
|
|
17592 |
|
|
|
17593 |
對於物件也適用,需要中斷.
|
|
|
17594 |
const obj = { a: 1, b: 2, c: 3 };
|
|
|
17595 |
|
|
|
17596 |
for (const prop in obj) {
|
|
|
17597 |
console.log(`obj.${prop} = ${obj[prop]}`);
|
|
|
17598 |
}
|
|
|
17599 |
|
|
|
17600 |
// Logs:
|
|
|
17601 |
// "obj.a = 1"
|
|
|
17602 |
// "obj.b = 2"
|
|
|
17603 |
// "obj.c = 3"
|
|
|
17604 |
|
|
|
17605 |
//參考資料:
|
|
|
17606 |
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in
|
|
|
17607 |
|
|
|
17608 |
#陣列操作,於尾端添加元素
|
|
|
17609 |
queue=[];
|
|
|
17610 |
queue.push('ele2add2tail');
|
|
|
17611 |
#陣列操作,於首端添加元素
|
|
|
17612 |
queue.unshift('ele2add2head');
|
|
|
17613 |
#陣列操作,移除尾端元素
|
|
|
17614 |
queue.pop('ele2delFromTail');
|
|
|
17615 |
|
|
|
17616 |
//參考資料:
|
|
|
17617 |
//https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Global_Objects/Array/pop
|
|
|
17618 |
|
|
|
17619 |
/*
|
|
|
17620 |
|
|
|
17621 |
//針對特定元素做操作
|
|
|
17622 |
|
|
|
17623 |
var myFish = ['angel', 'clown', 'mandarin', 'sturgeon'];
|
|
|
17624 |
var removed = myFish.splice(2, 0, 'drum');
|
|
|
17625 |
// myFish 為 ["angel", "clown", "drum", "mandarin", "sturgeon"]
|
|
|
17626 |
// removed 為 [], 沒有元素被刪除
|
|
|
17627 |
|
|
|
17628 |
var myFish = ['angel', 'clown', 'drum', 'mandarin', 'sturgeon'];
|
|
|
17629 |
var removed = myFish.splice(3, 1);
|
|
|
17630 |
// removed 為 ["mandarin"]
|
|
|
17631 |
// myFish 為 ["angel", "clown", "drum", "sturgeon"]
|
|
|
17632 |
|
|
|
17633 |
var myFish = ['angel', 'clown', 'drum', 'sturgeon'];
|
|
|
17634 |
var removed = myFish.splice(2, 1, 'trumpet');
|
|
|
17635 |
// myFish 為 ["angel", "clown", "trumpet", "sturgeon"]
|
|
|
17636 |
// removed 為 ["drum"]
|
|
|
17637 |
|
|
|
17638 |
*/
|
|
|
17639 |
|
|
|
17640 |
/*
|
|
|
17641 |
|
|
|
17642 |
針對物件中的每個key
|
|
|
17643 |
Object.keys(data.content).forEach(function(key)
|
|
|
17644 |
{
|
|
|
17645 |
console.log('key');
|
|
|
17646 |
});
|
|
|
17647 |
//參考資料:
|
|
|
17648 |
https://stackoverflow.com/questions/921789/how-to-loop-through-a-plain-javascript-object-with-the-objects-as-members
|
|
|
17649 |
|
|
|
17650 |
//參考資料:
|
|
|
17651 |
//https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Global_Objects/Array/splice
|
|
|
17652 |
|
|
|
17653 |
*/
|
|
|
17654 |
|
|
|
17655 |
/*
|
|
|
17656 |
|
|
|
17657 |
物件長度
|
|
|
17658 |
temp0=
|
|
|
17659 |
{
|
|
|
17660 |
0:'a',
|
|
|
17661 |
1:'b',
|
|
|
17662 |
2:'c',
|
|
|
17663 |
};
|
|
|
17664 |
Object.keys(temp0).length
|
|
|
17665 |
|
|
|
17666 |
*/
|
|
|
17667 |
|
|
|
17668 |
/*
|
|
|
17669 |
|
|
|
17670 |
存取複雜的物件屬性
|
|
|
17671 |
var object={
|
|
|
17672 |
"@attribute":"complex",
|
|
|
17673 |
};
|
|
|
17674 |
object["@attribute"];
|
|
|
17675 |
|
|
|
17676 |
*/
|
|
|
17677 |
|
|
|
17678 |
/*
|
|
|
17679 |
萬用的取得物件屬性方法
|
|
|
17680 |
bit16toNoZeroHead=function(p)
|
|
|
17681 |
{
|
|
|
17682 |
//範例物件
|
|
|
17683 |
table={a:A,b:B,c:C};
|
| 226 |
liveuser |
17684 |
|
| 3 |
liveuser |
17685 |
//取得物件有多少key
|
|
|
17686 |
keyCount=Object.keys(table).length;
|
| 226 |
liveuser |
17687 |
|
| 3 |
liveuser |
17688 |
//針對物件每個key
|
|
|
17689 |
for(i=0;i<keyCount;i++)
|
|
|
17690 |
{
|
|
|
17691 |
//如果物件的key等於參數p
|
|
|
17692 |
if(p===Object.keys(table)[i])
|
|
|
17693 |
{
|
|
|
17694 |
//取得該key指到的value
|
|
|
17695 |
return Object.values(table)[i];
|
|
|
17696 |
}
|
|
|
17697 |
}
|
|
|
17698 |
}
|
|
|
17699 |
*/
|
|
|
17700 |
|
|
|
17701 |
/*
|
|
|
17702 |
|
|
|
17703 |
desc:
|
|
|
17704 |
取得元素屬性的數值內容
|
|
|
17705 |
|
|
|
17706 |
param:
|
|
|
17707 |
element,元素
|
|
|
17708 |
name,屬性名稱
|
|
|
17709 |
|
|
|
17710 |
return:
|
|
|
17711 |
回傳屬性的數值
|
|
|
17712 |
function getAttrData(element,name)
|
|
|
17713 |
{
|
|
|
17714 |
var attrs=element.attributes.length;
|
|
|
17715 |
for(i=0;i<attrs;i++)
|
|
|
17716 |
{
|
|
|
17717 |
var attrName=element.attributes[i].name;
|
|
|
17718 |
var attrValue=element.attributes[i].value;
|
|
|
17719 |
if(attrName===name)
|
|
|
17720 |
{
|
|
|
17721 |
return attrValue;
|
|
|
17722 |
}
|
|
|
17723 |
}
|
|
|
17724 |
}
|
|
|
17725 |
|
|
|
17726 |
*/
|
|
|
17727 |
|
|
|
17728 |
/*
|
|
|
17729 |
|
|
|
17730 |
desc:
|
|
|
17731 |
設置屬性的數值內容
|
|
|
17732 |
|
|
|
17733 |
param:
|
|
|
17734 |
element,元素
|
|
|
17735 |
name,屬性名稱
|
|
|
17736 |
value,屬性的數值
|
|
|
17737 |
|
|
|
17738 |
return:
|
|
|
17739 |
回傳屬性的名稱與數值
|
|
|
17740 |
function setAttrData(element,name,value)
|
|
|
17741 |
{
|
|
|
17742 |
var attrs=element.attributes.length;
|
|
|
17743 |
for(i=0;i<attrs;i++)
|
|
|
17744 |
{
|
|
|
17745 |
var attrName=element.attributes[i].name;
|
|
|
17746 |
var attrValue=element.attributes[i].value;
|
|
|
17747 |
if(attrName===name)
|
|
|
17748 |
{
|
|
|
17749 |
element.attributes[i].value=value;
|
|
|
17750 |
return element.attributes[i];
|
|
|
17751 |
}
|
|
|
17752 |
}
|
|
|
17753 |
}
|
|
|
17754 |
|
|
|
17755 |
*/
|
|
|
17756 |
|
|
|
17757 |
/*
|
|
|
17758 |
#取得屬性的列表與資訊
|
|
|
17759 |
#html:
|
|
|
17760 |
<span title="code" data-a="A" data-b="B">Fusion</span>
|
|
|
17761 |
#js console:
|
|
|
17762 |
spanStr=document.querySelector('span[title]');
|
|
|
17763 |
spanStr.dataset => DOMStringMap { a → "A", b → "B" }
|
|
|
17764 |
spanStr.dataset.a => "A"
|
|
|
17765 |
spanStr.dataset.b => "B"
|
|
|
17766 |
*/
|
|
|
17767 |
|
|
|
17768 |
/*
|
|
|
17769 |
#取得符合條件的第一個項目,選項的採用css的格式
|
|
|
17770 |
document.querySelector('span[title="code"]');
|
|
|
17771 |
*/
|
|
|
17772 |
|
|
|
17773 |
/*
|
|
|
17774 |
#取得每個符合的項目,選擇的方式採用css的格式
|
|
|
17775 |
#document.querySelectorAll('div > div._drags > span.img');
|
|
|
17776 |
*/
|
|
|
17777 |
|
|
|
17778 |
/*
|
|
|
17779 |
#用 inclues 來搜尋字串裡面有無對應的關鍵字.
|
|
|
17780 |
a="abc";
|
|
|
17781 |
a.includes('d'); //will be false
|
|
|
17782 |
a.includes('a'); //will be true
|
|
|
17783 |
*/
|
|
|
17784 |
|
|
|
17785 |
/*
|
|
|
17786 |
解析string為dom字串
|
|
|
17787 |
parser = new DOMParser();
|
|
|
17788 |
doc = parser.parseFromString(stringContainingHTMLSource, "text/html");
|
|
|
17789 |
// returns a HTMLDocument, which also is a Document.
|
|
|
17790 |
https://developer.mozilla.org/en-US/docs/Web/API/DOMParser
|
|
|
17791 |
*/
|
|
|
17792 |
|
|
|
17793 |
/*
|
|
|
17794 |
|
|
|
17795 |
#取得元素ID為eleID的下一個元素
|
|
|
17796 |
#document.getElementById('eleID').nextElementSibling;
|
|
|
17797 |
|
|
|
17798 |
#取得元素ID為eleID的上一個元素
|
|
|
17799 |
#document.getElementById('eleID').preElementSibling;
|
|
|
17800 |
|
|
|
17801 |
*/
|
|
|
17802 |
|
|
|
17803 |
/*
|
|
|
17804 |
|
|
|
17805 |
//no use?
|
|
|
17806 |
stateObj={};
|
|
|
17807 |
|
|
|
17808 |
//取得新 title
|
|
|
17809 |
title=res.title;
|
|
|
17810 |
|
|
|
17811 |
//取得新 url
|
|
|
17812 |
newUrl=res.URL;
|
|
|
17813 |
|
|
|
17814 |
//更新網頁標題與網址
|
|
|
17815 |
//參考資料:https://developer.mozilla.org/en-US/docs/Web/API/History_API
|
|
|
17816 |
history.pushState(stateObj, title, newUrl);
|
|
|
17817 |
|
|
|
17818 |
*/
|
|
|
17819 |
|
|
|
17820 |
/*
|
|
|
17821 |
#webSocket:
|
|
|
17822 |
|
|
|
17823 |
//設定webSocket的連線目標
|
|
|
17824 |
var conn = new WebSocket('wss://dns/wss/chatDemo');
|
|
|
17825 |
|
|
|
17826 |
//狀態1代表正常可通訊
|
|
|
17827 |
conn.readyState=1;
|
|
|
17828 |
|
|
|
17829 |
//建立與當連線成功後
|
|
|
17830 |
conn.onopen = function(e)
|
| 174 |
liveuser |
17831 |
{
|
|
|
17832 |
|
| 3 |
liveuser |
17833 |
}
|
|
|
17834 |
|
|
|
17835 |
//當有收到訊息時
|
|
|
17836 |
conn.onmessage = function(e)
|
| 174 |
liveuser |
17837 |
{
|
| 3 |
liveuser |
17838 |
//將訊息顯現在console
|
|
|
17839 |
console.log(e.data);
|
| 226 |
liveuser |
17840 |
|
| 3 |
liveuser |
17841 |
//傳送訊息
|
|
|
17842 |
conn.send('mag');
|
|
|
17843 |
}
|
|
|
17844 |
|
|
|
17845 |
//當連線斷開後, 每秒重新嘗試一次.
|
|
|
17846 |
conn.onclose = function(e)
|
| 174 |
liveuser |
17847 |
{
|
| 3 |
liveuser |
17848 |
//指定1秒刷新一次
|
|
|
17849 |
setTimeout('window.webSock.connWebSock.call(this)',1000);
|
|
|
17850 |
}
|
| 226 |
liveuser |
17851 |
|
| 3 |
liveuser |
17852 |
//所有內容跑完之後再執行的事件
|
|
|
17853 |
window.addEventListener('load',function()
|
|
|
17854 |
{
|
|
|
17855 |
//傳送訊息
|
|
|
17856 |
conn.send('mag');
|
| 226 |
liveuser |
17857 |
});
|
| 3 |
liveuser |
17858 |
|
|
|
17859 |
eval(),將變數的數值印出.
|
|
|
17860 |
i=0;
|
|
|
17861 |
window.eval(i)='aa';
|
|
|
17862 |
window.0 //會印出 aa
|
|
|
17863 |
|
|
|
17864 |
//定義物件的屬性 - start
|
|
|
17865 |
|
|
|
17866 |
//初始化物件
|
|
|
17867 |
var object1 = {};
|
|
|
17868 |
|
|
|
17869 |
Object.defineProperty(object1, 'property1', {
|
|
|
17870 |
value: 42,
|
|
|
17871 |
writable: false
|
|
|
17872 |
});
|
|
|
17873 |
|
|
|
17874 |
object1.property1 = 77;
|
|
|
17875 |
// throws an error in strict mode
|
|
|
17876 |
|
|
|
17877 |
console.log(object1.property1);
|
|
|
17878 |
// expected output: 42
|
|
|
17879 |
|
|
|
17880 |
//參考資料
|
|
|
17881 |
//https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty
|
|
|
17882 |
|
|
|
17883 |
//卸除 Object object1 的 property1 屬性
|
|
|
17884 |
delete object1.property1;
|
|
|
17885 |
|
|
|
17886 |
//參考資料
|
|
|
17887 |
//https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/seal
|
|
|
17888 |
|
|
|
17889 |
//定義物件的屬性 - end
|
|
|
17890 |
|
|
|
17891 |
//將圖片上下左右置中
|
| 226 |
liveuser |
17892 |
#over {position:relative; text-align:center;
|
| 3 |
liveuser |
17893 |
width:100%; height:100%; background:#CCC;}
|
|
|
17894 |
|
|
|
17895 |
#over img{
|
|
|
17896 |
position: absolute;
|
|
|
17897 |
margin: auto;
|
|
|
17898 |
top: 0;
|
|
|
17899 |
left: 0;
|
|
|
17900 |
right: 0;
|
|
|
17901 |
bottom: 0;
|
|
|
17902 |
}
|
|
|
17903 |
|
|
|
17904 |
//參考資料
|
|
|
17905 |
https://stackoverflow.com/questions/4888223/align-image-in-center-and-middle-within-div
|
|
|
17906 |
|
|
|
17907 |
//override addEventListener
|
|
|
17908 |
(function(){
|
|
|
17909 |
Element.prototype._addEventListener = Element.prototype.addEventListener;
|
|
|
17910 |
Element.prototype.addEventListener = function(a,b,c){
|
|
|
17911 |
this._addEventListener(a,b,c);
|
|
|
17912 |
if(!this.eventListenerList) this.eventListenerList = {};
|
|
|
17913 |
if(!this.eventListenerList[a]) this.eventListenerList[a] = [];
|
|
|
17914 |
this.eventListenerList[a].push(b);
|
|
|
17915 |
};
|
| 226 |
liveuser |
17916 |
})();
|
|
|
17917 |
|
| 3 |
liveuser |
17918 |
//access binded events
|
|
|
17919 |
var clicks = someElement.eventListenerList.click;
|
|
|
17920 |
if(clicks) clicks.forEach(function(f) {
|
|
|
17921 |
alert("I listen to this function: "+f.toString());
|
|
|
17922 |
});
|
| 226 |
liveuser |
17923 |
|
| 3 |
liveuser |
17924 |
//參考資料 https://stackoverflow.com/questions/446892/how-to-find-event-listeners-on-a-dom-node-when-debugging-or-from-the-javascript
|
|
|
17925 |
|
|
|
17926 |
//get user agent
|
|
|
17927 |
navigator.userAgent;
|
|
|
17928 |
|
|
|
17929 |
//參考資料 https://developer.mozilla.org/en-US/docs/Web/API/NavigatorID/userAgent
|
|
|
17930 |
|
|
|
17931 |
//判斷 user agent 是不是 windows
|
|
|
17932 |
navigator.userAgent.includes('Windows');
|
|
|
17933 |
|
|
|
17934 |
//參考資料 https://www.w3schools.com/jsref/jsref_includes.asp
|
|
|
17935 |
|
|
|
17936 |
//取得目前瀏覽的 hostname
|
|
|
17937 |
window.location.hostname
|
|
|
17938 |
|
|
|
17939 |
//參考資料 https://www.w3schools.com/jsref/prop_loc_hostname.asp
|
|
|
17940 |
|
|
|
17941 |
//DOMParser,解析html字串為dom
|
|
|
17942 |
parser = new DOMParser();
|
|
|
17943 |
doc = parser.parseFromString(stringContainingHTMLSource, "text/html");
|
|
|
17944 |
// returns a HTMLDocument, which also is a Document.
|
|
|
17945 |
//參考資料 https://developer.mozilla.org/zh-TW/docs/Web/API/DOMParser
|
|
|
17946 |
|
|
|
17947 |
//寫入減貼簿,需要時使用者的操作。
|
|
|
17948 |
ele.addEventListener('click',function(event)
|
|
|
17949 |
{
|
|
|
17950 |
navigator.clipboard.writeText('text write to clipboard');
|
|
|
17951 |
});
|
|
|
17952 |
|
|
|
17953 |
//重複字串內容
|
|
|
17954 |
'a'.repeat(3)等於'aaa'
|
|
|
17955 |
|
|
|
17956 |
//類似php的substr
|
|
|
17957 |
//-1代表找不到關鍵字的位置
|
|
|
17958 |
str='123456';
|
|
|
17959 |
str.indexOf('abc'); // -1
|
|
|
17960 |
str.indexOf('123'); // 0
|
|
|
17961 |
//參考資料 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf
|
|
|
17962 |
|
|
|
17963 |
//reduce
|
|
|
17964 |
var tmpArray=[1,2,3,4,5,6,7,8,9];
|
|
|
17965 |
tmpArray.reduce(function(preValue,currentValue,currentIndex)
|
|
|
17966 |
{
|
|
|
17967 |
return preValue+currentValue;
|
|
|
17968 |
});
|
|
|
17969 |
//參考資料 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce
|
|
|
17970 |
|
|
|
17971 |
//join
|
|
|
17972 |
var tmpArray=['Fire', 'Air', 'Water'];
|
|
|
17973 |
tmpArray.join(",");
|
|
|
17974 |
//參考資料 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join
|
|
|
17975 |
|
|
|
17976 |
//產生uuid
|
|
|
17977 |
crypto.randomUUID();
|
|
|
17978 |
//參考資料 https://developer.mozilla.org/en-US/docs/Web/API/Crypto/randomUUID
|
|
|
17979 |
|
| 174 |
liveuser |
17980 |
置換網頁整體內容 - start
|
|
|
17981 |
|
|
|
17982 |
//清空當前頁面的dom
|
|
|
17983 |
document.replaceChildren();
|
|
|
17984 |
|
|
|
17985 |
//建立html
|
|
|
17986 |
var html=document.createElement('html');
|
|
|
17987 |
|
|
|
17988 |
//建立head
|
|
|
17989 |
var head=document.createElement('head');
|
|
|
17990 |
|
|
|
17991 |
//建立body
|
|
|
17992 |
var body=document.createElement('body');
|
|
|
17993 |
|
|
|
17994 |
//將回應的dom放到body,res.dom為透過ajax取得的回應內容.
|
|
|
17995 |
body.append(res.dom);
|
|
|
17996 |
|
|
|
17997 |
//將head放到html裡面
|
|
|
17998 |
html.append(head);
|
|
|
17999 |
|
|
|
18000 |
//將body放到html裡面
|
|
|
18001 |
html.append(body);
|
|
|
18002 |
|
|
|
18003 |
//置換畫面為新的內榮
|
|
|
18004 |
document.replaceChildren(html);
|
|
|
18005 |
|
|
|
18006 |
置換網頁整體內容 - en
|
|
|
18007 |
|
|
|
18008 |
//參考資料
|
|
|
18009 |
//https://developer.mozilla.org/en-US/docs/Web/API/Document/replaceChildren
|
|
|
18010 |
|
| 3 |
liveuser |
18011 |
*/
|
|
|
18012 |
|
|
|
18013 |
?>
|