I could use help with creating a style sheet to override the default ones from Magnific Popup (https://github.com/joshuajansen/magnific-popup-rails).
I have the code for a user to select their default_profile_id
from their uploaded images. The problem I have is I need code that will allow the current user to make that decision from their page. For example the current user hovers over their photo, and the text "Make Profile Photo" appears on it (https://s18.postimg.cc/arl81snll/mouse.jpg). I don't know how to create a style sheet or modify what I do have so that this action can work.
Any help with adding this action to the photos would be much appreciated.
Photos Controller:
def new
@photo = Photo.new
end
def create
@photo = Photo.new(params[:photo])
@photo.user = current_user
if @photo.save
flash[:notice] = "Successfully created photos."
redirect_to :back
else
render :action => 'new'
end
end
def resize(width, height, gravity = 'Center')
manipulate! do |img|
img.combine_options do |cmd|
cmd.resize "#{width}"
if img[:width] < img[:height]
cmd.gravity gravity
cmd.background "rgba(255,255,255,0.0)"
cmd.extent "#{width}x#{height}"
end
end
img = yield(img) if block_given?
img
end
end
def edit
@photo = Photo.find(params[:id])
end
def update
@photo = Photo.find(params[:id])
if @photo.update_attributes(paramas[:photo])
flash[:notice] = "Successfully updated photo."
redirect_to @photo.gallery
else
render :action => 'edit'
end
end
def destroy
@photo = Photo.find(params[:id])
@photo.destroy
flash[:notice] = "Successfully destroyed photo."
redirect_to @photo.gallery
end
def choose_default_photo
@photo = Photo.find params[:photo_id]
current_user.default_photo = @photo
redirect_to '/profile' # or wherever I want to send them
end
end
Photo model:
attr_accessible :title, :body, :gallery_id, :name, :image, :remote_image_url
belongs_to :gallery
has_many :gallery_users, :through => :gallery, :source => :user
belongs_to :user
mount_uploader :image, ImageUploader
LIMIT = 5
validate do |record|
record.validate_photo_quota
end
def validate_photo_quota
return unless self.user
if self.user.photos(:reload).count >= LIMIT
errors.add(:base, :exceeded_quota)
end
end
end
User Model:
has_many :photos
belongs_to :default_photo, :class_name => "Photo"
after_create :setup_gallery
private
def setup_gallery
Gallery.create(user: self)
end
end
User Controller:
def new
@user = User.new
end
def show
@user = User.find(params[:id])
end
def destroy
User.find(id_params).destroy
flash[:success] = "User deleted."
redirect_to users_url
end
def choose_default_photo
@photo = Photo.find params[:photo_id]
current_user.default_photo = @photo
redirect_to '/profile'
end
The columns for the photos table are:
id
, created_at
, updated_at
, image
, name
, user_id
Users table has the following related columns:
id
, default_photo_id (integer)
Magnific requires it's own CSS code in order to display things properly. Simply add the magnific-popup. css to your page like a normal CSS document. You should include it after your reset/normalize, but before your own styles.
This can be done by using the Google-hosted version of jQuery or downloading and using the distribution files. Include CSS: Add the magnific-popup. css file from the dist folder of Magnific.
We can close magnific popup in various ways We can add a button within the popup and assign a function on click event like $('#close-button-verify'). click(function(){ //This will close the most recently popped dialog //This method specially works for auto popped dialogs i.e. //Popup you opened using $. magnificPopup.
You can either have two images and swap images when a mouse-over occurs or you can use CSS effects such as :hover and opacity to make the image appear as you like.
Sample CSS showing em, px, and % for a 190x190 pixel image. Sizing and position would need to be adjusted to suite your needs.
/* resize so easier to view */
img.profImg {
width: 480px;
/* z-index: 1; */
}
/* all hover items */
.overImg {
background: #111111;
color: white;
opacity: 0.6;
border-radius: 0.5em;
width: 190px;
height: 190px;
/* z-index: 2; */
}
/* hover effects */
.carImg:hover .overImg { display:block; }
.carImg .overImg { display:none; }
/* specific to car image, will need to be adjusted */
.car-over-2 {
position: absolute;
top: 310px;
left: 25px;
}
.car-over {
position: absolute;
top: 36px;
left: 25px;
}
/* text near bottom of image */
.overText {
color: white;
font-size: 1.1em;
position: relative;
top: 85%;
left: 12.5%;
z-index: 3;
}
/* X button to close: should use an icon for this */
.closer {
background-color: white;
color: black;
font-size: 0.8em;
border-radius: 5em;
padding: 0.2em;
width: 2em;
height: 1em;
position: relative;
left: 85%;
top: -8px;
}
Corresponding HTML:
<a class="carImg">
<img src="http://s18.postimg.org/arl81snll/mouse.jpg" class="profImg">
<span class="overImg car-over">
<div class="msgFlash overText">Make Profile Photo</div>
<b class="icon icon-close closer">X</b>
</span>
</a>
And a plunker file: http://plnkr.co/edit/44G96cTdYsfJh6NCQUjE?p=preview
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With