code
stringlengths 28
313k
| docstring
stringlengths 25
85.3k
| func_name
stringlengths 1
74
| language
stringclasses 1
value | repo
stringlengths 5
60
| path
stringlengths 4
172
| url
stringlengths 44
218
| license
stringclasses 7
values |
|---|---|---|---|---|---|---|---|
getCounts = async post_id => {
let [{ tags_count }] = await db.query(
'SELECT COUNT(post_tag_id) AS tags_count FROM post_tags WHERE post_id=?',
[post_id]
),
[{ likes_count }] = await db.query(
'SELECT COUNT(like_id) AS likes_count FROM likes WHERE post_id=?',
[post_id]
),
[{ shares_count }] = await db.query(
'SELECT COUNT(share_id) AS shares_count FROM shares WHERE post_id=?',
[post_id]
),
[{ comments_count }] = await db.query(
'SELECT COUNT(comment_id) AS comments_count FROM comments WHERE post_id=?',
[post_id]
)
return {
tags_count,
likes_count,
shares_count,
comments_count,
}
}
|
Returns tags count, likes count, ...
@param {Number} post_id Post ID
@returns {Object} Tags Count, Likes Count, ...
|
getCounts
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
config/Post.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/config/Post.js
|
MIT
|
getId = async username => {
let s = await db.query('SELECT id FROM users WHERE username=? LIMIT 1', [
username,
])
return s ? s[0].id : null
}
|
Returns ID of a user
@param {String} username Username
|
getId
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
config/User.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/config/User.js
|
MIT
|
getWhat = async (what, id) => {
let s = await db.query(`SELECT ${what} FROM users WHERE id=? LIMIT 1`, [id])
return s[0][what]
}
|
Returns [what] of user ID
eq. getWhat('username', id) => id's username
@param {String} what Eq. Username
@param {String} id ID to be used to return [what]
|
getWhat
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
config/User.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/config/User.js
|
MIT
|
create_user = async user => {
let hash = bcrypt.hashSync(user.password)
user.password = hash
let [e, s] = await catchify(db.query('INSERT INTO users SET ?', user))
e ? console.log(e) : null
return s
}
|
creates a new user
@param {Object} User User details
|
create_user
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
config/User.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/config/User.js
|
MIT
|
comparePassword = (password, hash) => {
let comp = bcrypt.compareSync(password, hash)
return comp
}
|
compares password
@param {String} password Password
@param {String} hash Hash to be compared with password
@returns {Boolean} Boolean
|
comparePassword
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
config/User.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/config/User.js
|
MIT
|
isFollowing = async (session, user) => {
let is = await db.query(
'SELECT COUNT(follow_id) AS is_following FROM follow_system WHERE follow_by=? AND follow_to=? LIMIT 1',
[session, user]
)
return db.tf(is[0].is_following)
}
|
Returns whether session is following user
@param {Number} session Session ID
@param {Number} user User
|
isFollowing
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
config/User.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/config/User.js
|
MIT
|
favouriteOrNot = async (fav_by, user) => {
let s = await db.query(
'SELECT COUNT(fav_id) AS fav_count FROM favourites WHERE fav_by=? AND user=?',
[fav_by, user]
)
return db.tf(s[0].fav_count)
}
|
Returns whether User is fav_by's favorite
@param {Number} fav_by Favorite By
@param {Number} user User ID
|
favouriteOrNot
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
config/User.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/config/User.js
|
MIT
|
isBlocked = async (block_by, user) => {
let s = await db.query(
'SELECT COUNT(block_id) AS block_count FROM blocks WHERE block_by=? AND user=?',
[block_by, user]
)
return db.tf(s[0].block_count)
}
|
Returns whether User is blocked by user
@param {Number} block_by Block By
@param {Number} user User ID
|
isBlocked
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
config/User.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/config/User.js
|
MIT
|
deactivate = async (user, req, res) => {
let posts = await db.query('SELECT post_id FROM posts WHERE user=?', [user]),
groups = await db.query('SELECT group_id FROM groups WHERE admin=?', [
user,
]),
cons = await db.query(
'SELECT con_id FROM conversations WHERE user_one=? OR user_two=?',
[user, user]
),
dltDir = promisify(rmdir),
QLusers = JSON.parse(req.cookies.users),
filtered = QLusers.filter(u => u.id != user)
// DELETE ALL POSTS
posts.map(async p => {
await deletePost({
post: p.post_id,
user,
when: 'user',
})
})
// DELETE ALL GROUPS
groups.map(async g => {
await deleteGroup(g.group_id)
})
await db.query('DELETE FROM group_members WHERE member=? OR added_by=?', [
user,
user,
])
// DELETE ALL CONVERSATIONS
cons.map(async c => {
await deleteCon(c.con_id)
})
await db.query('DELETE FROM tags WHERE user=?', [user])
await db.query('DELETE FROM favourites WHERE fav_by=? OR user=?', [
user,
user,
])
await db.query('DELETE FROM follow_system WHERE follow_by=? OR follow_to=?', [
user,
user,
])
await db.query(
'DELETE FROM notifications WHERE notify_by=? OR notify_to=? OR user=?',
[user, user, user]
)
await db.query('DELETE FROM profile_views WHERE view_by=? OR view_to=?', [
user,
user,
])
await db.query(
'DELETE FROM recommendations WHERE recommend_by=? OR recommend_to=? OR recommend_of=?',
[user, user, user]
)
await db.query('DELETE FROM hashtags WHERE user=?', [user])
DeleteAllOfFolder(`${root}/dist/users/${user}/`)
await dltDir(`${root}/dist/users/${user}`)
await db.query('DELETE FROM users WHERE id=?', [user])
res.cookie('users', `${JSON.stringify(filtered)}`)
req.session.reset()
}
|
Deactivates user
@param {user} user User to deactivate
@param {Object} req Express' Req object
@param {Object} res Express' Res Object
|
deactivate
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
config/User.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/config/User.js
|
MIT
|
mutualUsers = async (session, user) => {
let myFollowings = await db.query(
'SELECT follow_system.follow_id, follow_system.follow_to AS user, follow_system.follow_to_username AS username, users.firstname, users.surname FROM follow_system, users WHERE follow_system.follow_by=? AND follow_system.follow_to = users.id',
[session]
),
userFollowers = await db.query(
'SELECT follow_system.follow_id, follow_system.follow_by AS user, follow_system.follow_by_username AS username, users.firstname, users.surname FROM follow_system, users WHERE follow_system.follow_to=? AND follow_system.follow_by = users.id',
[user]
),
mutuals = intersectionBy(myFollowings, userFollowers, 'user')
return mutuals
}
|
Returns mutual users
Returns mutual users of session & user
@param {Number} session Session ID
@param {Number} user User ID
|
mutualUsers
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
config/User.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/config/User.js
|
MIT
|
mentionUsers = async (str, session, post, when) => {
let users = str.match(/[^|\s]?@[\d\w]+/g)
if (users) {
for (let h of users) {
let hash = h.slice(1)
if (hash.substr(0, 1) !== '@') {
let [{ userCount }] = await db.query(
'SELECT COUNT(id) AS userCount FROM users WHERE username=?',
[hash]
)
let id = await getId(hash)
if (userCount == 1 && id != session) {
await db.query('INSERT INTO notifications SET ?', {
notify_by: session,
notify_to: id,
post_id: post,
type: when == 'post' ? 'mention_post' : 'mention_comment',
notify_time: new Date().getTime(),
})
}
}
}
}
}
|
Mention users
@param {String} str Text which will be used to get mentioned users
@param {Number} session sessionID
@param {Number} post PostID
@param {String} when For fn to have knowledge when users were mentioned
|
mentionUsers
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
config/User.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/config/User.js
|
MIT
|
render() {
let { unreadNotifications, unreadMessages } = this.props
return (
<Router>
<div className="app">
<Header />
<NotiSpeak un={unreadNotifications} />
<SideBar un={unreadNotifications} uc={unreadMessages} />
<AppRoutes />
</div>
</Router>
)
}
|
@author Faiyaz Shaikh <[email protected]>
GitHub repo: https://github.com/yTakkar/React-Instagram-Clone-2.0
|
render
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/components/App.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/components/App.js
|
MIT
|
Follow = ({
userDetails,
followed,
updateFollowings,
updateFollowers,
dispatch,
}) => {
let { user, username, firstname, surname } = userDetails
let followUser = e => {
e.preventDefault()
let obj = {
user,
username,
firstname,
surname,
dispatch,
update_followings: updateFollowings,
update_followers: updateFollowers,
done: () => followed(),
}
follow(obj)
}
return (
<Fragment>
<PrimaryButton label="Follow" onClick={followUser} extraClass="follow" />
</Fragment>
)
}
|
If there's no need to update store, then only provide user, username (within userDetails) & followed arguements.
Provide firstname & surname when update_followings=true
|
Follow
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/components/others/follow/follow.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/components/others/follow/follow.js
|
MIT
|
Unfollow = ({
user,
unfollowed,
updateFollowings,
updateFollowers,
dispatch,
}) => {
let unfollowUser = e => {
e.preventDefault()
let obj = {
user,
dispatch,
update_followings: updateFollowings,
update_followers: updateFollowers,
done: () => unfollowed(),
}
unfollow(obj)
}
return (
<Fragment>
<PrimaryButton
label="Unfollow"
onClick={unfollowUser}
extraClass="unfollow"
/>
</Fragment>
)
}
|
If there's no need to update store, then only provide user (within userDetails) & followed arguements.
|
Unfollow
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/components/others/follow/unfollow.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/components/others/follow/unfollow.js
|
MIT
|
upload_avatar = async options => {
let { file: userFile, of, group } = options,
form = new FormData(),
file = await imageCompressor(userFile),
action = new Action('.c_a_add')
if (file.size > 6000000) {
Notify({ value: 'Image should be less than 4MB!!' })
} else {
action.start('Changing avatar..')
form.append('avatar', file)
form.append('of', of)
form.append('group', group)
let {
data: { success, mssg },
} = await post('/api/upload-avatar', form)
Notify({
value: mssg,
done: () => (success ? location.reload() : null),
})
action.end('Change avatar')
}
}
|
Upload avatar
@param {Object} options
@param {File} options.file
@param {String} options.of
@param {Number} options.group
|
upload_avatar
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/avatar-utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/avatar-utils.js
|
MIT
|
commentDispatchHelper = async options => {
let {
user,
post_id,
comment_id,
commentExtraDetails,
when,
dispatch,
} = options
let session = uData('session')
let username = uData('username')
if (when == 'viewPost') {
dispatch(
comment({
comment_id,
comment_by: Number(session),
comment_by_username: username,
post_id,
comment_time: `${new Date().getTime()}`,
...commentExtraDetails,
})
)
}
if (!Me(user)) {
insta_notify({
to: user,
type: 'comment',
post_id,
})
}
}
|
A helper for dispatching actions related to comments
@param {Object} options
|
commentDispatchHelper
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/comment-utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/comment-utils.js
|
MIT
|
imageComment = async options => {
let { post_id, dispatch, when, user, file: commentFile, done } = options,
form = new FormData(),
file = await imageCompressor(commentFile),
o = new d('.overlay-2')
o.show()
wait()
form.append('commentImage', file)
form.append('post', post_id)
let {
data: { success, mssg, filename, comment_id },
} = await post('/api/comment-image', form)
if (success) {
await commentDispatchHelper({
user,
post_id,
comment_id,
when,
dispatch,
commentExtraDetails: {
type: 'image',
commentSrc: filename,
text: '',
},
})
done()
}
o.hide()
Notify({ value: mssg })
}
|
Image comment
@param {Object} options
@param {Number} options.post_id
@param {Function} options.dispatch
@param {String} options.when
@param {Number} options.user
@param {File} options.file
@param {Function} options.done
|
imageComment
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/comment-utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/comment-utils.js
|
MIT
|
stickerComment = async options => {
let { sticker, post_id, user, when, dispatch, done } = options
let {
data: { mssg, success, comment_id, filename },
} = await post('/api/comment-sticker', { sticker: sticker, post: post_id })
wait()
if (success) {
await commentDispatchHelper({
user,
post_id,
comment_id,
when,
dispatch,
commentExtraDetails: {
type: 'sticker',
commentSrc: filename,
text: '',
},
})
done()
}
Notify({ value: mssg })
}
|
Sticker comment
@param {Object} options
@param {String} options.sticker
@param {Number} options.post_id
@param {Number} options.user
@param {String} options.when
@param {Function} options.dispatch
|
stickerComment
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/comment-utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/comment-utils.js
|
MIT
|
textComment = async options => {
let { post: post_id, text, when, dispatch, postOwner, done } = options
let {
data: { success, mssg, comment_id },
} = await post('/api/comment-text', { post_id, text })
if (success) {
await commentDispatchHelper({
user: postOwner,
post_id,
comment_id,
when,
dispatch,
commentExtraDetails: {
type: 'text',
commentSrc: '',
text,
},
})
done()
}
Notify({ value: mssg })
}
|
Text comment
@param {Object} options
@param {Number} options.post
@param {String} options.text
@param {String} options.when
@param {Function} options.dispatch
@param {Number} options.postOwner
|
textComment
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/comment-utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/comment-utils.js
|
MIT
|
addUserTags = options => {
let { value, user, dispatch } = options
if (value) {
dispatch(
addTag({
user,
tag: value,
})
)
} else {
Notify({ value: 'Please enter a tag!!' })
}
}
|
Add user tags
@param {Object} options
@param {String} options.value
@param {Number} options.user
@param {Function} options.dispatch
|
addUserTags
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/edit-profile-utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/edit-profile-utils.js
|
MIT
|
editProfile = async options => {
let {
susername,
semail,
values,
values: { username, email },
} = options,
{ data: uCount } = await post('/api/what-exists', {
what: 'username',
value: username,
}),
{ data: eCount } = await post('/api/what-exists', {
what: 'email',
value: email,
}),
action = new Action('.edit_done')
action.start('Processing..')
if (!username) {
Notify({ value: 'Username must not be empty!!' })
} else if (!email) {
Notify({ value: 'Email must not be empty!!' })
} else if (uCount == 1 && username != susername) {
Notify({ value: 'Username already exists!!' })
} else if (eCount == 1 && email != semail) {
Notify({ value: 'Email already exists!!' })
} else {
let {
data: { mssg, success },
} = await post('/api/edit-profile', values)
Notify({
value: ObjectMssg(mssg),
done: () => (success ? location.reload() : null),
})
}
action.end('Done Editing')
}
|
Edit profile
@param {Object} options
@param {String} options.susername
@param {String} options.semail
@param {Object} options.values
@param {String} options.values.username
@param {String} options.values.email
|
editProfile
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/edit-profile-utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/edit-profile-utils.js
|
MIT
|
fieldsToArray = fields => {
let array = []
for (let key in fields) {
array.push({
key,
value: fields[key],
})
}
return array
}
|
Converts a fields object into array so we can map though the array and follow DRY pattern.
@param {Object} fields Fields to convert into an array
|
fieldsToArray
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/edit-profile-utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/edit-profile-utils.js
|
MIT
|
createGroup = async options => {
let { name, bio, created } = options
let action = new Action('.c_g_update')
action.start('Please wait..')
wait()
let {
data: { mssg, success, groupId },
} = await post('/api/create-group', { name, bio })
if (success) {
Notify({ value: mssg })
created(groupId)
} else {
Notify({
value: ObjectMssg(mssg),
})
}
action.end('Create group')
}
|
Creates a group
@param {Object} options
@param {String} options.name
@param {String} options.bio
|
createGroup
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/group-utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/group-utils.js
|
MIT
|
editGroup = async options => {
let { group_id, name, bio, isPrivate, dispatch } = options,
group_type = isPrivate ? 'private' : 'public',
action = new Action('.g_e_save_btn', true, 'sec_btn_disabled')
action.start('Updating..')
wait()
let {
data: { success, mssg },
} = await post('/api/edit-group', { name, bio, group_type, group: group_id })
success ? dispatch(updateGroup({ name, bio, group_type })) : null
Notify({ value: mssg })
action.end('Update')
}
|
Edit group
@param {Number} options.group_id
@param {Object} options
@param {String} options.name
@param {String} options.bio
@param {Boolean} options.isPrivate
@param {Function} options.dispatch
|
editGroup
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/group-utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/group-utils.js
|
MIT
|
joinGroup = async options => {
let defaults = {
user: null,
added_by: null,
group: null,
when: '',
done: () => null,
},
obj = { ...defaults, ...options },
{ user, added_by, group, when, done } = obj,
{
data: { mssg, success },
} = await post('/api/join-group', { user, added_by, group, when })
if (success) {
if (when == 'add_grp_member') {
insta_notify({
to: user,
type: 'add_grp_member',
group_id: group,
})
}
done()
}
Notify({ value: mssg })
}
|
Join group
user, group, when & done properties must be provided
@param {Object} options Options for joining group
@param {Number} options.user
@param {Number} options.added_by
@param {Number} options.group
@param {String} options.when
@param {Function} options.done
|
joinGroup
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/group-utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/group-utils.js
|
MIT
|
leaveGroup = async options => {
let defaults = {
user: null,
group: null,
updateGroups: false,
dispatch: () => null,
done: () => null,
},
obj = { ...defaults, ...options },
{ user, group, updateGroups, dispatch, done } = obj,
{
data: { success, mssg },
} = await post('/api/leave-group', { user, group })
if (success) {
updateGroups ? dispatch(leftGroup(group)) : null
done()
}
Notify({ value: mssg })
}
|
Leave group
user, group & done properties must be provided
@param {Object} options Options for leaving group
@param {Number} options.user
@param {Number} options.group
@param {Boolean} options.updateGroups
@param {Function} options.dispatch
@param {Function} options.done
|
leaveGroup
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/group-utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/group-utils.js
|
MIT
|
changeAdmin = async options => {
let { member, group } = options
let {
data: { success, mssg },
} = await post('/api/change-admin', { user: member, group })
if (success) {
insta_notify({
to: member,
type: 'change_admin',
group_id: group,
})
}
Notify({
value: mssg,
done: () => (success ? location.reload() : null),
})
}
|
Change admin of the group
@param {Object} options
@param {Number} options.member
@param {Number} options.group
|
changeAdmin
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/group-utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/group-utils.js
|
MIT
|
geolocation = success => {
if (navigator.geolocation) {
navigator.geolocation.watchPosition(success, geolocationError)
} else {
Notify({ value: 'Geolocation not supported' })
}
}
|
Geolocation setup
@param {Function} success Success function
|
geolocation
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/location-utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/location-utils.js
|
MIT
|
getAddress = async pos => {
let { latitude, longitude } = pos.coords,
{
data: { results },
} = await post(
`https://maps.googleapis.com/maps/api/geocode/json?latlng=${latitude},${longitude}&key=${GOOGLE_GEOLOCATION_KEY}`
),
loc = results[0].formatted_address
return loc
}
|
Returns human readable address from the given the cordinates
@param {Object} pos
|
getAddress
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/location-utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/location-utils.js
|
MIT
|
messageScroll = () => {
new d('.mssg_end').scrollTop()
}
|
Scrolls down to bottom of the conversation
|
messageScroll
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/message-utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/message-utils.js
|
MIT
|
newConversation = async options => {
let { user, username, updateConversations, dispatch, done } = options
let {
data: { mssg, success, con_id },
} = await post('/api/create-new-conversation', { user })
wait()
if (success) {
done()
if (updateConversations) {
dispatch(
conversationAdded({
key: con_id,
con_id,
con_with: user,
con_with_username: username,
lastMssg: {
lastMessage: '',
lastMssgBy: null,
lastMssgTime: null,
lastMssgType: '',
},
unreadMssgs: 0,
})
)
}
insta_notify({
to: user,
type: 'new_con',
})
}
Notify({ value: mssg })
}
|
Creates a new conversation
@param {Object} options
@param {Number} options.user
@param {String} options.username
@param {Function} options.dispatch
@param {Boolean} options.updateConversations
@param {Function} options.done
|
newConversation
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/message-utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/message-utils.js
|
MIT
|
messageDispatchHelper = async options => {
let { con_id, con_with, message_id, message, messageType, dispatch } = options
let session = uData('session')
dispatch(
messaged({
con_id,
message,
message_id,
message_time: `${new Date().getTime()}`,
mssg_by: Number(session),
mssg_to: con_with,
type: messageType,
status: 'read',
})
)
dispatch(
changeLastMssg({
con_id,
lastMssg: {
lastMessage: message,
lastMssgBy: session,
lastMssgTime: `${new Date().getTime()}`,
lastMssgType: messageType,
},
})
)
}
|
A helper for dispatching actions related to messages
@param {Object} options
|
messageDispatchHelper
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/message-utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/message-utils.js
|
MIT
|
textMessage = async options => {
let { message, con_id, con_with, dispatch } = options
let action = new Action('.mssg_send')
action.start()
if (!message) {
Notify({ value: 'Comment field is empty!!' })
} else {
let {
data: { success, mssg, message_id },
} = await post('/api/text-message', { message, con_id, con_with })
if (success) {
messageDispatchHelper({
con_id,
con_with,
message_id,
message,
messageType: 'text',
dispatch,
})
} else {
Notify({ value: mssg })
}
}
messageScroll()
action.end('Send')
}
|
Test message
@param {Object} options
@param {String} options.message
@param {Number} options.con_id
@param {Number} options.con_with
@param {Function} options.dispatch
|
textMessage
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/message-utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/message-utils.js
|
MIT
|
imageMessage = async options => {
let { file: messageFile, con_id, con_with, dispatch } = options,
form = new FormData(),
file = await imageCompressor(messageFile),
o = new d('.overlay-2')
o.show()
wait()
form.append('messageFile', file)
form.append('con_id', con_id)
form.append('con_with', con_with)
let {
data: { success, mssg, message_id, filename },
} = await post('/api/image-message', form)
if (success) {
messageDispatchHelper({
con_id,
con_with,
message_id,
message: filename,
messageType: 'image',
dispatch,
})
}
messageScroll()
o.hide()
Notify({ value: mssg })
}
|
Image message
@param {Object} options
@param {File} options.file
@param {Number} options.con_id
@param {Number} options.con_with
@param {Function} options.dispatch
|
imageMessage
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/message-utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/message-utils.js
|
MIT
|
stickerMessage = async options => {
let { con_id, con_with, sticker, dispatch } = options
let {
data: { success, mssg, filename, message_id },
} = await post('/api/sticker-message', { con_id, con_with, sticker })
wait()
if (success) {
messageDispatchHelper({
con_id,
con_with,
message_id,
message: filename,
messageType: 'sticker',
dispatch,
})
}
Notify({ value: mssg })
messageScroll()
}
|
Sticker message
@param {Object} options
@param {Number} options.con_id
@param {Number} options.con_with
@param {String} options.sticker
@param {Function} options.dispatch
|
stickerMessage
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/message-utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/message-utils.js
|
MIT
|
deleteYourMssgs = async options => {
let { con_id, dispatch } = options
let session = uData('session')
wait()
let {
data: { success, mssg },
} = await post('/api/unsend-all-mssgs', { con_id })
success ? dispatch(unsendAllMessages(session)) : null
Notify({ value: mssg })
}
|
Unsend all messages
@param {Object} options
@param {Number} options.con_id
@param {Function} options.dispatch
|
deleteYourMssgs
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/message-utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/message-utils.js
|
MIT
|
deleteConversation = async options => {
let { con_id, dispatch, hideConversation } = options
let {
data: { success, mssg },
} = await post('/api/delete-conversation', { con_id })
wait()
if (success) {
dispatch(deleteCon(con_id))
hideConversation()
}
Notify({ value: mssg })
}
|
Deletes a conversation
@param {Object} options
@param {Number} options.con_id
@param {Function} options.dispatch
@param {Function} options.hideConversation
|
deleteConversation
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/message-utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/message-utils.js
|
MIT
|
deleteMessage = async options => {
let { message_id, message, type, dispatch, done } = options
let {
data: { success, mssg },
} = await post('/api/delete-message', { message_id, message, type })
if (success) {
dispatch(deleteMssg(message_id))
done()
}
Notify({ value: mssg })
}
|
@param {Object} options
@param {Number} options.message_id
@param {String} options.message
@param {String} options.type
@param {Function} options.dispatch
@param {Function} options.done
|
deleteMessage
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/message-utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/message-utils.js
|
MIT
|
addPost = async options => {
let {
dispatch,
desc,
targetFile,
filter,
location,
type,
group,
group_name,
tags,
} = options,
user = Number(uData('session')),
username = uData('username'),
form = new FormData(),
file = await imageCompressor(targetFile),
action = new Action('.p_post')
action.start()
wait()
form.append('desc', desc)
form.append('image', file)
form.append('filter', filter)
form.append('location', location)
form.append('type', type)
form.append('group', group)
let {
data: { success, mssg, post_id, firstname, surname, filename },
} = await post('/api/post-it', form)
await post('/api/tag-post', { tags, post_id })
tags.forEach(async t => {
await insta_notify({
to: t.user,
type: 'tag',
post_id: post_id,
})
})
if (success) {
let newPost = {
key: post_id,
comments_count: 0,
likes_count: 0,
shares_count: 0,
tags_count: tags.length,
user,
username,
firstname,
surname,
description: desc,
filter,
imgSrc: filename,
location,
post_time: `${new Date().getTime()}`,
post_id,
group_id: 0,
group_name: '',
type: 'user',
}
type == 'user'
? dispatch(
addUserPost({
...newPost,
when: 'feed',
})
)
: dispatch(
addGroupPost({
...newPost,
group_id: group,
group_name,
type: 'group',
when: 'groupPosts',
})
)
}
action.end()
Notify({ value: mssg })
}
|
Add post
@param {Object} options Options for creating a new post
@param {Function} options.dispatch
@param {String} options.desc
@param {String} options.targetFile
@param {String} options.filter
@param {String} options.location
@param {String} options.type
@param {Number} options.group
@param {String} options.group_name
@param {Object[]} options.tags
@param {Number} options.tags.user
@param {String} options.tags.username
|
addPost
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/post-utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/post-utils.js
|
MIT
|
editPost = async options => {
let { post_id, description, dispatch, done, failed } = options
let {
data: { success, mssg },
} = await post('/api/edit-post', { description, post_id })
if (success) {
dispatch(PostActions.editPost({ post_id, description }))
done()
} else {
failed()
}
Notify({ value: mssg })
}
|
Edit post
@param {Object} options
@param {Number} options.post_id
@param {String} options.description
@param {Function} options.dispatch
@param {Function} options.done
@param {Function} options.failed
|
editPost
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/post-utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/post-utils.js
|
MIT
|
deletePost = async options => {
let { post_id, when, dispatch, redirect } = options
wait()
let {
data: { success, mssg },
} = await post('/api/delete-post', { post: post_id })
if (success) {
dispatch(PostActions.deletePost(post_id))
when == 'viewPost' ? redirect() : null
}
Notify({ value: mssg })
}
|
Deletes a post
@param {Object} options
@param {Number} options.post_id
@param {String} options.when
@param {Function} options.dispatch
@param {Function} options.redirect
|
deletePost
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/post-utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/post-utils.js
|
MIT
|
like = async options => {
let { post_id, user, done } = options
let {
data: { success, mssg },
} = await post('/api/like-post', { post: post_id })
if (success) {
!Me(user)
? insta_notify({
to: user,
type: 'like',
post_id,
})
: null
done()
} else {
Notify({ value: mssg })
}
}
|
Like post
@param {Object} options
@param {Number} options.post_id
@param {Number} options.user
@param {Function} options.done
|
like
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/post-utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/post-utils.js
|
MIT
|
unlike = async options => {
let { post_id, done } = options
let {
data: { success, mssg },
} = await post('/api/unlike-post', { post_id })
success ? done() : Notify({ value: mssg })
}
|
Unlikes a post
@param {Object} options
@param {Number} options.post_id
@param {Function} options.done
|
unlike
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/post-utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/post-utils.js
|
MIT
|
bookmark = async options => {
let { post_id, done } = options
let {
data: { success, mssg },
} = await post('/api/bookmark-post', { post_id })
success ? done() : null
Notify({ value: mssg })
}
|
Bookmarks a post
@param {Object} options
@param {Number} options.post_id
@param {Function} options.done
|
bookmark
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/post-utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/post-utils.js
|
MIT
|
unbookmark = async options => {
let { post_id, when, user, dispatch, done } = options
let session = uData('session')
let {
data: { success, mssg },
} = await post('/api/unbookmark-post', { post: post_id, user: session })
if (success) {
if (when == 'bookmarks' && Me(user)) {
dispatch(PostActions.unbookmark(post_id))
Notify({ value: 'Post unbookmarked!!' })
}
done()
} else {
Notify({ value: mssg })
}
}
|
Unbookmark post
@param {Object} options
@param {Number} options.post_id
@param {String} options.when
@param {Number} options.user
@param {Function} options.dispatch
@param {Function} options.done
|
unbookmark
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/post-utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/post-utils.js
|
MIT
|
share = async options => {
let { user, post_id, postOwner, done } = options
new d('.share_btn').blur()
let {
data: { mssg, success },
} = await post('/api/share-post', { share_to: user, post_id })
if (success) {
insta_notify({
to: user,
type: 'share',
post_id,
})
!Me(postOwner)
? insta_notify({
to: postOwner,
type: 'shared_your_post',
post_id,
})
: null
done()
}
Notify({ value: mssg })
}
|
Share post
@param {Object} options
@param {Number} options.user
@param {Number} options.post_id
@param {Number} options.postOwner
@param {Function} options.done
|
share
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/post-utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/post-utils.js
|
MIT
|
unshare = async options => {
let { user, post_id, done } = options
new d('.share_btn').blur()
let {
data: { success, mssg },
} = await post('/api/unshare-post', { unshare_to: user, post_id })
success ? done() : null
Notify({ value: mssg })
}
|
Unshare post
@param {Object} options
@param {Number} options.user
@param {Number} options.post_id
@param {Function} options.done
|
unshare
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/post-utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/post-utils.js
|
MIT
|
quickLogin = options => {
let { id, username } = options,
usernameDiv = new d('.q_l_username'),
imgDiv = new d('.q_l_m_img'),
icon = new d('.s_p_ql'),
password = new d('#q_l_password')
new d('.overlay-2-black').show()
new d('.q_l_model').show()
password.focus().setAttr('type', 'password')
icon.html('<i class="fas fa-lock"></i>')
icon.css('color', 'darkturquoise')
usernameDiv.text(`@${username}`)
imgDiv.setAttr('src', `/users/${id}/avatar.jpg`)
// QUICK LOGIN SUBMIT
new d('.q_l_m_form').on('submit', e => {
e.preventDefault()
quickLoginSubmit(username)
})
// CLEAR QUICK LOGIN
new d('.q_l_remove').on('click', async e => {
e.preventDefault()
await post('/api/remove-quick-login', { id })
Notify({
value: `Removed ${username} from quick login!!`,
done: () => location.reload(),
})
})
// TOGGLE VIEW PASSWORD
new d('.s_p_ql').on('click', () => {
viewPassword({
input: '#q_l_password',
icon: '.s_p_ql',
})
})
}
|
Quick login
@param {Object} options
@param {Number} options.id
@param {String} options.username
|
quickLogin
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/quick-login-utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/quick-login-utils.js
|
MIT
|
block = async user => {
let {
data: { mssg },
} = await post('/api/block', { user })
Notify({ value: mssg })
}
|
Block user
@param {Number} user User to block
|
block
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/setting-utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/setting-utils.js
|
MIT
|
unblock = async options => {
let { block_id, username, dispatch } = options
let {
data: { success, mssg },
} = await post('/api/unblock-user', { block_id })
if (success) {
dispatch(unblockUser(block_id))
Notify({ value: `Unblocked ${username}!!` })
} else {
Notify({ value: mssg })
}
}
|
@param {Object} options
@param {Number} options.block_id
@param {String} options.username
@param {Function} options.dispatch
|
unblock
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/setting-utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/setting-utils.js
|
MIT
|
changePassword = async (old, new_, new_a) => {
let action = new Action('.c_p_btn')
if (!old || !new_ || !new_a) {
Notify({ value: 'Some values are missing!!' })
} else if (new_ != new_a) {
Notify({ value: "New passwords don't match" })
} else {
action.start('Changing password..')
wait()
let {
data: { mssg, success },
} = await post('/user/change-password', { old, new_, new_a })
if (success) {
Notify({
value: mssg,
done: () => location.reload(),
})
} else {
Notify({
value: ObjectMssg(mssg),
})
action.end('Change password')
}
}
}
|
Changes the password of session user
@param {String} old Old/Current password
@param {String} new_ New password
@param {String} new_a New password again for surety
|
changePassword
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/setting-utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/setting-utils.js
|
MIT
|
deactivateAccount = async (password, hidePrompt) => {
let action = new Action('.prompt-done')
action.start('Deactivating..')
wait()
let {
data: { mssg, success },
} = await post('/user/deactivate-account', { password })
action.end('Deactivate')
Notify({
value: mssg,
done: () => {
success ? (location.href = '/login') : hidePrompt()
},
})
}
|
Change user's password
@param {String} password User's password
|
deactivateAccount
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/setting-utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/setting-utils.js
|
MIT
|
follow = async options => {
let defaults = {
user: null,
username: null,
firstname: null,
surname: null,
update_followers: false,
update_followings: false,
dispatch: () => null,
done: () => null,
},
obj = { ...defaults, ...options },
{
user,
username,
firstname,
surname,
dispatch,
update_followers,
update_followings,
done,
} = obj,
{
data: { mssg, success, ff },
} = await post('/api/follow', { user, username })
if (success) {
let fwing = {
follow_id: ff.follow_id,
follow_to: user,
follow_by: Number(uData('session')),
username,
firstname,
surname,
isFollowing: true,
follow_time: ff.follow_time,
}
update_followers ? dispatch(followA.Follower(ff)) : null
update_followings ? dispatch(followA.Following(fwing)) : null
insta_notify({
to: user,
type: 'follow',
})
done()
}
Notify({ value: mssg })
}
|
Follow user
user, username & done properties must be provided.
Provide update_followers when user's followers data need to be updated.
Eg. On Banner Comp.
Provide update_followings when user's followings data need to be updated.
Eg. On Followers Comp.
Provide dispatch when either update_followers OR update_followings needs to be updated
Provide Firstname & Surname when update_followings=true
Provide username as it used for notifying.
@param {Object} options Options for following user
@param {Number} options.user
@param {String} options.username
@param {firstname} options.firstname
@param {surname} options.surname
@param {Boolean} options.update_followers
@param {Boolean} options.update_followings
@param {Function} options.dispatch
@param {Function} options.done
|
follow
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/user-interact-utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/user-interact-utils.js
|
MIT
|
unfollow = async options => {
let defaults = {
user: null,
update_followers: false,
update_followings: false,
dispatch: () => null,
done: () => null,
}
let obj = { ...defaults, ...options }
let { user, dispatch, update_followers, update_followings, done } = obj
let session = uData('session')
let {
data: { success, mssg },
} = await post('/api/unfollow', { user })
if (success) {
update_followers ? dispatch(followA.Unfollower(session)) : null
update_followings ? dispatch(followA.Unfollowing(user)) : null
done()
}
Notify({ value: mssg })
}
|
Unfollow user
user & done properties must be provided.
Provide update_followers when user's followers data need to be updated.
Eg. On Banner Comp.
Provide update_followings when user's followings data need to be updated.
Eg. On Followers Comp.
Provide dispatch when either update_followers OR update_followings needs to be updated
@param {Object} options Options for unfollowing user
@param {Number} options.user
@param {Boolean} options.update_followers
@param {Boolean} options.update_followings
@param {Function} options.dispatch
@param {Function} options.done
|
unfollow
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/user-interact-utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/user-interact-utils.js
|
MIT
|
addToFavourites = async user => {
let {
data: { success, mssg },
} = await post('/api/add-to-favourites', { user })
if (success) {
insta_notify({
to: user,
type: 'favourites',
})
}
Notify({ value: mssg })
}
|
Add user to favorites
@param {Number} user User to add to favorites
|
addToFavourites
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/user-interact-utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/user-interact-utils.js
|
MIT
|
recommendUser = async options => {
let { recommend_to, user } = options
let {
data: { mssg, success },
} = await post('/api/recommend-user', { user, recommend_to: recommend_to })
if (success) {
insta_notify({
to: recommend_to,
type: 'recommend',
user,
})
}
Notify({ value: mssg })
}
|
Recommends a user
@param {Object} options
@param {Number} options.recommend_to
@param {Number} options.user
|
recommendUser
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/user-interact-utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/user-interact-utils.js
|
MIT
|
username_checker = el => {
let element = new d(el)
let uc = new d('.username_checker')
element.on('keyup', async e => {
let value = e.target.value
uc.show()
if (value) {
let { data: count } = await post('/user/username-checker', { value })
let html
if (count == 0) {
html =
'<span class="checker_text">username is available</span><span class="checker_icon"><i class="far fa-smile"></i></span>'
uc.mutipleCSS({
width: '160px',
right: '-188px',
})
} else {
html =
'<span class="checker_text">username already taken</span><span class="checker_icon"><i class="far fa-frown"></i></span>'
uc.mutipleCSS({
width: '167px',
right: '-194px',
})
}
uc.html(html)
} else {
uc.hide()
}
})
element.on('blur', () => uc.hide())
}
|
For username checker
@param {String} el
|
username_checker
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/user-system-utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/user-system-utils.js
|
MIT
|
commonLogin = options => {
let { data, btn, url, redirect, defBtnValue } = options,
overlay2 = new d('.overlay-2'),
button = new d(btn),
action = new Action(btn)
action.start('Please wait..')
post(url, data)
.then(s => {
let {
data: { mssg, success },
} = s
if (success) {
Notify({
value: mssg,
done: () => (location.href = redirect),
})
button.setValue('Redirecting..')
overlay2.show()
} else {
Notify({
value: ObjectMssg(mssg),
})
action.end(defBtnValue)
}
button.blur()
})
.catch(e => console.log(e))
}
|
Common function for login & signup
@param {Object} options Options
@param {Object} options.data
@param {String} options.btn
@param {String} options.url
@param {String} options.redirect
@param {String} options.defBtnValue
|
commonLogin
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/user-system-utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/user-system-utils.js
|
MIT
|
shortener = (what, length) => {
let parse = parseInt(length),
len = what.length
if (!parse) {
return
}
return len >= parse
? `${what.substr(0, length - 2)}..`
: len < parse
? what
: null
}
|
Shortens what with string length
@param {String} what
@param {Number} length
|
shortener
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/utils.js
|
MIT
|
uniq = () =>
Math.random()
.toString(5)
.slice(2)
|
Returns unique string, useful for key
|
uniq
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/utils.js
|
MIT
|
humanReadable = (value, text) => {
let hr =
value == 0 ? `No ${text}s` : value == 1 ? `1 ${text}` : `${value} ${text}s`
return hr
}
|
Returns human-readable text
@param {Number} value
@param {String} text
|
humanReadable
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/utils.js
|
MIT
|
toggle = el => {
let style = el.style.display
style === 'none' ? (el.style.display = 'block') : (el.style.display = 'none')
}
|
Toggles the element
@param {HTMLElement} el element to toggle
|
toggle
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/utils.js
|
MIT
|
llr = () => {
let elements = Array.from(new d('.modal_items').toAll())
let element = elements[elements.length - 1]
element
? Array.from(element.children).map(
child => (child.nodeName == 'HR' ? child.remove() : null)
)
: null
}
|
Removes hr of last element of modal
|
llr
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/utils.js
|
MIT
|
imageCompressor = file => {
return new Promise(resolve => {
new Compress(file, {
quality: 0.6,
success: file => resolve(file),
error: err => console.log(err.message),
})
})
}
|
Compresses and returns file
@param {File} file
|
imageCompressor
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/utils.js
|
MIT
|
insta_notify = async options => {
let defaults = {
to: null,
type: '',
post_id: 0,
group_id: 0,
user: 0,
},
obj = { ...defaults, ...options },
{ to, type, post_id, group_id, user } = obj
await post('/api/notify', {
to,
type,
post_id,
group_id,
user,
})
}
|
Notifies user [on the notification page]
@param {Object} options
@param {Number} options.to
@param {String} options.type
@param {Number} options.post_id
@param {Number} options.group_id
@param {Number} options.user
|
insta_notify
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/utils.js
|
MIT
|
dispatchHelper = (type, url, data = {}) => {
return dispatch =>
post(`/api/${url}`, data)
.then(p => dispatch({ type, payload: p.data }))
.catch(e => console.log(e))
}
|
Dispatcher helper for dispatching data retrieved from URL
@param {String} type Dispatch type
@param {String} url /api/URL to get data from
@param {Object} data data requested with the url
|
dispatchHelper
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/utils.js
|
MIT
|
ObjectMssg = mssg => {
return typeof mssg == 'object' ? (mssg.length > 0 ? mssg[0] : mssg) : mssg
}
|
If mssg is an array returns first element else returns it as a string.
@param {String} mssg Message value
@returns { String } Individual string message
|
ObjectMssg
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/utils.js
|
MIT
|
APIRequest = (url, data = {}, method = 'post') => {
return new Promise((resolve, reject) => {
axios[method](url, data)
.then(resp => resolve(resp))
.catch(err => reject(err))
})
}
|
Request a response from an API endpoint.
@param {String} url Url to get response from
@param {Object} data Optional data to pass
@param {String} method Method type. Default is post
|
APIRequest
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/utils.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/utils.js
|
MIT
|
constructor(button, withOverlay, disabledClass) {
this.button = button
this.withOverlay = withOverlay
this.disabledClass = disabledClass
}
|
@author Faiyaz Shaikh <[email protected]>
GitHub repo: https://github.com/yTakkar/React-Instagram-Clone-2.0
Suppose, we're posting an image, and don't want user to post again, or perform any different action until response comes back from the server either sucess or failure, this library enables to do exactly the same.
|
constructor
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/API/Action.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/API/Action.js
|
MIT
|
constructor(element) {
this.element = element
}
|
@author Faiyaz Shaikh <[email protected]>
GitHub repo: https://github.com/yTakkar/React-Instagram-Clone-2.0
A library for DOM manipulation (inspired by jQuery) which also enables to chain mathods.
|
constructor
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/API/DOM.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/API/DOM.js
|
MIT
|
MockDataElement = () => {
let dataElement = document.createElement('div')
dataElement.setAttribute('class', 'data')
dataElement.setAttribute('data-session', '24')
dataElement.setAttribute('data-username', 'takkar')
dataElement.setAttribute('data-email-verified', 'no')
dataElement.setAttribute('data-isadmin', 'false')
document.body.prepend(dataElement)
return dataElement
}
|
Creates a fake div.data with required data attributes for use in tests.
@returns {HTMLDivElement} dataElementDIV
|
MockDataElement
|
javascript
|
yTakkar/React-Instagram-Clone-2.0
|
src/utils/__mocks__/mock-dataElement.js
|
https://github.com/yTakkar/React-Instagram-Clone-2.0/blob/master/src/utils/__mocks__/mock-dataElement.js
|
MIT
|
function isFunction(functionToCheck) {
var getType = {};
return functionToCheck && getType.toString.call(functionToCheck) === '[object Function]';
}
|
Check if the given variable is a function
@method
@memberof Popper.Utils
@argument {Any} functionToCheck - variable to check
@returns {Boolean} answer to: is a function?
|
isFunction
|
javascript
|
gxtrobot/bustag
|
bustag/app/static/js/bootstrap.bundle.js
|
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
|
MIT
|
function getStyleComputedProperty(element, property) {
if (element.nodeType !== 1) {
return [];
}
// NOTE: 1 DOM access here
var window = element.ownerDocument.defaultView;
var css = window.getComputedStyle(element, null);
return property ? css[property] : css;
}
|
Get CSS computed property of the given element
@method
@memberof Popper.Utils
@argument {Eement} element
@argument {String} property
|
getStyleComputedProperty
|
javascript
|
gxtrobot/bustag
|
bustag/app/static/js/bootstrap.bundle.js
|
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
|
MIT
|
function getParentNode(element) {
if (element.nodeName === 'HTML') {
return element;
}
return element.parentNode || element.host;
}
|
Returns the parentNode or the host of the element
@method
@memberof Popper.Utils
@argument {Element} element
@returns {Element} parent
|
getParentNode
|
javascript
|
gxtrobot/bustag
|
bustag/app/static/js/bootstrap.bundle.js
|
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
|
MIT
|
function getScrollParent(element) {
// Return body, `getScroll` will take care to get the correct `scrollTop` from it
if (!element) {
return document.body;
}
switch (element.nodeName) {
case 'HTML':
case 'BODY':
return element.ownerDocument.body;
case '#document':
return element.body;
}
// Firefox want us to check `-x` and `-y` variations as well
var _getStyleComputedProp = getStyleComputedProperty(element),
overflow = _getStyleComputedProp.overflow,
overflowX = _getStyleComputedProp.overflowX,
overflowY = _getStyleComputedProp.overflowY;
if (/(auto|scroll|overlay)/.test(overflow + overflowY + overflowX)) {
return element;
}
return getScrollParent(getParentNode(element));
}
|
Returns the scrolling parent of the given element
@method
@memberof Popper.Utils
@argument {Element} element
@returns {Element} scroll parent
|
getScrollParent
|
javascript
|
gxtrobot/bustag
|
bustag/app/static/js/bootstrap.bundle.js
|
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
|
MIT
|
function isIE(version) {
if (version === 11) {
return isIE11;
}
if (version === 10) {
return isIE10;
}
return isIE11 || isIE10;
}
|
Determines if the browser is Internet Explorer
@method
@memberof Popper.Utils
@param {Number} version to check
@returns {Boolean} isIE
|
isIE
|
javascript
|
gxtrobot/bustag
|
bustag/app/static/js/bootstrap.bundle.js
|
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
|
MIT
|
function getOffsetParent(element) {
if (!element) {
return document.documentElement;
}
var noOffsetParent = isIE(10) ? document.body : null;
// NOTE: 1 DOM access here
var offsetParent = element.offsetParent || null;
// Skip hidden elements which don't have an offsetParent
while (offsetParent === noOffsetParent && element.nextElementSibling) {
offsetParent = (element = element.nextElementSibling).offsetParent;
}
var nodeName = offsetParent && offsetParent.nodeName;
if (!nodeName || nodeName === 'BODY' || nodeName === 'HTML') {
return element ? element.ownerDocument.documentElement : document.documentElement;
}
// .offsetParent will return the closest TH, TD or TABLE in case
// no offsetParent is present, I hate this job...
if (['TH', 'TD', 'TABLE'].indexOf(offsetParent.nodeName) !== -1 && getStyleComputedProperty(offsetParent, 'position') === 'static') {
return getOffsetParent(offsetParent);
}
return offsetParent;
}
|
Returns the offset parent of the given element
@method
@memberof Popper.Utils
@argument {Element} element
@returns {Element} offset parent
|
getOffsetParent
|
javascript
|
gxtrobot/bustag
|
bustag/app/static/js/bootstrap.bundle.js
|
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
|
MIT
|
function getRoot(node) {
if (node.parentNode !== null) {
return getRoot(node.parentNode);
}
return node;
}
|
Finds the root node (document, shadowDOM root) of the given element
@method
@memberof Popper.Utils
@argument {Element} node
@returns {Element} root node
|
getRoot
|
javascript
|
gxtrobot/bustag
|
bustag/app/static/js/bootstrap.bundle.js
|
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
|
MIT
|
function findCommonOffsetParent(element1, element2) {
// This check is needed to avoid errors in case one of the elements isn't defined for any reason
if (!element1 || !element1.nodeType || !element2 || !element2.nodeType) {
return document.documentElement;
}
// Here we make sure to give as "start" the element that comes first in the DOM
var order = element1.compareDocumentPosition(element2) & Node.DOCUMENT_POSITION_FOLLOWING;
var start = order ? element1 : element2;
var end = order ? element2 : element1;
// Get common ancestor container
var range = document.createRange();
range.setStart(start, 0);
range.setEnd(end, 0);
var commonAncestorContainer = range.commonAncestorContainer;
// Both nodes are inside #document
if (element1 !== commonAncestorContainer && element2 !== commonAncestorContainer || start.contains(end)) {
if (isOffsetContainer(commonAncestorContainer)) {
return commonAncestorContainer;
}
return getOffsetParent(commonAncestorContainer);
}
// one of the nodes is inside shadowDOM, find which one
var element1root = getRoot(element1);
if (element1root.host) {
return findCommonOffsetParent(element1root.host, element2);
} else {
return findCommonOffsetParent(element1, getRoot(element2).host);
}
}
|
Finds the offset parent common to the two provided nodes
@method
@memberof Popper.Utils
@argument {Element} element1
@argument {Element} element2
@returns {Element} common offset parent
|
findCommonOffsetParent
|
javascript
|
gxtrobot/bustag
|
bustag/app/static/js/bootstrap.bundle.js
|
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
|
MIT
|
function getScroll(element) {
var side = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'top';
var upperSide = side === 'top' ? 'scrollTop' : 'scrollLeft';
var nodeName = element.nodeName;
if (nodeName === 'BODY' || nodeName === 'HTML') {
var html = element.ownerDocument.documentElement;
var scrollingElement = element.ownerDocument.scrollingElement || html;
return scrollingElement[upperSide];
}
return element[upperSide];
}
|
Gets the scroll value of the given element in the given side (top and left)
@method
@memberof Popper.Utils
@argument {Element} element
@argument {String} side `top` or `left`
@returns {number} amount of scrolled pixels
|
getScroll
|
javascript
|
gxtrobot/bustag
|
bustag/app/static/js/bootstrap.bundle.js
|
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
|
MIT
|
function getClientRect(offsets) {
return _extends({}, offsets, {
right: offsets.left + offsets.width,
bottom: offsets.top + offsets.height
});
}
|
Given element offsets, generate an output similar to getBoundingClientRect
@method
@memberof Popper.Utils
@argument {Object} offsets
@returns {Object} ClientRect like output
|
getClientRect
|
javascript
|
gxtrobot/bustag
|
bustag/app/static/js/bootstrap.bundle.js
|
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
|
MIT
|
function getBoundingClientRect(element) {
var rect = {};
// IE10 10 FIX: Please, don't ask, the element isn't
// considered in DOM in some circumstances...
// This isn't reproducible in IE10 compatibility mode of IE11
try {
if (isIE(10)) {
rect = element.getBoundingClientRect();
var scrollTop = getScroll(element, 'top');
var scrollLeft = getScroll(element, 'left');
rect.top += scrollTop;
rect.left += scrollLeft;
rect.bottom += scrollTop;
rect.right += scrollLeft;
} else {
rect = element.getBoundingClientRect();
}
} catch (e) {}
var result = {
left: rect.left,
top: rect.top,
width: rect.right - rect.left,
height: rect.bottom - rect.top
};
// subtract scrollbar size from sizes
var sizes = element.nodeName === 'HTML' ? getWindowSizes(element.ownerDocument) : {};
var width = sizes.width || element.clientWidth || result.right - result.left;
var height = sizes.height || element.clientHeight || result.bottom - result.top;
var horizScrollbar = element.offsetWidth - width;
var vertScrollbar = element.offsetHeight - height;
// if an hypothetical scrollbar is detected, we must be sure it's not a `border`
// we make this check conditional for performance reasons
if (horizScrollbar || vertScrollbar) {
var styles = getStyleComputedProperty(element);
horizScrollbar -= getBordersSize(styles, 'x');
vertScrollbar -= getBordersSize(styles, 'y');
result.width -= horizScrollbar;
result.height -= vertScrollbar;
}
return getClientRect(result);
}
|
Get bounding client rect of given element
@method
@memberof Popper.Utils
@param {HTMLElement} element
@return {Object} client rect
|
getBoundingClientRect
|
javascript
|
gxtrobot/bustag
|
bustag/app/static/js/bootstrap.bundle.js
|
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
|
MIT
|
function isFixed(element) {
var nodeName = element.nodeName;
if (nodeName === 'BODY' || nodeName === 'HTML') {
return false;
}
if (getStyleComputedProperty(element, 'position') === 'fixed') {
return true;
}
var parentNode = getParentNode(element);
if (!parentNode) {
return false;
}
return isFixed(parentNode);
}
|
Check if the given element is fixed or is inside a fixed parent
@method
@memberof Popper.Utils
@argument {Element} element
@argument {Element} customContainer
@returns {Boolean} answer to "isFixed?"
|
isFixed
|
javascript
|
gxtrobot/bustag
|
bustag/app/static/js/bootstrap.bundle.js
|
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
|
MIT
|
function getFixedPositionOffsetParent(element) {
// This check is needed to avoid errors in case one of the elements isn't defined for any reason
if (!element || !element.parentElement || isIE()) {
return document.documentElement;
}
var el = element.parentElement;
while (el && getStyleComputedProperty(el, 'transform') === 'none') {
el = el.parentElement;
}
return el || document.documentElement;
}
|
Finds the first parent of an element that has a transformed property defined
@method
@memberof Popper.Utils
@argument {Element} element
@returns {Element} first transformed parent or documentElement
|
getFixedPositionOffsetParent
|
javascript
|
gxtrobot/bustag
|
bustag/app/static/js/bootstrap.bundle.js
|
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
|
MIT
|
function computeAutoPlacement(placement, refRect, popper, reference, boundariesElement) {
var padding = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0;
if (placement.indexOf('auto') === -1) {
return placement;
}
var boundaries = getBoundaries(popper, reference, padding, boundariesElement);
var rects = {
top: {
width: boundaries.width,
height: refRect.top - boundaries.top
},
right: {
width: boundaries.right - refRect.right,
height: boundaries.height
},
bottom: {
width: boundaries.width,
height: boundaries.bottom - refRect.bottom
},
left: {
width: refRect.left - boundaries.left,
height: boundaries.height
}
};
var sortedAreas = Object.keys(rects).map(function (key) {
return _extends({
key: key
}, rects[key], {
area: getArea(rects[key])
});
}).sort(function (a, b) {
return b.area - a.area;
});
var filteredAreas = sortedAreas.filter(function (_ref2) {
var width = _ref2.width,
height = _ref2.height;
return width >= popper.clientWidth && height >= popper.clientHeight;
});
var computedPlacement = filteredAreas.length > 0 ? filteredAreas[0].key : sortedAreas[0].key;
var variation = placement.split('-')[1];
return computedPlacement + (variation ? '-' + variation : '');
}
|
Utility used to transform the `auto` placement to the placement with more
available space.
@method
@memberof Popper.Utils
@argument {Object} data - The data object generated by update method
@argument {Object} options - Modifiers configuration and options
@returns {Object} The data object, properly modified
|
computeAutoPlacement
|
javascript
|
gxtrobot/bustag
|
bustag/app/static/js/bootstrap.bundle.js
|
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
|
MIT
|
function getReferenceOffsets(state, popper, reference) {
var fixedPosition = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
var commonOffsetParent = fixedPosition ? getFixedPositionOffsetParent(popper) : findCommonOffsetParent(popper, reference);
return getOffsetRectRelativeToArbitraryNode(reference, commonOffsetParent, fixedPosition);
}
|
Get offsets to the reference element
@method
@memberof Popper.Utils
@param {Object} state
@param {Element} popper - the popper element
@param {Element} reference - the reference element (the popper will be relative to this)
@param {Element} fixedPosition - is in fixed position mode
@returns {Object} An object containing the offsets which will be applied to the popper
|
getReferenceOffsets
|
javascript
|
gxtrobot/bustag
|
bustag/app/static/js/bootstrap.bundle.js
|
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
|
MIT
|
function getOuterSizes(element) {
var window = element.ownerDocument.defaultView;
var styles = window.getComputedStyle(element);
var x = parseFloat(styles.marginTop || 0) + parseFloat(styles.marginBottom || 0);
var y = parseFloat(styles.marginLeft || 0) + parseFloat(styles.marginRight || 0);
var result = {
width: element.offsetWidth + y,
height: element.offsetHeight + x
};
return result;
}
|
Get the outer sizes of the given element (offset size + margins)
@method
@memberof Popper.Utils
@argument {Element} element
@returns {Object} object containing width and height properties
|
getOuterSizes
|
javascript
|
gxtrobot/bustag
|
bustag/app/static/js/bootstrap.bundle.js
|
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
|
MIT
|
function getOppositePlacement(placement) {
var hash = { left: 'right', right: 'left', bottom: 'top', top: 'bottom' };
return placement.replace(/left|right|bottom|top/g, function (matched) {
return hash[matched];
});
}
|
Get the opposite placement of the given one
@method
@memberof Popper.Utils
@argument {String} placement
@returns {String} flipped placement
|
getOppositePlacement
|
javascript
|
gxtrobot/bustag
|
bustag/app/static/js/bootstrap.bundle.js
|
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
|
MIT
|
function getPopperOffsets(popper, referenceOffsets, placement) {
placement = placement.split('-')[0];
// Get popper node sizes
var popperRect = getOuterSizes(popper);
// Add position, width and height to our offsets object
var popperOffsets = {
width: popperRect.width,
height: popperRect.height
};
// depending by the popper placement we have to compute its offsets slightly differently
var isHoriz = ['right', 'left'].indexOf(placement) !== -1;
var mainSide = isHoriz ? 'top' : 'left';
var secondarySide = isHoriz ? 'left' : 'top';
var measurement = isHoriz ? 'height' : 'width';
var secondaryMeasurement = !isHoriz ? 'height' : 'width';
popperOffsets[mainSide] = referenceOffsets[mainSide] + referenceOffsets[measurement] / 2 - popperRect[measurement] / 2;
if (placement === secondarySide) {
popperOffsets[secondarySide] = referenceOffsets[secondarySide] - popperRect[secondaryMeasurement];
} else {
popperOffsets[secondarySide] = referenceOffsets[getOppositePlacement(secondarySide)];
}
return popperOffsets;
}
|
Get offsets to the popper
@method
@memberof Popper.Utils
@param {Object} position - CSS position the Popper will get applied
@param {HTMLElement} popper - the popper element
@param {Object} referenceOffsets - the reference offsets (the popper will be relative to this)
@param {String} placement - one of the valid placement options
@returns {Object} popperOffsets - An object containing the offsets which will be applied to the popper
|
getPopperOffsets
|
javascript
|
gxtrobot/bustag
|
bustag/app/static/js/bootstrap.bundle.js
|
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
|
MIT
|
function find(arr, check) {
// use native find if supported
if (Array.prototype.find) {
return arr.find(check);
}
// use `filter` to obtain the same behavior of `find`
return arr.filter(check)[0];
}
|
Mimics the `find` method of Array
@method
@memberof Popper.Utils
@argument {Array} arr
@argument prop
@argument value
@returns index or -1
|
find
|
javascript
|
gxtrobot/bustag
|
bustag/app/static/js/bootstrap.bundle.js
|
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
|
MIT
|
function findIndex(arr, prop, value) {
// use native findIndex if supported
if (Array.prototype.findIndex) {
return arr.findIndex(function (cur) {
return cur[prop] === value;
});
}
// use `find` + `indexOf` if `findIndex` isn't supported
var match = find(arr, function (obj) {
return obj[prop] === value;
});
return arr.indexOf(match);
}
|
Return the index of the matching object
@method
@memberof Popper.Utils
@argument {Array} arr
@argument prop
@argument value
@returns index or -1
|
findIndex
|
javascript
|
gxtrobot/bustag
|
bustag/app/static/js/bootstrap.bundle.js
|
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
|
MIT
|
function runModifiers(modifiers, data, ends) {
var modifiersToRun = ends === undefined ? modifiers : modifiers.slice(0, findIndex(modifiers, 'name', ends));
modifiersToRun.forEach(function (modifier) {
if (modifier['function']) {
// eslint-disable-line dot-notation
console.warn('`modifier.function` is deprecated, use `modifier.fn`!');
}
var fn = modifier['function'] || modifier.fn; // eslint-disable-line dot-notation
if (modifier.enabled && isFunction(fn)) {
// Add properties to offsets to make them a complete clientRect object
// we do this before each modifier to make sure the previous one doesn't
// mess with these values
data.offsets.popper = getClientRect(data.offsets.popper);
data.offsets.reference = getClientRect(data.offsets.reference);
data = fn(data, modifier);
}
});
return data;
}
|
Loop trough the list of modifiers and run them in order,
each of them will then edit the data object.
@method
@memberof Popper.Utils
@param {dataObject} data
@param {Array} modifiers
@param {String} ends - Optional modifier name used as stopper
@returns {dataObject}
|
runModifiers
|
javascript
|
gxtrobot/bustag
|
bustag/app/static/js/bootstrap.bundle.js
|
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
|
MIT
|
function update() {
// if popper is destroyed, don't perform any further update
if (this.state.isDestroyed) {
return;
}
var data = {
instance: this,
styles: {},
arrowStyles: {},
attributes: {},
flipped: false,
offsets: {}
};
// compute reference element offsets
data.offsets.reference = getReferenceOffsets(this.state, this.popper, this.reference, this.options.positionFixed);
// compute auto placement, store placement inside the data object,
// modifiers will be able to edit `placement` if needed
// and refer to originalPlacement to know the original value
data.placement = computeAutoPlacement(this.options.placement, data.offsets.reference, this.popper, this.reference, this.options.modifiers.flip.boundariesElement, this.options.modifiers.flip.padding);
// store the computed placement inside `originalPlacement`
data.originalPlacement = data.placement;
data.positionFixed = this.options.positionFixed;
// compute the popper offsets
data.offsets.popper = getPopperOffsets(this.popper, data.offsets.reference, data.placement);
data.offsets.popper.position = this.options.positionFixed ? 'fixed' : 'absolute';
// run the modifiers
data = runModifiers(this.modifiers, data);
// the first `update` will call `onCreate` callback
// the other ones will call `onUpdate` callback
if (!this.state.isCreated) {
this.state.isCreated = true;
this.options.onCreate(data);
} else {
this.options.onUpdate(data);
}
}
|
Updates the position of the popper, computing the new offsets and applying
the new style.<br />
Prefer `scheduleUpdate` over `update` because of performance reasons.
@method
@memberof Popper
|
update
|
javascript
|
gxtrobot/bustag
|
bustag/app/static/js/bootstrap.bundle.js
|
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
|
MIT
|
function isModifierEnabled(modifiers, modifierName) {
return modifiers.some(function (_ref) {
var name = _ref.name,
enabled = _ref.enabled;
return enabled && name === modifierName;
});
}
|
Helper used to know if the given modifier is enabled.
@method
@memberof Popper.Utils
@returns {Boolean}
|
isModifierEnabled
|
javascript
|
gxtrobot/bustag
|
bustag/app/static/js/bootstrap.bundle.js
|
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
|
MIT
|
function getSupportedPropertyName(property) {
var prefixes = [false, 'ms', 'Webkit', 'Moz', 'O'];
var upperProp = property.charAt(0).toUpperCase() + property.slice(1);
for (var i = 0; i < prefixes.length; i++) {
var prefix = prefixes[i];
var toCheck = prefix ? '' + prefix + upperProp : property;
if (typeof document.body.style[toCheck] !== 'undefined') {
return toCheck;
}
}
return null;
}
|
Get the prefixed supported property name
@method
@memberof Popper.Utils
@argument {String} property (camelCase)
@returns {String} prefixed property (camelCase or PascalCase, depending on the vendor prefix)
|
getSupportedPropertyName
|
javascript
|
gxtrobot/bustag
|
bustag/app/static/js/bootstrap.bundle.js
|
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
|
MIT
|
function destroy() {
this.state.isDestroyed = true;
// touch DOM only if `applyStyle` modifier is enabled
if (isModifierEnabled(this.modifiers, 'applyStyle')) {
this.popper.removeAttribute('x-placement');
this.popper.style.position = '';
this.popper.style.top = '';
this.popper.style.left = '';
this.popper.style.right = '';
this.popper.style.bottom = '';
this.popper.style.willChange = '';
this.popper.style[getSupportedPropertyName('transform')] = '';
}
this.disableEventListeners();
// remove the popper if user explicity asked for the deletion on destroy
// do not use `remove` because IE11 doesn't support it
if (this.options.removeOnDestroy) {
this.popper.parentNode.removeChild(this.popper);
}
return this;
}
|
Destroys the popper.
@method
@memberof Popper
|
destroy
|
javascript
|
gxtrobot/bustag
|
bustag/app/static/js/bootstrap.bundle.js
|
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
|
MIT
|
function getWindow(element) {
var ownerDocument = element.ownerDocument;
return ownerDocument ? ownerDocument.defaultView : window;
}
|
Get the window associated with the element
@argument {Element} element
@returns {Window}
|
getWindow
|
javascript
|
gxtrobot/bustag
|
bustag/app/static/js/bootstrap.bundle.js
|
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
|
MIT
|
function setupEventListeners(reference, options, state, updateBound) {
// Resize event listener on window
state.updateBound = updateBound;
getWindow(reference).addEventListener('resize', state.updateBound, { passive: true });
// Scroll event listener on scroll parents
var scrollElement = getScrollParent(reference);
attachToScrollParents(scrollElement, 'scroll', state.updateBound, state.scrollParents);
state.scrollElement = scrollElement;
state.eventsEnabled = true;
return state;
}
|
Setup needed event listeners used to update the popper position
@method
@memberof Popper.Utils
@private
|
setupEventListeners
|
javascript
|
gxtrobot/bustag
|
bustag/app/static/js/bootstrap.bundle.js
|
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
|
MIT
|
function enableEventListeners() {
if (!this.state.eventsEnabled) {
this.state = setupEventListeners(this.reference, this.options, this.state, this.scheduleUpdate);
}
}
|
It will add resize/scroll events and start recalculating
position of the popper element when they are triggered.
@method
@memberof Popper
|
enableEventListeners
|
javascript
|
gxtrobot/bustag
|
bustag/app/static/js/bootstrap.bundle.js
|
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
|
MIT
|
function removeEventListeners(reference, state) {
// Remove resize event listener on window
getWindow(reference).removeEventListener('resize', state.updateBound);
// Remove scroll event listener on scroll parents
state.scrollParents.forEach(function (target) {
target.removeEventListener('scroll', state.updateBound);
});
// Reset state
state.updateBound = null;
state.scrollParents = [];
state.scrollElement = null;
state.eventsEnabled = false;
return state;
}
|
Remove event listeners used to update the popper position
@method
@memberof Popper.Utils
@private
|
removeEventListeners
|
javascript
|
gxtrobot/bustag
|
bustag/app/static/js/bootstrap.bundle.js
|
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
|
MIT
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.