<commit_before>// <nowiki>
/* globals CloseRfpp:true */
(function() {

    if (typeof CloseRfpp == 'undefined')
        CloseRfpp = {};

    if (typeof CloseRfpp.summarySuffix == 'undefined') {
        CloseRfpp.summarySuffix = ' via [[User:Xiplus/js/close-rfpp.js|close-rfpp]]';
    }

    if (mw.config.get('wgPageName') !== 'Wikipedia:请求保护页面'
        || mw.config.get('wgAction') !== 'view'
        || mw.config.get('wgRevisionId') !== mw.config.get('wgCurRevisionId')) {
        return;
    }

    var getPageContent = new Promise(function(resolve, reject) {
        new mw.Api().get({
            action: 'query',
            prop: 'revisions',
            rvprop: ['content', 'timestamp'],
            titles: 'Wikipedia:请求保护页面',
            formatversion: '2',
            curtimestamp: true
        }).then(function(data) {
            var page, revision;
            if (!data.query || !data.query.pages) {
                mw.notify('未能抓取頁面內容（unknown）');
                reject('unknown');
            }
            page = data.query.pages[0];
            if (!page || page.invalid) {
                mw.notify('未能抓取頁面內容（invalidtitle）');
                reject('invalidtitle');
            }
            if (page.missing) {
                mw.notify('未能抓取頁面內容（nocreate-missing）');
                reject('nocreate-missing');
            }
            revision = page.revisions[0];
            var content = revision.content;
            var basetimestamp = revision.timestamp;
            var curtimestamp = data.curtimestamp;
            resolve({
                content: content,
                basetimestamp: basetimestamp,
                curtimestamp: curtimestamp
            });
        })
    }
    );

    function showCloseButton() {
        var titles = $('#bodyContent').find('h2:has(.mw-headline), h3:has(.mw-headline)');

        var spanTag = function(color, content) {
            var span = document.createElement('span');
            span.style.color = color;
            span.appendChild(document.createTextNode(content));
            return span;
        };
        var delNode = document.createElement('strong');
        var delLink = document.createElement('a');
        delLink.appendChild(spanTag('Black', '['));
        delLink.appendChild(spanTag('Red', wgULS('关闭', '關閉')));
        delLink.appendChild(spanTag('Black', ']'));
        delNode.setAttribute('class', 'CloseRfppBtn');
        delNode.appendChild(delLink);

        titles.each(function(key, current) {
            if (current.nodeName != 'H3') {
                return;
            }
            var node = current.getElementsByClassName('mw-headline')[0];
            var title = $(current).find('.mw-headline')[0].id;

            var tmpNode = delNode.cloneNode(true);
            $(tmpNode.firstChild).click(function() {
                processClose(key, title);
                return false;
            });
            node.appendChild(tmpNode)
        });
    }

    function processClose(sectionid, title) {
        mw.loader.using(['jquery.ui'], function() {
            var html = '
';
            html += '{{RFPP}}
';
            html += '<select class="rfpp">';
            html += '<option value="">選擇</option>';
            html += '<option value="{{RFPP|ch}}">正在檢查以確定是否需要保護</option>';
            html += '<option value="{{RFPP|do}}">完成</option>';
            html += '<option value="{{RFPP|no}}">未完成</option>';
            html += '<option value="{{RFPP|d}}">拒絕</option>';
            html += '<option value="{{RFPP|pf}}">拒絕，暫時不需要改變目前的保護等級</option>';
            html += '<option value="{{RFPP|nea}}">拒絕，近期沒有足夠的擾亂性行為使該頁被保護</option>';
            html += '<option value="{{RFPP|co}}">拒絕，此請求保護可能會額外影響一些正在改善此頁的用戶</option>';
            html += '<option value="{{RFPP|aiv}}">拒絕，請恰當地警告用戶，如繼續請將用戶報告至當前的破壞</option>';
            html += '<option value="{{RFPP|np}}">拒絕，不會做出預見性的保護</option>';
            html += '<option value="{{RFPP|nhr}}">拒絕，模板未有足夠的使用量以使其成為高風險模板</option>';
            html += '<option value="{{RFPP|dr}}">拒絕，內容爭議。請使用條目的討論頁或以其他形式解決爭論</option>';
            html += '<option value="{{RFPP|ut}}">拒絕，除非遇到了嚴重或持續的破壞，否則用戶討論頁不會被保護</option>';
            html += '<option value="{{RFPP|bot}}">拒絕，實際情況可能並非如此（僅用於拒絕機器人的過度提報）</option>';
            html += '<option value="{{RFPP|b}}">用戶已被封禁</option>';
            html += '<option value="{{RFPP|tb}}">用戶已被重新封禁，並禁止其編輯自己的討論頁</option>';
            html += '<option value="{{RFPP|u}}">已解除</option>';
            html += '<option value="{{RFPP|nu}}">未解除保護</option>';
            html += '<option value="{{RFPP|cr}}">未解除保護，請在草稿頁創建條目有可靠來源的版本，完成後請重新提交請求或尋求管理員幫助</option>';
            html += '<option value="{{RFPP|er}}">未解除保護，請在編輯請求以請求對受保護頁面進行特定的更改</option>';
            html += '<option value="{{RFPP|au}}">已解除保護</option>';
            html += '<option value="{{RFPP|ap}}">已保護</option>';
            html += '<option value="{{RFPP|ad}}">已完成</option>';
            html += '<option value="{{RFPP|q}}" data-summary="回應">問題</option>';
            html += '<option value="{{RFPP|n}}" data-summary="回應">備註：</option>';
            html += '<option value="{{RFPP|w}}">請求者取消</option>';
            html += '<option value="{{RFPP|ew}}">考慮舉報3RR，這可能是一兩個用戶間的編輯戰</option>';
            html += '</select>
';
            html += '{{RFPP}}（保護）
';
            html += '<select class="rfpp2">';
            html += '<option value="">選擇等級</option>';
            html += '<option value="s" data-summary="半保護">半保護X，X過後系統會自動解除此頁保護</option>';
            html += '<option value="p" data-summary="全保護">全保護X，X過後系統會自動解除此頁保護</option>';
            html += '<option value="m" data-summary="移動保護">移動保護X，X過後系統會自動解除此頁保護</option>';
            html += '<option value="t" data-summary="白紙保護">白紙保護X ，X過後系統會自動解除此頁保護</option>';
            html += '</select>';
            html += '<select class="rfpptime">';
            html += '<option value="">選擇時長</option>';
            html += '<option value="1天">1天</option>';
            html += '<option value="3天">3天</option>';
            html += '<option value="1週">1週</option>';
            html += '<option value="2週">2週</option>';
            html += '<option value="1個月">1個月</option>';
            html += '<option value="3個月">3個月</option>';
            html += '<option value="6個月">6個月</option>';
            html += '<option value="1年">1年</option>';
            html += '<option value="indef">無限期</option>';
            html += '</select>
';
            html += '留言
';
            html += '<input type="text" class="comment" size="85">';
            html += '編輯摘要
';
            html += '<input type="text" class="summary" size="85" value="回應">';
            html += '
';
            $(html).dialog({
                title: '關閉請求或留言 - ' + title,
                minWidth: 590,
                minHeight: 150,
                buttons: [{
                    text: '確定',
                    click: function() {
                        if ($(this).find('.comment').val().trim() !== '') {
                            processEdit(
                                sectionid,
                                title,
                                $(this).find('.comment').val(),
                                $(this).find('.summary').val()
                            );
                        } else {
                            mw.notify('動作已取消');
                        }
                        $(this).dialog('close');
                    }
                }, {
                    text: '取消',
                    click: function() {
                        $(this).dialog('close');
                    }
                }]
            });
            $('.rfpp').on('change', function(e) {
                var comment = $(e.target).parent().find(".comment");
                var rfpp = $(e.target).parent().find(".rfpp");
                var summary = $(e.target).parent().find(".summary");
                if (rfpp.val() != '') {
                    comment.val(comment.val() + rfpp.val());

                    if (summary.val() === '回應') {
                        summary.val('');
                    }
                    if (summary.val() !== '') {
                        summary.val(summary.val() + '，');
                    }
                    var option = $('option:selected', rfpp);
                    var dataSummary = option.attr('data-summary');
                    if (dataSummary) {
                        summary.val(summary.val() + dataSummary);
                    } else {
                        summary.val(summary.val() + option.text());
                    }

                    rfpp.val('');
                }
            });
            function selectRFPP2(e) {
                var comment = $(e.target).parent().find(".comment");
                var rfpp2 = $(e.target).parent().find(".rfpp2");
                var rfpptime = $(e.target).parent().find(".rfpptime");
                var summary = $(e.target).parent().find(".summary");
                if (rfpp2.val() != '' && rfpptime.val() != '') {
                    comment.val(comment.val() + '{{RFPP|' + rfpp2.val() + '|' + rfpptime.val() + '}}');

                    if (summary.val() === '回應') {
                        summary.val('');
                    }
                    if (summary.val() !== '') {
                        summary.val(summary.val() + '，');
                    }
                    var dataSummary = $('option:selected', rfpp2).attr('data-summary');
                    if (dataSummary) {
                        summary.val(summary.val() + dataSummary + $('option:selected', rfpptime).text());
                    } else {
                        summary.val('回應');
                    }

                    rfpp2.val('');
                    rfpptime.val('');
                }
            }
            $('.rfpp2').on('change', selectRFPP2);
            $('.rfpptime').on('change', selectRFPP2);
        });
    }

    function processEdit(sectionid, title, comment, summary) {
        new mw.Api().edit('Wikipedia:请求保护页面', function(revision) {
            var content = revision.content;
            const splittoken = 'CLOSE_SPLIT_TOKEN';
            content = content.replace(/^==/gm, splittoken + '==');
            var contents = content.split(splittoken);
            var newtext = contents[sectionid];
            newtext = newtext.trim();
            comment = comment.trim();
            if (comment !== '') {
                if (comment.search(/[.?!;。？！；]$/) === -1) {
                    comment += '。';
                }
                newtext += '\n: ' + comment + '--~~~~';
            }
            $($('#bodyContent').find('h2:has(.mw-headline), h3:has(.mw-headline)')[sectionid]).find('.CloseRfppBtn span').css('color', 'grey');
            return {
                text: newtext,
                section: sectionid,
                basetimestamp: revision.timestamp,
                summary: '/* ' + title + ' */ ' + summary + CloseRfpp.summarySuffix,
                minor: true
            };
        }).then(function() {
            mw.notify('已修改 ' + title);
        }, function(e) {
            if (e == 'editconflict') {
                mw.notify('修改 ' + title + ' 時發生編輯衝突');
            } else {
                mw.notify('修改 ' + title + ' 時發生未知錯誤：' + e);
            }
        });
    }

    getPageContent.then(function(result) {
        window.content = result.content;
        var lenintext = result.content.split(/^==/gm).length - 2;
        var leninhtml = $('#bodyContent').find('h2:has(.mw-headline), h3:has(.mw-headline)').length - 2;
        if (leninhtml !== lenintext) {
            mw.notify('抓取章節錯誤，在HTML找到 ' + leninhtml + ' 個章節，在原始碼找到 ' + lenintext + ' 個章節');
        } else {
            showCloseButton();
        }
    });

}
)();
// </nowiki>
<commit_msg>Disable minor edit<commit_after>// <nowiki>
/* globals CloseRfpp:true */
(function() {

    if (typeof CloseRfpp == 'undefined')
        CloseRfpp = {};

    if (typeof CloseRfpp.summarySuffix == 'undefined') {
        CloseRfpp.summarySuffix = ' via [[User:Xiplus/js/close-rfpp.js|close-rfpp]]';
    }

    if (mw.config.get('wgPageName') !== 'Wikipedia:请求保护页面'
        || mw.config.get('wgAction') !== 'view'
        || mw.config.get('wgRevisionId') !== mw.config.get('wgCurRevisionId')) {
        return;
    }

    var getPageContent = new Promise(function(resolve, reject) {
        new mw.Api().get({
            action: 'query',
            prop: 'revisions',
            rvprop: ['content', 'timestamp'],
            titles: 'Wikipedia:请求保护页面',
            formatversion: '2',
            curtimestamp: true
        }).then(function(data) {
            var page, revision;
            if (!data.query || !data.query.pages) {
                mw.notify('未能抓取頁面內容（unknown）');
                reject('unknown');
            }
            page = data.query.pages[0];
            if (!page || page.invalid) {
                mw.notify('未能抓取頁面內容（invalidtitle）');
                reject('invalidtitle');
            }
            if (page.missing) {
                mw.notify('未能抓取頁面內容（nocreate-missing）');
                reject('nocreate-missing');
            }
            revision = page.revisions[0];
            var content = revision.content;
            var basetimestamp = revision.timestamp;
            var curtimestamp = data.curtimestamp;
            resolve({
                content: content,
                basetimestamp: basetimestamp,
                curtimestamp: curtimestamp
            });
        })
    }
    );

    function showCloseButton() {
        var titles = $('#bodyContent').find('h2:has(.mw-headline), h3:has(.mw-headline)');

        var spanTag = function(color, content) {
            var span = document.createElement('span');
            span.style.color = color;
            span.appendChild(document.createTextNode(content));
            return span;
        };
        var delNode = document.createElement('strong');
        var delLink = document.createElement('a');
        delLink.appendChild(spanTag('Black', '['));
        delLink.appendChild(spanTag('Red', wgULS('关闭', '關閉')));
        delLink.appendChild(spanTag('Black', ']'));
        delNode.setAttribute('class', 'CloseRfppBtn');
        delNode.appendChild(delLink);

        titles.each(function(key, current) {
            if (current.nodeName != 'H3') {
                return;
            }
            var node = current.getElementsByClassName('mw-headline')[0];
            var title = $(current).find('.mw-headline')[0].id;

            var tmpNode = delNode.cloneNode(true);
            $(tmpNode.firstChild).click(function() {
                processClose(key, title);
                return false;
            });
            node.appendChild(tmpNode)
        });
    }

    function processClose(sectionid, title) {
        mw.loader.using(['jquery.ui'], function() {
            var html = '
';
            html += '{{RFPP}}
';
            html += '<select class="rfpp">';
            html += '<option value="">選擇</option>';
            html += '<option value="{{RFPP|ch}}">正在檢查以確定是否需要保護</option>';
            html += '<option value="{{RFPP|do}}">完成</option>';
            html += '<option value="{{RFPP|no}}">未完成</option>';
            html += '<option value="{{RFPP|d}}">拒絕</option>';
            html += '<option value="{{RFPP|pf}}">拒絕，暫時不需要改變目前的保護等級</option>';
            html += '<option value="{{RFPP|nea}}">拒絕，近期沒有足夠的擾亂性行為使該頁被保護</option>';
            html += '<option value="{{RFPP|co}}">拒絕，此請求保護可能會額外影響一些正在改善此頁的用戶</option>';
            html += '<option value="{{RFPP|aiv}}">拒絕，請恰當地警告用戶，如繼續請將用戶報告至當前的破壞</option>';
            html += '<option value="{{RFPP|np}}">拒絕，不會做出預見性的保護</option>';
            html += '<option value="{{RFPP|nhr}}">拒絕，模板未有足夠的使用量以使其成為高風險模板</option>';
            html += '<option value="{{RFPP|dr}}">拒絕，內容爭議。請使用條目的討論頁或以其他形式解決爭論</option>';
            html += '<option value="{{RFPP|ut}}">拒絕，除非遇到了嚴重或持續的破壞，否則用戶討論頁不會被保護</option>';
            html += '<option value="{{RFPP|bot}}">拒絕，實際情況可能並非如此（僅用於拒絕機器人的過度提報）</option>';
            html += '<option value="{{RFPP|b}}">用戶已被封禁</option>';
            html += '<option value="{{RFPP|tb}}">用戶已被重新封禁，並禁止其編輯自己的討論頁</option>';
            html += '<option value="{{RFPP|u}}">已解除</option>';
            html += '<option value="{{RFPP|nu}}">未解除保護</option>';
            html += '<option value="{{RFPP|cr}}">未解除保護，請在草稿頁創建條目有可靠來源的版本，完成後請重新提交請求或尋求管理員幫助</option>';
            html += '<option value="{{RFPP|er}}">未解除保護，請在編輯請求以請求對受保護頁面進行特定的更改</option>';
            html += '<option value="{{RFPP|au}}">已解除保護</option>';
            html += '<option value="{{RFPP|ap}}">已保護</option>';
            html += '<option value="{{RFPP|ad}}">已完成</option>';
            html += '<option value="{{RFPP|q}}" data-summary="回應">問題</option>';
            html += '<option value="{{RFPP|n}}" data-summary="回應">備註：</option>';
            html += '<option value="{{RFPP|w}}">請求者取消</option>';
            html += '<option value="{{RFPP|ew}}">考慮舉報3RR，這可能是一兩個用戶間的編輯戰</option>';
            html += '</select>
';
            html += '{{RFPP}}（保護）
';
            html += '<select class="rfpp2">';
            html += '<option value="">選擇等級</option>';
            html += '<option value="s" data-summary="半保護">半保護X，X過後系統會自動解除此頁保護</option>';
            html += '<option value="p" data-summary="全保護">全保護X，X過後系統會自動解除此頁保護</option>';
            html += '<option value="m" data-summary="移動保護">移動保護X，X過後系統會自動解除此頁保護</option>';
            html += '<option value="t" data-summary="白紙保護">白紙保護X ，X過後系統會自動解除此頁保護</option>';
            html += '</select>';
            html += '<select class="rfpptime">';
            html += '<option value="">選擇時長</option>';
            html += '<option value="1天">1天</option>';
            html += '<option value="3天">3天</option>';
            html += '<option value="1週">1週</option>';
            html += '<option value="2週">2週</option>';
            html += '<option value="1個月">1個月</option>';
            html += '<option value="3個月">3個月</option>';
            html += '<option value="6個月">6個月</option>';
            html += '<option value="1年">1年</option>';
            html += '<option value="indef">無限期</option>';
            html += '</select>
';
            html += '留言
';
            html += '<input type="text" class="comment" size="85">';
            html += '編輯摘要
';
            html += '<input type="text" class="summary" size="85" value="回應">';
            html += '
';
            $(html).dialog({
                title: '關閉請求或留言 - ' + title,
                minWidth: 590,
                minHeight: 150,
                buttons: [{
                    text: '確定',
                    click: function() {
                        if ($(this).find('.comment').val().trim() !== '') {
                            processEdit(
                                sectionid,
                                title,
                                $(this).find('.comment').val(),
                                $(this).find('.summary').val()
                            );
                        } else {
                            mw.notify('動作已取消');
                        }
                        $(this).dialog('close');
                    }
                }, {
                    text: '取消',
                    click: function() {
                        $(this).dialog('close');
                    }
                }]
            });
            $('.rfpp').on('change', function(e) {
                var comment = $(e.target).parent().find(".comment");
                var rfpp = $(e.target).parent().find(".rfpp");
                var summary = $(e.target).parent().find(".summary");
                if (rfpp.val() != '') {
                    comment.val(comment.val() + rfpp.val());

                    if (summary.val() === '回應') {
                        summary.val('');
                    }
                    if (summary.val() !== '') {
                        summary.val(summary.val() + '，');
                    }
                    var option = $('option:selected', rfpp);
                    var dataSummary = option.attr('data-summary');
                    if (dataSummary) {
                        summary.val(summary.val() + dataSummary);
                    } else {
                        summary.val(summary.val() + option.text());
                    }

                    rfpp.val('');
                }
            });
            function selectRFPP2(e) {
                var comment = $(e.target).parent().find(".comment");
                var rfpp2 = $(e.target).parent().find(".rfpp2");
                var rfpptime = $(e.target).parent().find(".rfpptime");
                var summary = $(e.target).parent().find(".summary");
                if (rfpp2.val() != '' && rfpptime.val() != '') {
                    comment.val(comment.val() + '{{RFPP|' + rfpp2.val() + '|' + rfpptime.val() + '}}');

                    if (summary.val() === '回應') {
                        summary.val('');
                    }
                    if (summary.val() !== '') {
                        summary.val(summary.val() + '，');
                    }
                    var dataSummary = $('option:selected', rfpp2).attr('data-summary');
                    if (dataSummary) {
                        summary.val(summary.val() + dataSummary + $('option:selected', rfpptime).text());
                    } else {
                        summary.val('回應');
                    }

                    rfpp2.val('');
                    rfpptime.val('');
                }
            }
            $('.rfpp2').on('change', selectRFPP2);
            $('.rfpptime').on('change', selectRFPP2);
        });
    }

    function processEdit(sectionid, title, comment, summary) {
        new mw.Api().edit('Wikipedia:请求保护页面', function(revision) {
            var content = revision.content;
            const splittoken = 'CLOSE_SPLIT_TOKEN';
            content = content.replace(/^==/gm, splittoken + '==');
            var contents = content.split(splittoken);
            var newtext = contents[sectionid];
            newtext = newtext.trim();
            comment = comment.trim();
            if (comment !== '') {
                if (comment.search(/[.?!;。？！；]$/) === -1) {
                    comment += '。';
                }
                newtext += '\n: ' + comment + '--~~~~';
            }
            $($('#bodyContent').find('h2:has(.mw-headline), h3:has(.mw-headline)')[sectionid]).find('.CloseRfppBtn span').css('color', 'grey');
            return {
                text: newtext,
                section: sectionid,
                basetimestamp: revision.timestamp,
                summary: '/* ' + title + ' */ ' + summary + CloseRfpp.summarySuffix
            };
        }).then(function() {
            mw.notify('已修改 ' + title);
        }, function(e) {
            if (e == 'editconflict') {
                mw.notify('修改 ' + title + ' 時發生編輯衝突');
            } else {
                mw.notify('修改 ' + title + ' 時發生未知錯誤：' + e);
            }
        });
    }

    getPageContent.then(function(result) {
        window.content = result.content;
        var lenintext = result.content.split(/^==/gm).length - 2;
        var leninhtml = $('#bodyContent').find('h2:has(.mw-headline), h3:has(.mw-headline)').length - 2;
        if (leninhtml !== lenintext) {
            mw.notify('抓取章節錯誤，在HTML找到 ' + leninhtml + ' 個章節，在原始碼找到 ' + lenintext + ' 個章節');
        } else {
            showCloseButton();
        }
    });

}
)();
// </nowiki>
<|endoftext|>


<commit_before>import React from 'react';
import PropTypes from 'prop-types';
import { variables } from 'cf-style-const';

import { rem } from 'polished';

var numberOrString = PropTypes.oneOfType([PropTypes.string, PropTypes.number]);

const pxToRem = value => {
  if (typeof value === 'number' || /\d+px/.test(value)) {
    return rem(value, variables.fontSize);
  }
  return value;
};

// The export of this module is a datastructuer containing metadata
// which powers:
//  - the creation of fela style rules
//  - the creation of the theme in BoxTheme
//  - a number of safety checks
//
// At a bare minimum, the propType must be specified to support a
// new style property
//
// In addition, several other properties can be specified in the spec.
//
// Conflicts with shows an error if the developer tries to use both props.
//
// For example, given the following spec:
//
//    foo: {
//      propType: numberOrString,
//      conflictsWith: [
//        'bar',
//      ]
//    },
//
//  passing the foo and bar props to the component will cause a warning.
//
//  Providing 'preprocessWith' will cause all the provided callbacks
//  to be invoked on the passed prop when building the components styles
//
//  For example, given the following spec:
//    foo: {
//      propType: number,
//      preprocessWith: [ 'pxToRem' ]
//   },
//
//  The value of the 'foo' prop will be transformed with pxToRem.
//
//  The default property is currently un-used. They're left in place
//  in case we arrive upon a performant solution to using them (like
//  generating the code for the Box component).
//
export default {
  margin: {
    propType: numberOrString,
    conflictsWith: ['marginTop', 'marginBottom', 'marginLeft', 'marginRight']
  },
  marginTop: {
    propType: numberOrString,
    default: 0,
    preprocessWith: [pxToRem]
  },
  marginBottom: {
    propType: numberOrString,
    default: 0,
    preprocessWith: [pxToRem]
  },
  marginLeft: {
    propType: numberOrString,
    default: 0,
    preprocessWith: [pxToRem]
  },
  marginRight: {
    propType: numberOrString,
    default: 0,
    preprocessWith: [pxToRem]
  },

  padding: {
    propType: numberOrString,
    conflictsWith: [
      'paddingTop',
      'paddingBottom',
      'paddingLeft',
      'paddingRight'
    ]
  },
  paddingTop: {
    propType: numberOrString,
    default: 0,
    preprocessWith: [pxToRem]
  },
  paddingBottom: {
    propType: numberOrString,
    default: 0,
    preprocessWith: [pxToRem]
  },
  paddingLeft: {
    propType: numberOrString,
    default: 0,
    preprocessWith: [pxToRem]
  },
  paddingRight: {
    propType: numberOrString,
    default: 0,
    preprocessWith: [pxToRem]
  },

  overflow: {
    propType: PropTypes.oneOf([
      'visible',
      'hidden',
      'scroll',
      'auto',
      'inherit',
      'initial',
      'unset'
    ])
  },

  border: {
    propType: PropTypes.string,
    conflictsWith: [
      'borderStyle',
      'borderColor',
      'borderWidth',
      'borderTopColor',
      'borderBottomColor',
      'borderLeftColor',
      'borderRightColor',
      'borderTopStyle',
      'borderBottomStyle',
      'borderLeftStyle',
      'borderRightStyle',
      'borderTopWidth',
      'borderBottomWidth',
      'borderLeftWidth',
      'borderRightWidth'
    ]
  },

  borderColor: {
    propType: PropTypes.string,
    conflictsWith: [
      'borderTopColor',
      'borderBottomColor',
      'borderLeftColor',
      'borderRightColor'
    ]
  },
  borderTopColor: {
    propType: PropTypes.string
  },
  borderBottomColor: {
    propType: PropTypes.string
  },
  borderLeftColor: {
    propType: PropTypes.string
  },
  borderRightColor: {
    propType: PropTypes.string
  },

  borderStyle: {
    propType: PropTypes.string,
    conflictsWith: [
      'borderTopStyle',
      'borderBottomStyle',
      'borderLeftStyle',
      'borderRightStyle'
    ]
  },
  borderTopStyle: {
    propType: PropTypes.string
  },
  borderBottomStyle: {
    propType: PropTypes.string
  },
  borderLeftStyle: {
    propType: PropTypes.string
  },
  borderRightStyle: {
    propType: PropTypes.string
  },

  borderWidth: {
    propType: PropTypes.number,
    conflictsWith: [
      'borderTopWidth',
      'borderBottomWidth',
      'borderLeftWidth',
      'borderRightWidth'
    ]
  },
  borderTopWidth: {
    propType: PropTypes.number
  },
  borderBottomWidth: {
    propType: PropTypes.number
  },
  borderLeftWidth: {
    propType: PropTypes.number
  },
  borderRightWidth: {
    propType: PropTypes.number
  },

  lineHeight: {
    propType: PropTypes.number,
    default: variables.lineHeight
  },
  fontSize: {
    propType: numberOrString,
    default: variables.fontSize
  },
  fontWeight: {
    propType: PropTypes.number,
    default: variables.fontWeight
  },
  fontFamily: {
    propType: PropTypes.string,
    default: variables.fontFamily
  },
  color: {
    propType: PropTypes.string,
    default: variables.fontColor
  },

  backgroundColor: {
    propType: PropTypes.string,
    default: 'transparent'
  },

  backgroundImage: {
    propType: PropTypes.string
  },

  backgroundPosition: {
    propType: PropTypes.string
  },

  backgroundPositionX: {
    propType: PropTypes.string
  },

  backgroundPositionY: {
    propType: PropTypes.string
  },

  display: {
    propType: PropTypes.oneOf([
      'inline',
      'block',
      'inline-block',
      'flex',
      'inline-flex'
    ]),
    default: 'block'
  },

  position: {
    propType: PropTypes.oneOf(['static', 'relative', 'absolute', 'fixed']),
    default: 'static'
  },

  float: {
    propType: PropTypes.oneOf([
      'left',
      'right',
      'none',
      'inline-start',
      'inline-end'
    ])
  },

  top: {
    propType: numberOrString,
    default: 'auto',
    preprocessWith: [pxToRem]
  },
  bottom: {
    propType: numberOrString,
    default: 'auto',
    preprocessWith: [pxToRem]
  },
  left: {
    propType: numberOrString,
    default: 'auto',
    preprocessWith: [pxToRem]
  },
  right: {
    propType: numberOrString,
    default: 'auto',
    preprocessWith: [pxToRem]
  },

  width: {
    propType: numberOrString,
    default: 'auto',
    preprocessWith: [pxToRem]
  },
  height: {
    propType: numberOrString,
    default: 'auto',
    preprocessWith: [pxToRem]
  },
  minWidth: {
    propType: numberOrString,
    default: 0,
    preprocessWith: [pxToRem]
  },
  minHeight: {
    propType: numberOrString,
    default: 0,
    preprocessWith: [pxToRem]
  },
  maxWidth: {
    propType: numberOrString,
    default: 0,
    preprocessWith: [pxToRem]
  },
  maxHeight: {
    propType: numberOrString,
    default: 0,
    preprocessWith: [pxToRem]
  },

  verticalAlign: {
    propType: numberOrString,
    default: 'baseline'
  },

  transform: {
    propType: PropTypes.string
  },

  flexDirection: {
    propType: PropTypes.oneOf([
      'row',
      'row-reverse',
      'column',
      'column-reverse'
    ]),
    default: 'row'
  },

  flexWrap: {
    propType: PropTypes.oneOf(['nowrap', 'wrap', 'wrap-reverse']),
    default: 'nowrap'
  },

  justifyContent: {
    propType: PropTypes.oneOf([
      'flex-start',
      'flex-end',
      'center',
      'space-between',
      'space-around'
    ]),
    default: 'flex-start'
  },

  alignItems: {
    propType: PropTypes.oneOf([
      'flex-start',
      'flex-end',
      'center',
      'baseline',
      'stretch'
    ]),
    default: 'stretch'
  },

  alignContent: {
    propType: PropTypes.oneOf([
      'flex-start',
      'flex-end',
      'center',
      'space-between',
      'space-around',
      'stretch'
    ]),
    default: 'stretch'
  },

  order: {
    propType: PropTypes.number,
    default: 0
  },

  flexGrow: {
    propType: PropTypes.number,
    default: 0
  },

  flexShrink: {
    propType: PropTypes.number,
    default: 1
  },

  flexBasis: {
    propType: numberOrString,
    default: 'auto'
  },

  flex: {
    propType: PropTypes.string
  },

  alignSelf: {
    propType: PropTypes.oneOf([
      'auto',
      'flex-start',
      'flex-end',
      'center',
      'baseline',
      'stretch'
    ]),
    default: 'auto'
  },

  zIndex: {
    propType: numberOrString,
    default: 'auto'
  },

  textAlign: {
    propType: PropTypes.oneOf([
      'left',
      'right',
      'center',
      'justify',
      'justify-all',
      'start',
      'end',
      'match-parent'
    ]),
    default: 'start'
  },

  textDecoration: {
    propType: PropTypes.oneOf([
      'none',
      'underline',
      'overline',
      'line-through',
      'initial',
      'inherit'
    ]),
    default: 'initial'
  },

  opacity: {
    propType: numberOrString,
    default: 1.0
  },

  userSelect: {
    propType: PropTypes.oneOf(['none', 'auto', 'text', 'container', 'all']),
    default: 'auto'
  },

  wordWrap: {
    propType: PropTypes.oneOf([
      'normal',
      'break-word',
      'inherit',
      'initial',
      'unset'
    ]),
    default: 'normal'
  },

  clear: {
    propType: PropTypes.oneOf([
      'none',
      'left',
      'right',
      'both',
      'initial',
      'inherit'
    ]),
    default: 'none'
  }
};

/*
 * Need support for:
   content
   outline
   border-radius
   box-shadow
*/
<commit_msg>chore(cf-component-box): Added missing display table props (#327)<commit_after>import React from 'react';
import PropTypes from 'prop-types';
import { variables } from 'cf-style-const';

import { rem } from 'polished';

var numberOrString = PropTypes.oneOfType([PropTypes.string, PropTypes.number]);

const pxToRem = value => {
  if (typeof value === 'number' || /\d+px/.test(value)) {
    return rem(value, variables.fontSize);
  }
  return value;
};

// The export of this module is a datastructuer containing metadata
// which powers:
//  - the creation of fela style rules
//  - the creation of the theme in BoxTheme
//  - a number of safety checks
//
// At a bare minimum, the propType must be specified to support a
// new style property
//
// In addition, several other properties can be specified in the spec.
//
// Conflicts with shows an error if the developer tries to use both props.
//
// For example, given the following spec:
//
//    foo: {
//      propType: numberOrString,
//      conflictsWith: [
//        'bar',
//      ]
//    },
//
//  passing the foo and bar props to the component will cause a warning.
//
//  Providing 'preprocessWith' will cause all the provided callbacks
//  to be invoked on the passed prop when building the components styles
//
//  For example, given the following spec:
//    foo: {
//      propType: number,
//      preprocessWith: [ 'pxToRem' ]
//   },
//
//  The value of the 'foo' prop will be transformed with pxToRem.
//
//  The default property is currently un-used. They're left in place
//  in case we arrive upon a performant solution to using them (like
//  generating the code for the Box component).
//
export default {
  margin: {
    propType: numberOrString,
    conflictsWith: ['marginTop', 'marginBottom', 'marginLeft', 'marginRight']
  },
  marginTop: {
    propType: numberOrString,
    default: 0,
    preprocessWith: [pxToRem]
  },
  marginBottom: {
    propType: numberOrString,
    default: 0,
    preprocessWith: [pxToRem]
  },
  marginLeft: {
    propType: numberOrString,
    default: 0,
    preprocessWith: [pxToRem]
  },
  marginRight: {
    propType: numberOrString,
    default: 0,
    preprocessWith: [pxToRem]
  },

  padding: {
    propType: numberOrString,
    conflictsWith: [
      'paddingTop',
      'paddingBottom',
      'paddingLeft',
      'paddingRight'
    ]
  },
  paddingTop: {
    propType: numberOrString,
    default: 0,
    preprocessWith: [pxToRem]
  },
  paddingBottom: {
    propType: numberOrString,
    default: 0,
    preprocessWith: [pxToRem]
  },
  paddingLeft: {
    propType: numberOrString,
    default: 0,
    preprocessWith: [pxToRem]
  },
  paddingRight: {
    propType: numberOrString,
    default: 0,
    preprocessWith: [pxToRem]
  },

  overflow: {
    propType: PropTypes.oneOf([
      'visible',
      'hidden',
      'scroll',
      'auto',
      'inherit',
      'initial',
      'unset'
    ])
  },

  border: {
    propType: PropTypes.string,
    conflictsWith: [
      'borderStyle',
      'borderColor',
      'borderWidth',
      'borderTopColor',
      'borderBottomColor',
      'borderLeftColor',
      'borderRightColor',
      'borderTopStyle',
      'borderBottomStyle',
      'borderLeftStyle',
      'borderRightStyle',
      'borderTopWidth',
      'borderBottomWidth',
      'borderLeftWidth',
      'borderRightWidth'
    ]
  },

  borderColor: {
    propType: PropTypes.string,
    conflictsWith: [
      'borderTopColor',
      'borderBottomColor',
      'borderLeftColor',
      'borderRightColor'
    ]
  },
  borderTopColor: {
    propType: PropTypes.string
  },
  borderBottomColor: {
    propType: PropTypes.string
  },
  borderLeftColor: {
    propType: PropTypes.string
  },
  borderRightColor: {
    propType: PropTypes.string
  },

  borderStyle: {
    propType: PropTypes.string,
    conflictsWith: [
      'borderTopStyle',
      'borderBottomStyle',
      'borderLeftStyle',
      'borderRightStyle'
    ]
  },
  borderTopStyle: {
    propType: PropTypes.string
  },
  borderBottomStyle: {
    propType: PropTypes.string
  },
  borderLeftStyle: {
    propType: PropTypes.string
  },
  borderRightStyle: {
    propType: PropTypes.string
  },

  borderWidth: {
    propType: PropTypes.number,
    conflictsWith: [
      'borderTopWidth',
      'borderBottomWidth',
      'borderLeftWidth',
      'borderRightWidth'
    ]
  },
  borderTopWidth: {
    propType: PropTypes.number
  },
  borderBottomWidth: {
    propType: PropTypes.number
  },
  borderLeftWidth: {
    propType: PropTypes.number
  },
  borderRightWidth: {
    propType: PropTypes.number
  },

  lineHeight: {
    propType: PropTypes.number,
    default: variables.lineHeight
  },
  fontSize: {
    propType: numberOrString,
    default: variables.fontSize
  },
  fontWeight: {
    propType: PropTypes.number,
    default: variables.fontWeight
  },
  fontFamily: {
    propType: PropTypes.string,
    default: variables.fontFamily
  },
  color: {
    propType: PropTypes.string,
    default: variables.fontColor
  },

  backgroundColor: {
    propType: PropTypes.string,
    default: 'transparent'
  },

  backgroundImage: {
    propType: PropTypes.string
  },

  backgroundPosition: {
    propType: PropTypes.string
  },

  backgroundPositionX: {
    propType: PropTypes.string
  },

  backgroundPositionY: {
    propType: PropTypes.string
  },

  display: {
    propType: PropTypes.oneOf([
      'inline',
      'block',
      'inline-block',
      'flex',
      'inline-flex',
      'table',
      'table-cell'
    ]),
    default: 'block'
  },

  position: {
    propType: PropTypes.oneOf(['static', 'relative', 'absolute', 'fixed']),
    default: 'static'
  },

  float: {
    propType: PropTypes.oneOf([
      'left',
      'right',
      'none',
      'inline-start',
      'inline-end'
    ])
  },

  top: {
    propType: numberOrString,
    default: 'auto',
    preprocessWith: [pxToRem]
  },
  bottom: {
    propType: numberOrString,
    default: 'auto',
    preprocessWith: [pxToRem]
  },
  left: {
    propType: numberOrString,
    default: 'auto',
    preprocessWith: [pxToRem]
  },
  right: {
    propType: numberOrString,
    default: 'auto',
    preprocessWith: [pxToRem]
  },

  width: {
    propType: numberOrString,
    default: 'auto',
    preprocessWith: [pxToRem]
  },
  height: {
    propType: numberOrString,
    default: 'auto',
    preprocessWith: [pxToRem]
  },
  minWidth: {
    propType: numberOrString,
    default: 0,
    preprocessWith: [pxToRem]
  },
  minHeight: {
    propType: numberOrString,
    default: 0,
    preprocessWith: [pxToRem]
  },
  maxWidth: {
    propType: numberOrString,
    default: 0,
    preprocessWith: [pxToRem]
  },
  maxHeight: {
    propType: numberOrString,
    default: 0,
    preprocessWith: [pxToRem]
  },

  verticalAlign: {
    propType: numberOrString,
    default: 'baseline'
  },

  transform: {
    propType: PropTypes.string
  },

  flexDirection: {
    propType: PropTypes.oneOf([
      'row',
      'row-reverse',
      'column',
      'column-reverse'
    ]),
    default: 'row'
  },

  flexWrap: {
    propType: PropTypes.oneOf(['nowrap', 'wrap', 'wrap-reverse']),
    default: 'nowrap'
  },

  justifyContent: {
    propType: PropTypes.oneOf([
      'flex-start',
      'flex-end',
      'center',
      'space-between',
      'space-around'
    ]),
    default: 'flex-start'
  },

  alignItems: {
    propType: PropTypes.oneOf([
      'flex-start',
      'flex-end',
      'center',
      'baseline',
      'stretch'
    ]),
    default: 'stretch'
  },

  alignContent: {
    propType: PropTypes.oneOf([
      'flex-start',
      'flex-end',
      'center',
      'space-between',
      'space-around',
      'stretch'
    ]),
    default: 'stretch'
  },

  order: {
    propType: PropTypes.number,
    default: 0
  },

  flexGrow: {
    propType: PropTypes.number,
    default: 0
  },

  flexShrink: {
    propType: PropTypes.number,
    default: 1
  },

  flexBasis: {
    propType: numberOrString,
    default: 'auto'
  },

  flex: {
    propType: PropTypes.string
  },

  alignSelf: {
    propType: PropTypes.oneOf([
      'auto',
      'flex-start',
      'flex-end',
      'center',
      'baseline',
      'stretch'
    ]),
    default: 'auto'
  },

  zIndex: {
    propType: numberOrString,
    default: 'auto'
  },

  textAlign: {
    propType: PropTypes.oneOf([
      'left',
      'right',
      'center',
      'justify',
      'justify-all',
      'start',
      'end',
      'match-parent'
    ]),
    default: 'start'
  },

  textDecoration: {
    propType: PropTypes.oneOf([
      'none',
      'underline',
      'overline',
      'line-through',
      'initial',
      'inherit'
    ]),
    default: 'initial'
  },

  opacity: {
    propType: numberOrString,
    default: 1.0
  },

  userSelect: {
    propType: PropTypes.oneOf(['none', 'auto', 'text', 'container', 'all']),
    default: 'auto'
  },

  wordWrap: {
    propType: PropTypes.oneOf([
      'normal',
      'break-word',
      'inherit',
      'initial',
      'unset'
    ]),
    default: 'normal'
  },

  clear: {
    propType: PropTypes.oneOf([
      'none',
      'left',
      'right',
      'both',
      'initial',
      'inherit'
    ]),
    default: 'none'
  }
};

/*
 * Need support for:
   content
   outline
   border-radius
   box-shadow
*/
<|endoftext|>


<commit_before>// @flow
import {PSEUDO} from 'shared/constants'
import {property} from 'lodash'

export const Match = {
    lastMessage: match => {
        if (match.messages.length === 0) {
            return {
                formattedMessage: "It's a match!",
                status: PSEUDO
            }
        } else {
            const message = match.messages[match.messages.length - 1];
            if (message.isGIPHY) {
                return {
                    formattedMessage: "GIPHY",
                    status: PSEUDO
                }
            } else {
                return message
            }
        }
    },
    lastActivityDate: property('last_activity_date'),
    isSuperLike: match => {
        if (typeof match.is_super_like === 'undefined') {
            return false
        } else {
            return match.is_super_like
        }
    }
}<commit_msg>Adds _id for proper normalization<commit_after>// @flow
import {PSEUDO} from 'shared/constants'
import {property} from 'lodash'

export const Match = {
    lastMessage: match => {
        if (match.messages.length === 0) {
            return {
                formattedMessage: "It's a match!",
                status: PSEUDO,
                _id: `${match._id}_last`
            }
        } else {
            const message = match.messages[match.messages.length - 1];
            if (message.isGIPHY) {
                return {
                    formattedMessage: "GIPHY",
                    status: PSEUDO,
                    _id: `${match._id}_last`
                }
            } else {
                return message
            }
        }
    },
    lastActivityDate: property('last_activity_date'),
    isSuperLike: match => {
        if (typeof match.is_super_like === 'undefined') {
            return false
        } else {
            return match.is_super_like
        }
    }
}<|endoftext|>


<commit_before>import Ember from 'ember';
import adobeBlank from './adobe-blank';
import { measureText } from "dom-ruler";

const { RSVP } = Ember;

var sheet;
function injectAdobeBlank() {
  if (sheet) {
    return sheet;
  }

  const element = document.createElement('style');
  const head = document.getElementsByTagName('head')[0] ||
               document.documentElement;
  element.type = 'text/css';
  head.appendChild(element);

  sheet = document.styleSheets[document.styleSheets.length - 1];
  if (sheet.insertRule) {
    sheet.insertRule(`@font-face { ${adobeBlank} }`, 0);
  } else {
    sheet.addRule('@font-face', adobeBlank, 0);
  }
}

const SPECIMEN = " !\"\\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~";
var referenceSize;

function getReferenceSize() {
  if (referenceSize) {
    return referenceSize;
  }
  return referenceSize = measureText(SPECIMEN, {
    fontFamily: `"AdobeBlank"`
  }, {});
}

function checkIfFontLoaded(fontFamily, options, resolve, reject) {
  let blankSize = getReferenceSize();
  let size = measureText(SPECIMEN, {
    "font-family": `${fontFamily}, "AdobeBlank"`
  }, {});

  if (size.width !== blankSize.width ||
      size.height !== blankSize.height) {
    resolve();
  } else if (options.timeout <= 0) {
    reject();
  } else {
    setTimeout(function () {
      options.timeout -= 50;
      checkIfFontLoaded(fontFamily, options, resolve, reject);
    }, 50);
  }
}

var loadedFonts = {};
export default function (fontFamily, options={ timeout: 3000 }) {
  injectAdobeBlank();

  if (loadedFonts[fontFamily] == null) {
    loadedFonts[fontFamily] = new RSVP.Promise(function (resolve, reject) {
      checkIfFontLoaded(fontFamily, Ember.copy(options, true), resolve, reject);
    });
  }

  return loadedFonts[fontFamily];
}
<commit_msg>be more conservative in where to inject the stylesheet for adobe blank<commit_after>import Ember from 'ember';
import adobeBlank from './adobe-blank';
import { measureText } from "dom-ruler";

const { RSVP } = Ember;

var sheet;
function injectAdobeBlank() {
  if (sheet) {
    return sheet;
  }

  const element = document.createElement('style');
  const parent = document.head || document.body;
  parent.appendChild(element);

  // Find the stylesheet object created by the DOM element
  for (var i = document.styleSheets.length - 1; i >= 0; i--) {
    let stylesheet = document.styleSheets[i];
    if (stylesheet.ownerNode === element) {
      sheet = stylesheet;
      break;
    }
  }

  if (sheet.insertRule) {
    sheet.insertRule(`@font-face { ${adobeBlank} }`, 0);
  } else {
    sheet.addRule('@font-face', adobeBlank, 0);
  }
}

const SPECIMEN = " !\"\\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~";
var referenceSize;

function getReferenceSize() {
  if (referenceSize) {
    return referenceSize;
  }
  return referenceSize = measureText(SPECIMEN, {
    fontFamily: `"AdobeBlank"`
  }, {});
}

function checkIfFontLoaded(fontFamily, options, resolve, reject) {
  let blankSize = getReferenceSize();
  let size = measureText(SPECIMEN, {
    "font-family": `${fontFamily}, "AdobeBlank"`
  }, {});

  if (size.width !== blankSize.width ||
      size.height !== blankSize.height) {
    resolve();
  } else if (options.timeout <= 0) {
    reject();
  } else {
    setTimeout(function () {
      options.timeout -= 50;
      checkIfFontLoaded(fontFamily, options, resolve, reject);
    }, 50);
  }
}

var loadedFonts = {};
export default function (fontFamily, options={ timeout: 3000 }) {
  injectAdobeBlank();

  if (loadedFonts[fontFamily] == null) {
    loadedFonts[fontFamily] = new RSVP.Promise(function (resolve, reject) {
      checkIfFontLoaded(fontFamily, Ember.copy(options, true), resolve, reject);
    });
  }

  return loadedFonts[fontFamily];
}
<|endoftext|>


<commit_before>enchant.DomManager = enchant.Class.create({
    initialize: function(node, elementDefinition) {
        var game = enchant.Game.instance;
        this.layer = null;
        this.targetNode = node;
        if (typeof elementDefinition === 'string') {
            this.element = document.createElement(elementDefinition);
        } else if (elementDefinition instanceof HTMLElement) {
            this.element = elementDefinition;
        } else {
            // TODO error
        }
        this.style = this.element.style;
        this.style.position = 'absolute';
        this.style[enchant.ENV.VENDOR_PREFIX + 'TransformOrigin'] = '0px 0px';
        if (game._debug) {
            this.style.border = '1px solid blue';
            this.style.margin = '-1px';
        }

        var manager = this;
        this._setDomTarget = function() {
            manager.layer._touchEventTarget = manager.targetNode;
        };
        this._attachEvent();
    },
    getDomElement: function() {
        return this.element;
    },
    getDomElementAsNext: function() {
        return this.element;
    },
    getNextManager: function(manager) {
        var i = this.targetNode.parentNode.childNodes.indexOf(manager.targetNode);
        if (i !== this.targetNode.parentNode.childNodes.length - 1) {
            return this.targetNode.parentNode.childNodes[i + 1]._domManager;
        } else {
            return null;
        }
    },
    addManager: function(childManager, nextManager) {
        var nextElement;
        if (nextManager) {
            nextElement = nextManager.getDomElementAsNext();
        } else if (this.targetNode.parentNode) {
            //nextElement = this.getNextManager(this);
        }
        this.element.insertBefore(childManager.getDomElement(), nextElement);
        this.setLayer(this.layer);
    },
    removeManager: function(childManager) {
        if (childManager instanceof enchant.DomlessManager) {
            childManager._domRef.forEach(function(element) {
                this.element.removeChild(element);
            }, this);
        } else {
            this.element.removeChild(childManager.element);
        }
        this.setLayer(this.layer);
    },
    setLayer: function(layer) {
        this.layer = layer;
        var node = this.targetNode;
        var manager;
        if (node.childNodes) {
            for (var i = 0, l = node.childNodes.length; i < l; i++) {
                manager = node.childNodes[i]._domManager;
                manager.setLayer(layer);
            }
        }
    },
    render: function() {
        var node = this.targetNode;
        if (!node._dirty) {
            return;
        }
        var matrix = enchant.Matrix.instance;
        var stack = matrix.stack;
        var dest = [];
        matrix.makeTransformMatrix(node, dest);
        matrix.multiply(stack[stack.length - 1], dest, dest);
        var ox = (typeof node._originX === 'number') ? node._originX : node._width / 2 || 0;
        var oy = (typeof node._originY === 'number') ? node._originY : node._height / 2 || 0;
        var vec = [ ox, oy ];
        matrix.multiplyVec(dest, vec, vec);
        node._offsetX = vec[0] - ox;
        node._offsetY = vec[1] - oy;
        this.cssUpdate();
        this.style[enchant.ENV.VENDOR_PREFIX + 'Transform'] = 'matrix(' + dest + ')';
    },
    cssUpdate: function() {
        var node = this.targetNode;
        this.style.width = node._width + 'px';
        this.style.height = node._height + 'px';
        this.style.opacity = node._opacity;
        if (typeof node._visible !== 'undefined') {
            this.style.display = node._visible ? 'block' : 'none';
        }
        if (typeof node.cssUpdate === 'function') {
            node.cssUpdate();
        }
    },
    _attachEvent: function() {
        if (enchant.ENV.TOUCH_ENABLED) {
            this.element.addEventListener('touchstart', this._setDomTarget, true);
        }
        this.element.addEventListener('mousedown', this._setDomTarget, true);
    },
    _detachEvent: function() {
        if (enchant.ENV.TOUCH_ENABLED) {
            this.element.removeEventListener('touchstart', this._setDomTarget, true);
        }
        this.element.removeEventListener('mousedown', this._setDomTarget, true);
    },
    remove: function() {
        this._detachEvent();
        this.element = this.style = this.targetNode = null;
    }
});

enchant.DomlessManager = enchant.Class.create({
    initialize: function(node) {
        this._domRef = [];
        this.targetNode = node;
    },
    _register: function(element, nextElement) {
        var i = this._domRef.indexOf(nextElement);
        if (element instanceof DocumentFragment) {
            if (i === -1) {
                Array.prototype.push.apply(this._domRef, element.childNodes);
            } else {
                //this._domRef.splice(i, 0, element);
                Array.prototype.splice.apply(this._domRef, [i, 0].join(element.childNodes));
            }
        } else {
            if (i === -1) {
                this._domRef.push(element);
            } else {
                this._domRef.splice(i, 0, element);
            }
        }
    },
    getNextManager: function(manager) {
        var i = this.targetNode.parentNode.childNodes.indexOf(manager.targetNode);
        if (i !== this.targetNode.parentNode.childNodes.length - 1) {
            return this.targetNode.parentNode.childNodes[i + 1]._domManager;
        } else {
            return null;
        }
    },
    getDomElement: function() {
        var frag = document.createDocumentFragment();
        var children = this.targetNode.childNodes;
        children.forEach(function(child) {
            var element = child._domManager.getDomElement();
            this._domRef.push(element);
            frag.appendChild(element);
        }, this);
        return frag;
    },
    getDomElementAsNext: function() {
        if (this._domRef.length) {
            return this._domRef[0];
        } else {
            var nextManager = this.getNextManager(this);
            if (nextManager) {
                return nextManager.element;
            } else {
                return null;
            }
        }
    },
    addManager: function(childManager, nextManager) {
        if (this.targetNode.parentNode) {
            if (nextManager === null) {
                nextManager = this.getNextManager(this);
            }
            this.targetNode.parentNode._domManager.addManager(childManager, nextManager);
        }
        var nextElement = nextManager ? nextManager.getDomElementAsNext() : null;
        this._register(childManager.getDomElement(), nextElement);
        this.setLayer(this.layer);
    },
    removeManager: function(childManager) {
        var dom;
        var i = this._domRef.indexOf(childManager.element);
        if (i !== -1) {
            dom = this._domRef[i];
            dom.parentNode.removeChild(dom);
            this._domRef.splice(i, 1);
        }
        this.setLayer(this.layer);
    },
    setLayer: function(layer) {
        this.layer = layer;
        var node = this.targetNode;
        var manager;
        if (node.childNodes) {
            for (var i = 0, l = node.childNodes.length; i < l; i++) {
                manager = node.childNodes[i]._domManager;
                manager.setLayer(layer);
            }
        }
    },
    render: function() {
        var matrix = enchant.Matrix.instance;
        var stack = matrix.stack;
        var node = this.targetNode;
        var dest = [];
        matrix.makeTransformMatrix(node, dest);
        matrix.multiply(stack[stack.length - 1], dest, dest);
        var ox = (typeof node._originX === 'number') ? node._originX : node._width / 2 || 0;
        var oy = (typeof node._originY === 'number') ? node._originY : node._height / 2 || 0;
        var vec = [ ox, oy ];
        matrix.multiplyVec(dest, vec, vec);
        node._offsetX = vec[0] - ox;
        node._offsetY = vec[1] - oy;
        stack.push(dest);
        for (var i = 0, l = node.childNodes.length; i < l; i++) {
            node.childNodes[i]._dirty = true;
        }
    },
    remove: function() {
        this._domRef = [];
        this.targetNode = null;
    }
});
<commit_msg>render Entity#backgroundColor in dom<commit_after>enchant.DomManager = enchant.Class.create({
    initialize: function(node, elementDefinition) {
        var game = enchant.Game.instance;
        this.layer = null;
        this.targetNode = node;
        if (typeof elementDefinition === 'string') {
            this.element = document.createElement(elementDefinition);
        } else if (elementDefinition instanceof HTMLElement) {
            this.element = elementDefinition;
        } else {
            // TODO error
        }
        this.style = this.element.style;
        this.style.position = 'absolute';
        this.style[enchant.ENV.VENDOR_PREFIX + 'TransformOrigin'] = '0px 0px';
        if (game._debug) {
            this.style.border = '1px solid blue';
            this.style.margin = '-1px';
        }

        var manager = this;
        this._setDomTarget = function() {
            manager.layer._touchEventTarget = manager.targetNode;
        };
        this._attachEvent();
    },
    getDomElement: function() {
        return this.element;
    },
    getDomElementAsNext: function() {
        return this.element;
    },
    getNextManager: function(manager) {
        var i = this.targetNode.parentNode.childNodes.indexOf(manager.targetNode);
        if (i !== this.targetNode.parentNode.childNodes.length - 1) {
            return this.targetNode.parentNode.childNodes[i + 1]._domManager;
        } else {
            return null;
        }
    },
    addManager: function(childManager, nextManager) {
        var nextElement;
        if (nextManager) {
            nextElement = nextManager.getDomElementAsNext();
        } else if (this.targetNode.parentNode) {
            //nextElement = this.getNextManager(this);
        }
        this.element.insertBefore(childManager.getDomElement(), nextElement);
        this.setLayer(this.layer);
    },
    removeManager: function(childManager) {
        if (childManager instanceof enchant.DomlessManager) {
            childManager._domRef.forEach(function(element) {
                this.element.removeChild(element);
            }, this);
        } else {
            this.element.removeChild(childManager.element);
        }
        this.setLayer(this.layer);
    },
    setLayer: function(layer) {
        this.layer = layer;
        var node = this.targetNode;
        var manager;
        if (node.childNodes) {
            for (var i = 0, l = node.childNodes.length; i < l; i++) {
                manager = node.childNodes[i]._domManager;
                manager.setLayer(layer);
            }
        }
    },
    render: function() {
        var node = this.targetNode;
        if (!node._dirty) {
            return;
        }
        var matrix = enchant.Matrix.instance;
        var stack = matrix.stack;
        var dest = [];
        matrix.makeTransformMatrix(node, dest);
        matrix.multiply(stack[stack.length - 1], dest, dest);
        var ox = (typeof node._originX === 'number') ? node._originX : node._width / 2 || 0;
        var oy = (typeof node._originY === 'number') ? node._originY : node._height / 2 || 0;
        var vec = [ ox, oy ];
        matrix.multiplyVec(dest, vec, vec);
        node._offsetX = vec[0] - ox;
        node._offsetY = vec[1] - oy;
        this.cssUpdate();
        this.style[enchant.ENV.VENDOR_PREFIX + 'Transform'] = 'matrix(' + dest + ')';
    },
    cssUpdate: function() {
        var node = this.targetNode;
        this.style.width = node._width + 'px';
        this.style.height = node._height + 'px';
        this.style.opacity = node._opacity;
        this.style.backgroundColor = node._backgroundColor;
        if (typeof node._visible !== 'undefined') {
            this.style.display = node._visible ? 'block' : 'none';
        }
        if (typeof node.cssUpdate === 'function') {
            node.cssUpdate();
        }
    },
    _attachEvent: function() {
        if (enchant.ENV.TOUCH_ENABLED) {
            this.element.addEventListener('touchstart', this._setDomTarget, true);
        }
        this.element.addEventListener('mousedown', this._setDomTarget, true);
    },
    _detachEvent: function() {
        if (enchant.ENV.TOUCH_ENABLED) {
            this.element.removeEventListener('touchstart', this._setDomTarget, true);
        }
        this.element.removeEventListener('mousedown', this._setDomTarget, true);
    },
    remove: function() {
        this._detachEvent();
        this.element = this.style = this.targetNode = null;
    }
});

enchant.DomlessManager = enchant.Class.create({
    initialize: function(node) {
        this._domRef = [];
        this.targetNode = node;
    },
    _register: function(element, nextElement) {
        var i = this._domRef.indexOf(nextElement);
        if (element instanceof DocumentFragment) {
            if (i === -1) {
                Array.prototype.push.apply(this._domRef, element.childNodes);
            } else {
                //this._domRef.splice(i, 0, element);
                Array.prototype.splice.apply(this._domRef, [i, 0].join(element.childNodes));
            }
        } else {
            if (i === -1) {
                this._domRef.push(element);
            } else {
                this._domRef.splice(i, 0, element);
            }
        }
    },
    getNextManager: function(manager) {
        var i = this.targetNode.parentNode.childNodes.indexOf(manager.targetNode);
        if (i !== this.targetNode.parentNode.childNodes.length - 1) {
            return this.targetNode.parentNode.childNodes[i + 1]._domManager;
        } else {
            return null;
        }
    },
    getDomElement: function() {
        var frag = document.createDocumentFragment();
        var children = this.targetNode.childNodes;
        children.forEach(function(child) {
            var element = child._domManager.getDomElement();
            this._domRef.push(element);
            frag.appendChild(element);
        }, this);
        return frag;
    },
    getDomElementAsNext: function() {
        if (this._domRef.length) {
            return this._domRef[0];
        } else {
            var nextManager = this.getNextManager(this);
            if (nextManager) {
                return nextManager.element;
            } else {
                return null;
            }
        }
    },
    addManager: function(childManager, nextManager) {
        if (this.targetNode.parentNode) {
            if (nextManager === null) {
                nextManager = this.getNextManager(this);
            }
            this.targetNode.parentNode._domManager.addManager(childManager, nextManager);
        }
        var nextElement = nextManager ? nextManager.getDomElementAsNext() : null;
        this._register(childManager.getDomElement(), nextElement);
        this.setLayer(this.layer);
    },
    removeManager: function(childManager) {
        var dom;
        var i = this._domRef.indexOf(childManager.element);
        if (i !== -1) {
            dom = this._domRef[i];
            dom.parentNode.removeChild(dom);
            this._domRef.splice(i, 1);
        }
        this.setLayer(this.layer);
    },
    setLayer: function(layer) {
        this.layer = layer;
        var node = this.targetNode;
        var manager;
        if (node.childNodes) {
            for (var i = 0, l = node.childNodes.length; i < l; i++) {
                manager = node.childNodes[i]._domManager;
                manager.setLayer(layer);
            }
        }
    },
    render: function() {
        var matrix = enchant.Matrix.instance;
        var stack = matrix.stack;
        var node = this.targetNode;
        var dest = [];
        matrix.makeTransformMatrix(node, dest);
        matrix.multiply(stack[stack.length - 1], dest, dest);
        var ox = (typeof node._originX === 'number') ? node._originX : node._width / 2 || 0;
        var oy = (typeof node._originY === 'number') ? node._originY : node._height / 2 || 0;
        var vec = [ ox, oy ];
        matrix.multiplyVec(dest, vec, vec);
        node._offsetX = vec[0] - ox;
        node._offsetY = vec[1] - oy;
        stack.push(dest);
        for (var i = 0, l = node.childNodes.length; i < l; i++) {
            node.childNodes[i]._dirty = true;
        }
    },
    remove: function() {
        this._domRef = [];
        this.targetNode = null;
    }
});
<|endoftext|>


<commit_before>'use strict';

describe('ResultatService', function () {
    var service, droits, situation, openfiscaResult, DROITS_DESCRIPTION;

    beforeEach(function() {
        module('ddsApp');
        inject(function(ResultatService, droitsDescription)
        {
            service = ResultatService;
            DROITS_DESCRIPTION = droitsDescription;
            DROITS_DESCRIPTION.prestationsNationales.assurance_retraite.prestations.private_aid = {
                private: true
            };
        });

        situation = {
            dateDeValeur: '2014-11-01',
            individus: [{
                aah: {
                    '2014-11': 100
                },
                aide_logement: {
                    '2014-11': 100
                }
            }, {
                ppa: {
                    '2014-11': 100
                }
            }]
        };

        openfiscaResult = {
            familles: {
                _: {
                    rsa_non_calculable: {
                        '2014-11': 'error'
                    },
                    paris_logement_familles: {
                        '2014-11': 10
                    },
                    private_aid: {
                        '2014-11': 10
                    }
                }
            },
            menages: {
                _: {
                    personne_de_reference: ['demandeur'],
                    depcom: {
                        '2014-11': '00000'
                    },
                }
            },
            individus: {
                demandeur: {
                    acs: {
                        '2014-11':100.25
                    },
                    cmu_c: {
                        '2014-11': false
                    }
                }
            }
        };
    });

    describe('_computeAides injected values', function() {
        beforeEach(function() {
            droits = service._computeAides(situation, openfiscaResult);
        });

        it('should extract injected droits', function() {
            expect(droits.droitsInjectes).toContain(DROITS_DESCRIPTION.prestationsNationales.caf.prestations.aah);
            expect(droits.droitsInjectes).toContain(DROITS_DESCRIPTION.prestationsNationales.caf.prestations.aide_logement);
            expect(droits.droitsInjectes).toContain(DROITS_DESCRIPTION.prestationsNationales.caf.prestations.ppa);
        });

        it('should not have injected droits duplicates', function() {
            expect(droits.droitsInjectes.filter(function(d) { return d.label == "Allocation aux adultes handicapés"; }).length).toEqual(1);
        });
    });

    describe('_computeAides of numeric value', function() {
        beforeEach(function() {
            droits = service._computeAides(situation, openfiscaResult);
        });

        it('should extract eligibles droits from openfisca result', function() {
            expect(droits.droitsEligibles.prestationsNationales.acs).toBeTruthy();
            expect(droits.droitsEligibles.prestationsNationales.acs.montant).toEqual(100);
            expect(droits.droitsEligibles.prestationsNationales.acs.provider.label).toEqual('Assurance maladie');

            expect(droits.droitsEligibles.partenairesLocaux[0].label).toEqual('Ville de Paris');
            expect(droits.droitsEligibles.partenairesLocaux[0].prestations.paris_logement_familles).toBeTruthy();
            expect(droits.droitsEligibles.partenairesLocaux[0].prestations.paris_logement_familles.montant).toEqual(10);

            expect(droits.droitsNonEligibles.prestationsNationales.cmu_c).toBeTruthy();
            expect(droits.droitsNonEligibles.prestationsNationales.cmu_c.montant).toBeFalsy();
            expect(droits.droitsNonEligibles.prestationsNationales.cmu_c.provider.label).toEqual('Assurance maladie');
        });
    });

    describe('_computeAides of true boolean values', function() {
        beforeEach(function() {
            openfiscaResult.individus.demandeur.cmu_c['2014-11'] = true;
            droits = service._computeAides(situation, openfiscaResult);
        });

        it('should extract eligibles droits from openfisca result', function() {
            expect(droits.droitsEligibles.prestationsNationales.cmu_c).toBeTruthy();
            expect(droits.droitsEligibles.prestationsNationales.cmu_c.montant).toBeTruthy();
        });
    });

    describe('_computeAides uncomputability highlighted', function() {
        beforeEach(function() {
            droits = service._computeAides(situation, openfiscaResult);
        });

        it('should extract reason of uncomputability', function() {
            expect(droits.droitsEligibles.prestationsNationales.rsa.montant).toEqual('error');
        });
    });

    describe('_computeAides extraction of local partenaire without prestation', function() {
        beforeEach(function() {
            droits = service._computeAides(situation, openfiscaResult);
        });

        it('should exclude local partenaire without prestation', function() {
            expect(droits.droitsEligibles.partenairesLocaux.filter(function(p) { return p.label == "Rennes Métropole"; }).length).toBeFalsy();
        });
    });

    describe('_computeAides exclude private aids', function() {
        beforeEach(function() {
            droits = service._computeAides(situation, openfiscaResult);
        });

        it('should exclude private aid', function() {
            expect(droits.droitsEligibles.prestationsNationales.private_aid).toBeFalsy();
        });
    });

    describe('round', function() {
        it('should not round for type "bool"', function() {
            expect(service.round(true, { type: 'bool' })).toEqual(true);
        });

        it('should floor for unit "%"', function() {
            expect(service.round(10.25, { unit: '%' })).toEqual(10);
            expect(service.round(10.2499, { unit: '%', floorAt: 0.01 })).toEqual(10.24);
        });

        it('should floor to nearest 10', function() {
            expect(service.round(132.17, { floorAt: 10 })).toEqual(130);
            expect(service.round(135, { floorAt: 10 })).toEqual(130);
            expect(service.round(139.47, { floorAt: 10 })).toEqual(130);
            expect(service.round(139.7, { floorAt: 10 })).toEqual(130);
        });

        it('should floor to nearest cent', function() {
            expect(service.round(132.1789, { floorAt: 0.01 })).toBeCloseTo(132.17);
            expect(service.round(135, { floorAt: 0.01 })).toEqual(135);
            expect(service.round(139.0001, { floorAt: 0.01 })).toEqual(139.00);
        });

        it('should floor to nearest 10 by default', function() {
            expect(service.round(132.17, {})).toEqual(130);
            expect(service.round(135, {})).toEqual(130);
            expect(service.round(139.47, {})).toEqual(130);
        });
    });
});
<commit_msg>Met à jour les tests<commit_after>'use strict';

describe('ResultatService', function () {
    var service, droits, situation, openfiscaResult, DROITS_DESCRIPTION;

    beforeEach(function() {
        module('ddsApp');
        inject(function(ResultatService, droitsDescription)
        {
            service = ResultatService;
            DROITS_DESCRIPTION = droitsDescription;
            DROITS_DESCRIPTION.prestationsNationales.assurance_retraite.prestations.private_aid = {
                private: true
            };
        });

        situation = {
            dateDeValeur: '2014-11-01',
            individus: [{
                aah: {
                    '2014-11': 100
                },
                aide_logement: {
                    '2014-11': 100
                }
            }, {
                ppa: {
                    '2014-11': 100
                }
            }]
        };

        openfiscaResult = {
            familles: {
                _: {
                    rsa_non_calculable: {
                        '2014-11': 'error'
                    },
                    paris_logement_familles: {
                        '2014-11': 10
                    },
                    private_aid: {
                        '2014-11': 10
                    }
                }
            },
            menages: {
                _: {
                    personne_de_reference: ['demandeur'],
                    depcom: {
                        '2014-11': '00000'
                    },
                }
            },
            individus: {
                demandeur: {
                    acs: {
                        '2014-11':100.25
                    },
                    cmu_c: {
                        '2014-11': false
                    }
                }
            }
        };
    });

    describe('_computeAides injected values', function() {
        beforeEach(function() {
            droits = service._computeAides(situation, openfiscaResult);
        });

        it('should extract injected droits', function() {
            expect(droits.droitsInjectes).toContain(DROITS_DESCRIPTION.prestationsNationales.caf.prestations.aah);
            expect(droits.droitsInjectes).toContain(DROITS_DESCRIPTION.prestationsNationales.caf.prestations.aide_logement);
            expect(droits.droitsInjectes).toContain(DROITS_DESCRIPTION.prestationsNationales.caf.prestations.ppa);
        });

        it('should not have injected droits duplicates', function() {
            expect(droits.droitsInjectes.filter(function(d) { return d.label == "Allocation aux adultes handicapés"; }).length).toEqual(1);
        });
    });

    describe('_computeAides of numeric value', function() {
        beforeEach(function() {
            droits = service._computeAides(situation, openfiscaResult);
        });

        it('should extract eligibles droits from openfisca result', function() {
            expect(droits.droitsEligibles.prestationsNationales.acs).toBeTruthy();
            expect(droits.droitsEligibles.prestationsNationales.acs.montant).toEqual(100);
            expect(droits.droitsEligibles.prestationsNationales.acs.provider.label).toEqual('Assurance maladie');

            expect(droits.droitsEligibles.partenairesLocaux[0].label).toEqual('Ville de Paris');
            expect(droits.droitsEligibles.partenairesLocaux[0].prestations.paris_logement_familles).toBeTruthy();
            expect(droits.droitsEligibles.partenairesLocaux[0].prestations.paris_logement_familles.montant).toEqual(10);

            expect(droits.droitsNonEligibles.prestationsNationales.cmu_c).toBeTruthy();
            expect(droits.droitsNonEligibles.prestationsNationales.cmu_c.montant).toBeFalsy();
            expect(droits.droitsNonEligibles.prestationsNationales.cmu_c.provider.label).toEqual('Assurance maladie');
        });
    });

    describe('_computeAides of true boolean values', function() {
        beforeEach(function() {
            openfiscaResult.individus.demandeur.cmu_c['2014-11'] = true;
            droits = service._computeAides(situation, openfiscaResult);
        });

        it('should extract eligibles droits from openfisca result', function() {
            expect(droits.droitsEligibles.prestationsNationales.cmu_c).toBeTruthy();
            expect(droits.droitsEligibles.prestationsNationales.cmu_c.montant).toBeTruthy();
        });
    });

    describe('_computeAides uncomputability highlighted', function() {
        beforeEach(function() {
            droits = service._computeAides(situation, openfiscaResult);
        });

        it('should extract reason of uncomputability', function() {
            expect(droits.droitsEligibles.prestationsNationales.rsa.montant).toEqual('error');
        });
    });

    describe('_computeAides extraction of local partenaire without prestation', function() {
        beforeEach(function() {
            droits = service._computeAides(situation, openfiscaResult);
        });

        it('should exclude local partenaire without prestation', function() {
            expect(droits.droitsEligibles.partenairesLocaux.filter(function(p) { return p.label == "Rennes Métropole"; }).length).toBeFalsy();
        });
    });

    describe('_computeAides exclude private aids', function() {
        beforeEach(function() {
            droits = service._computeAides(situation, openfiscaResult);
        });

        it('should exclude private aid', function() {
            expect(droits.droitsEligibles.prestationsNationales.private_aid).toBeFalsy();
        });
    });

    describe('round', function() {
        it('should not round for type "bool"', function() {
            expect(service.round(true, { type: 'bool' })).toEqual(true);
        });

        it('should floor for unit "%"', function() {
            expect(service.round(10.25, { unit: '%' })).toEqual(10);
            expect(service.round(10.2499, { unit: '%', floorAt: 0.01 })).toEqual(10.24);
        });

        it('should floor to lower 10s', function() {
            expect(service.round(132.17, { floorAt: 10 })).toEqual(130);
            expect(service.round(135, { floorAt: 10 })).toEqual(130);
            expect(service.round(139.47, { floorAt: 10 })).toEqual(130);
            expect(service.round(139.7, { floorAt: 10 })).toEqual(130);
        });

        it('should floor to lower cent', function() {
            expect(service.round(132.1789, { floorAt: 0.01 })).toBeCloseTo(132.17);
            expect(service.round(135, { floorAt: 0.01 })).toEqual(135);
            expect(service.round(139.0001, { floorAt: 0.01 })).toEqual(139.00);
        });

        it('should floor to lower integer by default', function() {
            expect(service.round(132.17, {})).toEqual(132);
            expect(service.round(135, {})).toEqual(135);
            expect(service.round(139.47, {})).toEqual(139);
        });
    });
});
<|endoftext|>


<commit_before>/*
 * LightShow.js v0.7.1-beta
 * http://romankozak.cz
 *
 * Copyright (c) 2014 Roman Kozák
 */

(function($) {

  	$.fn.lightshow = function(options) {

	    var settings = $.extend({
	    	autoplay        : true,    // (boolean) animate automatically
	    	pause           : true,    // (boolean) pause on hover
	    	duration        : 3000,    // (integer) single slide duration, in milliseconds
	    	animation       : 500,     // (integer) animation duration, in milliseconds
	    	transition      : "fade",  // (string)  transition between slides (fade, slide)
	    	controls        : true,    // (boolean) show controls
	    	big_controls    : false,   // (boolean) big controls - half of an image
	    	circles         : true,    // (boolean) jumping between slides using little circles below LightShow
	    	title           : false,   // (boolean) show title from 'data-title' attribute of

	    	change_url      : false,   // (boolean) put current slide number into url
	    	keyboard        : false,   // (boolean) enables keyboard navigation - left and right arrow

	    	responsive      : false,   // (boolean) LightShow is responsive by default, but sometimes big controls aren't as big as they should be - this corrects them
	     	different_sizes : false,   // (boolean) set to true if your slides have different sizes (fixes transitions between them)

	    	after_autoplay  : function() {}, // callback function after slide is changed by autoplay
	    	after_next      : function() {}, // callback function after next button is clicked
	    	after_prev      : function() {} // callback function after prev button is clicked
	    }, options);

	    function button_next_click(content) {
	    	if(!content.find('li').is(':animated'))
	    	{
	        	var first = content.find('li:first-child');
	        	var next = first.next('li');

	        	switch(settings.transition)
	        	{
	          		case "fade":
	            		first.fadeOut(settings.animation);
	            		if(settings.different_sizes)
	              			next.fadeIn(settings.animation);
	            		else
	              			next.show();
	            	break;

	          		case "slide":
	            		first.animate({ left: "-100%" }, settings.animation, function() { $(this).css("left", "0").hide(); });
	             		next.css("left", "100%").show().animate({ left: "0" }, settings.animation);
	            	break;
	        	}
	        	first.appendTo(content);
	        	if(settings.change_url)
	          		window.location.hash = "#slide" + next.data('index');
	      	}
	    }

	    function button_prev_click(content) {
	      	if(!content.find('li').is(':animated'))
	      	{
	        	var first = content.find('li:first-child');
	        	var prev = content.find('li:last-child');

	        	switch(settings.transition)
	        	{
	          		case "fade":
	            		first.fadeOut(settings.animation);
	            		if(settings.different_sizes)
	              			prev.fadeIn(settings.animation);
	            		else
	              			prev.show();
	            	break;

	          		case "slide":
	            		first.animate({ left: "100%" }, settings.animation, function() { $(this).css("left", "0").hide(); });
	            		prev.css("left", "-100%").show().animate({ left: "0" }, settings.animation);
	            	break;
	        	}
	        	prev.prependTo(content);
	        	if(settings.change_url)
	          		window.location.hash = "#slide" + prev.data('index');
	      	}
	    }

	    function jump_to(content, i) {
	     	content.find('li:eq('+i+')').show();
	      	content.find('li:lt('+i+')').appendTo(content);
	    }

    	// main code
    	this.each(function() {
      		var $this = $(this);

      		var content = $this.find('ul');
      		content.addClass("lightshow-content");

      		var lis = content.find('li');

      		$this.addClass("lightshow-wrapper");

      		lis.each(function(index) {
        		$(this).data("index", index);
      		});

      		// jump to #slideX in url
      		if(settings.change_url){
        		var i = window.location.hash.substr(6);
        		jump_to(content, i);
      		} else {
        		content.find('li:first-child').show();
      		}

      		// autoplay
      		if(settings.autoplay) {
        		settings.duration += settings.animation;
        		setInterval(function() {
          			if(!(settings.pause && $this.is(':hover'))) {
            			button_next_click(content);
            			if(typeof settings.after_autoplay == 'function')
              				settings.after_autoplay.call(this);
          			}
        		}, settings.duration);
      		}

      		// controls
      		if(settings.controls) {
        		var sirka = $this.find("li").outerWidth();
        		if(settings.responsive || !(sirka > 0))
          			sirka = "40%";
        		else
          			sirka = (sirka/2)-30 + "px";

        		var vyska = $this.find("li").outerHeight();

        		var button_next = $("
", { class: "lightshow-next" }).appendTo($this);
        		var button_prev = $("
", { class: "lightshow-prev" }).appendTo($this);

        		var top = (vyska/2 - 30) + "px";
        		if(top > 0) {
          			button_next.css("top", top);
          			button_prev.css("top", top);
        		}

        		if(settings.big_controls) {
          			var css = {
            			height: vyska + "px",
            			width: sirka
          			}

          			button_next.addClass("lightshow-big").css(css);
          			button_prev.addClass("lightshow-big").css(css);
        		}

        		button_next.click(function() {
          			button_next_click(content);
          			if(typeof settings.after_next == 'function')
            			settings.after_next.call(this);
        		});

        		button_prev.click(function() {
          			button_prev_click(content);
          			if(typeof settings.after_prev == 'function')
            			settings.after_prev.call(this);
        		});
      		}

/*
			// circles - not ready yet
      		if(settings.circles) {
        		var circles = $("
", { class: "lightshow-circles" }).appendTo($this);
        		var n_of_lis = lis.length;
        		for (var i = 0; i < n_of_lis; i++) {
          			$("
").data("index", i).appendTo(circles);
        		};
        		circles.find("li").click(function() {
          			var i = $(this).data("index");
          			//jump_to(content, i);
          			content.find("li").each(function() {
            			$this = $(this);
            			if($this.data("index") == i)
              				$this.show();
            			else
              				$this.appendTo(content).hide();
          			});
        		})
      		}
*/

      		// keyboard
      		if(settings.keyboard) {
        		$(document).keydown(function(e) {
          			switch(e.which) {
              			case 39:
                			button_next_click(content);
                			if(typeof options.after_prev == 'function')
                  				options.after_prev.call(this);
                		break;

              			case 37:
                			button_prev_click(content);
                			if(typeof options.after_next == 'function')
                  				options.after_next.call(this);
                		break;

	              		default:
                			return;
          			}
          			e.preventDefault();
        		});
      		}

      		// title
      		if(settings.title) {
        		content.find("li").each(function() {
          			var $this = $(this),
              			title = $this.data("title");
          			$("
", { class: "lightshow-title" }).text(title).appendTo($this);
        		});
      		}

    	});

    	return this;
  	};

}(jQuery));

<commit_msg>Version number correction<commit_after>/*
 * LightShow.js v0.7.4-beta
 * http://romankozak.cz
 *
 * Copyright (c) 2014 Roman Kozák
 */

(function($) {

  	$.fn.lightshow = function(options) {

	    var settings = $.extend({
	    	autoplay        : true,    // (boolean) animate automatically
	    	pause           : true,    // (boolean) pause on hover
	    	duration        : 3000,    // (integer) single slide duration, in milliseconds
	    	animation       : 500,     // (integer) animation duration, in milliseconds
	    	transition      : "fade",  // (string)  transition between slides (fade, slide)
	    	controls        : true,    // (boolean) show controls
	    	big_controls    : false,   // (boolean) big controls - half of an image
	    	circles         : true,    // (boolean) jumping between slides using little circles below LightShow
	    	title           : false,   // (boolean) show title from 'data-title' attribute of

	    	change_url      : false,   // (boolean) put current slide number into url
	    	keyboard        : false,   // (boolean) enables keyboard navigation - left and right arrow

	    	responsive      : false,   // (boolean) LightShow is responsive by default, but sometimes big controls aren't as big as they should be - this corrects them
	     	different_sizes : false,   // (boolean) set to true if your slides have different sizes (fixes transitions between them)

	    	after_autoplay  : function() {}, // callback function after slide is changed by autoplay
	    	after_next      : function() {}, // callback function after next button is clicked
	    	after_prev      : function() {} // callback function after prev button is clicked
	    }, options);

	    function button_next_click(content) {
	    	if(!content.find('li').is(':animated'))
	    	{
	        	var first = content.find('li:first-child');
	        	var next = first.next('li');

	        	switch(settings.transition)
	        	{
	          		case "fade":
	            		first.fadeOut(settings.animation);
	            		if(settings.different_sizes)
	              			next.fadeIn(settings.animation);
	            		else
	              			next.show();
	            	break;

	          		case "slide":
	            		first.animate({ left: "-100%" }, settings.animation, function() { $(this).css("left", "0").hide(); });
	             		next.css("left", "100%").show().animate({ left: "0" }, settings.animation);
	            	break;
	        	}
	        	first.appendTo(content);
	        	if(settings.change_url)
	          		window.location.hash = "#slide" + next.data('index');
	      	}
	    }

	    function button_prev_click(content) {
	      	if(!content.find('li').is(':animated'))
	      	{
	        	var first = content.find('li:first-child');
	        	var prev = content.find('li:last-child');

	        	switch(settings.transition)
	        	{
	          		case "fade":
	            		first.fadeOut(settings.animation);
	            		if(settings.different_sizes)
	              			prev.fadeIn(settings.animation);
	            		else
	              			prev.show();
	            	break;

	          		case "slide":
	            		first.animate({ left: "100%" }, settings.animation, function() { $(this).css("left", "0").hide(); });
	            		prev.css("left", "-100%").show().animate({ left: "0" }, settings.animation);
	            	break;
	        	}
	        	prev.prependTo(content);
	        	if(settings.change_url)
	          		window.location.hash = "#slide" + prev.data('index');
	      	}
	    }

	    function jump_to(content, i) {
	     	content.find('li:eq('+i+')').show();
	      	content.find('li:lt('+i+')').appendTo(content);
	    }

    	// main code
    	this.each(function() {
      		var $this = $(this);

      		var content = $this.find('ul');
      		content.addClass("lightshow-content");

      		var lis = content.find('li');

      		$this.addClass("lightshow-wrapper");

      		lis.each(function(index) {
        		$(this).data("index", index);
      		});

      		// jump to #slideX in url
      		if(settings.change_url){
        		var i = window.location.hash.substr(6);
        		jump_to(content, i);
      		} else {
        		content.find('li:first-child').show();
      		}

      		// autoplay
      		if(settings.autoplay) {
        		settings.duration += settings.animation;
        		setInterval(function() {
          			if(!(settings.pause && $this.is(':hover'))) {
            			button_next_click(content);
            			if(typeof settings.after_autoplay == 'function')
              				settings.after_autoplay.call(this);
          			}
        		}, settings.duration);
      		}

      		// controls
      		if(settings.controls) {
        		var sirka = $this.find("li").outerWidth();
        		if(settings.responsive || !(sirka > 0))
          			sirka = "40%";
        		else
          			sirka = (sirka/2)-30 + "px";

        		var vyska = $this.find("li").outerHeight();

        		var button_next = $("
", { class: "lightshow-next" }).appendTo($this);
        		var button_prev = $("
", { class: "lightshow-prev" }).appendTo($this);

        		var top = (vyska/2 - 30) + "px";
        		if(top > 0) {
          			button_next.css("top", top);
          			button_prev.css("top", top);
        		}

        		if(settings.big_controls) {
          			var css = {
            			height: vyska + "px",
            			width: sirka
          			}

          			button_next.addClass("lightshow-big").css(css);
          			button_prev.addClass("lightshow-big").css(css);
        		}

        		button_next.click(function() {
          			button_next_click(content);
          			if(typeof settings.after_next == 'function')
            			settings.after_next.call(this);
        		});

        		button_prev.click(function() {
          			button_prev_click(content);
          			if(typeof settings.after_prev == 'function')
            			settings.after_prev.call(this);
        		});
      		}

/*
			// circles - not ready yet
      		if(settings.circles) {
        		var circles = $("
", { class: "lightshow-circles" }).appendTo($this);
        		var n_of_lis = lis.length;
        		for (var i = 0; i < n_of_lis; i++) {
          			$("
").data("index", i).appendTo(circles);
        		};
        		circles.find("li").click(function() {
          			var i = $(this).data("index");
          			//jump_to(content, i);
          			content.find("li").each(function() {
            			$this = $(this);
            			if($this.data("index") == i)
              				$this.show();
            			else
              				$this.appendTo(content).hide();
          			});
        		})
      		}
*/

      		// keyboard
      		if(settings.keyboard) {
        		$(document).keydown(function(e) {
          			switch(e.which) {
              			case 39:
                			button_next_click(content);
                			if(typeof options.after_prev == 'function')
                  				options.after_prev.call(this);
                		break;

              			case 37:
                			button_prev_click(content);
                			if(typeof options.after_next == 'function')
                  				options.after_next.call(this);
                		break;

	              		default:
                			return;
          			}
          			e.preventDefault();
        		});
      		}

      		// title
      		if(settings.title) {
        		content.find("li").each(function() {
          			var $this = $(this),
              			title = $this.data("title");
          			$("
", { class: "lightshow-title" }).text(title).appendTo($this);
        		});
      		}

    	});

    	return this;
  	};

}(jQuery));

<|endoftext|>