{"action":"created","comment":{"url":"https://api.github.com/repos/ecomfe/ub-ria-ui/pulls/comments/42457542","id":42457542,"diff_hunk":"@@ -0,0 +1,262 @@\n+/**\n+ * 图片,Flash和视频的预览控件\n+ * @file MediaPreview.js\n+ * @author chuzhenyang(chuzhenyang@baidu.com)\n+ */\n+\n+define(function (require) {\n+    var u = require('underscore');\n+    var esui = require('esui');\n+    var lib = require('esui/lib');\n+    var Control = require('esui/Control');\n+    var eoo = require('eoo');\n+    var $ = require('jquery');\n+    var painters = require('esui/painters');\n+    var PreviewHelper = require('./helper/PreviewHelper');\n+\n+    /**\n+     * 图片,视频和Flash预览控件\n+     *\n+     * 显示图片,视频和Flash资源,并提供配置\n+     *\n+     * @extends {Control}\n+     * @param {Object} options 初始化参数\n+     * @constructor\n+     */\n+    var MediaPreview = eoo.create(\n+        Control,\n+        {\n+            /**\n+             * 控件类型,始终为`\"MediaPreview\"`\n+             *\n+             * @type {string}\n+             * @readonly\n+             * @override\n+             */\n+            type: 'MediaPreview',\n+\n+            /**\n+             * 初始化参数\n+             *\n+             * 对于图片资源,显示的宽度为容器宽度\n+             * 而高度是默认高度,最大高度为容器高度\n+             *\n+             * @param {Object} [options] 构造函数传入的参数\n+             * @protected\n+             * @override\n+             */\n+            initOptions: function (options) {\n+                var properties = {\n+                    /**\n+                     * @property {number} [width=300]\n+                     *\n+                     * 默认宽度\n+                     */\n+                    width: 300,\n+                    /**\n+                     * @property {number} [width=500]\n+                     *\n+                     * 默认高度\n+                     */\n+                    height: 500,\n+                    /**\n+                     * @property {String} [toolClass='']\n+                     *\n+                     * 要设置的工具图标的class名称,要以','分隔,用来标识点击了那个工具icon\n+                     */\n+                    toolClass: '',\n+                    /**\n+                     * @property {String} [sourceUrl='']\n+                     *\n+                     * 资源路径\n+                     */\n+                    sourceUrl: '',\n+                    /**\n+                     * @property {String} [sourceType='']\n+                     *\n+                     * 资源的类别,共支持以下四种类型\n+                     * 1.image: 图片类型\n+                     * 2.flash: 带有'swf'后缀名的flash文件\n+                     * 3.flv: 带有'flv'后缀名的视频文件\n+                     * 4.video: 带有'mp4|mov|mkv|mpg|avi|rmvb|rm|ogg|wmv|mp3|wma|mid'后缀名的文件\n+                     */\n+                    sourceType: ''\n+                };\n+\n+                u.extend(properties, MediaPreview.defaultProperties, options);\n+\n+                this.setProperties(properties);\n+            },\n+\n+            /**\n+             * 初始化DOM结构\n+             *\n+             * @protected\n+             * @override\n+             */\n+            initStructure: function () {\n+                var helper = this.helper;\n+\n+                var tpl = [\n+                    '<div id=\"${containerId}\" class=\"${containerClass}\">',\n+                        '<div id=\"${bodyId}\" class=\"${bodyClass}\"></div>',\n+                        '<div id=\"${toolId}\" class=\"${toolClass}\"></div>',\n+                    '</div>'\n+                ].join('');\n+\n+                var mainElement = this.main;\n+\n+                mainElement.innerHTML = lib.format(\n+                    tpl,\n+                    {\n+                        containerId: helper.getId('container'),\n+                        containerClass: helper.getPartClasses('container'),\n+                        bodyId: helper.getId('body'),\n+                        bodyClass: helper.getPartClasses('body'),\n+                        toolId: helper.getId('tool'),\n+                        toolClass: helper.getPartClasses('tool')\n+                    }\n+                );\n+            },\n+\n+            /**\n+             * 重渲染\n+             *\n+             * @method\n+             * @protected\n+             * @override\n+             */\n+            repaint: painters.createRepaint(\n+                Control.prototype.repaint,\n+                /**\n+                 * @property {String} sourceUrl\n+                 * @property {String} sourceType\n+                 *\n+                 * 资源的路径以及type\n+                 */\n+                {\n+                    name: ['sourceUrl', 'sourceType'],\n+                    paint: function (mediaPreview, sourceUrl, sourceType) {\n+                        initBody.call(mediaPreview);\n+                    }\n+                },\n+                /**\n+                 * @property {String} toolClass\n+                 *\n+                 * 工具栏工具的class,以','分隔,用来标志工具icon\n+                 */\n+                {\n+                    name: ['toolClass'],\n+                    paint: function (mediaPreview, toolClass) {\n+                        initToolBar.call(mediaPreview);\n+                    }\n+                },\n+                /**\n+                 * @property {number} width\n+                 * @property {number} height\n+                 *\n+                 * 文本框的宽度及高度\n+                 */\n+                {\n+                    name: ['width', 'height'],\n+                    paint: function (mediaPreview, width, height) {\n+                        $(mediaPreview.main).width(width).height(height);\n+                    }\n+                }\n+            ),\n+\n+            /**\n+             * 初始化事件交互\n+             *\n+             * @protected\n+             * @override\n+             */\n+            initEvents: function () {\n+                var me = this;\n+\n+                // 为所有的具有'data-role=\"tool\"'属性的span节点添加点击事件\n+                // 并在该控件上fire一个'iconclick'的事件,参数是点击的span的class\n+                this.helper.addDOMEvent(\n+                    this.helper.getPart('tool'),\n+                    'click',\n+                    '[data-role=\"tool\"]',\n+                    function (event) {\n+                        var toolNode = event.target;\n+                        me.fire('iconclick', {iconClass: $(toolNode).attr('class')});","path":"src/MediaPreview.js","position":185,"original_position":185,"commit_id":"bc6fdc303b0b214e4d436bbcdf4204bb11d29402","original_commit_id":"bc6fdc303b0b214e4d436bbcdf4204bb11d29402","user":{"login":"otakustay","id":639549,"avatar_url":"https://avatars.githubusercontent.com/u/639549?v=3","gravatar_id":"","url":"https://api.github.com/users/otakustay","html_url":"https://github.com/otakustay","followers_url":"https://api.github.com/users/otakustay/followers","following_url":"https://api.github.com/users/otakustay/following{/other_user}","gists_url":"https://api.github.com/users/otakustay/gists{/gist_id}","starred_url":"https://api.github.com/users/otakustay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/otakustay/subscriptions","organizations_url":"https://api.github.com/users/otakustay/orgs","repos_url":"https://api.github.com/users/otakustay/repos","events_url":"https://api.github.com/users/otakustay/events{/privacy}","received_events_url":"https://api.github.com/users/otakustay/received_events","type":"User","site_admin":false},"body":"是的，这样更合适一些","created_at":"2015-10-20T05:33:29Z","updated_at":"2015-10-20T05:33:29Z","html_url":"https://github.com/ecomfe/ub-ria-ui/pull/101#discussion_r42457542","pull_request_url":"https://api.github.com/repos/ecomfe/ub-ria-ui/pulls/101","_links":{"self":{"href":"https://api.github.com/repos/ecomfe/ub-ria-ui/pulls/comments/42457542"},"html":{"href":"https://github.com/ecomfe/ub-ria-ui/pull/101#discussion_r42457542"},"pull_request":{"href":"https://api.github.com/repos/ecomfe/ub-ria-ui/pulls/101"}}},"pull_request":{"url":"https://api.github.com/repos/ecomfe/ub-ria-ui/pulls/101","id":48052928,"html_url":"https://github.com/ecomfe/ub-ria-ui/pull/101","diff_url":"https://github.com/ecomfe/ub-ria-ui/pull/101.diff","patch_url":"https://github.com/ecomfe/ub-ria-ui/pull/101.patch","issue_url":"https://api.github.com/repos/ecomfe/ub-ria-ui/issues/101","number":101,"state":"open","locked":false,"title":"新增一个资源预览控件","user":{"login":"PacoIrene","id":3017934,"avatar_url":"https://avatars.githubusercontent.com/u/3017934?v=3","gravatar_id":"","url":"https://api.github.com/users/PacoIrene","html_url":"https://github.com/PacoIrene","followers_url":"https://api.github.com/users/PacoIrene/followers","following_url":"https://api.github.com/users/PacoIrene/following{/other_user}","gists_url":"https://api.github.com/users/PacoIrene/gists{/gist_id}","starred_url":"https://api.github.com/users/PacoIrene/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PacoIrene/subscriptions","organizations_url":"https://api.github.com/users/PacoIrene/orgs","repos_url":"https://api.github.com/users/PacoIrene/repos","events_url":"https://api.github.com/users/PacoIrene/events{/privacy}","received_events_url":"https://api.github.com/users/PacoIrene/received_events","type":"User","site_admin":false},"body":"将原来LightBox中渲染图片，flash，视频的逻辑抽出来\r\n并增加一个资源预览控件，可预览类型同LightBox","created_at":"2015-10-19T10:14:05Z","updated_at":"2015-10-20T05:33:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"04ca83f3faa923cd54ff35451b41bbf157a7400e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ecomfe/ub-ria-ui/pulls/101/commits","review_comments_url":"https://api.github.com/repos/ecomfe/ub-ria-ui/pulls/101/comments","review_comment_url":"https://api.github.com/repos/ecomfe/ub-ria-ui/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ecomfe/ub-ria-ui/issues/101/comments","statuses_url":"https://api.github.com/repos/ecomfe/ub-ria-ui/statuses/bc6fdc303b0b214e4d436bbcdf4204bb11d29402","head":{"label":"PacoIrene:master","ref":"master","sha":"bc6fdc303b0b214e4d436bbcdf4204bb11d29402","user":{"login":"PacoIrene","id":3017934,"avatar_url":"https://avatars.githubusercontent.com/u/3017934?v=3","gravatar_id":"","url":"https://api.github.com/users/PacoIrene","html_url":"https://github.com/PacoIrene","followers_url":"https://api.github.com/users/PacoIrene/followers","following_url":"https://api.github.com/users/PacoIrene/following{/other_user}","gists_url":"https://api.github.com/users/PacoIrene/gists{/gist_id}","starred_url":"https://api.github.com/users/PacoIrene/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PacoIrene/subscriptions","organizations_url":"https://api.github.com/users/PacoIrene/orgs","repos_url":"https://api.github.com/users/PacoIrene/repos","events_url":"https://api.github.com/users/PacoIrene/events{/privacy}","received_events_url":"https://api.github.com/users/PacoIrene/received_events","type":"User","site_admin":false},"repo":{"id":39172234,"name":"ub-ria-ui","full_name":"PacoIrene/ub-ria-ui","owner":{"login":"PacoIrene","id":3017934,"avatar_url":"https://avatars.githubusercontent.com/u/3017934?v=3","gravatar_id":"","url":"https://api.github.com/users/PacoIrene","html_url":"https://github.com/PacoIrene","followers_url":"https://api.github.com/users/PacoIrene/followers","following_url":"https://api.github.com/users/PacoIrene/following{/other_user}","gists_url":"https://api.github.com/users/PacoIrene/gists{/gist_id}","starred_url":"https://api.github.com/users/PacoIrene/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PacoIrene/subscriptions","organizations_url":"https://api.github.com/users/PacoIrene/orgs","repos_url":"https://api.github.com/users/PacoIrene/repos","events_url":"https://api.github.com/users/PacoIrene/events{/privacy}","received_events_url":"https://api.github.com/users/PacoIrene/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/PacoIrene/ub-ria-ui","description":"UI components for ub ria applications - standardized & implemented","fork":true,"url":"https://api.github.com/repos/PacoIrene/ub-ria-ui","forks_url":"https://api.github.com/repos/PacoIrene/ub-ria-ui/forks","keys_url":"https://api.github.com/repos/PacoIrene/ub-ria-ui/keys{/key_id}","collaborators_url":"https://api.github.com/repos/PacoIrene/ub-ria-ui/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/PacoIrene/ub-ria-ui/teams","hooks_url":"https://api.github.com/repos/PacoIrene/ub-ria-ui/hooks","issue_events_url":"https://api.github.com/repos/PacoIrene/ub-ria-ui/issues/events{/number}","events_url":"https://api.github.com/repos/PacoIrene/ub-ria-ui/events","assignees_url":"https://api.github.com/repos/PacoIrene/ub-ria-ui/assignees{/user}","branches_url":"https://api.github.com/repos/PacoIrene/ub-ria-ui/branches{/branch}","tags_url":"https://api.github.com/repos/PacoIrene/ub-ria-ui/tags","blobs_url":"https://api.github.com/repos/PacoIrene/ub-ria-ui/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/PacoIrene/ub-ria-ui/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/PacoIrene/ub-ria-ui/git/refs{/sha}","trees_url":"https://api.github.com/repos/PacoIrene/ub-ria-ui/git/trees{/sha}","statuses_url":"https://api.github.com/repos/PacoIrene/ub-ria-ui/statuses/{sha}","languages_url":"https://api.github.com/repos/PacoIrene/ub-ria-ui/languages","stargazers_url":"https://api.github.com/repos/PacoIrene/ub-ria-ui/stargazers","contributors_url":"https://api.github.com/repos/PacoIrene/ub-ria-ui/contributors","subscribers_url":"https://api.github.com/repos/PacoIrene/ub-ria-ui/subscribers","subscription_url":"https://api.github.com/repos/PacoIrene/ub-ria-ui/subscription","commits_url":"https://api.github.com/repos/PacoIrene/ub-ria-ui/commits{/sha}","git_commits_url":"https://api.github.com/repos/PacoIrene/ub-ria-ui/git/commits{/sha}","comments_url":"https://api.github.com/repos/PacoIrene/ub-ria-ui/comments{/number}","issue_comment_url":"https://api.github.com/repos/PacoIrene/ub-ria-ui/issues/comments{/number}","contents_url":"https://api.github.com/repos/PacoIrene/ub-ria-ui/contents/{+path}","compare_url":"https://api.github.com/repos/PacoIrene/ub-ria-ui/compare/{base}...{head}","merges_url":"https://api.github.com/repos/PacoIrene/ub-ria-ui/merges","archive_url":"https://api.github.com/repos/PacoIrene/ub-ria-ui/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/PacoIrene/ub-ria-ui/downloads","issues_url":"https://api.github.com/repos/PacoIrene/ub-ria-ui/issues{/number}","pulls_url":"https://api.github.com/repos/PacoIrene/ub-ria-ui/pulls{/number}","milestones_url":"https://api.github.com/repos/PacoIrene/ub-ria-ui/milestones{/number}","notifications_url":"https://api.github.com/repos/PacoIrene/ub-ria-ui/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/PacoIrene/ub-ria-ui/labels{/name}","releases_url":"https://api.github.com/repos/PacoIrene/ub-ria-ui/releases{/id}","created_at":"2015-07-16T02:32:25Z","updated_at":"2015-07-16T02:32:26Z","pushed_at":"2015-10-19T09:56:53Z","git_url":"git://github.com/PacoIrene/ub-ria-ui.git","ssh_url":"git@github.com:PacoIrene/ub-ria-ui.git","clone_url":"https://github.com/PacoIrene/ub-ria-ui.git","svn_url":"https://github.com/PacoIrene/ub-ria-ui","homepage":null,"size":3917,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"ecomfe:master","ref":"master","sha":"2f51a9bad26943dd1a55a258811197604f3b5479","user":{"login":"ecomfe","id":2268460,"avatar_url":"https://avatars.githubusercontent.com/u/2268460?v=3","gravatar_id":"","url":"https://api.github.com/users/ecomfe","html_url":"https://github.com/ecomfe","followers_url":"https://api.github.com/users/ecomfe/followers","following_url":"https://api.github.com/users/ecomfe/following{/other_user}","gists_url":"https://api.github.com/users/ecomfe/gists{/gist_id}","starred_url":"https://api.github.com/users/ecomfe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ecomfe/subscriptions","organizations_url":"https://api.github.com/users/ecomfe/orgs","repos_url":"https://api.github.com/users/ecomfe/repos","events_url":"https://api.github.com/users/ecomfe/events{/privacy}","received_events_url":"https://api.github.com/users/ecomfe/received_events","type":"Organization","site_admin":false},"repo":{"id":23924615,"name":"ub-ria-ui","full_name":"ecomfe/ub-ria-ui","owner":{"login":"ecomfe","id":2268460,"avatar_url":"https://avatars.githubusercontent.com/u/2268460?v=3","gravatar_id":"","url":"https://api.github.com/users/ecomfe","html_url":"https://github.com/ecomfe","followers_url":"https://api.github.com/users/ecomfe/followers","following_url":"https://api.github.com/users/ecomfe/following{/other_user}","gists_url":"https://api.github.com/users/ecomfe/gists{/gist_id}","starred_url":"https://api.github.com/users/ecomfe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ecomfe/subscriptions","organizations_url":"https://api.github.com/users/ecomfe/orgs","repos_url":"https://api.github.com/users/ecomfe/repos","events_url":"https://api.github.com/users/ecomfe/events{/privacy}","received_events_url":"https://api.github.com/users/ecomfe/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ecomfe/ub-ria-ui","description":"UI components for ub ria applications - standardized & implemented","fork":false,"url":"https://api.github.com/repos/ecomfe/ub-ria-ui","forks_url":"https://api.github.com/repos/ecomfe/ub-ria-ui/forks","keys_url":"https://api.github.com/repos/ecomfe/ub-ria-ui/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ecomfe/ub-ria-ui/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ecomfe/ub-ria-ui/teams","hooks_url":"https://api.github.com/repos/ecomfe/ub-ria-ui/hooks","issue_events_url":"https://api.github.com/repos/ecomfe/ub-ria-ui/issues/events{/number}","events_url":"https://api.github.com/repos/ecomfe/ub-ria-ui/events","assignees_url":"https://api.github.com/repos/ecomfe/ub-ria-ui/assignees{/user}","branches_url":"https://api.github.com/repos/ecomfe/ub-ria-ui/branches{/branch}","tags_url":"https://api.github.com/repos/ecomfe/ub-ria-ui/tags","blobs_url":"https://api.github.com/repos/ecomfe/ub-ria-ui/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ecomfe/ub-ria-ui/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ecomfe/ub-ria-ui/git/refs{/sha}","trees_url":"https://api.github.com/repos/ecomfe/ub-ria-ui/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ecomfe/ub-ria-ui/statuses/{sha}","languages_url":"https://api.github.com/repos/ecomfe/ub-ria-ui/languages","stargazers_url":"https://api.github.com/repos/ecomfe/ub-ria-ui/stargazers","contributors_url":"https://api.github.com/repos/ecomfe/ub-ria-ui/contributors","subscribers_url":"https://api.github.com/repos/ecomfe/ub-ria-ui/subscribers","subscription_url":"https://api.github.com/repos/ecomfe/ub-ria-ui/subscription","commits_url":"https://api.github.com/repos/ecomfe/ub-ria-ui/commits{/sha}","git_commits_url":"https://api.github.com/repos/ecomfe/ub-ria-ui/git/commits{/sha}","comments_url":"https://api.github.com/repos/ecomfe/ub-ria-ui/comments{/number}","issue_comment_url":"https://api.github.com/repos/ecomfe/ub-ria-ui/issues/comments{/number}","contents_url":"https://api.github.com/repos/ecomfe/ub-ria-ui/contents/{+path}","compare_url":"https://api.github.com/repos/ecomfe/ub-ria-ui/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ecomfe/ub-ria-ui/merges","archive_url":"https://api.github.com/repos/ecomfe/ub-ria-ui/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ecomfe/ub-ria-ui/downloads","issues_url":"https://api.github.com/repos/ecomfe/ub-ria-ui/issues{/number}","pulls_url":"https://api.github.com/repos/ecomfe/ub-ria-ui/pulls{/number}","milestones_url":"https://api.github.com/repos/ecomfe/ub-ria-ui/milestones{/number}","notifications_url":"https://api.github.com/repos/ecomfe/ub-ria-ui/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ecomfe/ub-ria-ui/labels{/name}","releases_url":"https://api.github.com/repos/ecomfe/ub-ria-ui/releases{/id}","created_at":"2014-09-11T15:43:21Z","updated_at":"2015-09-16T08:55:58Z","pushed_at":"2015-10-20T03:35:57Z","git_url":"git://github.com/ecomfe/ub-ria-ui.git","ssh_url":"git@github.com:ecomfe/ub-ria-ui.git","clone_url":"https://github.com/ecomfe/ub-ria-ui.git","svn_url":"https://github.com/ecomfe/ub-ria-ui","homepage":null,"size":5347,"stargazers_count":4,"watchers_count":4,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":24,"mirror_url":null,"open_issues_count":24,"forks":24,"open_issues":24,"watchers":4,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ecomfe/ub-ria-ui/pulls/101"},"html":{"href":"https://github.com/ecomfe/ub-ria-ui/pull/101"},"issue":{"href":"https://api.github.com/repos/ecomfe/ub-ria-ui/issues/101"},"comments":{"href":"https://api.github.com/repos/ecomfe/ub-ria-ui/issues/101/comments"},"review_comments":{"href":"https://api.github.com/repos/ecomfe/ub-ria-ui/pulls/101/comments"},"review_comment":{"href":"https://api.github.com/repos/ecomfe/ub-ria-ui/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ecomfe/ub-ria-ui/pulls/101/commits"},"statuses":{"href":"https://api.github.com/repos/ecomfe/ub-ria-ui/statuses/bc6fdc303b0b214e4d436bbcdf4204bb11d29402"}}}}