Created
February 10, 2014 08:03
-
-
Save marvinjeng/8912041 to your computer and use it in GitHub Desktop.
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
function textarea_fetch_blog($output){ | |
$output .= '<div>'; | |
$output .= '<span style="font-size:16px;float:left;margin:18px 12px 18px 0px">匯入部落格的最新文章</span>'; | |
$output .= '<select id="optSource" style="height:30px;position:absolute;margin-top:12px;border:1px solid #ccc;"><option value="tpTumblr">Tumblr</option> | |
<option value="tpWordpress">Wordpress</option> | |
</select>'; | |
$output .= '<textarea id="txUrl" style="margin:10px 10px 10px 100px;border:1px solid #ccc;width:300px;height:20px;font-size:14px;padding:6px;"></textarea>'; | |
$output .= '<span style="position:absolute;margin-top:12px;"><button id="btFetch" style="height:32px">Import</button></span>'; | |
$output .= '</div>'; | |
$output .= '<script>'; | |
$output .= ' | |
function getScript(url, success) { | |
var script = document.createElement("script"); | |
script.src = url; | |
var head = document.getElementsByTagName("head")[0], | |
done = false; | |
// Attach handlers for all browsers | |
script.onload = script.onreadystatechange = function() { | |
if (!done && (!this.readyState | |
|| this.readyState == "loaded" | |
|| this.readyState == "complete")) { | |
done = true; | |
success(); | |
script.onload = script.onreadystatechange = null; | |
head.removeChild(script); | |
} | |
}; | |
head.appendChild(script); | |
} | |
getScript("http://code.jquery.com/jquery-latest.min.js", function(){ | |
console.log("cors support: " + $.support.cors); | |
$("#edit-body-und-0-format--2").val("full_html"); | |
$("#btFetch").click(function(e){ | |
e.preventDefault(); | |
var txUrl = $("#txUrl").val(); | |
var optSource = $("#optSource").find(":selected").text(); | |
console.log(txUrl); | |
var qs = "http://192.241.213.113:1985/"; | |
if (optSource=="Tumblr"){ | |
qs = qs + "tumblr?target=" + txUrl; | |
}else if(optSource=="Wordpress"){ | |
qs = qs + "wordpress?target=" + txUrl; | |
} | |
$.get(qs, function(ret){ | |
$("#edit-title").val(ret.title); | |
$("#edit-body-und-0-value").val(ret.body); | |
console.log(ret); | |
}, "jsonp"); | |
console.log(optSource); | |
}); | |
}); | |
'; | |
$output .= '</script>'; | |
return $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment