キケッツ掲示板のリポジトリです. https://bbs.kekec.wiki
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

1291 lines
45 KiB

  1. // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  2. //
  3. // 【 カラーパレットPOPアップ 】 http://www.cman.jp
  4. //
  5. // 商用,改変,再配布はすべて自由ですですが、動作保証はありません
  6. //
  7. // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  8. // maintenance history
  9. //
  10. // Ver Date contents
  11. // 1.0 2015/7/15 New
  12. // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  13. //
  14. // 使用方法
  15. // htmlのタグに以下の設定をしてください
  16. //
  17. // 「 onclick="cmanCP_JS_open(this)" cmanCPat="rc_text:id001,下記URL参照"> 」
  18. //
  19. //
  20. // 【注意】
  21. // 引数やユーザ設定内容についてはノーチェックです
  22. // 解析しやすいようにコメントを多く入れています。
  23. // JavaScriptのファイルサイズを削減する場合は、コメントやスペースを消してください。
  24. //
  25. //
  26. // 詳細は以下でご確認ください
  27. // https://web-designer.cman.jp/javascript_ref/color/palette/
  28. //
  29. // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  30. var cmanCP_VAR = {};
  31. // =========================================================================================
  32. // カラーパレットの作成
  33. // =========================================================================================
  34. function cmanCP_JS_open(argThis){
  35. // カラーリスト一覧
  36. var wColorList =[ '#ffffff','#cccccc','#a6a6a6','#7f7f7f','#595959','#333333','#000000',
  37. '#ff9999','#ff4d4d','#ff0000','#b30000','#660000',
  38. '#ffcc99','#ffa64d','#ff7f00','#b35900','#663300',
  39. '#ffff99','#ffff4d','#ffff00','#b3b300','#666600',
  40. '#ccff99','#a6ff4d','#7fff00','#59b300','#336600',
  41. '#99ff99','#4dff4d','#00ff00','#00b300','#006600',
  42. '#99ffcc','#4dffa6','#00ff7f','#00b359','#006633',
  43. '#99ffff','#4dffff','#00ffff','#00b3b3','#006666',
  44. '#99ccff','#4da6ff','#007fff','#0059b3','#003366',
  45. '#9999ff','#4d4dff','#0000ff','#0000b3','#000066',
  46. '#cc99ff','#a64dff','#7f00ff','#5900b3','#330066',
  47. '#ff99ff','#ff4dff','#ff00ff','#b300b3','#660066',
  48. '#ff99cc','#ff4da6','#ff007f','#b30059','#660033'
  49. ];
  50. cmanCP_VAR["popId"] = 'cmanCP_POP'; // POP枠のID
  51. var wRGB_List = [ 'R', 'G', 'B' ];
  52. var wRGB_TitleJP = [ '赤み', '緑み', '青み' ];
  53. var wRGB_TitleEn = [ 'red', 'green', 'blue' ];
  54. var wHSL_List = [ 'H', 'S', 'L' ];
  55. var wHSL_TitleJP = [ '色相', '彩度', '輝度' ];
  56. var wHSL_Max = [ '359', '1', '1' ];
  57. var wHSL_Step = [ '1', '0.001', '0.001' ];
  58. var wA_TitleJP = '不透明度';
  59. // ----- 属性取得 ------------------------------------------------------------
  60. var wAttr = argThis.getAttribute("cmanCPat").split(",");
  61. for(var i=0; i<wAttr.length; i++){
  62. if(wAttr[i] != ""){
  63. var wAttrItem = wAttr[i].split(":");
  64. wAttrItem[0] = cmanCP_JS_zen_TO_han(wAttrItem[0]).toLowerCase();
  65. wAttrItem[1] = cmanCP_JS_zen_TO_han(wAttrItem[1]);
  66. switch (wAttrItem[0]){
  67. case 'def_size' :
  68. case 'def_color':
  69. case 'def_tab' :
  70. case 'def_alpha':
  71. case 'rc_form' :
  72. case 'rc_func' :
  73. cmanCP_VAR[wAttrItem[0]] = wAttrItem[1];
  74. break;
  75. case 'rc_text' :
  76. case 'rc_bg' :
  77. if(cmanCP_VAR[wAttrItem[0]] != ''){
  78. cmanCP_VAR[wAttrItem[0]] += ',' + wAttrItem[1];
  79. }else{
  80. cmanCP_VAR[wAttrItem[0]] = wAttrItem[1];
  81. }
  82. break;
  83. }
  84. }
  85. }
  86. // ----- CSS定義 ------------------------------------------------------------
  87. var wCss = '<style type="text/css">';
  88. wCss += '.cmanCP_CSS_ALL{' +
  89. 'font-family:"Osaka?等幅","MS ゴシック","monospace";' +
  90. 'font-size: 10pt;' +
  91. 'color: #333;' +
  92. 'padding: 0;' +
  93. 'background-color: #fff;' +
  94. 'border: 1px solid #666;' +
  95. 'box-shadow: 10px 10px 10px rgba(0,0,0,0.4);' +
  96. '}';
  97. wCss += '.cmanCP_CSS_CL{' +
  98. 'cursor: pointer;' +
  99. 'width: 19px;' +
  100. 'height: 19px;' +
  101. 'margin: 1px;' +
  102. 'float: left; ' +
  103. 'border: 1px solid #ccc;' +
  104. '}';
  105. wCss += '.cmanCP_CSS_CL:hover{' +
  106. 'box-shadow: none;' +
  107. '}';
  108. wCss += '.cmanCP_CSS_select{' +
  109. 'cursor: pointer;' +
  110. 'box-shadow: 3px 3px 2px rgba(0,0,0,0.5);' +
  111. '}';
  112. wCss += '.cmanCP_CSS_select:hover{' +
  113. 'box-shadow: none;' +
  114. '}';
  115. wCss += '.cmanCP_CSS_Tbl{' +
  116. 'background-color: #fff;' +
  117. 'border-collapse: collapse;' +
  118. 'color: #333333;' +
  119. '}';
  120. wCss += '.cmanCP_CSS_Tbl td{' +
  121. 'border: 1px #999 solid;' +
  122. 'padding: 8px 2px;' +
  123. 'letter-spacing: 1px;' +
  124. 'font-size:9pt;' +
  125. 'text-align: center;' +
  126. '}';
  127. wCss += '.cmanCP_CSS_Tab {' +
  128. 'cursor: pointer;' +
  129. 'float: left;' +
  130. 'width: 88px;' +
  131. 'font-weight:bold;' +
  132. 'text-align: center;' +
  133. 'padding-top: 5px;' +
  134. 'padding-bottom: 5px;' +
  135. 'border-left: 1px solid #999;' +
  136. 'border-top: 1px solid #999;' +
  137. 'border-right: 1px solid #999;' +
  138. 'border-top-left-radius: 6px;' +
  139. 'border-top-right-radius: 6px;' +
  140. '-webkit-border-top-left-radius: 6px;' +
  141. '-webkit-border-top-right-radius: 6px;' +
  142. '-moz-border-radius-topleft: 6px;' +
  143. '-moz-border-radius-topright: 6px;' +
  144. '}';
  145. wCss += '.cmanCP_CSS_TabS {' +
  146. 'color: #fff;' +
  147. 'background-color: #999;' +
  148. '}';
  149. wCss += '.cmanCP_CSS_TabN {' +
  150. 'color: #666;' +
  151. 'background-color: #ddd;' +
  152. '}';
  153. wCss += '.cmanCP_CSS_TabN:hover {' +
  154. 'color: #0063dc;' +
  155. '}';
  156. wCss += '#'+cmanCP_VAR["popId"]+' input[type="text"],input[type="number"]{' +
  157. 'width: 100%;' +
  158. 'max-width: 75px;' +
  159. 'height: 20px;' +
  160. 'font-weight :bold;' +
  161. 'color: #333333;' +
  162. 'vertical-align: middle;' +
  163. 'text-align: center;' +
  164. 'letter-spacing: 1px;' +
  165. 'ime-mode: disabled;' +
  166. 'border: 1px #cccccc solid;' +
  167. 'background-color: #EEFFFF;' +
  168. 'text-align: center;' +
  169. '}';
  170. wCss += '#'+cmanCP_VAR["popId"]+' input[type="range"]{' +
  171. 'width: 96%;' +
  172. 'height: 20px;' +
  173. '}';
  174. wCss += '.cmanCP_CSS_range{' +
  175. 'padding: 0;' +
  176. '}';
  177. wCss += '.cmanCP_CSS_Gaid{' +
  178. 'margin-left: auto;' +
  179. 'margin-right: auto;' +
  180. 'width: 96%;' +
  181. 'height: 5px;' +
  182. '}';
  183. wCss += '.cmanCP_CSS_GaidHSL{' +
  184. 'float: left;' +
  185. 'width: 5%;' +
  186. 'height: 5px;' +
  187. '}';
  188. wCss += '.cmanCP_CSS_sbg0{' +
  189. 'background-color: #fff;' +
  190. 'height: 12px;' +
  191. '}';
  192. wCss += '.cmanCP_CSS_sbg1{' +
  193. 'background-color: #ddd;' +
  194. 'height: 12px;' +
  195. '}';
  196. wCss += '</style>';
  197. // ----- HTML定義 ------------------------------------------------------------
  198. var wHtml = '';
  199. // ----- 表題 -----
  200. wHtml += '<div>' +
  201. '<div style="position: absolute; top:2px; left:2px;width: 18px;height: 18px;margin-right:3px;margin-left: auto;background-color: #ccc;cursor: pointer;" onclick="cmanCP_JS_close();">' +
  202. '<svg viewBox="0 0 14 14">' +
  203. '<path stroke="#666" stroke-width="2" fill="none" d="M 3 3 L 11 11 , M 3 11 L 11 3">' +
  204. '</svg>' +
  205. '</div>' +
  206. '<div style="text-align: center;padding: 2px 10px;font-weight:bold;color: #666;background-color: #eee;border-bottom: 1px solid #999;cursor: pointer;" id="cmanCP_ID_title">' +
  207. '色を選んでね♥' +
  208. '</div>' +
  209. '</div>';
  210. // ----- サンプル&カラーリスト -----
  211. wHtml += '<div style="margin: 10px 0;clear: both;">' +
  212. '<table style="width: 100%;border:0px;border-spacing: 0;letter-spacing:0;padding:0;">' +
  213. '<tr>' +
  214. '<td>' +
  215. '<div class="cmanCP_CSS_select" style="margin:0 10px 5px 10px;" onclick="cmanCP_JS_select()">' +
  216. '<div style="width: 90px;height: 52px;padding:2px;position: relative;overflow:hidden;">' +
  217. '<table style="width: 100%;border:0px;border-spacing: 0;letter-spacing:0;padding:0;">' +
  218. '<tr><td class="cmanCP_CSS_sbg1"></td><td class="cmanCP_CSS_sbg0"></td><td class="cmanCP_CSS_sbg1"></td><td class="cmanCP_CSS_sbg0"></td><td class="cmanCP_CSS_sbg1"></td></tr>' +
  219. '<tr><td class="cmanCP_CSS_sbg0"></td><td class="cmanCP_CSS_sbg1"></td><td class="cmanCP_CSS_sbg0"></td><td class="cmanCP_CSS_sbg1"></td><td class="cmanCP_CSS_sbg0"></td></tr>' +
  220. '<tr><td class="cmanCP_CSS_sbg1"></td><td class="cmanCP_CSS_sbg0"></td><td class="cmanCP_CSS_sbg1"></td><td class="cmanCP_CSS_sbg0"></td><td class="cmanCP_CSS_sbg1"></td></tr>' +
  221. '<tr><td class="cmanCP_CSS_sbg0"></td><td class="cmanCP_CSS_sbg1"></td><td class="cmanCP_CSS_sbg0"></td><td class="cmanCP_CSS_sbg1"></td><td class="cmanCP_CSS_sbg0"></td></tr>' +
  222. '<tr><td class="cmanCP_CSS_sbg1"></td><td class="cmanCP_CSS_sbg0"></td><td class="cmanCP_CSS_sbg1"></td><td class="cmanCP_CSS_sbg0"></td><td class="cmanCP_CSS_sbg1"></td></tr>' +
  223. '</table>' +
  224. '<div style="position: absolute; top:0px; left:0px;width: 90px;height: 52px;border: 2px solid #ccc;margin: 0 auto 0 auto;" id="cmanCP_ID_sample">' +
  225. '</div>' +
  226. '</div>' +
  227. '</div>' +
  228. '<div class="cmanCP_CSS_select" style="width: 90px;border: 1px solid #999;font-size:80%;margin: 0 auto;text-align: center;padding-top:2px;padding-bottom:2px;" onclick="cmanCP_JS_select()">この色を選択</div>' +
  229. '</td>' +
  230. '<td style="text-align: right;line-height: 0;padding-left: 5px;">';
  231. for(var i=0; i<wColorList.length; i++){
  232. wHtml += '<div onclick="cmanCP_JS_csel(this)" style="background-color:'+wColorList[i]+'" class="cmanCP_CSS_CL"> </div>'; // 選択カラーリスト
  233. }
  234. wHtml += '</td>' +
  235. '</tr>' +
  236. '</table>' +
  237. '</div>';
  238. // ----- 色の文字列表示 -----
  239. wHtml += '<div style="clear: both;margin: 5px 5px 10px 5px;padding:5px;font-size: 110%;border: 1px solid #999;font-weight:bold;text-align: left;" id="cmanCP_ID_outstr">';
  240. wHtml += '</div>';
  241. // ----- レンジバー -----
  242. wHtml += '<!-- -->';
  243. wHtml += '<div style="margin: 5px 5px 0 5px;">';
  244. wHtml += '<!-- タブ -->';
  245. wHtml += '<div class="cmanCP_CSS_Tab cmanCP_CSS_TabN" id="cmanCP_ID_tab_RGB16" onclick="cmanCP_JS_tanCng(\'RGB16\');">RGB(16)</div>';
  246. wHtml += '<div class="cmanCP_CSS_Tab cmanCP_CSS_TabN" id="cmanCP_ID_tab_RGB" style="margin-left: 5px;" onclick="cmanCP_JS_tanCng(\'RGB\');">RGB(255)</div>';
  247. wHtml += '<div class="cmanCP_CSS_Tab cmanCP_CSS_TabN" id="cmanCP_ID_tab_HSL" style="margin-left: 5px;" onclick="cmanCP_JS_tanCng(\'HSL\');">HSL</div>';
  248. wHtml += '<!-- カラーレンジ -->';
  249. wHtml += '<div style="clear: both;border: 3px solid #999">';
  250. wHtml += '<table border="0" cellspacing="0" class="cmanCP_CSS_Tbl" style="width: 100%;margin-top:0;">';
  251. wHtml += '<colgroup span="1" style="width:15%;"></colgroup>';
  252. wHtml += '<colgroup span="1" style="width:25%;"></colgroup>';
  253. wHtml += '<colgroup span="1" style="width:60%;"></colgroup>';
  254. wHtml += '<tbody>';
  255. wHtml += '<!-- RGB -->';
  256. // --- RGB ---
  257. for(var i=0; i<=2; i++){
  258. wHtml += '<tr id="cmanCP_ID_aRGB_'+wRGB_List[i]+'">';
  259. wHtml += '<td>'+wRGB_TitleJP[i]+'</td>';
  260. wHtml += '<td>';
  261. wHtml += '<input type="number" min="0" max="255" step="1" maxlength="3" id="cmanCP_ID_t'+wRGB_List[i]+'" onchange="cmanCP_JS_textCng(\'RGB\')" onInput="cmanCP_JS_textCng(\'RGB\')">';
  262. wHtml += '<input type="text" maxlength="2" id="cmanCP_ID_t'+wRGB_List[i]+'16" onchange="cmanCP_JS_textCng(\'RGB16\')" onInput="cmanCP_JS_textCng(\'RGB16\')">';
  263. wHtml += '</td>';
  264. wHtml += '<td style="line-height: 1em;">';
  265. wHtml += '<input type="range" min="0" max="255" step="1" class="cmanCP_CSS_range" id="cmanCP_ID_r'+wRGB_List[i]+'" onchange="cmanCP_JS_rangeCng(\'RGB\')" onInput="cmanCP_JS_rangeCng(\'RGB\')">';
  266. wHtml += '<div class="cmanCP_CSS_Gaid" style="background: linear-gradient(to right, #fff, '+wRGB_TitleEn[i]+');"></div>';
  267. wHtml += '</td>';
  268. wHtml += '</tr>';
  269. }
  270. // --- HSL ---
  271. for(var i=0; i<=2; i++){
  272. wHtml += '<tr id="cmanCP_ID_aHSL_'+wHSL_List[i]+'">';
  273. wHtml += '<td>'+wHSL_TitleJP[i]+'</td>';
  274. wHtml += '<td>';
  275. wHtml += '<input type="number" min="0" max="'+wHSL_Max[i]+'" step="'+wHSL_Step[i]+'" maxlength="3" id="cmanCP_ID_t'+wHSL_List[i]+'" onchange="cmanCP_JS_textCng(\'HSL\')" onInput="cmanCP_JS_textCng(\'HSL\')">';
  276. wHtml += '</td>';
  277. wHtml += '<td style="line-height: 1em;">';
  278. wHtml += '<input type="range" min="0" max="'+wHSL_Max[i]+'" step="'+wHSL_Step[i]+'" class="cmanCP_CSS_range" id="cmanCP_ID_r'+wHSL_List[i]+'" onchange="cmanCP_JS_rangeCng(\'HSL\')" onInput="cmanCP_JS_rangeCng(\'HSL\')">';
  279. wHtml += '<div class="cmanCP_CSS_Gaid">';
  280. for(var j=1; j<=20; j++){
  281. wHtml += '<div class="cmanCP_CSS_GaidHSL" id="cmanCP_ID_gHSL_'+wHSL_List[i]+j+'"></div>';
  282. }
  283. wHtml += '</div>';
  284. wHtml += '</td>';
  285. wHtml += '</tr>';
  286. }
  287. // --- 透明 ---
  288. wHtml += '<tr id="cmanCP_ID_aA">';
  289. wHtml += '<td>'+wA_TitleJP+'</td>';
  290. wHtml += '<td>';
  291. wHtml += '<input type="number" min="0" max="1" step="0.01" maxlength="3" id="cmanCP_ID_tA" onchange="cmanCP_JS_textCng(\'A\')" onInput="cmanCP_JS_textCng(\'A\')">';
  292. wHtml += '</td>';
  293. wHtml += '<td style="line-height: 1em;">';
  294. wHtml += '<input type="range" min="0" max="1" step="0.01" value="1" class="cmanCP_CSS_range" id="cmanCP_ID_rA" onchange="cmanCP_JS_rangeCng(\'A\')" onInput="cmanCP_JS_rangeCng(\'A\')">';
  295. wHtml += '<div class="cmanCP_CSS_Gaid" style="background: linear-gradient(to right, #fff, #000);"></div>';
  296. wHtml += '</td>';
  297. wHtml += '</tr>';
  298. wHtml += '</tbody>';
  299. wHtml += '</table>';
  300. wHtml += '</div>';
  301. wHtml += '</div>';
  302. wHtml += '<div style="text-align: right;font-size: 80%;padding-right: 5px;color:#666">' +
  303. 'パクリ元:' +
  304. '<a href="http://web-designer.cman.jp/javascript_ref/color/palette/" target="_blank" style="color:#666;font-weight:normal;">web-designer.cman.jp</a>' +
  305. '</div>';
  306. // ----- 表示枠の作成&割り当て -----------------------------------
  307. if(document.getElementById(cmanCP_VAR["popId"])){
  308. document.getElementById(cmanCP_VAR["popId"]).style.display = "none";
  309. }else{
  310. var wEle = document.createElement("div"); // 新規に要素(タグ)を生成
  311. wEle.id = cmanCP_VAR["popId"];
  312. wEle.style.display = "none";
  313. wEle.style.position = 'fixed';
  314. document.body.appendChild(wEle); // このページ (document.body) の最後に生成した要素を追加
  315. }
  316. // ----- カラーポップをの初期設定 ---------------------------------
  317. cmanCP_VAR["objPop"] = document.getElementById(cmanCP_VAR["popId"]);
  318. cmanCP_VAR["objPop"].innerHTML = wCss+"\n"+wHtml;
  319. cmanCP_VAR["objPop"].style.opacity = 0;
  320. cmanCP_VAR["objPop"].className = 'cmanCP_CSS_ALL';
  321. cmanCP_VAR["objPop"].style.left = '0px';
  322. cmanCP_VAR["objPop"].style.top = '0px';
  323. // ----- オブジェクトの設定 ---------------------------------------
  324. cmanCP_VAR["obj_tR16"] = document.getElementById("cmanCP_ID_tR16");
  325. cmanCP_VAR["obj_tG16"] = document.getElementById("cmanCP_ID_tG16");
  326. cmanCP_VAR["obj_tB16"] = document.getElementById("cmanCP_ID_tB16");
  327. cmanCP_VAR["obj_tR"] = document.getElementById("cmanCP_ID_tR");
  328. cmanCP_VAR["obj_tG"] = document.getElementById("cmanCP_ID_tG");
  329. cmanCP_VAR["obj_tB"] = document.getElementById("cmanCP_ID_tB");
  330. cmanCP_VAR["obj_tH"] = document.getElementById("cmanCP_ID_tH");
  331. cmanCP_VAR["obj_tS"] = document.getElementById("cmanCP_ID_tS");
  332. cmanCP_VAR["obj_tL"] = document.getElementById("cmanCP_ID_tL");
  333. cmanCP_VAR["obj_tA"] = document.getElementById("cmanCP_ID_tA");
  334. cmanCP_VAR["obj_rR"] = document.getElementById("cmanCP_ID_rR");
  335. cmanCP_VAR["obj_rG"] = document.getElementById("cmanCP_ID_rG");
  336. cmanCP_VAR["obj_rB"] = document.getElementById("cmanCP_ID_rB");
  337. cmanCP_VAR["obj_rH"] = document.getElementById("cmanCP_ID_rH");
  338. cmanCP_VAR["obj_rS"] = document.getElementById("cmanCP_ID_rS");
  339. cmanCP_VAR["obj_rL"] = document.getElementById("cmanCP_ID_rL");
  340. cmanCP_VAR["obj_rA"] = document.getElementById("cmanCP_ID_rA");
  341. // ----------------------------------------------------------------
  342. // パレットの初期設定
  343. // ----------------------------------------------------------------
  344. // ----- サイズの設定 ---------------------------------------------
  345. if('def_size' in cmanCP_VAR){
  346. cmanCP_VAR["def_size"] = cmanCP_VAR["def_size"].replace("px","");
  347. if(cmanCP_VAR["def_size"].toString().match(/^[0-9]+$/)){
  348. cmanCP_VAR["maxWidth"] = cmanCP_VAR["def_size"];
  349. }
  350. }
  351. if('maxWidth' in cmanCP_VAR){
  352. }else{
  353. cmanCP_VAR["maxWidth"] = 530;
  354. }
  355. cmanCP_VAR["objPop"].style.maxWidth = cmanCP_VAR["maxWidth"]+'px';
  356. // ----- 初期カラー設定 -------------------------------------------
  357. var wDefColorSet = '';
  358. var wDefColor = '';
  359. if('def_color' in cmanCP_VAR){
  360. try{
  361. if (cmanCP_VAR["def_color"].indexOf('cns=') == 0){wDefColor = cmanCP_VAR["def_color"].substr(4);}
  362. else{
  363. var wObjDefColor = document.getElementById(cmanCP_VAR["def_color"].substr(4));
  364. if(wObjDefColor){
  365. if (cmanCP_VAR["def_color"].indexOf('val=') == 0){wDefColor = wObjDefColor.value;}
  366. else if (cmanCP_VAR["def_color"].indexOf('txt=') == 0){wDefColor = wObjDefColor.innerText;}
  367. else if (cmanCP_VAR["def_color"].indexOf('col=') == 0){wDefColor = wObjDefColor.style.color;}
  368. else if (cmanCP_VAR["def_color"].indexOf('bgc=') == 0){wDefColor = wObjDefColor.style.backgroundColor;}
  369. wDefColor = cmanCP_JS_zen_TO_han(wDefColor.toLowerCase());
  370. }
  371. }
  372. }
  373. catch(e){
  374. wDefColor = "";
  375. }
  376. }
  377. if (wDefColor == ""){
  378. }
  379. else if (wDefColor.substr(0,1) == '#'){
  380. if(wDefColor.substr(1).toString().match(/^[0-9a-f]+$/i)){
  381. switch (wDefColor.length){
  382. case 4:
  383. cmanCP_VAR["obj_tR16"].value = wDefColor.substr(1,1).toString() + wDefColor.substr(1,1).toString();
  384. cmanCP_VAR["obj_tG16"].value = wDefColor.substr(2,1).toString() + wDefColor.substr(2,1).toString();
  385. cmanCP_VAR["obj_tB16"].value = wDefColor.substr(3,1).toString() + wDefColor.substr(3,1).toString();
  386. wDefColorSet = 'RGB16';
  387. break;
  388. case 7:
  389. cmanCP_VAR["obj_tR16"].value = wDefColor.substr(1,2).toString();
  390. cmanCP_VAR["obj_tG16"].value = wDefColor.substr(3,2).toString();
  391. cmanCP_VAR["obj_tB16"].value = wDefColor.substr(5,2).toString();
  392. wDefColorSet = 'RGB16';
  393. break;
  394. }
  395. }
  396. }
  397. else if (wDefColor.indexOf('rgb(') == 0){
  398. wDefColor = wDefColor.replace('rgb(','');
  399. wDefColor = wDefColor.replace(')','');
  400. var wSplit = wDefColor.split(',');
  401. if(wSplit.length == 3){
  402. cmanCP_VAR["obj_tR"].value = wSplit[0];
  403. cmanCP_VAR["obj_tG"].value = wSplit[1];
  404. cmanCP_VAR["obj_tB"].value = wSplit[2];
  405. wDefColorSet = 'RGB';
  406. }
  407. }
  408. else if (wDefColor.indexOf('rgba(') == 0){
  409. wDefColor = wDefColor.replace('rgba(','');
  410. wDefColor = wDefColor.replace(')','');
  411. var wSplit = wDefColor.split(',');
  412. if(wSplit.length == 4){
  413. cmanCP_VAR["obj_tR"].value = wSplit[0];
  414. cmanCP_VAR["obj_tG"].value = wSplit[1];
  415. cmanCP_VAR["obj_tB"].value = wSplit[2];
  416. cmanCP_VAR["obj_tA"].value = wSplit[3];
  417. wDefColorSet = 'RGB';
  418. }
  419. }
  420. else if (wDefColor.indexOf('hsl(') == 0){
  421. wDefColor = wDefColor.replace('hsl(','');
  422. wDefColor = wDefColor.replace('%','');
  423. wDefColor = wDefColor.replace(')','');
  424. var wSplit = wDefColor.split(',');
  425. if(wSplit.length == 3){
  426. cmanCP_VAR["obj_tH"].value = wSplit[0];
  427. cmanCP_VAR["obj_tS"].value = parseFloat(wSplit[1])/100;
  428. cmanCP_VAR["obj_tL"].value = parseFloat(wSplit[2])/100;
  429. wDefColorSet = 'HSL';
  430. }
  431. }
  432. else if (wDefColor.indexOf('hsla(') == 0){
  433. wDefColor = wDefColor.replace('hsla(','');
  434. wDefColor = wDefColor.replace('%','');
  435. wDefColor = wDefColor.replace(')','');
  436. var wSplit = wDefColor.split(',');
  437. if(wSplit.length == 3){
  438. cmanCP_VAR["obj_tH"].value = wSplit[0];
  439. cmanCP_VAR["obj_tS"].value = parseFloat(wSplit[1])/100;
  440. cmanCP_VAR["obj_tL"].value = parseFloat(wSplit[2])/100;
  441. cmanCP_VAR["obj_tA"].value = wSplit[3];
  442. wDefColorSet = 'HSL';
  443. }
  444. }
  445. if(wDefColorSet == ""){
  446. cmanCP_VAR["obj_tR16"].value = "ff";
  447. cmanCP_VAR["obj_tG16"].value = "80";
  448. cmanCP_VAR["obj_tB16"].value = "0";
  449. wDefColorSet = 'RGB16';
  450. }
  451. if(cmanCP_VAR["obj_tA"].value == ''){
  452. cmanCP_VAR["obj_tA"].value = '1';
  453. }
  454. cmanCP_JS_textCng(wDefColorSet);
  455. // ----- 初期TAB設定 ----------------------------------------------
  456. var wDefTab = '';
  457. if('def_tab' in cmanCP_VAR){
  458. wDefTab = cmanCP_VAR['def_tab'].toUpperCase();
  459. }
  460. switch (wDefTab){
  461. case 'RGB':
  462. case 'RGB16':
  463. case 'HSL':
  464. cmanCP_JS_tanCng(wDefTab); break;
  465. default:
  466. cmanCP_JS_tanCng('HSL'); break; // DEBUG時はコメント
  467. }
  468. // ----- 透明の表示設定 ----------------------------------------------
  469. var wDefAlpha = '';
  470. if('def_alpha' in cmanCP_VAR){
  471. wDefAlpha = cmanCP_VAR['def_alpha'];
  472. }
  473. if(wDefAlpha == '0'){
  474. document.getElementById('cmanCP_ID_aA').style.display = 'none';
  475. }else{
  476. document.getElementById('cmanCP_ID_aA').style.display = '';
  477. }
  478. // ----- サイズ取得のため透明のまま表示 ---------------------------
  479. cmanCP_VAR["objPop"].style.display = "";
  480. // ----- 表示位置設定 ---------------------------------------------
  481. if(cmanCP_VAR["objPop"].scrollWidth >= document.documentElement.clientWidth){
  482. cmanCP_VAR["objPop"].style.left = '0px';
  483. }else{
  484. cmanCP_VAR["objPop"].style.left = Math.round((document.documentElement.clientWidth - cmanCP_VAR["objPop"].scrollWidth) / 2) + 'px';
  485. }
  486. if(cmanCP_VAR["objPop"].scrollHeight >= document.documentElement.clientHeight){
  487. cmanCP_VAR["objPop"].style.top = '0px';
  488. }else{
  489. cmanCP_VAR["objPop"].style.top = Math.round((document.documentElement.clientHeight - cmanCP_VAR["objPop"].scrollHeight) / 2) + 'px';
  490. }
  491. // ----- 移動イベント登録 -----------------------------------------
  492. document.getElementById('cmanCP_ID_title').onmousedown = cmanCP_JS_mdown;
  493. document.getElementById('cmanCP_ID_title').onmouseup = cmanCP_JS_mup;
  494. document.getElementById('cmanCP_ID_title').onmousemove = cmanCP_JS_mmove;
  495. document.getElementById('cmanCP_ID_title').onmouseout = cmanCP_JS_mout;
  496. // ----- 透明解除 -------------------------------------------------
  497. cmanCP_VAR["objPop"].style.opacity = 1;
  498. cmanCP_ID_title
  499. }
  500. // =========================================================================================
  501. // 閉じるボタンが押されたら
  502. // =========================================================================================
  503. function cmanCP_JS_close(){
  504. var wDelElm = document.getElementById(cmanCP_VAR["popId"]);
  505. document.body.removeChild(wDelElm);
  506. // ハッシュクリア
  507. for(var key in cmanCP_VAR){
  508. delete cmanCP_VAR[key];
  509. }
  510. }
  511. // =========================================================================================
  512. // 色リストが選択されたら
  513. // =========================================================================================
  514. function cmanCP_JS_csel(argObj){
  515. var wColor = argObj.style.backgroundColor.toString();
  516. var w16 = '';
  517. var wRcColor = '';
  518. if(wColor.substr(0,1) == '#'){
  519. wRcColor = argColor.substr(1);
  520. }
  521. else{
  522. //背景色の余計な文字列削除
  523. wColor = wColor.replace("rgb(","");
  524. wColor = wColor.replace(")","");
  525. //文字列分割
  526. var wColorSplit = wColor.split(",");
  527. //10進数を16進数に変換して連結
  528. for (var i = 0; i <= 2; i++) {
  529. w16 = parseInt(wColorSplit[i]).toString(16)
  530. if(w16.length == 1){
  531. wRcColor = wRcColor+'0'+w16;
  532. }else{
  533. wRcColor = wRcColor+w16;
  534. }
  535. }
  536. }
  537. cmanCP_VAR["obj_tR16"].value = wRcColor.substr(0,2);
  538. cmanCP_VAR["obj_tG16"].value = wRcColor.substr(2,2);
  539. cmanCP_VAR["obj_tB16"].value = wRcColor.substr(4,2);
  540. cmanCP_JS_textCng('RGB16');
  541. }
  542. // =========================================================================================
  543. // タブがクリックされたら
  544. // =========================================================================================
  545. function cmanCP_JS_tanCng(argID){
  546. var wTabCssS = 'cmanCP_CSS_Tab cmanCP_CSS_TabS';
  547. var wTabCssN = 'cmanCP_CSS_Tab cmanCP_CSS_TabN';
  548. if(document.getElementById('cmanCP_ID_tab_'+argID).className == wTabCssS){return;}
  549. var wObjTabRGB = document.getElementById('cmanCP_ID_tab_RGB');
  550. var wObjTabRGB16 = document.getElementById('cmanCP_ID_tab_RGB16');
  551. var wObjTabHSL = document.getElementById('cmanCP_ID_tab_HSL');
  552. var wObjTrRGB_R = document.getElementById('cmanCP_ID_aRGB_R');
  553. var wObjTrRGB_G = document.getElementById('cmanCP_ID_aRGB_G');
  554. var wObjTrRGB_B = document.getElementById('cmanCP_ID_aRGB_B');
  555. var wObjTrHSL_H = document.getElementById('cmanCP_ID_aHSL_H');
  556. var wObjTrHSL_S = document.getElementById('cmanCP_ID_aHSL_S');
  557. var wObjTrHSL_L = document.getElementById('cmanCP_ID_aHSL_L');
  558. switch (argID){
  559. case 'RGB':
  560. cmanCP_VAR["obj_tR"].style.display = "";
  561. cmanCP_VAR["obj_tG"].style.display = "";
  562. cmanCP_VAR["obj_tB"].style.display = "";
  563. cmanCP_VAR["obj_tR16"].style.display = "none";
  564. cmanCP_VAR["obj_tG16"].style.display = "none";
  565. cmanCP_VAR["obj_tB16"].style.display = "none";
  566. wObjTabRGB.className = wTabCssS;
  567. wObjTabRGB16.className = wTabCssN;
  568. wObjTabHSL.className = wTabCssN;
  569. break;
  570. case 'RGB16':
  571. cmanCP_VAR["obj_tR"].style.display = "none";
  572. cmanCP_VAR["obj_tG"].style.display = "none";
  573. cmanCP_VAR["obj_tB"].style.display = "none";
  574. cmanCP_VAR["obj_tR16"].style.display = "";
  575. cmanCP_VAR["obj_tG16"].style.display = "";
  576. cmanCP_VAR["obj_tB16"].style.display = "";
  577. wObjTabRGB.className = wTabCssN;
  578. wObjTabRGB16.className = wTabCssS;
  579. wObjTabHSL.className = wTabCssN;
  580. break;
  581. case 'HSL':
  582. wObjTabRGB.className = wTabCssN;
  583. wObjTabRGB16.className = wTabCssN;
  584. wObjTabHSL.className = wTabCssS;
  585. break;
  586. }
  587. switch (argID){
  588. case 'HSL':
  589. wObjTrRGB_R.style.display = "none";
  590. wObjTrRGB_G.style.display = "none";
  591. wObjTrRGB_B.style.display = "none";
  592. wObjTrHSL_H.style.display = "";
  593. wObjTrHSL_S.style.display = "";
  594. wObjTrHSL_L.style.display = "";
  595. break;
  596. default :
  597. wObjTrRGB_R.style.display = "";
  598. wObjTrRGB_G.style.display = "";
  599. wObjTrRGB_B.style.display = "";
  600. wObjTrHSL_H.style.display = "none";
  601. wObjTrHSL_S.style.display = "none";
  602. wObjTrHSL_L.style.display = "none";
  603. break;
  604. }
  605. }
  606. // =========================================================================================
  607. // レンジが変更された場合
  608. // =========================================================================================
  609. function cmanCP_JS_rangeCng(argID){
  610. switch (argID){
  611. case 'RGB':
  612. cmanCP_VAR["obj_tR"].value = cmanCP_VAR["obj_rR"].value;
  613. cmanCP_VAR["obj_tG"].value = cmanCP_VAR["obj_rG"].value;
  614. cmanCP_VAR["obj_tB"].value = cmanCP_VAR["obj_rB"].value;
  615. cmanCP_JS_textCng(argID);
  616. break;
  617. case 'HSL':
  618. cmanCP_VAR["obj_tH"].value = cmanCP_VAR["obj_rH"].value;
  619. cmanCP_VAR["obj_tS"].value = cmanCP_VAR["obj_rS"].value;
  620. cmanCP_VAR["obj_tL"].value = cmanCP_VAR["obj_rL"].value;
  621. cmanCP_JS_textCng(argID);
  622. break;
  623. case 'A':
  624. cmanCP_VAR["obj_tA"].value = cmanCP_VAR["obj_rA"].value;
  625. cmanCP_JS_textCng(argID);
  626. break;
  627. }
  628. }
  629. // =========================================================================================
  630. // テキスト入力が変更された場合
  631. // =========================================================================================
  632. function cmanCP_JS_textCng(argID){
  633. // テキストの整備
  634. switch (argID){
  635. case 'RGB16' : cmanCP_JS_rgb16_TO_rgb(); cmanCP_JS_rgb_TO_hsl(); break;
  636. case 'RGB' : cmanCP_JS_rgb_TO_rgb16(); cmanCP_JS_rgb_TO_hsl(); break;
  637. case 'HSL' : cmanCP_JS_hsl_TO_rgb(); cmanCP_JS_rgb_TO_rgb16(); break;
  638. case 'A' : cmanCP_JS_chk_a(); break;
  639. default : return; break;
  640. }
  641. // レンジの整備
  642. cmanCP_VAR["obj_rR"].value = cmanCP_VAR["obj_tR"].value;
  643. cmanCP_VAR["obj_rG"].value = cmanCP_VAR["obj_tG"].value;
  644. cmanCP_VAR["obj_rB"].value = cmanCP_VAR["obj_tB"].value;
  645. cmanCP_VAR["obj_rH"].value = cmanCP_VAR["obj_tH"].value;
  646. cmanCP_VAR["obj_rS"].value = cmanCP_VAR["obj_tS"].value;
  647. cmanCP_VAR["obj_rL"].value = cmanCP_VAR["obj_tL"].value;
  648. cmanCP_VAR["obj_rA"].value = cmanCP_VAR["obj_tA"].value;
  649. // サンプル更新
  650. cmanCP_JS_sampleCng();
  651. }
  652. // =========================================================================================
  653. // RGB16→RGB 設定
  654. // =========================================================================================
  655. function cmanCP_JS_rgb16_TO_rgb(){
  656. // RGB16の入力チェック&正規化
  657. cmanCP_VAR["obj_tR16"].value = cmanCP_JS_chk00toFF(cmanCP_VAR["obj_tR16"].value);
  658. cmanCP_VAR["obj_tG16"].value = cmanCP_JS_chk00toFF(cmanCP_VAR["obj_tG16"].value);
  659. cmanCP_VAR["obj_tB16"].value = cmanCP_JS_chk00toFF(cmanCP_VAR["obj_tB16"].value);
  660. // RGB置換
  661. cmanCP_VAR["obj_tR"].value = parseInt(cmanCP_VAR["obj_tR16"].value, 16);
  662. cmanCP_VAR["obj_tG"].value = parseInt(cmanCP_VAR["obj_tG16"].value, 16);
  663. cmanCP_VAR["obj_tB"].value = parseInt(cmanCP_VAR["obj_tB16"].value, 16);
  664. }
  665. // =========================================================================================
  666. // RGB→RGB16 設定
  667. // =========================================================================================
  668. function cmanCP_JS_rgb_TO_rgb16(){
  669. // RGBの入力チェック&正規化
  670. cmanCP_VAR["obj_tR"].value = cmanCP_JS_chk0to255(cmanCP_VAR["obj_tR"].value);
  671. cmanCP_VAR["obj_tG"].value = cmanCP_JS_chk0to255(cmanCP_VAR["obj_tG"].value);
  672. cmanCP_VAR["obj_tB"].value = cmanCP_JS_chk0to255(cmanCP_VAR["obj_tB"].value);
  673. // RGB16置換
  674. cmanCP_VAR["obj_tR16"].value = cmanCP_JS_chk00toFF(parseInt(cmanCP_VAR["obj_tR"].value).toString(16));
  675. cmanCP_VAR["obj_tG16"].value = cmanCP_JS_chk00toFF(parseInt(cmanCP_VAR["obj_tG"].value).toString(16));
  676. cmanCP_VAR["obj_tB16"].value = cmanCP_JS_chk00toFF(parseInt(cmanCP_VAR["obj_tB"].value).toString(16));
  677. }
  678. // =========================================================================================
  679. // RGB(10進数) → HSL
  680. // =========================================================================================
  681. function cmanCP_JS_rgb_TO_hsl(){
  682. var wR = parseInt(cmanCP_VAR["obj_tR"].value);
  683. var wG = parseInt(cmanCP_VAR["obj_tG"].value);
  684. var wB = parseInt(cmanCP_VAR["obj_tB"].value);
  685. var wMax = Math.max(wR, wG, wB);
  686. var wMin = Math.min(wR, wG, wB);
  687. var wH = 0;
  688. var wS = 0;
  689. var wL = 0;
  690. // --- 色相(H) ----------------------------------------------------------
  691. if (wMax == wMin) {}
  692. else if (wMax == wR) {wH = 60 * (( wG - wB ) / ( wMax - wMin ));}
  693. else if (wMax == wG) {wH = 60 * (( wB - wR ) / ( wMax - wMin )) + 120;}
  694. else {wH = 60 * (( wR - wG ) / ( wMax - wMin )) + 240;}
  695. if(wH < 0) {wH = wH + 360;}
  696. if(wH >= 360) {wH = 0;}
  697. // --- 輝度(L) ----------------------------------------------------------
  698. wL = ( wMax + wMin ) / 2;
  699. // --- 彩度(S) ----------------------------------------------------------
  700. if (wMax == wMin) {}
  701. else{
  702. if( wL <= (255 / 2) ) {wS = 255 * ( wMax -wMin ) / ( wMax + wMin );}
  703. else {wS = 255 * ( wMax -wMin ) / ( 2 * 255 - ( wMax + wMin ));}
  704. }
  705. // --- 色相(H)の整数化 -------------------------------------------------
  706. wH = Math.round(wH);
  707. // --- 彩度(S)の小数1桁整備(浮動小数のためテキストで処理) ------------
  708. wS = Math.round(wS / 255 * 1000).toString();
  709. if (wS == 0) {}
  710. else if (wS.length < 2) {wS = ''+'0.00'+wS;}
  711. else if (wS.length < 3) {wS = ''+'0.0'+wS;}
  712. else if (wS.length < 4) {wS = ''+'0.'+wS;}
  713. else {wS = wS.substr(0,1)+'.'+wS.substr(1);}
  714. // --- 輝度(L)の小数1桁整備(浮動小数のためテキストで処理) ------------
  715. wL = Math.round(wL / 255 * 1000).toString();
  716. if (wL == 0) {}
  717. else if (wL.length < 2) {wL = ''+'0.00'+wL;}
  718. else if (wL.length < 3) {wL = ''+'0.0'+wL;}
  719. else if (wL.length < 4) {wL = ''+'0.'+wL;}
  720. else {wL = wL.substr(0,1)+'.'+wL.substr(1);}
  721. // --- 変換結果を設定 --------------------------------------------------
  722. cmanCP_VAR["obj_tH"].value = wH;
  723. cmanCP_VAR["obj_tS"].value = wS;
  724. cmanCP_VAR["obj_tL"].value = wL;
  725. }
  726. // =========================================================================================
  727. // HSL → RGB(10進数)
  728. // =========================================================================================
  729. function cmanCP_JS_hsl_TO_rgb(){
  730. var wCal;
  731. // HSLの入力チェック&正規化
  732. cmanCP_VAR["obj_tH"].value = cmanCP_JS_chk0to359(cmanCP_VAR["obj_tH"].value);
  733. wCal = cmanCP_JS_chk0to1s3(cmanCP_VAR["obj_tS"].value);
  734. if(wCal.toString() != cmanCP_VAR["obj_tS"].value.toString()){cmanCP_VAR["obj_tS"].value = wCal;} // number対応
  735. wCal = cmanCP_JS_chk0to1s3(cmanCP_VAR["obj_tL"].value);
  736. if(wCal.toString() != cmanCP_VAR["obj_tL"].value.toString()){cmanCP_VAR["obj_tL"].value = wCal;} // number対応
  737. // HSLからRGB計算
  738. var wH = parseInt(cmanCP_VAR["obj_tH"].value);
  739. var wS = parseFloat(cmanCP_VAR["obj_tS"].value);
  740. var wL = parseFloat(cmanCP_VAR["obj_tL"].value);
  741. var wMax = 0;
  742. var wMin = 0;
  743. var wR = 0;
  744. var wG = 0;
  745. var wB = 0;
  746. wS = wS * 100;
  747. wL = wL * 100;
  748. if (wL < 50){
  749. wMax = 2.55 * ( wL + wL * (wS / 100));
  750. wMin = 2.55 * ( wL - wL * (wS / 100));
  751. }else{
  752. wMax = 2.55 * ( wL + ( 100 - wL) * (wS / 100));
  753. wMin = 2.55 * ( wL - ( 100 - wL) * (wS / 100));
  754. }
  755. if (wH < 60){
  756. wR = wMax;
  757. wG = (wH / 60) * (wMax - wMin ) + wMin;
  758. wB = wMin;
  759. }else if(wH < 120){
  760. wR = (( 120 - wH ) / 60 ) * ( wMax - wMin ) + wMin;
  761. wG = wMax;
  762. wB = wMin;
  763. }else if(wH < 180){
  764. wR = wMin;
  765. wG = wMax;
  766. wB = (( wH - 120 ) / 60 ) * ( wMax - wMin ) + wMin;
  767. }else if(wH < 240){
  768. wR = wMin;
  769. wG = (( 240 - wH ) / 60 ) * ( wMax - wMin ) + wMin;
  770. wB = wMax;
  771. }else if(wH < 300){
  772. wR = (( wH - 240 ) / 60 ) * ( wMax - wMin ) + wMin;
  773. wG = wMin;
  774. wB = wMax;
  775. }else{
  776. wR = wMax;
  777. wG = wMin;
  778. wB = (( 360 - wH ) / 60 ) * ( wMax - wMin ) + wMin;
  779. }
  780. // --- 色相(H)の整数化 -------------------------------------------------
  781. wR = Math.round(wR);
  782. wG = Math.round(wG);
  783. wB = Math.round(wB);
  784. // --- 変換結果を設定 --------------------------------------------------
  785. cmanCP_VAR["obj_tR"].value = wR;
  786. cmanCP_VAR["obj_tG"].value = wG;
  787. cmanCP_VAR["obj_tB"].value = wB;
  788. }
  789. // =========================================================================================
  790. // Aはチェック&正規化 設定
  791. // =========================================================================================
  792. function cmanCP_JS_chk_a(){
  793. var wCal = cmanCP_JS_chk0to1s2(cmanCP_VAR["obj_tA"].value);
  794. if(wCal.toString() != cmanCP_VAR["obj_tA"].value.toString()){cmanCP_VAR["obj_tA"].value = wCal;} // number対応
  795. }
  796. // =========================================================================================
  797. // 16進数チェック&正規化(0~ff)
  798. // =========================================================================================
  799. function cmanCP_JS_chk00toFF(arg16){
  800. var wChkStr = cmanCP_JS_zen_TO_han(arg16);
  801. var wRc = 0;
  802. var wStrPos = 0;
  803. if(wChkStr.toString().match(/^[0-9a-f]+$/i)){
  804. wRc = parseInt(wChkStr, 16);
  805. if(wRc < 0) {wRc = 0;}
  806. if(wRc > 255) {wRc = 255;}
  807. wRc = parseInt(wRc).toString(16);
  808. if(wRc.length == 1){wRc = '0'+wRc;}
  809. }
  810. return wRc;
  811. }
  812. // =========================================================================================
  813. // 10進数チェック&正規化(0~255)
  814. // =========================================================================================
  815. function cmanCP_JS_chk0to255(arg10){
  816. var wChkStr = cmanCP_JS_zen_TO_han(arg10);
  817. var wRc = 0;
  818. if(wChkStr.toString().match(/^[0-9]+$/)){
  819. wRc = parseInt(wChkStr);
  820. if(wRc < 0) {wRc = 0;}
  821. if(wRc > 255) {wRc = 255;}
  822. }
  823. return wRc;
  824. }
  825. // =========================================================================================
  826. // 10進数チェック&正規化(0~359)
  827. // =========================================================================================
  828. function cmanCP_JS_chk0to359(arg10){
  829. var wChkStr = cmanCP_JS_zen_TO_han(arg10);
  830. var wRc = 0;
  831. if(wChkStr.toString().match(/^[0-9]+$/)){
  832. wRc = parseInt(wChkStr);
  833. if(wRc < 0) {wRc = 0;}
  834. if(wRc > 359) {wRc = 359;}
  835. }
  836. return wRc;
  837. }
  838. // =========================================================================================
  839. // 10進数チェック(0~1,0.1刻み)
  840. // =========================================================================================
  841. function cmanCP_JS_chk0to100s1(arg10){
  842. var wChkStr = cmanCP_JS_zen_TO_han(arg10);
  843. var wRc = 0;
  844. if(wChkStr.toString().match(/^[0-9]+(\.[0-9]+)?$/)){
  845. wRc = Math.round(parseFloat(wChkStr) * 10) / 10;
  846. if(wRc < 0) {wRc = 0;}
  847. if(wRc > 100) {wRc = 100;}
  848. wRc = wRc.toString();
  849. wPos = wRc.indexOf('.');
  850. if(wPos < 0){
  851. }else{
  852. wRc = wRc.substr(0,wPos)+'.'+wRc.substr(wPos+1,1);
  853. }
  854. }
  855. return wRc;
  856. }
  857. // =========================================================================================
  858. // 10進数チェック(0~1,0.01刻み)
  859. // =========================================================================================
  860. function cmanCP_JS_chk0to1s2(arg10){
  861. var wChkStr = cmanCP_JS_zen_TO_han(arg10);
  862. var wRc = 0;
  863. if(wChkStr != ''){
  864. if(wChkStr.toString().match(/^[0-9]+\.$/)){
  865. wRc = wChkStr;
  866. }
  867. else if(wChkStr.toString().match(/^[0-9]+\.0$/)){
  868. wRc = wChkStr;
  869. }
  870. else if(wChkStr.toString().match(/^[0-9]+(\.[0-9]+)?$/)){
  871. wRc = Math.round(parseFloat(wChkStr) * 100) / 100;
  872. if(wRc < 0) {wRc = 0;}
  873. if(wRc > 1) {wRc = 1;}
  874. wRc = wRc.toString().substr(0,4);
  875. if((wChkStr.length > wRc.length)&&(wChkStr.length <= 4)&&(wRc.substr(1,1) == '.')){
  876. wRc += ''+Array((wChkStr.length - wRc.length) + 1).join('0');
  877. }
  878. }
  879. }
  880. return wRc;
  881. }
  882. // =========================================================================================
  883. // 10進数チェック(0~1,0.001刻み)
  884. // =========================================================================================
  885. function cmanCP_JS_chk0to1s3(arg10){
  886. var wChkStr = cmanCP_JS_zen_TO_han(arg10);
  887. var wRc = 0;
  888. if(wChkStr != ''){
  889. if(wChkStr.toString().match(/^[0-9]+\.$/)){
  890. wRc = wChkStr;
  891. }
  892. else if(wChkStr.toString().match(/^[0-9]+\.0$/)){
  893. wRc = wChkStr;
  894. }
  895. else if(wChkStr.toString().match(/^[0-9]+\.00$/)){
  896. wRc = wChkStr;
  897. }
  898. else if(wChkStr.toString().match(/^[0-9]+(\.[0-9]+)?$/)){
  899. wRc = Math.round(parseFloat(wChkStr) * 1000) / 1000;
  900. if(wRc < 0) {wRc = 0;}
  901. if(wRc > 1) {wRc = 1;}
  902. wRc = wRc.toString().substr(0,5);
  903. if((wChkStr.length > wRc.length)&&(wChkStr.length <= 5)&&(wRc.substr(1,1) == '.')){
  904. wRc += ''+Array((wChkStr.length - wRc.length) + 1).join('0');
  905. }
  906. }
  907. }
  908. return wRc;
  909. }
  910. // =========================================================================================
  911. // 全角入力対応(trimを含む)
  912. // =========================================================================================
  913. function cmanCP_JS_zen_TO_han(argStr){
  914. var wRcStr = argStr.toString();
  915. var befstr = new Array("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","a","b","c","d","e","f","あ","え",".","。");
  916. var aftstr = new Array("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","a","b","c","d","e","f","a","e",".",".");
  917. wRcStr = wRcStr.replace(/[ ]|[ ]/g, '');
  918. wRcStr = wRcStr.replace(/\t|\r|\n/g, '');
  919. for(var i=0; i<aftstr.length; i++){
  920. var reg = new RegExp(befstr[i],"g");
  921. wRcStr = wRcStr.replace(reg, aftstr[i]);
  922. }
  923. return wRcStr;
  924. }
  925. // =========================================================================================
  926. // サンプル更新
  927. // =========================================================================================
  928. function cmanCP_JS_sampleCng(){
  929. cmanCP_VAR["strRGB16"] = '#'+cmanCP_VAR["obj_tR16"].value+cmanCP_VAR["obj_tG16"].value+cmanCP_VAR["obj_tB16"].value;
  930. cmanCP_VAR["strRGB"] = 'rgb('+cmanCP_VAR["obj_tR"].value+', '+cmanCP_VAR["obj_tG"].value+', '+cmanCP_VAR["obj_tB"].value+')';
  931. cmanCP_VAR["strHSL"] = 'hsl('+cmanCP_VAR["obj_tH"].value+', '+(cmanCP_JS_chk0to100s1(parseFloat(cmanCP_VAR["obj_tS"].value) * 100))+'%, '+(cmanCP_JS_chk0to100s1(parseFloat(cmanCP_VAR["obj_tL"].value) * 100)) + '%)';
  932. cmanCP_VAR["strRGBA"] = 'rgba('+cmanCP_VAR["obj_tR"].value+', '+cmanCP_VAR["obj_tG"].value+', '+cmanCP_VAR["obj_tB"].value+', '+cmanCP_VAR["obj_tA"].value+')';
  933. cmanCP_VAR["strHSLA"] = 'hsla('+cmanCP_VAR["obj_tH"].value+', '+(cmanCP_JS_chk0to100s1(parseFloat(cmanCP_VAR["obj_tS"].value) * 100))+'%, '+(cmanCP_JS_chk0to100s1(parseFloat(cmanCP_VAR["obj_tL"].value) * 100)) + '%, '+cmanCP_VAR["obj_tA"].value+')';
  934. // サンプル色
  935. document.getElementById('cmanCP_ID_sample').style.backgroundColor = cmanCP_VAR["strRGBA"];
  936. // HSLのガイダンスカラー
  937. for( var i=1; i <= 20; i++){
  938. document.getElementById('cmanCP_ID_gHSL_H'+i).style.backgroundColor = 'hsl(' + ( (i - 1) * 18.9 ) + ',' + (parseFloat(cmanCP_VAR["obj_tS"].value) * 100) + '%,' + (parseFloat(cmanCP_VAR["obj_tL"].value) * 100) + '%)';
  939. document.getElementById('cmanCP_ID_gHSL_S'+i).style.backgroundColor = 'hsl(' + cmanCP_VAR["obj_tH"].value + ',' + ( i * 5 ) + '%,' + (parseFloat(cmanCP_VAR["obj_tL"].value) * 100) + '%)';
  940. document.getElementById('cmanCP_ID_gHSL_L'+i).style.backgroundColor = 'hsl(' + cmanCP_VAR["obj_tH"].value + ',' + (parseFloat(cmanCP_VAR["obj_tS"].value) * 100) + '%,' + ( i * 5 ) + '%)';
  941. }
  942. if(cmanCP_VAR["obj_tA"].value == '1'){
  943. document.getElementById('cmanCP_ID_outstr').innerHTML = '<span style="font-size:120%;white-space: nowrap;">' + cmanCP_VAR["strRGB16"] + '</span> ' +
  944. '<span style="padding-left:20px;white-space: nowrap;">' + cmanCP_VAR["strRGB"] + '</span> ' +
  945. '<span style="padding-left:20px;white-space: nowrap;">' + cmanCP_VAR["strHSL"] + '</span>';
  946. }else{
  947. document.getElementById('cmanCP_ID_outstr').innerHTML = '<span style="font-size:120%;">' + cmanCP_VAR["strRGB16"] + '<small> (opacity:' + cmanCP_VAR["obj_tA"].value + ')</small></span> ' +
  948. '<span style="padding-left:20px;">' + cmanCP_VAR["strRGBA"] + '</span> ' +
  949. '<span style="padding-left:20px;">' + cmanCP_VAR["strHSLA"] + '</span>';
  950. }
  951. }
  952. // =========================================================================================
  953. // この色を選択
  954. // =========================================================================================
  955. function cmanCP_JS_select(){
  956. // ----- 返却形式 -------------------------------------------------
  957. var wForm = '';
  958. var wOutText = '';
  959. if('rc_form' in cmanCP_VAR){
  960. wForm = cmanCP_VAR['rc_form'].toUpperCase();
  961. }
  962. switch (wForm){
  963. case '#16':
  964. wOutText = '#'+cmanCP_VAR["obj_tR16"].value+cmanCP_VAR["obj_tG16"].value+cmanCP_VAR["obj_tB16"].value;
  965. break;
  966. case '16':
  967. wOutText = ''+cmanCP_VAR["obj_tR16"].value+cmanCP_VAR["obj_tG16"].value+cmanCP_VAR["obj_tB16"].value;
  968. break;
  969. case 'RGB':
  970. wOutText = 'rgb('+cmanCP_VAR["obj_tR"].value+', '+cmanCP_VAR["obj_tG"].value+', '+cmanCP_VAR["obj_tB"].value+')';
  971. break;
  972. case 'RGBA':
  973. wOutText = 'rgba('+cmanCP_VAR["obj_tR"].value+', '+cmanCP_VAR["obj_tG"].value+', '+cmanCP_VAR["obj_tB"].value+', '+cmanCP_VAR["obj_tA"].value+')';
  974. break;
  975. case 'HSL':
  976. wOutText = 'hsl('+cmanCP_VAR["obj_tH"].value+', '+(cmanCP_JS_chk0to100s1(parseFloat(cmanCP_VAR["obj_tS"].value) * 100))+'%, '+(cmanCP_JS_chk0to100s1(parseFloat(cmanCP_VAR["obj_tL"].value) * 100)) + '%)';
  977. break;
  978. case 'HSLA':
  979. wOutText = 'hsla('+cmanCP_VAR["obj_tH"].value+', '+(cmanCP_JS_chk0to100s1(parseFloat(cmanCP_VAR["obj_tS"].value) * 100))+'%, '+(cmanCP_JS_chk0to100s1(parseFloat(cmanCP_VAR["obj_tL"].value) * 100)) + '%, '+cmanCP_VAR["obj_tA"].value+')';
  980. break;
  981. default:
  982. if(cmanCP_VAR["obj_tA"].value == '1'){
  983. wOutText = 'rgb('+cmanCP_VAR["obj_tR"].value+', '+cmanCP_VAR["obj_tG"].value+', '+cmanCP_VAR["obj_tB"].value+')';
  984. }else{
  985. wOutText = 'rgba('+cmanCP_VAR["obj_tR"].value+', '+cmanCP_VAR["obj_tG"].value+', '+cmanCP_VAR["obj_tB"].value+', '+cmanCP_VAR["obj_tA"].value+')';
  986. }
  987. break;
  988. }
  989. // ----- テキスト設定 ---------------------------------------------
  990. var wOutTextID = [];
  991. if('rc_text' in cmanCP_VAR){
  992. wOutTextID = cmanCP_VAR["rc_text"].split(',');
  993. }
  994. for(var i=0; i<wOutTextID.length; i++){
  995. var wSetObj = document.getElementById(wOutTextID[i]);
  996. if(wSetObj){
  997. switch (wSetObj.tagName.toLowerCase()){
  998. case 'button':
  999. case 'data':
  1000. case 'input':
  1001. case 'option':
  1002. case 'progress':
  1003. wSetObj.value = wOutText;
  1004. break;
  1005. default:
  1006. wSetObj.innerText = wOutText;
  1007. break;
  1008. }
  1009. }
  1010. }
  1011. // ----- 背景色設定 ---------------------------------------------
  1012. var wOutBgID = [];
  1013. if('rc_bg' in cmanCP_VAR){
  1014. wOutBgID = cmanCP_VAR["rc_bg"].split(',');
  1015. }
  1016. for(var i=0; i<wOutBgID.length; i++){
  1017. var wSetObj = document.getElementById(wOutBgID[i]);
  1018. if(wSetObj){
  1019. wSetObj.style.backgroundColor = wOutText;
  1020. }
  1021. }
  1022. // --- 個別画面のonload呼び出し ----------------------------------
  1023. if('rc_func' in cmanCP_VAR){
  1024. try{
  1025. eval(cmanCP_VAR["rc_func"]+'("'+wOutText+'")');
  1026. }
  1027. catch(e){
  1028. alert('関数('+cmanCP_VAR["rc_func"]+')を実行できません');
  1029. }
  1030. }
  1031. // --- カラーパレットを閉じる ----------------------------------
  1032. cmanCP_JS_close();
  1033. }
  1034. // =========================================================================================
  1035. // カラーパレット移動イベント
  1036. // =========================================================================================
  1037. function cmanCP_JS_mdown(argEvent){
  1038. cmanCP_VAR['mdown']=1;
  1039. cmanCP_VAR['sPosX'] = argEvent.clientX;
  1040. cmanCP_VAR['sPosY'] = argEvent.clientY;
  1041. cmanCP_VAR['sTop'] = parseInt(cmanCP_VAR["objPop"].style.top.replace("px", ""));
  1042. cmanCP_VAR['sLeft'] = parseInt(cmanCP_VAR["objPop"].style.left.replace("px", ""));
  1043. return false;
  1044. }
  1045. function cmanCP_JS_mup(argEvent){
  1046. cmanCP_VAR['mdown']=0;
  1047. }
  1048. function cmanCP_JS_mout(argEvent){
  1049. cmanCP_VAR['mdown']=0;
  1050. }
  1051. function cmanCP_JS_mmove(argEvent){
  1052. if(cmanCP_VAR['mdown'] != 1){return;}
  1053. cmanCP_VAR["objPop"].style.top = cmanCP_VAR['sTop'] - ( cmanCP_VAR['sPosY'] - argEvent.clientY) + 'px';
  1054. cmanCP_VAR["objPop"].style.left = cmanCP_VAR['sLeft'] - ( cmanCP_VAR['sPosX'] - argEvent.clientX) + 'px';
  1055. return false;
  1056. }