Archive for 四月, 2010

Backup and Migrate

Backup/restore your database or migrate data to or from another Drupal site.

http://drupal.org/project/backup_migrate

 

INSTALLATION:Put the module in your drupal modules directory and enable it inadmin/build/modules.

Configure and use the module at admin/content/backup_migrate

OPTIONAL:Enable token.module to allow token replacement in backup file names.

 


flash图片api

html
[code]
<object classid=”clsid:D27CDB6E-AE6D-11cf-96B8-444553540000″ id=scriptmain name=scriptmain codebase=”http://download.macromedia.com/pub/shockwave/cabs/
flash/swflash.cab#version=6,0,29,0″ width=”508″ height=”180″>   
<param name=”movie” value=”Public/swf/bcastr.swf?bcastr_xml_url=Public/xml/bcastr.xml”>   
<param name=”quality” value=”high”>   
<param name=”scale” value=”noscale”>
<param name=”LOOP” value=”false”>   
<param name=”menu” value=”false”>  
<param name=”wmode” value=”transparent”>   
<embed src=”/Public/swf/bcastr.swf?bcastr_xml_url=/Public/xml/bcastr.xml” width=”508″ height=”180″ loop=”false” quality=”high” pluginspage=”http://www.macromedia.com/go/getflashplayer” type=”application/x-shockwave-flash” salign=”T” name=”scriptmain” menu=”false” wmode=”transparent”></embed>
</object>
[/code]

bcastr.xml
[code]
<?xml version=”1.0″ encoding=”utf-8″?>
<bcaster autoPlayTime=”3″>
<item item_url=”/Public/images/1.jpg” link=”/activities/1/index.html”></item>
<item item_url=”/Public/images/2.jpg” link=”/activities/2/index.html”></item>
<item item_url=”/Public/images/3.jpg” link=”/activities/3/index.html”></item>
</bcaster>
[/code]
bcastr.swf在附件



phpToExcel

[code]php-excel.class.php

/**
* Simple excel generating from PHP5
*
* @package Utilities
* @license http://www.opensource.org/licenses/mit-license.php
* @author Oliver Schwarz * @version 1.0
*/ (continue reading…)


ExcelToPHP

example.php
[code]<?php
$allow_url_override = 1; // Set to 0 to not allow changed VIA POST or GET
if(!$allow_url_override || !isset($file_to_include))
{
$file_to_include = “test.xls”;
}
if(!$allow_url_override || !isset($max_rows))
{
$max_rows = 0; //USE 0 for no max
} (continue reading…)


mysqldump备份数据库

mysqldump -u用户名 -p密码 -h主机 数据库 > 路径 案例F:\wamp\bin\mysql\mysql5.1.36\bin>mysqldump -uroot -p -hlocalhost sqlhk9 a –no- data

mysqldump备份数据库和选项/Option作用

mysqldump -u用户名 -p密码 -h主机 数据库 > 路径 案例:F:\wamp\bin\mysql\mysql5.1.36\bin>mysqldump -uroot -p -hlocalhost sqlhk9 a –no-data (continue reading…)


使用mysqldump定时备份数据库的脚本

脚本描述

  每7天备份一次所有数据,每天备份binlog,也就是增量备份.

  (如果数据少,每天备份一次完整数据即可,可能没必要做增量备份)

  作者对shell脚本不太熟悉,所以很多地方写的很笨 🙂

  开启 bin log

  在mysql 4.1版本中,默认只有错误日志,没有其他日志.可以通过修改配置打开bin log.方法很多,其中一个是在/etc/my.cnf中的mysqld部分加入:

  [mysqld]

  log-bin

  这个日志的主要作用是增量备份或者复制(可能还有其他用途).

  如果想增量备份,必须打开这个日志.

  对于数据库操作频繁的mysql,这个日志会变得很大,而且可能会有多个.

  在数据库中flush-logs,或者使用mysqladmin,mysqldump调用flush-logs后并且使用参数delete-master-logs,这些日志文件会消失,并产生新的日志文件(开始是空的).

  所以如果从来不备份,开启日志可能没有必要.

  完整备份的同时可以调用flush-logs,增量备份之前flush-logs,以便备份最新的数据.

  完整备份脚本

  如果数据库数据比较多,我们一般是几天或者一周备份一次数据,以免影响应用运行,如果数据量比较小,那么一天备份一次也无所谓了.

  下载假设我们的数据量比较大,备份脚本如下:(参考过网络上一个mysql备份脚本,致谢 :))

#!/bin/sh

# mysql data backup script

# by scud http://www.jscud.com

# 2005-10-30

#

# use mysqldump –help,get more detail.

#

BakDir=/backup/mysql

LogFile=/backup/mysql/mysqlbak.log

DATE=`date +%Y%m%d`

echo " " >> $LogFile

echo " " >> $LogFile

echo "——————————————-" >> $LogFile

echo $(date +"%y-%m-%d %H:%M:%S") >> $LogFile

echo "————————–" >> $LogFile

cd $BakDir

DumpFile=$DATE.sql

GZDumpFile=$DATE.sql.tgz

mysqldump –quick –all-databases –flush-logs

–delete-master-logs –lock-all-tables > $DumpFile

echo "Dump Done" >> $LogFile

tar czvf $GZDumpFile $DumpFile >> $LogFile 2>&1

echo "[$GZDumpFile]Backup Success!" >> $LogFile

rm -f $DumpFile

#delete previous daily backup files:采用增量备份的文件,如果完整备份后,则删除增量备份的文件.

cd $BakDir/daily

rm -f *

cd $BakDir

echo "Backup Done!"

echo "please Check $BakDir Directory!"

echo "copy it to your local disk or ftp to somewhere !!!"

ls -al $BakDir

上面的脚本把mysql备份到本地的/backup/mysql目录,增量备份的文件放在/backup/mysql/daily目录下.

  注意:上面的脚本并没有把备份后的文件传送到其他远程计算机,也没有删除几天前的备份文件:需要用户增加相关脚本,或者手动操作.

  增量备份

  增量备份的数据量比较小,但是要在完整备份的基础上操作,用户可以在时间和成本上权衡,选择最有利于自己的方式.

  增量备份使用bin log,脚本如下:

#!/bin/sh

#

# mysql binlog backup script

#

/usr/bin/mysqladmin flush-logs

DATADIR=/var/lib/mysql

BAKDIR=/backup/mysql/daily

###如果你做了特殊设置,请修改此处或者修改应用此变量的行:缺省取机器名,mysql缺省也是取机器名

HOSTNAME=`uname -n`

cd $DATADIR

FILELIST=`cat $HOSTNAME-bin.index`

##计算行数,也就是文件数

COUNTER=0

for file in $FILELIST

do

COUNTER=`expr $COUNTER + 1 `

done

NextNum=0

for file in $FILELIST

do

base=`basename $file`

NextNum=`expr $NextNum + 1`

if [ $NextNum -eq $COUNTER ]

then

echo "skip lastest"

else

dest=$BAKDIR/$base

if(test -e $dest)

then

echo "skip exist $base"

else

echo "copying $base"

cp $base $BAKDIR

fi

fi

done

echo "backup mysql binlog ok"

  增量备份脚本是备份前flush-logs,mysql会自动把内存中的日志放到文件里,然后生成一个新的日志文件,所以我们只需要备份前面的几个即可,也就是不备份最后一个.

  因为从上次备份到本次备份也可能会有多个日志文件生成,所以要检测文件,如果已经备份过,就不用备份了.

  注:同样,用户也需要自己远程传送,不过不需要删除了,完整备份后程序会自动生成.

  访问设置

  脚本写完了,为了能让脚本运行,还需要设置对应的用户名和密码,mysqladmin和 mysqldump都是需要用户名和密码的,当然可以写在脚本中,但是修改起来不太方便,假设我们用系统的root用户来运行此脚本,那么我们需要在 /root(也就是root用户的home目录)创建一个.my.cnf文件,内容如下

[mysqladmin]

password =password

user= root

[mysqldump]

user=root

password=password

  注: 设置本文件只有root可读.(chmod 600 .my.cnf )

  此文件说明程序使用mysql的root用户备份数据,密码是对应的设置.这样就不需要在脚本里写用户名和密码了.

  自动运行

  为了让备份程序自动运行,我们需要把它加入crontab.

  有2种方法,一种是把脚本根据自己的选择放入到/etc/cron.daily,/etc/cron.weekly这么目录里.

  一种是使用crontab -e放入到root用户的计划任务里,例如完整备份每周日凌晨3点运行,日常备份每周一-周六凌晨3点运行.

  具体使用,请参考crontab的帮助.


Windows 下ImageMagick的安装测试

ImageMagick (TM) 是一个免费的创建、编辑、合成图片的软件。它可以读取、转换、写入多种格式的图片。图片切割、颜色替换、各种效果的应用,图片的旋转、组合,文本,直线, 多边形,椭圆,曲线,附加到图片伸展旋转。ImageMagick是免费软件:全部源码开放,可以自由使用,复制,修改,发布。它遵守GPL许可协议。它 可以运行于大多数的操作系统。ImageMagick的大多数功能的使用都来源于命令行工具。通常来说,它可以支持以下程序语言: Perl, C, C++, Python, PHP, Ruby, Java;现成的ImageMagick接口(PerlMagick, Magick++, PythonMagick, MagickWand for PHP, RubyMagick, and JMagick)是可利用的。这使得自动的动态的修改创建图片变为可能。ImageMagick支持至少90种图片格式。
    在PHP中使用ImageMagick需要安装扩展php_imagick.dll,下载地址:http://valokuva.org/outside-blog-content/imagick-windows-builds/ 本例使用php_imagick_st-Q16.dll。将该DLL放到php5.2的ext目录下,打开php.ini,在Windows Extensions后添加extension=php_imagick_st-Q16.dll重启Apache服务器,你可以在phpinfo()中看到:

表明imagick模块安装成功。但此时还不能正常工作,还需安装ImageMagick。
    去官方下载ImageMagick-6.5.9-9-Q16-windows-dll.exe,http://www.imagemagick.org/script/binary-releases.php#windows 或者http://www.imagemagick.com.cn/download.html 和普通软件一样没什么难的,一路"next"。
    测试ImageMagick,下载http://pecl.php.net/get/imagick-3.0.0b2.tgz,解压出里的examples文件夹,放到Apache文档目录下,测试例子,结果如下:

。。。


批处理改文件名-时间

打开控制面板里的区域选项,修改时间的分隔符(因为系统不允许目录名字有:/\之类的符号),把它改为"-"(或者全角的中文标点的":"),日期格式假设设置为dd-MM-yyyy。  

而且bat文件、test.txt文件要和需要改名的文件放在同一目录下。

@ECHO   OFF
ren   test.txt   %DATE%-%TIME%.txt

——————————————————————————

@ECHO   OFF
for   /f   %%1   in   (‘date   /t’)   do   ren   test.txt   %%1.txt

—————————————————————————-

  ren       北京.txt     01.txt  
  ren       天津.txt     02.txt  
  ren       河北.txt     03.txt  

 假设你已经有一个文件city.txt有如下内容: 

  北京   01 

  天津   02 

  河北   03 

  …… 

  那么可以这样写这个批处理: 

  @ECHO   OFF 

  FOR   /F   "tokens=1,2"   %%a   IN   (city.txt)   DO   ( 

  IF   EXIST   %%a%   %.txt   ( 

  REN   %%a%   %.txt   %%b%   %.txt 

  ) 

  )  

 

几个动态变量

%CD% #代表当前目录的字符串

%DATE% #当前日期

%TIME% #当前时间

%RANDOM% #随机整数,介于0~32767

%ERRORLEVEL% #当前 ERRORLEVEL 值

%CMDEXTVERSION% #当前命令处理器扩展名版本号

%CMDCMDLINE% #调用命令处理器的原始命令行

可以用echo命令查看每个变量值,如 echo %time%

注意 %time% 精确到毫秒


jquery.lightbox-0.5

http://www.balupton.com/sandbox/jquery_lightbox_bal/demo/

使用方法
先下载 jQuery lightBox plugin

leandrovieira.com/projects/jquery/lightbox/
http://www.balupton.com/sandbox/jquery_lightbox/

然后在网页中写入:
<script type="text/javas

cript" src="http://yourdomain/jquery.js"></script>
<script type="text/javascript" src="http://yourdomain/jquery.lightbox-0.3.1.js"></script>
<link rel="stylesheet" type="text/css" href="http://yourdomain/jquery.lightbox-0.3.css" media="screen">
<script type="text/javascript">
     $(function() {
         $(‘#id名 a’).lightBox();  
     });
</script>

上面代码完成后,在网页中加入图片:

or <a rel="lightbox" href="images/mountain-large.jpg" >

<div id="id名">
<a href="" title="">
     <img src="" width="" height="">
</a>
</div>

lightbox还加入了:

     *改变颜色重叠: overlaybgcolor : ‘ # fff ‘
     *覆盖的透明度: overlayopacity : 0.6
     *文本1 : txtimage : ‘图片’
     *文本2 : txtof : ""….

$(function() {
     $(‘#gallery a’).lightBox({
         overlayBgColor: ‘#FFF’,
         overlayOpacity: 0.7,
         txtImage: ‘图片’,
         txtOf: ‘。。。。。。。。。。’
         }
     );
});

 
 

jquery.lightbox-0.5.css

/**
 * jQuery lightBox plugin
 * This jQuery plugin was inspired and based on Lightbox 2 by Lokesh Dhakar (http://www.huddletogether.com/projects/lightbox2/)
 * and adapted to me for use like a plugin from jQuery.
 * @name jquery-lightbox-0.5.css
 * @author Leandro Vieira Pinho – http://leandrovieira.com
 * @version 0.5
 * @date April 11, 2008
 * @category jQuery plugin
 * @copyright (c) 2008 Leandro Vieira Pinho (leandrovieira.com)
 * @license CC Attribution-No Derivative Works 2.5 Brazil – http://creativecommons.org/licenses/by-nd/2.5/br/deed.en_US
 * @example Visit http://leandrovieira.com/projects/jquery/lightbox/ for more informations about this jQuery plugin
 */
#jquery-overlay {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 90;
    width: 100%;
    height: 500px;
}
#jquery-lightbox {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 100;
    text-align: center;
    line-height: 0;
}
#jquery-lightbox a img { border: none; }
#lightbox-container-image-box {
    position: relative;
    background-color: #fff;
    width: 250px;
    height: 250px;
    margin: 0 auto;
}
#lightbox-container-image { padding: 10px; }
#lightbox-loading {
    position: absolute;
    top: 40%;
    left: 0%;
    height: 25%;
    width: 100%;
    text-align: center;
    line-height: 0;
}
#lightbox-nav {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 100%;
    z-index: 10;
}
#lightbox-container-image-box > #lightbox-nav { left: 0; }
#lightbox-nav a { outline: none;}
#lightbox-nav-btnPrev, #lightbox-nav-btnNext {
    width: 49%;
    height: 100%;
    zoom: 1;
    display: block;
}
#lightbox-nav-btnPrev {
    left: 0;
    float: left;
}
#lightbox-nav-btnNext {
    right: 0;
    float: right;
}
#lightbox-container-image-data-box {
    font: 10px Verdana, Helvetica, sans-serif;
    background-color: #fff;
    margin: 0 auto;
    line-height: 1.4em;
    overflow: auto;
    width: 100%;
    padding: 0 10px 0;
}
#lightbox-container-image-data {
    padding: 0 10px;
    color: #666;
}
#lightbox-container-image-data #lightbox-image-details {
    width: 70%;
    float: left;
    text-align: left;
}   
#lightbox-image-details-caption { font-weight: bold; }
#lightbox-image-details-currentNumber {
    display: block;
    clear: left;
    padding-bottom: 1.0em;   
}           
#lightbox-secNav-btnClose {
    width: 66px;
    float: right;
    padding-bottom: 0.7em;   
}

#lightbox-loading-link { width:32px;height:32px; display:block;margin:0 auto;}

 

jquery.lightbox-0.5.js

/**
 * jQuery lightBox plugin
 * This jQuery plugin was inspired and based on Lightbox 2 by Lokesh Dhakar (http://www.huddletogether.com/projects/lightbox2/)
 * and adapted to me for use like a plugin from jQuery.
 * @name jquery-lightbox-0.5.js
 * @author Leandro Vieira Pinho – http://leandrovieira.com
 * @version 0.5
 * @date April 11, 2008
 * @category jQuery plugin
 * @copyright (c) 2008 Leandro Vieira Pinho (leandrovieira.com)
 * @license CC Attribution-No Derivative Works 2.5 Brazil – http://creativecommons.org/licenses/by-nd/2.5/br/deed.en_US
 * @example Visit http://leandrovieira.com/projects/jquery/lightbox/ for more informations about this jQuery plugin
 */

// Offering a Custom Alias suport – More info: http://docs.jquery.com/Plugins/Authoring#Custom_Alias
(function($) {
    /**
     * $ is an alias to jQuery object
     *
     */
    $.fn.lightBox = function(settings) {
        // Settings to configure the jQuery lightBox plugin how you like
        settings = jQuery.extend({
            // Configuration related to overlay
            overlayBgColor:         ‘#000’,        // (string) Background color to overlay; inform a hexadecimal value like: #RRGGBB. Where RR, GG, and BB are the hexadecimal values for the red, green, and blue values of the color.
            overlayOpacity:            0.8,        // (integer) Opacity value to overlay; inform: 0.X. Where X are number from 0 to 9
            // Configuration related to navigation
            fixedNavigation:        false,        // (boolean) Boolean that informs if the navigation (next and prev button) will be fixed or not in the interface.
            // Configuration related to images
            imageLoading:            ‘fileadmin/templates/images/lightbox/loading.gif’,        // (string) Path and the name of the loading icon
            imageBtnPrev:            ‘fileadmin/templates/images/lightbox/prev.gif’,            // (string) Path and the name of the prev button image
            imageBtnNext:            ‘fileadmin/templates/images/lightbox/next.gif’,            // (string) Path and the name of the next button image
            imageBtnClose:            ‘fileadmin/templates/images/lightbox/close.gif’,        // (string) Path and the name of the close btn
            imageBlank:                ‘fileadmin/templates/images/lightbox/blank.gif’,            // (string) Path and the name of a blank image (one pixel)
            // Configuration related to container image box
            containerBorderSize:    10,            // (integer) If you adjust the padding in the CSS for the container, #lightbox-container-image-box, you will need to update this value
            containerResizeSpeed:    400,        // (integer) Specify the resize duration of container image. These number are miliseconds. 400 is default.
            // Configuration related to texts in caption. For example: Image 2 of 8. You can alter either "Image" and "of" texts.
            txtImage:                ‘Bild’,    // (string) Specify text "Image"
            txtOf:                    ‘von’,        // (string) Specify text "of"
            // Configuration related to keyboard navigation
            keyToClose:                ‘c’,        // (string) (c = close) Letter to close the jQuery lightBox interface. Beyond this letter, the letter X and the SCAPE key is used to.
            keyToPrev:                ‘p’,        // (string) (p = previous) Letter to show the previous image
            keyToNext:                ‘n’,        // (string) (n = next) Letter to show the next image.
            // Don磘 alter these variables in any way
            imageArray:                [],
            activeImage:            0
        },settings);
        // Caching the jQuery object with all elements matched
        var jQueryMatchedObj = this; // This, in this context, refer to jQuery object
        /**
         * Initializing the plugin calling the start function
         *
         * @return boolean false
         */
        function _initialize() {
            _start(this,jQueryMatchedObj); // This, in this context, refer to object (link) which the user have clicked
            return false; // Avoid the browser following the link
        }
        /**
         * Start the jQuery lightBox plugin
         *
         * @param object objClicked The object (link) whick the user have clicked
         * @param object jQueryMatchedObj The jQuery object with all elements matched
         */
        function _start(objClicked,jQueryMatchedObj) {
            // Hime some elements to avoid conflict with overlay in IE. These elements appear above the overlay.
            $(’embed, object, select’).css({ ‘visibility’ : ‘hidden’ });
            // Call the function to create the markup structure; style some elements; assign events in some elements.
            _set_interface();
            // Unset total images in imageArray
            settings.imageArray.length = 0;
            // Unset image active information
            settings.activeImage = 0;
            // We have an image set? Or just an image? Let磗 see it.
            if ( jQueryMatchedObj.length == 1 ) {
                settings.imageArray.push(new Array(objClicked.getAttribute(‘href’),objClicked.getAttribute(‘title’)));
            } else {
                // Add an Array (as many as we have), with href and title atributes, inside the Array that storage the images references
                for ( var i = 0; i < jQueryMatchedObj.length; i++ ) {
                    settings.imageArray.push(new Array(jQueryMatchedObj[i].getAttribute(‘href’),jQueryMatchedObj[i].getAttribute(‘title’)));
                }
            }
            while ( settings.imageArray[settings.activeImage][0] != objClicked.getAttribute(‘href’) ) {
                settings.activeImage++;
            }
            // Call the function that prepares image exibition
            _set_image_to_view();
        }
        /**
         * Create the jQuery lightBox plugin interface
         *
         * The HTML markup will be like that:
            <div id="jquery-overlay"></div>
            <div id="jquery-lightbox">
                <div id="lightbox-container-image-box">
                    <div id="lightbox-container-image">
                        <img src="../fotos/XX.jpg" id="lightbox-image">
                        <div id="lightbox-nav">
                            <a href="#" id="lightbox-nav-btnPrev"></a>
                            <a href="#" id="lightbox-nav-btnNext"></a>
                        </div>
                        <div id="lightbox-loading">
                            <a href="#" id="lightbox-loading-link">
                                <img src="../images/lightbox-ico-loading.gif">
                            </a>
                        </div>
                    </div>
                </div>
                <div id="lightbox-container-image-data-box">
                    <div id="lightbox-container-image-data">
                        <div id="lightbox-image-details">
                            <span id="lightbox-image-details-caption"></span>
                            <span id="lightbox-image-details-currentNumber"></span>
                        </div>
                        <div id="lightbox-secNav">
                            <a href="#" id="lightbox-secNav-btnClose">
                                <img src="../images/lightbox-btn-close.gif">
                            </a>
                        </div>
                    </div>
                </div>
            </div>
         *
         */
        function _set_interface() {
            // Apply the HTML markup into body tag
            $(‘body’).append(‘<div id="jquery-overlay"></div><div id="jquery-lightbox"><div id="lightbox-container-image-box"><div id="lightbox-container-image"><img id="lightbox-image"><div style="" id="lightbox-nav"><a href="#" id="lightbox-nav-btnPrev"></a><a href="#" id="lightbox-nav-btnNext"></a></div><div id="lightbox-loading"><a href="#" id="lightbox-loading-link"><img src="’ + settings.imageLoading + ‘"></a></div></div></div><div id="lightbox-container-image-data-box"><div id="lightbox-container-image-data"><div id="lightbox-image-details"><span id="lightbox-image-details-caption"></span><span id="lightbox-image-details-currentNumber"></span></div><div id="lightbox-secNav"><a href="#" id="lightbox-secNav-btnClose"><img src="’ + settings.imageBtnClose + ‘"></a></div></div></div></div>’);
            // Get page sizes
            var arrPageSizes = ___getPageSize();
            // Style overlay and show it
            $(‘#jquery-overlay’).css({
                backgroundColor:    settings.overlayBgColor,
                opacity:            settings.overlayOpacity,
                width:                arrPageSizes[0],
                height:                arrPageSizes[1]
            }).fadeIn();
            // Get page scroll
            var arrPageScroll = ___getPageScroll();
            // Calculate top and left offset for the jquery-lightbox div object and show it
            $(‘#jquery-lightbox’).css({
                top:    arrPageScroll[1] + (arrPageSizes[3] / 10),
                left:    arrPageScroll[0]
            }).show();
            // Assigning click events in elements to close overlay
            $(‘#jquery-overlay,#jquery-lightbox’).click(function() {
                _finish();
            });
            // Assign the _finish function to lightbox-loading-link and lightbox-secNav-btnClose objects
            $(‘#lightbox-loading-link,#lightbox-secNav-btnClose’).click(function() {
                _finish();
                return false;
            });
            // If window was resized, calculate the new overlay dimensions
            $(window).resize(function() {
                // Get page sizes
                var arrPageSizes = ___getPageSize();
                // Style overlay and show it
                $(‘#jquery-overlay’).css({
                    width:        arrPageSizes[0],
                    height:        arrPageSizes[1]
                });
                // Get page scroll
                var arrPageScroll = ___getPageScroll();
                // Calculate top and left offset for the jquery-lightbox div object and show it
                $(‘#jquery-lightbox’).css({
                    top:    arrPageScroll[1] + (arrPageSizes[3] / 10),
                    left:    arrPageScroll[0]
                });
            });
        }
        /**
         * Prepares image exibition; doing a image磗 preloader to calculate it磗 size
         *
         */
        function _set_image_to_view() { // show the loading
            // Show the loading
            $(‘#lightbox-loading’).show();
            if ( settings.fixedNavigation ) {
                $(‘#lightbox-image,#lightbox-container-image-data-box,#lightbox-image-details-currentNumber’).hide();
            } else {
                // Hide some elements
                $(‘#lightbox-image,#lightbox-nav,#lightbox-nav-btnPrev,#lightbox-nav-btnNext,#lightbox-container-image-data-box,#lightbox-image-details-currentNumber’).hide();
            }
            // Image preload process
            var objImagePreloader = new Image();
            objImagePreloader.onload = function() {
                $(‘#lightbox-image’).attr(‘src’,settings.imageArray[settings.activeImage][0]);
                // Perfomance an effect in the image container resizing it
                _resize_container_image_box(objImagePreloader.width,objImagePreloader.height);
                //    clear onLoad, IE behaves irratically with animated gifs otherwise
                objImagePreloader.onload=function(){};
            };
            objImagePreloader.src = settings.imageArray[settings.activeImage][0];
        };
        /**
         * Perfomance an effect in the image container resizing it
         *
         * @param integer intImageWidth The image磗 width that will be showed
         * @param integer intImageHeight The image磗 height that will be showed
         */
        function _resize_container_image_box(intImageWidth,intImageHeight) {
            // Get current width and height
            var intCurrentWidth = $(‘#lightbox-container-image-box’).width();
            var intCurrentHeight = $(‘#lightbox-container-image-box’).height();
            // Get the width and height of the selected image plus the padding
            var intWidth = (intImageWidth + (settings.containerBorderSize * 2)); // Plus the image磗 width and the left and right padding value
            var intHeight = (intImageHeight + (settings.containerBorderSize * 2)); // Plus the image磗 height and the left and right padding value
            // Diferences
            var intDiffW = intCurrentWidth – intWidth;
            var intDiffH = intCurrentHeight – intHeight;
            // Perfomance the effect
            $(‘#lightbox-container-image-box’).animate({ width: intWidth, height: intHeight },settings.containerResizeSpeed,function() { _show_image(); });
            if ( ( intDiffW == 0 ) && ( intDiffH == 0 ) ) {
                if ( $.browser.msie ) {
                    ___pause(250);
                } else {
                    ___pause(100);
                }
            }
            $(‘#lightbox-container-image-data-box’).css({ width: intImageWidth });
            $(‘#lightbox-nav-btnPrev,#lightbox-nav-btnNext’).css({ height: intImageHeight + (settings.containerBorderSize * 2) });
        };
        /**
         * Show the prepared image
         *
         */
        function _show_image() {
            $(‘#lightbox-loading’).hide();
            $(‘#lightbox-image’).fadeIn(function() {
                _show_image_data();
                _set_navigation();
            });
            _preload_neighbor_images();
        };
        /**
         * Show the image information
         *
         */
        function _show_image_data() {
            $(‘#lightbox-container-image-data-box’).slideDown(‘fast’);
            $(‘#lightbox-image-details-caption’).hide();
            if ( settings.imageArray[settings.activeImage][1] ) {
                $(‘#lightbox-image-details-caption’).html(settings.imageArray[settings.activeImage][1]).show();
            }
            // If we have a image set, display ‘Image X of X’
            if ( settings.imageArray.length > 1 ) {
                $(‘#lightbox-image-details-currentNumber’).html(settings.txtImage + ‘ ‘ + ( settings.activeImage + 1 ) + ‘ ‘ + settings.txtOf + ‘ ‘ + settings.imageArray.length).show();
            }
        }
        /**
         * Display the button navigations
         *
         */
        function _set_navigation() {
            $(‘#lightbox-nav’).show();

            // Instead to define this configuration in CSS file, we define here. And it磗 need to IE. Just.
            $(‘#lightbox-nav-btnPrev,#lightbox-nav-btnNext’).css({ ‘background’ : ‘transparent url(‘ + settings.imageBlank + ‘) no-repeat’ });

            // Show the prev button, if not the first image in set
            if ( settings.activeImage != 0 ) {
                if ( settings.fixedNavigation ) {
                    $(‘#lightbox-nav-btnPrev’).css({ ‘background’ : ‘url(‘ + settings.imageBtnPrev + ‘) left 15% no-repeat’ })
                        .unbind()
                        .bind(‘click’,function() {
                            settings.activeImage = settings.activeImage – 1;
                            _set_image_to_view();
                            return false;
                        });
                } else {
                    // Show the images button for Next buttons
                    $(‘#lightbox-nav-btnPrev’).unbind().hover(function() {
                        $(this).css({ ‘background’ : ‘url(‘ + settings.imageBtnPrev + ‘) left 15% no-repeat’ });
                    },function() {
                        $(this).css({ ‘background’ : ‘transparent url(‘ + settings.imageBlank + ‘) no-repeat’ });
                    }).show().bind(‘click’,function() {
                        settings.activeImage = settings.activeImage – 1;
                        _set_image_to_view();
                        return false;
                    });
                }
            }

            // Show the next button, if not the last image in set
            if ( settings.activeImage != ( settings.imageArray.length -1 ) ) {
                if ( settings.fixedNavigation ) {
                    $(‘#lightbox-nav-btnNext’).css({ ‘background’ : ‘url(‘ + settings.imageBtnNext + ‘) right 15% no-repeat’ })
                        .unbind()
                        .bind(‘click’,function() {
                            settings.activeImage = settings.activeImage + 1;
                            _set_image_to_view();
                            return false;
                        });
                } else {
                    // Show the images button for Next buttons
                    $(‘#lightbox-nav-btnNext’).unbind().hover(function() {
                        $(this).css({ ‘background’ : ‘url(‘ + settings.imageBtnNext + ‘) right 15% no-repeat’ });
                    },function() {
                        $(this).css({ ‘background’ : ‘transparent url(‘ + settings.imageBlank + ‘) no-repeat’ });
                    }).show().bind(‘click’,function() {
                        settings.activeImage = settings.activeImage + 1;
                        _set_image_to_view();
                        return false;
                    });
                }
            }
            // Enable keyboard navigation
            _enable_keyboard_navigation();
        }
        /**
         * Enable a support to keyboard navigation
         *
         */
        function _enable_keyboard_navigation() {
            $(document).keydown(function(objEvent) {
                _keyboard_action(objEvent);
            });
        }
        /**
         * Disable the support to keyboard navigation
         *
         */
        function _disable_keyboard_navigation() {
            $(document).unbind();
        }
        /**
         * Perform the keyboard actions
         *
         */
        function _keyboard_action(objEvent) {
            // To ie
            if ( objEvent == null ) {
                keycode = event.keyCode;
                escapeKey = 27;
            // To Mozilla
            } else {
                keycode = objEvent.keyCode;
                escapeKey = objEvent.DOM_VK_ESCAPE;
            }
            // Get the key in lower case form
            key = String.fromCharCode(keycode).toLowerCase();
            // Verify the keys to close the ligthBox
            if ( ( key == settings.keyToClose ) || ( key == ‘x’ ) || ( keycode == escapeKey ) ) {
                _finish();
            }
            // Verify the key to show the previous image
            if ( ( key == settings.keyToPrev ) || ( keycode == 37 ) ) {
                // If we磖e not showing the first image, call the previous
                if ( settings.activeImage != 0 ) {
                    settings.activeImage = settings.activeImage – 1;
                    _set_image_to_view();
                    _disable_keyboard_navigation();
                }
            }
            // Verify the key to show the next image
            if ( ( key == settings.keyToNext ) || ( keycode == 39 ) ) {
                // If we磖e not showing the last image, call the next
                if ( settings.activeImage != ( settings.imageArray.length – 1 ) ) {
                    settings.activeImage = settings.activeImage + 1;
                    _set_image_to_view();
                    _disable_keyboard_navigation();
                }
            }
        }
        /**
         * Preload prev and next images being showed
         *
         */
        function _preload_neighbor_images() {
            if ( (settings.imageArray.length -1) > settings.activeImage ) {
                objNext = new Image();
                objNext.src = settings.imageArray[settings.activeImage + 1][0];
            }
            if ( settings.activeImage > 0 ) {
                objPrev = new Image();
                objPrev.src = settings.imageArray[settings.activeImage -1][0];
            }
        }
        /**
         * Remove jQuery lightBox plugin HTML markup
         *
         */
        function _finish() {
            $(‘#jquery-lightbox’).remove();
            $(‘#jquery-overlay’).fadeOut(function() { $(‘#jquery-overlay’).remove(); });
            // Show some elements to avoid conflict with overlay in IE. These elements appear above the overlay.
            $(’embed, object, select’).css({ ‘visibility’ : ‘visible’ });
        }
        /**
         / THIRD FUNCTION
         * getPageSize() by quirksmode.com
         *
         * @return Array Return an array with page width, height and window width, height
         */
        function ___getPageSize() {
            var xScroll, yScroll;
            if (window.innerHeight && window.scrollMaxY) {
                xScroll = window.innerWidth + window.scrollMaxX;
                yScroll = window.innerHeight + window.scrollMaxY;
            } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
                xScroll = document.body.scrollWidth;
                yScroll = document.body.scrollHeight;
            } else { // Explorer Mac…would also work in Explorer 6 Strict, Mozilla and Safari
                xScroll = document.body.offsetWidth;
                yScroll = document.body.offsetHeight;
            }
            var windowWidth, windowHeight;
            if (self.innerHeight) {    // all except Explorer
                if(document.documentElement.clientWidth){
                    windowWidth = document.documentElement.clientWidth;
                } else {
                    windowWidth = self.innerWidth;
                }
                windowHeight = self.innerHeight;
            } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
                windowWidth = document.documentElement.clientWidth;
                windowHeight = document.documentElement.clientHeight;
            } else if (document.body) { // other Explorers
                windowWidth = document.body.clientWidth;
                windowHeight = document.body.clientHeight;
            }
            // for small pages with total height less then height of the viewport
            if(yScroll < windowHeight){
                pageHeight = windowHeight;
            } else {
                pageHeight = yScroll;
            }
            // for small pages with total width less then width of the viewport
            if(xScroll < windowWidth){
                pageWidth = xScroll;
            } else {
                pageWidth = windowWidth;
            }
            arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
            return arrayPageSize;
        };
        /**
         / THIRD FUNCTION
         * getPageScroll() by quirksmode.com
         *
         * @return Array Return an array with x,y page scroll values.
         */
        function ___getPageScroll() {
            var xScroll, yScroll;
            if (self.pageYOffset) {
                yScroll = self.pageYOffset;
                xScroll = self.pageXOffset;
            } else if (document.documentElement && document.documentElement.scrollTop) {     // Explorer 6 Strict
                yScroll = document.documentElement.scrollTop;
                xScroll = document.documentElement.scrollLeft;
            } else if (document.body) {// all other Explorers
                yScroll = document.body.scrollTop;
                xScroll = document.body.scrollLeft;
            }
            arrayPageScroll = new Array(xScroll,yScroll);
            return arrayPageScroll;
        };
         /**
          * Stop the code execution from a escified time in milisecond
          *
          */
         function ___pause(ms) {
            var date = new Date();
            curDate = null;
            do { var curDate = new Date(); }
            while ( curDate – date < ms);
         };
        // Return the jQuery object for chaining. The unbind method is used to avoid click conflict when the plugin is called more than once
        return this.unbind(‘click’).click(_initialize);
    };
})(jQuery); // Call and execute the function immediately passing the jQuery object


Copyright © 1996-2010 Add Lives. All rights reserved.
iDream theme by Templates Next | Powered by WordPress