-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
191 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
WeSketch.sketchplugin/Contents/Sketch/library/panel/setCode.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<title></title> | ||
<script type="text/javascript" src="js/jquery.js"></script> | ||
<link href="css/normalize.css" rel="stylesheet"> | ||
<style type="text/css"> | ||
body, | ||
html { | ||
height: 100%; | ||
background-color: #ececec; | ||
font-size: 12px; | ||
} | ||
|
||
.wrap { | ||
padding: 10px 15px 20px 15px; | ||
} | ||
|
||
.savebutton { | ||
color: white; | ||
background: #3485f0; | ||
border: 1px solid #237fff; | ||
border-radius: 4px; | ||
padding: 0 15px; | ||
margin-right: 35px; | ||
float: right; | ||
cursor: pointer; | ||
} | ||
|
||
.textarea{ | ||
width: 100%; | ||
resize:none; | ||
height:330px; | ||
} | ||
|
||
.savebutton:active { | ||
background: linear-gradient(0deg, #4c98fe 0%, #0466e3 100%); | ||
} | ||
|
||
.buttonwrap { | ||
left: 0; | ||
bottom: 0; | ||
padding: 10px 0; | ||
width: 100%; | ||
border-top: 1px solid #bebebe; | ||
background: #f1f1f1; | ||
position: fixed; | ||
box-sizing: border-box; | ||
} | ||
|
||
</style> | ||
</head> | ||
|
||
<body> | ||
<div class="wrap"> | ||
<textarea name="" class="textarea" id="textarea" ></textarea> | ||
<div class="buttonwrap"> | ||
<div class="savebutton">确定</div> | ||
</div> | ||
</div> | ||
|
||
|
||
<script type="text/javascript"> | ||
|
||
var init = function (data) { | ||
$('.savebutton').on('click',function(){ | ||
var obj = {data:$('#textarea').val()}; | ||
SMAction('submit', obj); | ||
SMAction('close'); | ||
}) | ||
} | ||
</script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -230,7 +230,6 @@ | |
} | ||
}) | ||
} | ||
init(); | ||
</script> | ||
</body> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
@import "common.js" | ||
|
||
var symbolCodeKey = "com.sketchplugins.wechat.symbolCode"; | ||
|
||
function getSymbolCode(context) { | ||
if(context.selection.length == 0){ | ||
return; | ||
} | ||
var selection = context.selection[0]; | ||
if(selection.className() == 'MSSymbolInstance'){ | ||
var code = decodeURIComponent(encodeURIComponent(context.command.valueForKey_onLayer_forPluginIdentifier("symbolKey", context.selection[0].symbolMaster(), symbolCodeKey))); | ||
for (var key in selection.overrides()) { | ||
for(var i = 0;i<selection.symbolMaster().children().length;i++){ | ||
if(key == selection.symbolMaster().children()[i].objectID()){ | ||
code = code.replace(selection.symbolMaster().children()[i].stringValue(),selection.overrides()[key]); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
paste(code); | ||
context.document.showMessage('代码已经放入剪贴板'); | ||
var ga = new Analytics(context); | ||
if (ga) ga.sendEvent('code', 'get'); | ||
} | ||
|
||
function setSymbolCode(context) { | ||
if(context.selection[0].className() == 'MSSymbolMaster'){ | ||
var pluginSketch = context.plugin.url().URLByAppendingPathComponent("Contents").URLByAppendingPathComponent("Sketch").URLByAppendingPathComponent("library").path(); | ||
SMPanel({ | ||
url: pluginSketch + "/panel/setCode.html", | ||
width: 400, | ||
height: 400, | ||
data: { | ||
|
||
}, | ||
hiddenClose: false, | ||
floatWindow: false, | ||
identifier: "setCode", | ||
callback: function (data) { | ||
context.command.setValue_forKey_onLayer_forPluginIdentifier(data.data, "symbolKey", context.selection[0], symbolCodeKey); | ||
context.document.showMessage('设置成功'); | ||
}, | ||
closeCallback: function () { | ||
|
||
} | ||
}); | ||
var ga = new Analytics(context); | ||
if (ga) ga.sendEvent('code', 'set'); | ||
} | ||
|
||
|
||
} | ||
|
||
|
||
var onRun = function (context) { | ||
setSymbolCode(context); | ||
} |