added suggest title link

This commit is contained in:
Sacha Greif 2012-09-07 18:17:19 +09:00
parent 2071f4b01d
commit 61a2b47ccc
6 changed files with 136 additions and 15 deletions

View file

@ -763,8 +763,23 @@ form .control-group, .accounts-dialog .control-group {
float: left; }
/* line 8, ../sass/modules/_forms.scss */
form .control-group .controls, .accounts-dialog .control-group .controls {
margin-left: 100px; }
/* line 12, ../sass/modules/_forms.scss */
margin-left: 100px;
position: relative; }
/* line 11, ../sass/modules/_forms.scss */
form .control-group .controls .get-title-link, .accounts-dialog .control-group .controls .get-title-link {
position: absolute;
display: block;
top: 2px;
right: 8px; }
/* line 16, ../sass/modules/_forms.scss */
form .control-group .controls .get-title-link.loading, .accounts-dialog .control-group .controls .get-title-link.loading {
background: url(/img/loading.gif) center center no-repeat;
height: 22px;
width: 18px;
font: 0/0 a;
text-shadow: none;
color: transparent; }
/* line 25, ../sass/modules/_forms.scss */
form .form-actions, .accounts-dialog .form-actions {
/* For modern browsers */
/* For IE 6/7 (trigger hasLayout) */
@ -776,7 +791,7 @@ form .form-actions, .accounts-dialog .form-actions {
/* line 69, ../sass/partials/_mixins.scss */
form .form-actions:after, .accounts-dialog .form-actions:after {
clear: both; }
/* line 15, ../sass/modules/_forms.scss */
/* line 28, ../sass/modules/_forms.scss */
form input[type="text"], form input[type="password"], form textarea, form .login-form input, .accounts-dialog input[type="text"], .accounts-dialog input[type="password"], .accounts-dialog textarea, .accounts-dialog .login-form input {
display: block;
padding: 5px 6px;
@ -793,29 +808,29 @@ form input[type="text"], form input[type="password"], form textarea, form .login
-moz-transition: all, 500ms;
-o-transition: all, 500ms;
transition: all, 500ms; }
/* line 24, ../sass/modules/_forms.scss */
/* line 37, ../sass/modules/_forms.scss */
form input[type="text"]:focus, form input[type="password"]:focus, form textarea:focus, form .login-form input:focus, .accounts-dialog input[type="text"]:focus, .accounts-dialog input[type="password"]:focus, .accounts-dialog textarea:focus, .accounts-dialog .login-form input:focus {
outline: none;
border-color: #f36c3d;
-webkit-box-shadow: 0px 0px 5px 0px rgba(243, 108, 61, 0.3);
-moz-box-shadow: 0px 0px 5px 0px rgba(243, 108, 61, 0.3);
box-shadow: 0px 0px 5px 0px rgba(243, 108, 61, 0.3); }
/* line 30, ../sass/modules/_forms.scss */
/* line 43, ../sass/modules/_forms.scss */
form input[type="text"], form input[type="password"], form .login-form input, .accounts-dialog input[type="text"], .accounts-dialog input[type="password"], .accounts-dialog .login-form input {
height: 30px;
line-height: 20px; }
/* line 34, ../sass/modules/_forms.scss */
/* line 47, ../sass/modules/_forms.scss */
form textarea, .accounts-dialog textarea {
min-height: 100px;
line-height: 1.4; }
/* line 38, ../sass/modules/_forms.scss */
/* line 51, ../sass/modules/_forms.scss */
form .delete-link, .accounts-dialog .delete-link {
float: left; }
/* line 41, ../sass/modules/_forms.scss */
/* line 54, ../sass/modules/_forms.scss */
form input[type="submit"], form button, form .button, form .auth-buttons #login-buttons #login-buttons-password, .auth-buttons #login-buttons form #login-buttons-password, form .btn, .accounts-dialog input[type="submit"], .accounts-dialog button, .accounts-dialog .button, .accounts-dialog .auth-buttons #login-buttons #login-buttons-password, .auth-buttons #login-buttons .accounts-dialog #login-buttons-password, .accounts-dialog .btn {
float: right; }
/* line 45, ../sass/modules/_forms.scss */
/* line 58, ../sass/modules/_forms.scss */
input[type="submit"], button, .button, .auth-buttons #login-buttons #login-buttons-password, .btn {
-webkit-appearance: none;
-webkit-border-radius: 0px;

View file

@ -0,0 +1,75 @@
/**
* jQuery.ajax mid - CROSS DOMAIN AJAX
* ---
* @author James Padolsey (http://james.padolsey.com)
* @version 0.11
* @updated 12-JAN-10
* ---
* Note: Read the README!
* ---
* @info http://james.padolsey.com/javascript/cross-domain-requests-with-jquery/
*/
jQuery.ajax = (function(_ajax){
var protocol = location.protocol,
hostname = location.hostname,
exRegex = RegExp(protocol + '//' + hostname),
YQL = 'http' + (/^https/.test(protocol)?'s':'') + '://query.yahooapis.com/v1/public/yql?callback=?',
query = 'select * from html where url="{URL}" and xpath="*"';
function isExternal(url) {
return !exRegex.test(url) && /:\/\//.test(url);
}
return function(o) {
var url = o.url;
if ( /get/i.test(o.type) && !/json/i.test(o.dataType) && isExternal(url) ) {
// Manipulate options so that JSONP-x request is made to YQL
o.url = YQL;
o.dataType = 'json';
o.data = {
q: query.replace(
'{URL}',
url + (o.data ?
(/\?/.test(url) ? '&' : '?') + jQuery.param(o.data)
: '')
),
format: 'xml'
};
// Since it's a JSONP request
// complete === success
if (!o.success && o.complete) {
o.success = o.complete;
delete o.complete;
}
o.success = (function(_success){
return function(data) {
if (_success) {
// Fake XHR callback.
_success.call(this, {
responseText: (data.results[0] || '')
// YQL screws with <script>s
// Get rid of them
.replace(/<script[^>]+?\/>|<script(.|\s)*?\/script>/gi, '')
}, 'success');
}
};
})(o.success);
}
return _ajax.apply(this, arguments);
};
})(jQuery.ajax);

View file

@ -7,6 +7,19 @@ form, .accounts-dialog{
}
.controls{
margin-left:100px;
position:relative;
.get-title-link{
position:absolute;
display:block;
top:2px;
right:8px;
&.loading{
background:url(/img/loading.gif) center center no-repeat;
height:22px;
width:18px;
@include hide-text2;
}
}
}
}
.form-actions{

View file

@ -1,14 +1,14 @@
<template name="post_submit">
<div class="grid submit">
<form class="grid-block form-horizontal">
<div class="control-group">
<label class="control-label">Title</label>
<div class="controls"><input id="title" type="text" value="" /></div>
</div>
<div class="control-group">
<label class="control-label">URL</label>
<div class="controls"><input id="url" type="text" value="" /></div>
</div>
<div class="control-group">
<label class="control-label">Title</label>
<div class="controls"><input id="title" type="text" value="" /><a href="#" class="get-title-link">Suggest title</a></div>
</div>
<div class="control-group">
<label class="control-label">Message</label>
<div class="controls"><textarea id="body" value="" class="input-xlarge"/></div>

View file

@ -1,6 +1,6 @@
Template.post_submit.events = {
'click input[type=submit]': function(event){
event.preventDefault();
'click input[type=submit]': function(e){
e.preventDefault();
if(!Meteor.user()) throw 'You must be logged in.';
var title= $('#title').val();
@ -24,4 +24,22 @@ Template.post_submit.events = {
// Session.set('state', 'view_post');
Router.navigate('posts/'+postId, {trigger: true});
}
,'click .get-title-link': function(e){
e.preventDefault();
var url=$("#url").val();
$(".get-title-link").addClass("loading");
if(url){
$.get(url, function(response){
if ((suggestedTitle=((/<title>(.*?)<\/title>/m).exec(response.responseText))) != null){
$("#title").val(suggestedTitle[1]);
}else{
alert("Sorry, couldn't find a title...");
}
$(".get-title-link").removeClass("loading");
});
}else{
alert("Please fill in an URL first!");
}
}
};

BIN
public/img/loading.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 673 B