demo site widget
This commit is contained in:
1 parent
f223e4bb1e
commit
c0cac812c5
19 files changed
+312
-593
No files matched your search
@@ -0,0 +1,6 @@
|
||||
var pic = $(".app-pic").length,w,h;
|
||||
for(i=0; i<pic; i=i+1) {
|
||||
w = $(".app-pic").eq(i).width();
|
||||
h = $(".app-pic").eq(i).height();
|
||||
$(".app-pic").eq(i).find('img').muImageResize({width: w, height: h});
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
(function( $ ) {
|
||||
$.fn.muImageResize = function( params ) {
|
||||
var _defaultSettings = {
|
||||
width:300,
|
||||
height:300,
|
||||
wrap_fix:true // Let image display like in-line.
|
||||
};
|
||||
var _set = $.extend(_defaultSettings, params);
|
||||
var isIE7 = $.browser.msie && (7 == ~~ $.browser.version);
|
||||
|
||||
//var anyDynamicSource = $(this).attr("src");
|
||||
//$(this).attr("src",anyDynamicSource+ "?" + new Date().getTime());
|
||||
|
||||
// Just bind load event once per element.
|
||||
return this.one('load', function() {
|
||||
// Remove all attributes and CSS rules.
|
||||
this.removeAttribute( "width" );
|
||||
this.removeAttribute( "height" );
|
||||
this.style.width = this.style.height = "";
|
||||
|
||||
var ow, oh;
|
||||
|
||||
//[workaround] - msie need get width early
|
||||
if ($.browser.msie)
|
||||
{
|
||||
// Get original size for calcutation.
|
||||
ow = this.width;
|
||||
oh = this.height;
|
||||
}
|
||||
|
||||
if (_set.wrap_fix) {
|
||||
$(this).wrap(function(){
|
||||
return '<div style="width:'+_set.width+'px; height:'+_set.height+'px; display:inline-block;" />';
|
||||
});
|
||||
}
|
||||
|
||||
if (!$.browser.msie)
|
||||
{
|
||||
// Get original size for calcutation.
|
||||
ow = this.width;
|
||||
oh = this.height;
|
||||
}
|
||||
|
||||
// if cannot get width or height.
|
||||
if (0==ow || 0==oh){
|
||||
$(this).width(_set.width);
|
||||
$(this).height(_set.height);
|
||||
}else{
|
||||
|
||||
// Merge position settings
|
||||
var sh_margin_type='';
|
||||
|
||||
// if original image's width > height.
|
||||
if (ow > oh) {
|
||||
p = oh / _set.height;
|
||||
oh = _set.height;
|
||||
ow = ow / p;
|
||||
|
||||
// original image width smaller than settings.
|
||||
if (ow < _set.width){
|
||||
// need to resize again,
|
||||
// because new image size range must can cover settings' range, than we can crop it correctly.
|
||||
p = ow / _set.width;
|
||||
ow = _set.width;
|
||||
oh = oh / p;
|
||||
|
||||
// the crop range would be in the center of new image size.
|
||||
sh = (oh-_set.height)/2;
|
||||
t=sh+'px';
|
||||
r=_set.width+'px';
|
||||
b=(_set.height+sh)+'px';
|
||||
l='0px';
|
||||
|
||||
// need to be adjust top position latter.
|
||||
sh_margin_type = 'margin-top';
|
||||
|
||||
// original image width bigger than settings.
|
||||
}else{
|
||||
// new image range can cover settings' range.
|
||||
sh = (ow-_set.width)/2;
|
||||
t='0px';
|
||||
r=(_set.width+sh)+'px';
|
||||
b=_set.height+'px';
|
||||
l=sh+'px';
|
||||
// need to be adjust left position latter.
|
||||
sh_margin_type = 'margin-left';
|
||||
}
|
||||
// ref above, change width to height then do same things.
|
||||
}else{
|
||||
p = ow / _set.width;
|
||||
ow = _set.width;
|
||||
oh = oh / p;
|
||||
|
||||
if (oh < _set.height) {
|
||||
p = oh / _set.height;
|
||||
oh = _set.height;
|
||||
ow = ow / p;
|
||||
|
||||
sh = (ow-_set.width)/2;
|
||||
t='0px';
|
||||
r=(_set.width+sh)+'px';
|
||||
b=_set.height+'px';
|
||||
l=sh+'px';
|
||||
sh_margin_type = 'margin-left';
|
||||
}else{
|
||||
sh = (oh-_set.height)/2;
|
||||
t=sh+'px';
|
||||
r=_set.width+'px';
|
||||
b=(_set.height+sh)+'px';
|
||||
l='0px';
|
||||
sh_margin_type = 'margin-top';
|
||||
}
|
||||
}
|
||||
|
||||
// Resize img.
|
||||
$(this).width(ow);
|
||||
$(this).height(oh);
|
||||
|
||||
// Crop img by set clip style.
|
||||
$(this).css('clip','rect('+t+' '+r+' '+b+' '+l+')');
|
||||
|
||||
var osh = 0;
|
||||
if('auto' != $(this).css(sh_margin_type)){
|
||||
osh = parseInt($(this).css(sh_margin_type));
|
||||
}
|
||||
|
||||
if (0 < sh) {sh*=-1;}
|
||||
sh += osh;
|
||||
|
||||
$(this).css(sh_margin_type, sh+'px');
|
||||
$(this).css('position','absolute');
|
||||
}
|
||||
$(this).fadeIn('slow');
|
||||
})
|
||||
.one( "error", function() {
|
||||
//$(this).hide();
|
||||
})
|
||||
.each(function() {
|
||||
$(this).hide();
|
||||
// Trigger load event (for Gecko and MSIE)
|
||||
if ( this.complete || $.browser.msie ) {
|
||||
$( this ).trigger( "load" ).trigger( "error" );
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
})( jQuery );
|
||||
@@ -24,6 +24,10 @@ $("#module_app_list select").live('change', function() {
|
||||
$.getScript($(this).attr('rel') + '/' + $(this).val() + '/reload_widgets');
|
||||
});
|
||||
|
||||
$("#widget_list select").live('change', function() {
|
||||
$.getScript($(this).attr('rel') + '/' + $(this).val() + '/reload_widget_styles?module_app_id=' + $("#module_app_list select").val());
|
||||
});
|
||||
|
||||
$("#tag_list select").live('change', function() {
|
||||
$.getScript($(this).attr('rel') + '/' + $(this).val() + '/reload_r_tag_options');
|
||||
});
|
||||
|
||||
@@ -26,6 +26,10 @@ class Admin::PagePartsController < ApplicationController
|
||||
@module_app = @part.module_app ? @part.module_app : @module_apps[0]
|
||||
@r_tag = @part.public_r_tag.blank? ? LIST[:public_r_tags][0] : @part.public_r_tag
|
||||
@tag_objects = @r_tag.classify.constantize.all rescue nil
|
||||
|
||||
@widget_path = @part.widget_path ? @part.widget_path : @module_app.widgets.keys[0]
|
||||
@widget_style = @module_app.widgets[@widget_path]
|
||||
|
||||
case @module_app.key
|
||||
when 'announcement'
|
||||
@categories = BulletinCategory.all
|
||||
@@ -69,8 +73,12 @@ class Admin::PagePartsController < ApplicationController
|
||||
|
||||
def reload_widgets
|
||||
@module_app = ModuleApp.find(params[:id])
|
||||
|
||||
@widget_path = @module_app.widgets.keys[0]
|
||||
@widget_style = @module_app.widgets[@widget_path]
|
||||
case @module_app.key
|
||||
when 'announcement'
|
||||
# @widget_style = @module_app.widgets['index']
|
||||
@categories = BulletinCategory.all
|
||||
@tags = AnnouncementTag.all
|
||||
when 'news'
|
||||
@@ -84,6 +92,16 @@ class Admin::PagePartsController < ApplicationController
|
||||
format.js {}
|
||||
end
|
||||
end
|
||||
|
||||
def reload_widget_styles
|
||||
@module_app = ModuleApp.find(params[:module_app_id])
|
||||
|
||||
@widget_style = @module_app.widgets[params[:id]]
|
||||
|
||||
respond_to do |format|
|
||||
format.js {}
|
||||
end
|
||||
end
|
||||
|
||||
def reload_r_tag_options
|
||||
@r_tag = (ModuleApp.find(params[:id]) rescue nil) || params[:id]
|
||||
|
||||
@@ -16,6 +16,7 @@ class ModuleApp
|
||||
field :app_pages ,type: Array
|
||||
# field :widgets ,type: Array
|
||||
field :widgets ,type: Hash
|
||||
field :widget_fields ,type: Array
|
||||
|
||||
has_many :managers,as: :managing_app ,:class_name => "AppManager" #,:dependent => :destroy,:foreign_key => "managing_app_id",:inverse_of => :managing_app
|
||||
has_many :sub_managers,as: :sub_managing_app ,:class_name => "AppManager"#, :dependent => :destroy,:foreign_key => "sub_managing_app_id",:inverse_of => :sub_managing_app
|
||||
|
||||
@@ -11,6 +11,7 @@ class PagePart
|
||||
field :public_r_tag_option, :default => nil
|
||||
field :widget_path
|
||||
field :widget_style
|
||||
field :widget_field , :type => Array
|
||||
field :widget_data_count
|
||||
|
||||
has_one :i18n_variable, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
|
||||
|
||||
@@ -17,6 +17,8 @@ class Site
|
||||
|
||||
field :school
|
||||
field :department
|
||||
|
||||
mount_uploader :default_image, ImageUploader
|
||||
|
||||
has_one :title, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
|
||||
has_one :footer, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
|
||||
|
||||
@@ -30,7 +30,10 @@ class ImageUploader < CarrierWave::Uploader::Base
|
||||
# def default_url
|
||||
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
|
||||
# end
|
||||
|
||||
def default_url
|
||||
Site.first.default_image.url rescue "-sign-in-logo.png"
|
||||
end
|
||||
|
||||
# Process files as they are uploaded:
|
||||
# process :scale => [200, 300]
|
||||
#
|
||||
|
||||
@@ -14,13 +14,13 @@
|
||||
</span>
|
||||
|
||||
<span id='widget_list'>
|
||||
<%= f.select :widget_path, @module_app.widgets.collect{|widget| [widget.humanize, widget]}, :selected => @part.widget_path %>
|
||||
<%#= f.select :widget_path, @module_app.widgets.collect{|k,v| k}, :selected => @part.widget_path %>
|
||||
<%#= f.select :widget_path, @module_app.widgets.collect{|widget| [widget.humanize, widget]}, :selected => @part.widget_path %>
|
||||
<%= f.select :widget_path, @module_app.widgets.collect{|k,v| [k.humanize, k]}, {}, { :selected => @part.widget_path, :rel => admin_page_parts_path } %>
|
||||
</span>
|
||||
|
||||
<span id='widget_style_list'>
|
||||
<%= @module_app.widget_indexs.collect { |k,v| v } %>
|
||||
<%= f.select :widget_style, @module_app.widget_styles.each, :selected => @part.widget_style, :include_blank => 'None' %>
|
||||
<%= f.select :widget_style, @widget_style, :selected => @part.widget_style %>
|
||||
<%#= render 'widget_styles' %>
|
||||
</span>
|
||||
|
||||
:
|
||||
@@ -33,6 +33,19 @@
|
||||
<%= render 'widget_tags' %>
|
||||
</span>
|
||||
|
||||
<span id='widget_field'>
|
||||
|
||||
<%= f.label :widget_field %>
|
||||
|
||||
<% @module_app.widget_fields.each_with_index do |widget_field, i| %>
|
||||
<%= i+1 %>
|
||||
<%= select_tag "page_part[widget_field][]", options_for_select(@module_app.widget_fields.collect{|widget_field| [widget_field.humanize, widget_field]}, (@part.widget_field ? @part.widget_field[i] : nil) ), :include_blank => true %> <br />
|
||||
|
||||
<% end %>
|
||||
|
||||
<%#= select_tag "page_part[widget_field][]", options_for_select(@module_app.widget_fields.collect{|widget_field| [widget_field.humanize, widget_field]}, @part.widget_field.collect{|widget_field| widget_field}), {:multiple => :multiple, :size => 6} %>
|
||||
</span>
|
||||
|
||||
<div id="widget_data_count">
|
||||
<%= f.label :widget_data_count %>
|
||||
<%= f.text_field :widget_data_count %>
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
<%= select 'page_part', 'widget_style', @widget_style, :selected => (@part ? @part[:widget_style] : nil), :include_blank => true if @widget_style && @widget_style.size > 0 %>
|
||||
@@ -0,0 +1 @@
|
||||
$('#widget_style_list select').html("<%= j options_for_select(@module_app.widgets[params[:id]]) %>")
|
||||
@@ -1,3 +1,4 @@
|
||||
$('#widget_list select').html("<%= j options_for_select(@module_app.widgets.collect{|k,v| k}) %>")
|
||||
$('#widget_style_list select').html("<%= j options_for_select(@module_app.widgets[@widget_path]) %>")
|
||||
$('#widget_category').html("<%= j render 'widget_categories' %>")
|
||||
$('#widget_tag').html("<%= j render 'widget_tags' %>")
|
||||
@@ -1,3 +1,5 @@
|
||||
<% # encoding: utf-8 %>
|
||||
|
||||
<% content_for :side_bar do %>
|
||||
<%= render 'side_bar' %>
|
||||
<% end %>
|
||||
@@ -70,6 +72,24 @@
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label"><%= t 'admin.default_image' %></label>
|
||||
<div class="controls">
|
||||
<%= f.file_field :default_image, :id => "input-upload", :class => 'upload', :onchange => "document.getElementById('fu').innerHTML = this.form.fu.value = this.value;" %>
|
||||
<span id='fu' class="file-name"></span>
|
||||
<!--請程式務必將圖片尺寸加入到行內裡-->
|
||||
<% if @site.default_image %>
|
||||
<%= image_tag( @site.default_image, :size=>"120x120") rescue ''%>
|
||||
<% else %>
|
||||
<img class="pull-left upload-picture" src="/assets/default-img.png" />
|
||||
<% end %>
|
||||
<br>
|
||||
<% if @site.default_image.file %>
|
||||
<%= f.check_box :remove_default_image %>
|
||||
<%= t('刪除已上傳檔案') %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user