Skip to content

Commit

Permalink
Merge pull request #46 from weixin/color
Browse files Browse the repository at this point in the history
Color
  • Loading branch information
bugluo committed Sep 17, 2017
2 parents 9eaa440 + 9568008 commit 2834453
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 4 deletions.
15 changes: 12 additions & 3 deletions WeSketch.sketchplugin/Contents/Sketch/commonPreviewJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@import "commonPreview.js";


var commonPreviewJson = function (context, filePath) {
var commonPreviewJson = function (context, filePath, show) {
var i18 = _(context).commonPreview;

var BorderPositions = ["center", "inside", "outside"],
Expand Down Expand Up @@ -201,8 +201,11 @@ var commonPreviewJson = function (context, filePath) {
settingsWindow.addAccessoryView(fx);
return settingsWindow.runModal();
}
if (chooseDialog() != '1000') {
if (show || chooseDialog() != '1000') {
fxstyle = 'default';
if(show){
fxlocal = '20';
}
} else {
fx = fx.selectedCell();
var index = [fx tag];
Expand Down Expand Up @@ -430,8 +433,14 @@ var commonPreviewJson = function (context, filePath) {
var size = artBoards[i].absoluteRect().size().width;
if (size == 320 || size == 414 || size == 375) {
scale = 2;
exportSVGJson.width = parseInt(encodeURIComponent(size));
}else if(size == 750){
exportSVGJson.width = 375;
}else if(size == 640){
exportSVGJson.width = 320;
}else{
exportSVGJson.width = 414;
}
// getSliceHeader(artBoards[i],context,'header'+pageCount,filePath,scale);
exportPNG(artBoards[i], context, filePath, scale, newPreviewObject);
}
relationship(context.document,newPreviewObject);
Expand Down
8 changes: 8 additions & 0 deletions WeSketch.sketchplugin/Contents/Sketch/i18n/manifest-enUS.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@
"shortcut": "",
"handler" : "hidePreview"
},
{
"name" : "Show Preview",
"identifier" : "showPreview",
"script" : "showPreview.js",
"shortcut": "",
"istool":"",
"handler" : "onRun"
},
{
"name" : "Local Preview",
"identifier" : "localPreview",
Expand Down
8 changes: 8 additions & 0 deletions WeSketch.sketchplugin/Contents/Sketch/i18n/manifest-zhCN.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@
"shortcut": "",
"handler" : "hidePreview"
},
{
"name" : "直接预览",
"identifier" : "showPreview",
"script" : "showPreview.js",
"shortcut": "",
"istool":"",
"handler" : "onRun"
},
{
"name" : "生成本地预览",
"identifier" : "localPreview",
Expand Down
8 changes: 8 additions & 0 deletions WeSketch.sketchplugin/Contents/Sketch/i18n/manifest-zhTW.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@
"shortcut": "",
"handler" : "hidePreview"
},
{
"name" : "直接預覽",
"identifier" : "showPreview",
"script" : "showPreview.js",
"shortcut": "",
"istool":"",
"handler" : "onRun"
},
{
"name" : "生成本地預覽",
"identifier" : "localPreview",
Expand Down
9 changes: 9 additions & 0 deletions WeSketch.sketchplugin/Contents/Sketch/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@
"shortcut": "",
"handler" : "hidePreview"
},
{
"name" : "Show Preview",
"identifier" : "showPreview",
"script" : "showPreview.js",
"shortcut": "",
"istool":"",
"handler" : "onRun"
},
{
"name" : "Local Preview",
"identifier" : "localPreview",
Expand Down Expand Up @@ -363,6 +371,7 @@
"setNoBuild",
"previewClear",
"previewHide",
"showPreview",
"localPreview",
"webPreview",
"-",
Expand Down
8 changes: 7 additions & 1 deletion WeSketch.sketchplugin/Contents/Sketch/preview.html
Original file line number Diff line number Diff line change
Expand Up @@ -2449,6 +2449,9 @@
$('.loadding').show();
var loader = new PxLoader();
for (var i in content) {
if(i == 'width'){
continue;
}
if (content[i].content.name) {
loader.addImage('./' + content[i].content.name + '.png');
}
Expand All @@ -2471,7 +2474,7 @@



var size = 414;
var size = content.width;
var zoom = window.innerWidth / size;
var zindex = 1;
var firstPage;
Expand All @@ -2493,6 +2496,9 @@

var dom = [];
for (var i in content) {
if(i == 'width'){
continue;
}
if (content[i].firstPage) {
history.pushState(null, "", "?page=" + content[i].content.name);
firstPage = content[i].content.name;
Expand Down
68 changes: 68 additions & 0 deletions WeSketch.sketchplugin/Contents/Sketch/showPreview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
@import "common.js"
@import "link.js"
@import "commonPreviewJson.js"

function showPreview(context) {
var i18 = _(context).webPreview;
context.document.showMessage(i18.m5);

function chooseFilePath() {
var save = NSSavePanel.savePanel();
save.setAllowsOtherFileTypes(true);
save.setExtensionHidden(false);
return save.URL().path() + '/' + (Math.random());
}
var filePath = chooseFilePath();
var flag = commonPreviewJson(context, filePath, true);
if (!flag) {
return;
}
var fx;
var width = 414;
var height = 716;
function chooseDialog() {
var settingsWindow = COSAlertWindow.new();
settingsWindow.addButtonWithTitle('确定');
settingsWindow.addButtonWithTitle('取消');

settingsWindow.setMessageText('请选择预览尺寸');

var ButtonList = ['iPhone 6P', 'iPhone 6'];

fx = createRadioButtons(ButtonList, 0);
settingsWindow.addAccessoryView(fx);
return settingsWindow.runModal();
}
if(chooseDialog() == '1000'){
fx = fx.selectedCell();
var index = [fx tag];
if (index == 1) {
width = 375;
height = 647;
}


var pluginSketch = context.plugin.url().URLByAppendingPathComponent("Contents").URLByAppendingPathComponent("Sketch").URLByAppendingPathComponent("library").path();
SMPanel({
url: filePath+'/index.html',
width: width,
height: height,
hiddenClose: false,
floatWindow: false,
identifier: "preview",
callback: function (data) {
},
closeCallback: function () {
var fm = [NSFileManager defaultManager];
fm.removeItemAtPath_error(filePath, nil);
}
});
}
var ga = new Analytics(context);
if (ga) ga.sendEvent('showPreview', 'preview');

}

var onRun = function (context) {
showPreview(context);
}

0 comments on commit 2834453

Please sign in to comment.