123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- swfobject.addDomLoadEvent(function () {
-
- var webcamAvailable = false;
- var currentTab = 'upload';
- var sourcePic1Url = $.Cookie('swf1');
- var sourcePic2Url = $.Cookie('swf2');
- if(sourcePic2Url == null)
- {
- sourcePic2Url = "samplePictures/Default.jpg";
- }
- var callback = function (json) {
- var id = this.id;
- switch (json.code) {
- case 2:
-
- if (json.type == 0) {
- if(id == "swf2")
- {
- $('#webcamPanelButton').hide();
- $('#editorPanelButtons').show();
- }
- }
-
- else {
-
- if(id == "swf1")$('#editorPanelButtons,#webcamPanelButton').hide();
- }
- break;
- case 3:
-
- if (json.type == 0) {
- if(id == "swf2")
- {
- $('.button_shutter').removeClass('Disabled');
- $('#webcamPanelButton').show();
- webcamAvailable = true;
- }
- }
- else {
- if(id == "swf2")
- {
- webcamAvailable = false;
- $('#webcamPanelButton').hide();
- }
-
- if (json.type == 1) {
- alert('用户拒绝使用摄像头!');
- }
-
- else {
- alert('摄像头被占用!');
- }
- }
- break;
- case 4:
- alert("您选择的原图片文件大小(" + json.content + ")超出了指定的值(2MB)。");
- break;
- case 5:
-
- if (json.type == 0) {
- var e = this;
- var html = $('<div class="imgList"/>');
- for(var i = 0; i < json.content.avatarUrls.length; i++)
- {
- html.append('<dl><dt>头像图片'+(i+1)+'</dt><dd><img src="' + json.content.avatarUrls[i] + '" /></dd></dl>');
- }
- var button = [];
-
- if(json.content.sourceUrl)
- {
- button.push({text : '修改头像', callback:function(){
- this.close();
- $.Cookie(id, json.content.sourceUrl);
- location.reload();
-
- }});
- }
- else
- {
- $.Cookie(id, null);
- }
- button.push({text : '关闭窗口'});
- $.dialog({
- title:'图片已成功保存至服务器',
- content:html,
- button:button,
- mask:true,
- draggable:false
- });
- }
- else {
- switch (json.type)
- {
- case 1:alert('图片上传失败,接口返回的内容为:'+json.content);break;
- case 2:alert('图片上传失败,指定的上传地址不存在或有问题!\n'+json.content);break;
- case 3:alert('图片上传失败,发生了安全性错误!\n'+json.content);break;
- }
- }
- break;
- }
- };
-
- var swf1 = new fullAvatarEditor('swf1', {
- id: 'swf1',
- upload_url: 'upload.php',
- src_url: sourcePic2Url,
- src_upload: 2,
- avatar_scale:2,
- avatar_intro:'最终头像的尺寸为以下尺寸 * 2(设置的缩放系数)',
- avatar_sizes_desc:'100*100像素,缩放系数为2,保存后的大小为200*200像素。|50*50像素,缩放系数为2,保存后的大小为100*100像素。|32*32像素,缩放系数为2,保存后的大小为64*64像素。'
- }, callback);
- var swf2 = new fullAvatarEditor('swf2', 335, {
- id : 'swf2',
- upload_url: 'upload.php?size_number=1',
- method :'post',
- src_url : sourcePic1Url,
- tab_visible : false,
- button_visible : false,
- src_upload : 2,
- checkbox_visible : false,
- browse_box_align : 38,
- webcam_box_align : 38,
- avatar_sizes : '258*200',
- avatar_sizes_desc :'258*200像素',
- isShowUploadResultIcon:false,
-
- avatar_intro : ' 最终会生成下面这个尺寸的头像',
- avatar_tools_visible:true
- }, callback);
-
- $('dt').click(function () {
- if (currentTab != this.id) {
- currentTab = this.id;
- $(this).addClass('current');
- $(this).siblings().removeClass('current');
-
- if (this.id === 'albums') {
-
- hideSWF();
- showAlbums();
- }
- else {
- hideAlbums();
- showSWF();
- if (this.id === 'webcam') {
- $('#editorPanelButtons').hide();
- if (webcamAvailable) {
- $('.button_shutter').removeClass('Disabled');
- $('#webcamPanelButton').show();
- }
- }
- else {
-
- $('#editorPanelButtons,#webcamPanelButton').hide();
- }
- }
- swf2.call('changepanel', this.id);
- }
- });
-
- $('#src_upload').change(function () {
- swf2.call('srcUpload', this.checked);
- });
-
- $('.button_upload').click(function () {
- swf2.call('upload');
- });
-
- $('.button_cancel').click(function () {
- var activedTab = $('dt.current')[0].id;
- if (activedTab === 'albums') {
- hideSWF();
- showAlbums();
- }
- else {
- swf2.call('changepanel', activedTab);
- if (activedTab === 'webcam') {
- $('#editorPanelButtons').hide();
- if (webcamAvailable) {
- $('.button_shutter').removeClass('Disabled');
- $('#webcamPanelButton').show();
- }
- }
- else {
-
- $('#editorPanelButtons,#webcamPanelButton').hide();
- }
- }
- });
-
- $('.button_shutter').click(function () {
- if (!$(this).hasClass('Disabled')) {
- $(this).addClass('Disabled');
- swf2.call('pressShutter');
- }
- });
-
- $('#userAlbums a').click(function () {
- var sourcePic = this.href;
- swf2.call('loadPic', sourcePic);
-
- hideAlbums();
-
- showSWF();
- return false;
- });
-
- function hideSWF() {
-
- $('#flash').data({
- w: $('#flash').width(),
- h: $('#flash').height()
- })
- .css({
- width: '0px',
- height: '0px',
- overflow: 'hidden'
- });
-
- $('#editorPanelButtons,#webcamPanelButton').hide();
- }
- function showSWF() {
- $('#flash').css({
- width: $('#flash').data('w'),
- height: $('#flash').data('h')
- });
- }
-
- function showAlbums() {
- $('#userAlbums').show();
- }
-
- function hideAlbums() {
- $('#userAlbums').hide();
- }
- });
|