OSDN Git Service

ウィジェット「上へ参ります」バージョンアップ。
authornaoki hirata <naoki@magic3.org>
Thu, 27 Mar 2014 03:15:36 +0000 (12:15 +0900)
committernaoki hirata <naoki@magic3.org>
Thu, 27 Mar 2014 03:15:36 +0000 (12:15 +0900)
include/sql/update_widgets.sql
widgets/gotop/include/container/gotopWidgetContainer.php
widgets/gotop/include/template/index.tmpl.html
widgets/gotop/scripts/scrolltotop.js

index 8ba47b3..b82f7fd 100644 (file)
@@ -349,7 +349,7 @@ INSERT INTO _widgets
 DELETE FROM _widgets WHERE wd_id = 'gotop';\r
 INSERT INTO _widgets\r
 (wd_id,   wd_name,        wd_version, wd_author,      wd_copyright, wd_license, wd_official_level, wd_description,     wd_add_script_lib, wd_add_script_lib_a, wd_available, wd_editable, wd_has_admin, wd_enable_operation, wd_use_instance_def, wd_initialized, wd_cache_type, wd_view_control_type, wd_release_dt, wd_install_dt, wd_create_dt) VALUES\r
-('gotop', '上へ参ります', '1.1.0',    'Naoki Hirata', 'Magic3.org', 'GPL',      10,                '画面トップへ移動', 'jquery',          'elfinder',                  true,         true,        true,        false,               false,               true,           1,             -1, '2013-11-18', now(), now());\r
+('gotop', '上へ参ります', '2.0.0',    'Naoki Hirata', 'Magic3.org', 'GPL',      10,                '画面トップへ移動', 'jquery',          'elfinder',                  true,         true,        true,        false,               false,               true,           1,             -1, '2014-03-27', now(), now());\r
 DELETE FROM _widgets WHERE wd_id = 'portal_updateinfo';\r
 INSERT INTO _widgets\r
 (wd_id,              wd_name,                          wd_version, wd_author,      wd_copyright, wd_license, wd_official_level, wd_description, wd_has_admin, wd_enable_operation, wd_use_instance_def, wd_initialized, wd_cache_type, wd_view_control_type, wd_has_rss, wd_install_dt, wd_create_dt) VALUES\r
index 703c7e6..3c0bd68 100644 (file)
@@ -8,7 +8,7 @@
  *
  * @package    Magic3 Framework
  * @author     平田直毅(Naoki Hirata) <naoki@aplo.co.jp>
- * @copyright  Copyright 2006-2013 Magic3 Project.
+ * @copyright  Copyright 2006-2014 Magic3 Project.
  * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
  * @version    SVN: $Id$
  * @link       http://www.magic3.org
@@ -18,6 +18,7 @@ require_once($gEnvManager->getContainerPath()         . '/baseWidgetContainer.php');
 class gotopWidgetContainer extends BaseWidgetContainer
 {
        const DEFAULT_IMAGE_FILE = '/up.png';   // デフォルトの矢印アイコン
+       const DEFAULT_SCRIPT_FILE = '/scrolltotop.js';          // scriptファイル
        
        /**
         * コンストラクタ
@@ -60,5 +61,20 @@ class gotopWidgetContainer extends BaseWidgetContainer
                }
                $this->tmpl->addVar("_widget", "image_url",     $imageUrl);
        }
+       /**
+        * JavascriptファイルをHTMLヘッダ部に設定
+        *
+        * JavascriptファイルをHTMLのheadタグ内に追加出力する。
+        * _assign()よりも後に実行される。
+        *
+        * @param RequestManager $request               HTTPリクエスト処理クラス
+        * @param object         $param                 任意使用パラメータ。
+        * @return string                                               Javascriptファイル。出力しない場合は空文字列を設定。
+        */
+       function _addScriptFileToHead($request, &$param)
+       {
+               $scriptArray = array($this->getUrl($this->gEnv->getCurrentWidgetScriptsUrl() . self::DEFAULT_SCRIPT_FILE));
+               return $scriptArray;
+       }
 }
 ?>
index 0fa73fb..d6cc011 100644 (file)
@@ -5,7 +5,7 @@
  *
  * @package    Magic3 Framework
  * @author     \95½\93c\92¼\8bB(Naoki Hirata) <naoki@aplo.co.jp>
- * @copyright  Copyright 2006-2013 Magic3 Project.
+ * @copyright  Copyright 2006-2014 Magic3 Project.
  * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
  * @version    SVN: $Id$
  * @link       http://www.magic3.org
 <script type="text/javascript">
 //<![CDATA[
 $(function(){
-//** jQuery Scroll to Top Control script- (c) Dynamic Drive DHTML code library: http://www.dynamicdrive.com.
-//** Available/ usage terms at http://www.dynamicdrive.com (March 30th, 09')
-//** v1.1 (April 7th, 09'):
-//** 1) Adds ability to scroll to an absolute position (from top of page) or specific element on the page instead.
-//** 2) Fixes scroll animation not working in Opera. 
-var scrolltotop={
-       //startline: Integer. Number of pixels from top of doc scrollbar is scrolled before showing control
-       //scrollto: Keyword (Integer, or "Scroll_to_Element_ID"). How far to scroll document up when control is clicked on (0=top).
-       setting: {startline:100, scrollto: 0, scrollduration:1000, fadeduration:[500, 100]},
-       controlHTML: '<img src="{IMAGE_URL}" style="width:48px; height:48px" />', //HTML for control, which is auto wrapped in DIV w/ ID="topcontrol"
-       controlattrs: {offsetx:5, offsety:5}, //offset of control relative to right/ bottom of window corner
-       anchorkeyword: '#top', //Enter href value of HTML anchors on the page that should also act as "Scroll Up" links
-
-       state: {isvisible:false, shouldvisible:false},
-
-       scrollup:function(){
-               if (!this.cssfixedsupport) //if control is positioned using JavaScript
-                       this.$control.css({opacity:0}) //hide control immediately after clicking it
-               var dest=isNaN(this.setting.scrollto)? this.setting.scrollto : parseInt(this.setting.scrollto)
-               if (typeof dest=="string" && jQuery('#'+dest).length==1) //check element set by string exists
-                       dest=jQuery('#'+dest).offset().top
-               else
-                       dest=0
-               this.$body.animate({scrollTop: dest}, this.setting.scrollduration);
-       },
-
-       keepfixed:function(){
-               var $window=jQuery(window)
-               var controlx=$window.scrollLeft() + $window.width() - this.$control.width() - this.controlattrs.offsetx
-               var controly=$window.scrollTop() + $window.height() - this.$control.height() - this.controlattrs.offsety
-               this.$control.css({left:controlx+'px', top:controly+'px'})
-       },
-
-       togglecontrol:function(){
-               var scrolltop=jQuery(window).scrollTop()
-               if (!this.cssfixedsupport)
-                       this.keepfixed()
-               this.state.shouldvisible=(scrolltop>=this.setting.startline)? true : false
-               if (this.state.shouldvisible && !this.state.isvisible){
-                       this.$control.stop().animate({opacity:1}, this.setting.fadeduration[0])
-                       this.state.isvisible=true
-               }
-               else if (this.state.shouldvisible==false && this.state.isvisible){
-                       this.$control.stop().animate({opacity:0}, this.setting.fadeduration[1])
-                       this.state.isvisible=false
-               }
-       },
-       
-       init:function(){
-               jQuery(document).ready(function($){
-                       var mainobj=scrolltotop
-                       var iebrws=document.all
-                       mainobj.cssfixedsupport=!iebrws || iebrws && document.compatMode=="CSS1Compat" && window.XMLHttpRequest //not IE or IE7+ browsers in standards mode
-                       mainobj.$body=(window.opera)? (document.compatMode=="CSS1Compat"? $('html') : $('body')) : $('html,body')
-                       mainobj.$control=$('<div id="topcontrol">'+mainobj.controlHTML+'</div>')
-                               .css({position:mainobj.cssfixedsupport? 'fixed' : 'absolute', bottom:mainobj.controlattrs.offsety, right:mainobj.controlattrs.offsetx, opacity:0, cursor:'pointer'})
-                               .attr({title:'Scroll Back to Top'})
-                               .click(function(){mainobj.scrollup(); return false})
-                               .appendTo('body')
-                       if (document.all && !window.XMLHttpRequest && mainobj.$control.text()!='') //loose check for IE6 and below, plus whether control contains any text
-                               mainobj.$control.css({width:mainobj.$control.width()}) //IE6- seems to require an explicit width on a DIV containing text
-                       mainobj.togglecontrol()
-                       $('a[href="' + mainobj.anchorkeyword +'"]').click(function(){
-                               mainobj.scrollup()
-                               return false
-                       })
-                       $(window).bind('scroll resize', function(e){
-                               mainobj.togglecontrol()
-                       })
-               })
-       }
-}
-scrolltotop.init()
+       scrolltotop.init( {controlHTML: '<img src="{IMAGE_URL}" style="width:48px; height:48px" />'} );
 });
 //]]>
 </script>
index b66d7f9..6fbefed 100644 (file)
@@ -1,74 +1,79 @@
-
 //** jQuery Scroll to Top Control script- (c) Dynamic Drive DHTML code library: http://www.dynamicdrive.com.
 //** Available/ usage terms at http://www.dynamicdrive.com (March 30th, 09')
 //** v1.1 (April 7th, 09'):
 //** 1) Adds ability to scroll to an absolute position (from top of page) or specific element on the page instead.
 //** 2) Fixes scroll animation not working in Opera. 
+//** 2014/3/27 modified for Magic3 by naoki.
 var scrolltotop={
        //startline: Integer. Number of pixels from top of doc scrollbar is scrolled before showing control
        //scrollto: Keyword (Integer, or "Scroll_to_Element_ID"). How far to scroll document up when control is clicked on (0=top).
        setting: {startline:100, scrollto: 0, scrollduration:1000, fadeduration:[500, 100]},
-       controlHTML: '<img src="{IMAGE_URL}" style="width:48px; height:48px" />', //HTML for control, which is auto wrapped in DIV w/ ID="topcontrol"
+       controlHTML: '<img src="up.png" style="width:48px; height:48px" />', //HTML for control, which is auto wrapped in DIV w/ ID="topcontrol"
        controlattrs: {offsetx:5, offsety:5}, //offset of control relative to right/ bottom of window corner
        anchorkeyword: '#top', //Enter href value of HTML anchors on the page that should also act as "Scroll Up" links
 
-       state: {isvisible:false, shouldvisible:false},
+       state: { isvisible:false, shouldvisible:false },
 
        scrollup:function(){
-               if (!this.cssfixedsupport) //if control is positioned using JavaScript
-                       this.$control.css({opacity:0}) //hide control immediately after clicking it
-               var dest=isNaN(this.setting.scrollto)? this.setting.scrollto : parseInt(this.setting.scrollto)
-               if (typeof dest=="string" && jQuery('#'+dest).length==1) //check element set by string exists
-                       dest=jQuery('#'+dest).offset().top
-               else
-                       dest=0
+               if (!this.cssfixedsupport){     //if control is positioned using JavaScript
+                       this.$control.css({opacity:0}); //hide control immediately after clicking it
+               }
+               var dest=isNaN(this.setting.scrollto)? this.setting.scrollto : parseInt(this.setting.scrollto);
+               if (typeof dest=="string" && $('#'+dest).length==1){     //check element set by string exists
+                       dest=$('#'+dest).offset().top;
+               } else {
+                       dest=0;
+               }
                this.$body.animate({scrollTop: dest}, this.setting.scrollduration);
        },
 
        keepfixed:function(){
-               var $window=jQuery(window)
-               var controlx=$window.scrollLeft() + $window.width() - this.$control.width() - this.controlattrs.offsetx
-               var controly=$window.scrollTop() + $window.height() - this.$control.height() - this.controlattrs.offsety
-               this.$control.css({left:controlx+'px', top:controly+'px'})
+               var $window=$(window);
+               var controlx=$window.scrollLeft() + $window.width() - this.$control.width() - this.controlattrs.offsetx;
+               var controly=$window.scrollTop() + $window.height() - this.$control.height() - this.controlattrs.offsety;
+               this.$control.css({left:controlx+'px', top:controly+'px'});
        },
 
        togglecontrol:function(){
-               var scrolltop=jQuery(window).scrollTop()
-               if (!this.cssfixedsupport)
-                       this.keepfixed()
-               this.state.shouldvisible=(scrolltop>=this.setting.startline)? true : false
+               var scrolltop=$(window).scrollTop();
+               if (!this.cssfixedsupport) this.keepfixed();
+               this.state.shouldvisible=(scrolltop>=this.setting.startline) ? true : false;
                if (this.state.shouldvisible && !this.state.isvisible){
-                       this.$control.stop().animate({opacity:1}, this.setting.fadeduration[0])
-                       this.state.isvisible=true
-               }
-               else if (this.state.shouldvisible==false && this.state.isvisible){
-                       this.$control.stop().animate({opacity:0}, this.setting.fadeduration[1])
-                       this.state.isvisible=false
+                       this.$control.stop().animate({opacity:1}, this.setting.fadeduration[0]);
+                       this.state.isvisible=true;
+               } else if (this.state.shouldvisible==false && this.state.isvisible){
+                       this.$control.stop().animate({opacity:0}, this.setting.fadeduration[1]);
+                       this.state.isvisible=false;
                }
        },
-       
-       init:function(){
-               jQuery(document).ready(function($){
-                       var mainobj=scrolltotop
-                       var iebrws=document.all
-                       mainobj.cssfixedsupport=!iebrws || iebrws && document.compatMode=="CSS1Compat" && window.XMLHttpRequest //not IE or IE7+ browsers in standards mode
-                       mainobj.$body=(window.opera)? (document.compatMode=="CSS1Compat"? $('html') : $('body')) : $('html,body')
-                       mainobj.$control=$('<div id="topcontrol">'+mainobj.controlHTML+'</div>')
-                               .css({position:mainobj.cssfixedsupport? 'fixed' : 'absolute', bottom:mainobj.controlattrs.offsety, right:mainobj.controlattrs.offsetx, opacity:0, cursor:'pointer'})
-                               .attr({title:'Scroll Back to Top'})
-                               .click(function(){mainobj.scrollup(); return false})
-                               .appendTo('body')
-                       if (document.all && !window.XMLHttpRequest && mainobj.$control.text()!='') //loose check for IE6 and below, plus whether control contains any text
-                               mainobj.$control.css({width:mainobj.$control.width()}) //IE6- seems to require an explicit width on a DIV containing text
-                       mainobj.togglecontrol()
-                       $('a[href="' + mainobj.anchorkeyword +'"]').click(function(){
-                               mainobj.scrollup()
-                               return false
-                       })
-                       $(window).bind('scroll resize', function(e){
-                               mainobj.togglecontrol()
-                       })
-               })
+
+       init:function(options){
+               // パラメータ初期化
+               if (options.setting) this.setting = options.setting;
+               if (options.controlHTML) this.controlHTML = options.controlHTML;
+               if (options.controlattrs) this.controlattrs = options.controlattrs;
+               if (options.anchorkeyword) this.anchorkeyword = options.anchorkeyword;
+               
+               //var mainobj=scrolltotop;
+               var mainobj=this;
+               var iebrws=document.all;
+               mainobj.cssfixedsupport=!iebrws || iebrws && document.compatMode=="CSS1Compat" && window.XMLHttpRequest;        //not IE or IE7+ browsers in standards mode
+               mainobj.$body=(window.opera)? (document.compatMode=="CSS1Compat"? $('html') : $('body')) : $('html,body');
+               mainobj.$control=$('<div id="topcontrol">'+mainobj.controlHTML+'</div>')
+                       .css({position:mainobj.cssfixedsupport? 'fixed' : 'absolute', bottom:mainobj.controlattrs.offsety, right:mainobj.controlattrs.offsetx, opacity:0, cursor:'pointer'})
+                       .attr({title:'Scroll Back to Top'})
+                       .click(function(){ mainobj.scrollup(); return false; })
+                       .appendTo('body');
+               if (document.all && !window.XMLHttpRequest && mainobj.$control.text()!=''){     //loose check for IE6 and below, plus whether control contains any text
+                       mainobj.$control.css({width:mainobj.$control.width()});         //IE6- seems to require an explicit width on a DIV containing text
+               }
+               mainobj.togglecontrol();
+               $('a[href="' + mainobj.anchorkeyword +'"]').click(function(){
+                       mainobj.scrollup();
+                       return false;
+               });
+               $(window).bind('scroll resize', function(e){
+                       mainobj.togglecontrol();
+               });
        }
 }
-