[P2-php-svn] [867] expack:

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2010年 7月 28日 (水) 07:58:29 JST


Revision: 867
          http://sourceforge.jp/projects/p2-php/svn/view?view=rev&revision=867
Author:   rsk
Date:     2010-07-28 07:58:29 +0900 (Wed, 28 Jul 2010)

Log Message:
-----------
expack:
- FitImageをリファクタリング。
- iOS用レスポップアップをリファクタリング。

Modified Paths:
--------------
    p2ex/trunk/ic2_fitimage.php
    p2ex/trunk/js/fitimage.js
    p2ex/trunk/js/ic2_getinfo.js
    p2ex/trunk/js/respopup_iphone.js


-------------- next part --------------
Modified: p2ex/trunk/ic2_fitimage.php
===================================================================
--- p2ex/trunk/ic2_fitimage.php	2010-06-20 01:28:52 UTC (rev 866)
+++ p2ex/trunk/ic2_fitimage.php	2010-07-27 22:58:29 UTC (rev 867)
@@ -18,9 +18,6 @@
 // {{{ ‰æ‘œŒŸõEo—Í—p•Ï”Ý’è
 
 $url = $_GET['url'];
-$x = '';
-$y = '';
-
 $info_key_type = 'url';
 $info_key_value = $url;
 
@@ -36,25 +33,32 @@
     $url = rawurldecode($m[1]);
     if ($icdb->get($url)) {
         $url = $thumbnailer->srcPath($icdb->size, $icdb->md5, $icdb->mime);
-        $x = $icdb->width;
-        $y = $icdb->height;
+        $x = (int)$icdb->width;
+        $y = (int)$icdb->height;
+    } else {
+        $x = 0;
+        $y = 0;
     }
     $info_key_type = 'id';
     $info_key_value = $icdb->id;
+} else {
+    // ‘O‚à‚Á‚ăLƒƒƒbƒVƒ…‚³‚ꂽ‰æ‘œ‚ð•\Ž¦‚·‚é‚̂ŁA‚±‚±‚É‚Í—ˆ‚È‚¢‚Í‚¸
+    $x = 0;
+    $y = 0;
 }
 
 $info_key_value = htmlspecialchars($info_key_value, ENT_QUOTES);
 
 $alt = htmlspecialchars(basename($url));
 
-$afi_js = '';
+$autofit = '';
 if ($x && $y) {
     if ($_conf['expack.ic2.fitimage'] == 1) {
-        $afi_js = "fi.fitTo('contract');";
+        $autofit = 'contract';
     } elseif ($_conf['expack.ic2.fitimage'] == 2) {
-        $afi_js = "fi.fitTo('width');";
+        $autofit = 'width';
     } elseif ($_conf['expack.ic2.fitimage'] == 3) {
-        $afi_js = "fi.fitTo('height');";
+        $autofit = 'height';
     }
 }
 
@@ -78,61 +82,8 @@
     <script type="text/javascript" src="js/json2.js?{$_conf['p2_version_id']}"></script>
     <script type="text/javascript" src="js/ic2_getinfo.js?{$_conf['p2_version_id']}"></script>
     <script type="text/javascript" src="js/fitimage.js?{$_conf['p2_version_id']}"></script>
-    <script type="text/javascript">
-    //<![CDATA[
-    var fi, fiTimer = null;
-
-    function fiSetup()
-    {
-        window.focus();
-
-        function \$(id) { return document.getElementById(id); }
-
-        var img = \$('picture');
-
-        fi = new FitImage(img, {$x}, {$y});
-        {$afi_js}
-
-        img.onclick = function(evt)
-        {
-            if (fiTimer) {
-                clearTimeout(fiTimer);
-            }
-            fiTimer = setTimeout('fiShowHide(); fiTimer = null;', 250);
-        };
-
-        img.ondblclick = function(evt)
-        {
-            if (fiTimer) {
-                clearTimeout(fiTimer);
-                fiTimer = null;
-            }
-            if (fi.currentMode == 'auto') {
-                fi.fitTo(fi.defaultMode);
-            } else {
-                fi.fitTo(fi.currentMode);
-            }
-        };
-
-        //\$('fi_fit_xy').onclick = function(evt){ fi.fitTo('full'); };
-        \$('fi_fit_x').onclick = function(evt){ fi.fitTo('width'); };
-        \$('fi_fit_y').onclick = function(evt){ fi.fitTo('height'); };
-
-        fiGetImageInfo('{$info_key_type}', '{$info_key_value}');
-
-        if (\$('fi_id').value != '') {
-            var stars = \$('fi_stars').getElementsByTagName('img');
-            for (var i = 0; i < stars.length; i++) {
-                stars[i].onclick = (function(n){
-                    return function(){ fiUpdateRank(n); };
-                })(i - 1);
-            }
-        }
-    }
-    //]]>
-    </script>
 </head>
-<body onload="fiSetup()">
+<body onload="fiSetup({$x},{$y},'{$autofit}','{$info_key_type}','{$info_key_value}')">
 <div id="btn">
     <input type="hidden" id="fi_id" value="">
     <!-- <input type="text" id="fi_memo" size="50" value=""><br> -->

Modified: p2ex/trunk/js/fitimage.js
===================================================================
--- p2ex/trunk/js/fitimage.js	2010-06-20 01:28:52 UTC (rev 866)
+++ p2ex/trunk/js/fitimage.js	2010-07-27 22:58:29 UTC (rev 867)
@@ -2,12 +2,17 @@
  * ImageCache2::FitImage
  */
 
+// {{{ GLOBALS
+
+var fiTimer = null;
+
+// }}}
 // {{{ FitImage ƒIƒuƒWƒFƒNƒg
 
 /*
  * ƒRƒ“ƒXƒgƒ‰ƒNƒ^
  *
- * @param String id     ‰æ‘œ‚Ìid‚Ü‚½‚ÍDOM—v‘f
+ * @param String id	 ‰æ‘œ‚Ìid‚Ü‚½‚ÍDOM—v‘f
  * @param Number width  ‰æ‘œ‚Ì•
  * @param Number height ‰æ‘œ‚̍‚‚³
  */
@@ -130,6 +135,10 @@
 
 /*
  * ƒf[ƒ^ƒx[ƒX‚©‚ç‰æ‘œî•ñ‚ðŽæ“¾‚·‚é
+ *
+ * @param String type
+ * @param String value
+ * @return void
  */
 function fiGetImageInfo(type, value)
 {
@@ -271,8 +280,79 @@
 }
 
 // }}}
+// {{{ fiSetup()
 
 /*
+ * FitImage‚ðƒZƒbƒgƒAƒbƒv‚·‚é
+ *
+ * @param Number width
+ * @param Number height
+ * @param String autofit
+ * @param String infoKeyType
+ * @param String infoKeyValue
+ * @return void
+ */
+function fiSetup(width, height, autofit, infoKeyType, infoKeyValue)
+{
+	var $, fi, img;
+
+	if (typeof(width) !== 'number' || width < 1 ||
+		typeof(height) !== 'number' || height < 1) {
+		alert('FitImage‚̃ZƒbƒgƒAƒbƒvŽ¸”s: ‰æ‘œƒTƒCƒY‚ª•s³‚Å‚·');
+		return;
+	}
+
+	window.focus();
+
+	$ = function(id){
+		return document.getElementById(id);
+	};
+
+	img = $('picture');
+
+	fi = new FitImage(img, width, height);
+	if (autofit && autofit !== '') {
+		fi.fitTo(autofit);
+	}
+
+	img.onclick = function(evt){
+		if (fiTimer) {
+			clearTimeout(fiTimer);
+		}
+		fiTimer = setTimeout('fiShowHide(); fiTimer = null;', 250);
+	};
+
+	img.ondblclick = function(evt){
+		if (fiTimer) {
+			clearTimeout(fiTimer);
+			fiTimer = null;
+		}
+		if (fi.currentMode == 'auto') {
+			fi.fitTo(fi.defaultMode);
+		} else {
+			fi.fitTo(fi.currentMode);
+		}
+	};
+
+	//$('fi_fit_xy').onclick = function(evt){ fi.fitTo('full'); };
+	$('fi_fit_x').onclick = function(evt){ fi.fitTo('width'); };
+	$('fi_fit_y').onclick = function(evt){ fi.fitTo('height'); };
+
+	fiGetImageInfo(infoKeyType, infoKeyValue);
+
+	if ($('fi_id').value != '') {
+		var stars = $('fi_stars').getElementsByTagName('img');
+		for (var i = 0; i < stars.length; i++) {
+			stars[i].onclick = (function(n){
+				return function(){ fiUpdateRank(n); };
+			})(i - 1);
+		}
+	}
+}
+
+// }}}
+
+/*
  * Local Variables:
  * mode: javascript
  * coding: cp932

Modified: p2ex/trunk/js/ic2_getinfo.js
===================================================================
--- p2ex/trunk/js/ic2_getinfo.js	2010-06-20 01:28:52 UTC (rev 866)
+++ p2ex/trunk/js/ic2_getinfo.js	2010-07-27 22:58:29 UTC (rev 867)
@@ -37,7 +37,12 @@
 		return null;
 	}
 
-	return (typeof res === 'object' && typeof res.id === 'number') ? res : null;
+	if (res) {
+		if (typeof res.id === 'number') {
+			return res;
+		}
+	}
+	return null;
 }
 
 // }}}

Modified: p2ex/trunk/js/respopup_iphone.js
===================================================================
--- p2ex/trunk/js/respopup_iphone.js	2010-06-20 01:28:52 UTC (rev 866)
+++ p2ex/trunk/js/respopup_iphone.js	2010-07-27 22:58:29 UTC (rev 867)
@@ -32,7 +32,7 @@
 };
 
 // }}}
-// {{{ getActivator()
+// {{{ ipoputil.getActivator()
 
 /**
  * ƒIƒuƒWƒFƒNƒg‚ðÅ‘O–ʂɈړ®‚·‚éŠÖ”‚ð•Ô‚·
@@ -48,7 +48,7 @@
 };
 
 // }}}
-// {{{ getDeactivator()
+// {{{ ipoputil.getDeactivator()
 
 /**
  * DOMƒcƒŠ[‚©‚çƒIƒuƒWƒFƒNƒg‚ðŽæ‚菜‚­ŠÖ”‚ð•Ô‚·
@@ -66,7 +66,7 @@
 };
 
 // }}}
-// {{{ iResPopUp()
+// {{{ ipoputil.popup()
 
 /**
  * iPhone—pƒŒƒXƒ|ƒbƒvƒAƒbƒv
@@ -76,7 +76,7 @@
  * @return {Boolean}
  * @todo use asynchronous request
  */
-var iResPopUp = function(url, evt) {
+ipoputil.popup = function(url, evt) {
 	var yOffset = Math.max(10, iutil.getPageY(evt) - 20);
 
 	if (_IRESPOPG.hash[url]) {
@@ -156,7 +156,31 @@
 };
 
 // }}}
+// {{{ iResPopUp()
 
+/**
+ * iPhone—pƒŒƒXƒ|ƒbƒvƒAƒbƒv
+ *
+ * @param {String} url
+ * @param {Event} evt
+ * @return {Boolean}
+ * @todo use asynchronous request
+ * @see iutil.popup
+ */
+var iResPopUp = function(url, evt) {
+	if (typeof url !== 'string' && typeof url.href === 'string') {
+		url = url.href;
+	}
+	evt = evt || window.event;
+	if (false === ipoputil.popup(url, evt)) {
+		iutil.stopEvent(evt);
+		return false;
+	}
+	return true;
+};
+
+// }}}
+
 /*
  * Local Variables:
  * mode: javascript



P2-php-svn メーリングリストの案内
Back to archive index