<commit_before>/*
 * Tangram
 * Copyright 2010 Baidu Inc. All right reserved.
 */

///import baidu.dom.g;
///import baidu.dom.getAttr;
///import baidu.dom.setAttr;
///import baidu.dom.getStyle;
///import baidu.dom.getPosition;
///import baidu.dom.setStyle;
///import baidu.dom.setStyles;
///import baidu.event.on;
///import baidu.event.un;
///import baidu.browser.ie;
///import baidu.object.extend;
///import baidu.page.getViewHeight;
///import baidu.page.getViewWidth;

/**
 * 使目标元素拥有可进行与页面可见区域相对位置保持不变的移动的能力
 * @name baidu.dom.fixable
 * @function
 * @param {HTMLElement|String} element 目标元素或目标元素的id
 * @param {Object} options 配置项
 * @config {String} [vertival] 取值[top|bottom] 默认值 top
 * @config {Strgin} [horizontal] 取值[left|right] 默认值 left
 * @config {Object} offset {x:String|Number, y:String|Number}} 横向与纵向的取值
 * @config {Function} onrender
 * @config {Function} onupdate
 * @config {Function} onrelease
 * @return {Object} 
 * @config {Function} render
 * @config {Function} update
 * @config {Function} release
 */

baidu.dom.fixable = function(element, options){

    var target  = baidu.g(element),
        isIE6 = baidu.browser.ie && baidu.browser.ie <= 6 ? true : false,
        isIE7 = baidu.browser.ie && baidu.browser.ie == 7 ? true : false,
        vertival = options.vertival || 'top',
        horizontal = options.horizontal || 'left',
        origPos,offset,isRender = false,
        onrender = options.onrender || new Function(),
        onupdate = options.onupdate || new Function(),
        onrelease = options.onrelease || new Function();

    if(!target) return;

    //获取target原始值
    origPos = _getOriginalStyle();
    //设置offset值
    offset = {y:origPos.top,x:origPos.left};
    baidu.extend(offset, options.offset || {});

    render();
   
    function _convert(){
        return {
            top : vertival == "top" ? offset.y : baidu.page.getViewHeight() - offset.y - origPos.height,
            left: horizontal == "left" ? offset.x : baidu.page.getViewWidth() - offset.x - origPos.width
        };
    }

    /**
     * 
     */
    function _handleOnMove(){
        var p = _convert(); 
        
        target.style.setExpression("left","eval((document.body.scrollLeft || document.documentElement.scrollLeft) + " + p.left + ") + 'px'");
        target.style.setExpression("top", "eval((document.body.scrollTop || document.documentElement.scrollTop) + " + p.top + ") + 'px'");
    }

    /**
     * 返回target原始position值
     * @return {Object}
     */
    function _getOriginalStyle(){
        var result = {
            position: baidu.getStyle(target,"position"),
            height: function(){
                var h = baidu.getStyle(target,"height");
                return (h != "auto") ? (/\d+/.exec(h)[0]) : target.offsetHeight;
            }(),
            width: function(){			
                var w = baidu.getStyle(target,"width");<commit_msg>添加参数 fixable: autofix [Boolean]<commit_after>/*
 * Tangram
 * Copyright 2010 Baidu Inc. All right reserved.
 */

///import baidu.dom.g;
///import baidu.dom.getAttr;
///import baidu.dom.setAttr;
///import baidu.dom.getStyle;
///import baidu.dom.getPosition;
///import baidu.dom.setStyle;
///import baidu.dom.setStyles;
///import baidu.event.on;
///import baidu.event.un;
///import baidu.browser.ie;
///import baidu.object.extend;
///import baidu.page.getViewHeight;
///import baidu.page.getViewWidth;

/**
 * 使目标元素拥有可进行与页面可见区域相对位置保持不变的移动的能力
 * @name baidu.dom.fixable
 * @function
 * @param {HTMLElement|String} element 目标元素或目标元素的id
 * @param {Object} options 配置项
 * @config {String} [vertival] 取值[top|bottom] 默认值 top
 * @config {Strgin} [horizontal] 取值[left|right] 默认值 left
 * @config {Object} offset {x:String|Number, y:String|Number}} 横向与纵向的取值
 * @config {Boolean} [autofix] 是否自动进行fix，默认值为true
 * @config {Function} onrender
 * @config {Function} onupdate
 * @config {Function} onrelease
 * @return {Object} 
 * @config {Function} render
 * @config {Function} update
 * @config {Function} release
 */

baidu.dom.fixable = function(element, options){

    var target  = baidu.g(element),
        isIE6 = baidu.browser.ie && baidu.browser.ie <= 6 ? true : false,
        isIE7 = baidu.browser.ie && baidu.browser.ie == 7 ? true : false,
        vertival = options.vertival || 'top',
        horizontal = options.horizontal || 'left',
        autofix = options.autofix || true,
        origPos,offset,isRender = false,
        onrender = options.onrender || new Function(),
        onupdate = options.onupdate || new Function(),
        onrelease = options.onrelease || new Function();

    if(!target) return;

    //获取target原始值
    origPos = _getOriginalStyle();
    //设置offset值
    offset = {y:origPos.top,x:origPos.left};
    baidu.extend(offset, options.offset || {});

    autofix && render();
   
    function _convert(){
        return {
            top : vertival == "top" ? offset.y : baidu.page.getViewHeight() - offset.y - origPos.height,
            left: horizontal == "left" ? offset.x : baidu.page.getViewWidth() - offset.x - origPos.width
        };
    }

    /**
     * 
     */
    function _handleOnMove(){
        var p = _convert(); 
        
        target.style.setExpression("left","eval((document.body.scrollLeft || document.documentElement.scrollLeft) + " + p.left + ") + 'px'");
        target.style.setExpression("top", "eval((document.body.scrollTop || document.documentElement.scrollTop) + " + p.top + ") + 'px'");
    }

    /**
     * 返回target原始position值
     * @return {Object}
     */
    function _getOriginalStyle(){
        var result = {
            position: baidu.getStyle(target,"position"),
            height: function(){
                var h = baidu.getStyle(target,"height");
                return (h != "auto") ? (/\d+/.exec(h)[0]) : target.offsetHeight;
            }(),
            width: function(){			
                var w = baidu.getStyle(target,"width");
{'fraction_non_alphanumeric': 0.15920651068158698, 'fraction_numerical': 0.003051881993896236, 'mean_word_length': 2.710062893081761, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3916399', 'n_tokens_mistral': 2046, 'n_tokens_neox': 2037, 'n_words': 388}