wejsv2old-plugin-cdp-profile
Version:
We.js plugin wejsv2old-plugin-cdp-profile
91 lines (79 loc) • 4.48 kB
JavaScript
App.MoreAboutYouMixin = Ember.Mixin.create({
textFieldLimit: 140,
countCharacters: function () {
// body...
if (!this.get('model.biography')) return this.set('textFieldCount', this.get('textFieldLimit'));
var diff = this.get('textFieldLimit') - this.get('model.biography').length;
if (diff > -1){
this.set('textFieldCount', diff);
} else {
this.setProperties({
textFieldCount: 0,
'model.biography': this.get('model.biography').substr(0, 140)
})
}
}.observes('model.biography'),
checkFacebookUrl: function(){
Ember.run.scheduleOnce('afterRender', this, function() {
if ( Ember.isEmpty(this.get('fbprofile')) ) return this.set('fbprofileErr', false);
var fbregex = /^(https?:\/\/)?(www\.)?facebook.com\/[a-zA-Z0-9(\.\?)?]/;
if ( !fbregex.test(this.get('fbprofile')) ) return this.set('fbprofileErr', true);
this.set('fbprofileErr', false);
});
}.observes('model.fbprofile'),
checkInstagramUrl: function(){
Ember.run.scheduleOnce('afterRender', this, function() {
if ( Ember.isEmpty(this.get('instprofile')) ) return this.set('instprofileErr', false);
var instprofileregex = /^(http?:\/\/)?(www\.)?instagram.com\/[a-zA-Z0-9(\.\?)?]/;
if ( !instprofileregex.test(this.get('instprofile')) ) return this.set('instprofileErr', true);
this.set('instprofileErr', false);
});
}.observes('model.instprofile'),
checkLikedinUrl: function(){
Ember.run.scheduleOnce('afterRender', this, function() {
if ( Ember.isEmpty(this.get('lkinprofile')) ) return this.set('lkinprofileErr', false);
var lkinprofileregex = /^(http(s)?:\/\/)?([\w]+\.)?linkedin\.com\/(pub|in|profile)\//;
if ( !lkinprofileregex.test(this.get('lkinprofile')) ) return this.set('lkinprofileErr', true);
this.set('lkinprofileErr', false);
});
}.observes('model.lkinprofile'),
checkTwitterUrl: function(){
Ember.run.scheduleOnce('afterRender', this, function() {
if ( Ember.isEmpty(this.get('twitprofile')) ) return this.set('twitprofileErr', false);
var twitprofileregex = /^(https?:\/\/)?(www\.)?twitter.com\/[a-zA-Z0-9(\.\?)?]/;
if ( !twitprofileregex.test(this.get('twitprofile')) ) return this.set('twitprofileErr', true);
this.set('twitprofileErr', false);
});
}.observes('model.twitprofile'),
checkYoutubeUrl: function(){
Ember.run.scheduleOnce('afterRender', this, function() {
if ( Ember.isEmpty(this.get('youtbprofile')) ) return this.set('youtbprofileErr', false);
var youtbprofileregex = /^(https?:\/\/)?(www\.)?youtube.com\/user\/[a-zA-Z0-9(\.\?)?]/;
if ( !youtbprofileregex.test(this.get('youtbprofile')) ) return this.set('youtbprofileErr', true);
this.set('youtbprofileErr', false);
});
}.observes('model.youtbprofile'),
checkSiteskUrl: function(){
Ember.run.scheduleOnce('afterRender', this, function() {
if ( Ember.isEmpty(this.get('otherprofile')) ) return this.set('otherprofileErr', false);
var otherprofileregex = /^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/i;
if ( !otherprofileregex.test(this.get('otherprofile')) ) return this.set('otherprofileErr', true);
this.set('otherprofileErr', false);
});
}.observes('model.otherprofile'),
checkLatteskUrl: function (){
Ember.run.scheduleOnce('afterRender', this, function() {
if ( Ember.isEmpty(this.get('lattes')) ) return this.set('lattesErr', false);
var lattesregex = /^(https?:\/\/)?(www\.)?lattes.cnpq.br\/[0-9]/;
if ( !lattesregex.test(this.get('lattes')) ) return this.set('lattesErr', true);
this.set('lattesErr', false);
});
}.observes('model.lattes'),
moreAboutYouInvalid: function (){
var bool = Boolean( this.get('fbprofileErr') || this.get('instprofileErr') ||
this.get('lkinprofileErr') || this.get('twitprofileErr') ||
this.get('youtbprofileErr') || this.get('otherprofileErr') ||
this.get('lattesErr'));
return bool;
}.property('fbprofileErr', 'instprofileErr', 'lkinprofileErr', 'twitprofileErr', 'youtbprofileErr', 'otherprofileErr', 'lattesErr')
});