Skip to content
Browse files

implement issue #123 requirement.

  • Loading branch information...
1 parent 2b8f2f6 commit 66514fd368d75d14ae21b8e996f515742774ed6d @ichord ichord committed Mar 7, 2012
Showing with 52 additions and 2 deletions.
  1. +6 −0 README.markdown
  2. +18 −1 Rakefile
  3. +12 −0 app/assets/javascripts/topics.coffee
  4. +0 −1 app/assets/javascripts/will_paginate.js
  5. +16 −0 app/views/topics/_form.html.erb
View
6 README.markdown
@@ -18,6 +18,12 @@ This is the source code of [Ruby China Group](http://ruby-china.org)
easy_install pygments # 或者 pip install pygments
rake db:migrate
```
+ or you can just this issue
+ ```
+ rake test:init
+ ```
+ to prepare all the config files and start essential services.
+
## Deploy
$ cap deploy
View
19 Rakefile
@@ -21,4 +21,21 @@ namespace :resque do
system("rm /var/run/god/resque-1.8.0*.pid")
end
-end
+end
+
+namespace :test do
+ desc "preparing config files..."
+ task :prepare => :init do
+ ["config","mongoid","redis"].each do |cfgfile|
+ system("cp config/#{cfgfile}.yml.default config/#{cfgfile}.yml") unless File.exist?("config/#{cfgfile}.yml")
+ end
+ end
+
+ desc "start essential services.."
+ task :init do
+ desc "starting resque..."
+ system("./script/resque start")
+ desc "starting sunspot..."
+ system("bundle exec rake sunspot:solr:start")
+ end
+end
View
12 app/assets/javascripts/topics.coffee
@@ -85,6 +85,18 @@ window.Topics =
Topics.preview($(textarea).val())
false
+ onCloseWarning: (msg) ->
+ msg = "离开本页面将丢失未保存页面!" if !msg
+ $(window).bind("beforeunload", (e) ->
+ if $.browser.msie
+ e.returnValue = msg
+ else
+ return msg
+ )
+
+ offCloseWarning: () ->
+ $(window).unbind("beforeunload")
+
# pages ready
$(document).ready ->
$("textarea").bind "keydown","ctrl+return",(el) ->
View
1 app/assets/javascripts/will_paginate.js
@@ -15,7 +15,6 @@
}
}
}
- end
}
function prevPage() {
View
16 app/views/topics/_form.html.erb
@@ -22,3 +22,19 @@
</div>
</fieldset>
<% end %>
+<script type="text/javascript">
+ // not loaded jquery yet.
+ window.onload = function() {
+ // have loaed all js now.
+ Topics.onCloseWarning();
+ $('.actions>input[type=submit]').click(function(e){
+ Topics.offCloseWarning();
+ });
+ // onbeforeunload conflict with <a> element in IE!!!
+ // except a.href is not empty(such as #) or a.onclick return false
+ // "###" let <a> not be a anchor point
+ if ($.browser.msie) {
+ $('a[href^="javascript"]').attr('href','###');
+ }
+ }
+</script>

0 comments on commit 66514fd

Please sign in to comment.
Something went wrong with that request. Please try again.