diff --git a/src/components/components.module.ts b/src/components/components.module.ts index 4c50dea20..2e834aa3b 100644 --- a/src/components/components.module.ts +++ b/src/components/components.module.ts @@ -41,7 +41,8 @@ import { CoreNavBarButtonsComponent } from './navbar-buttons/navbar-buttons'; import { CoreDynamicComponent } from './dynamic-component/dynamic-component'; import { CoreSendMessageFormComponent } from './send-message-form/send-message-form'; import { CoreTimerComponent } from './timer/timer'; -import { CoreRecaptchaComponent, CoreRecaptchaModalComponent } from './recaptcha/recaptcha'; +import { CoreRecaptchaComponent } from './recaptcha/recaptcha'; +import { CoreRecaptchaModalComponent } from './recaptcha/recaptchamodal'; import { CoreNavigationBarComponent } from './navigation-bar/navigation-bar'; import { CoreAttachmentsComponent } from './attachments/attachments'; diff --git a/src/components/recaptcha/recaptcha.ts b/src/components/recaptcha/recaptcha.ts index d9ccfa674..f95152044 100644 --- a/src/components/recaptcha/recaptcha.ts +++ b/src/components/recaptcha/recaptcha.ts @@ -13,34 +13,29 @@ // limitations under the License. import { Component, Input } from '@angular/core'; -import { ModalController, ViewController, NavParams } from 'ionic-angular'; +import { ModalController } from 'ionic-angular'; import { CoreSitesProvider } from '@providers/sites'; import { CoreLangProvider } from '@providers/lang'; import { CoreTextUtilsProvider } from '@providers/utils/text'; +import { CoreRecaptchaModalComponent } from './recaptchamodal'; /** - * Directive to display a reCaptcha. - * - * Accepts the following attributes: - * @param {any} model The model where to store the recaptcha response. - * @param {string} publicKey The site public key. - * @param {string} [modelValueName] Name of the model property where to store the response. Defaults to 'recaptcharesponse'. - * @param {string} [siteUrl] The site URL. If not defined, current site. + * Component that allows answering a recaptcha. */ @Component({ selector: 'core-recaptcha', templateUrl: 'recaptcha.html' }) export class CoreRecaptchaComponent { + @Input() model: any; // The model where to store the recaptcha response. + @Input() publicKey: string; // The site public key. + @Input() modelValueName = 'recaptcharesponse'; // Name of the model property where to store the response. + @Input() siteUrl?: string; // The site URL. If not defined, current site. + expired = false; protected lang: string; - @Input() model: any; - @Input() publicKey: string; - @Input() modelValueName = 'recaptcharesponse'; - @Input() siteUrl?: string; - constructor(private sitesProvider: CoreSitesProvider, langProvider: CoreLangProvider, private textUtils: CoreTextUtilsProvider, private modalCtrl: ModalController) { @@ -75,53 +70,3 @@ export class CoreRecaptchaComponent { modal.present(); } } - -@Component({ - selector: 'core-recaptcha-modal', - templateUrl: 'recaptchamodal.html' -}) -export class CoreRecaptchaModalComponent { - - expired = false; - value = ''; - src: string; - - constructor(protected viewCtrl: ViewController, params: NavParams) { - this.src = params.get('src'); - } - - /** - * Close modal. - */ - closeModal(): void { - this.viewCtrl.dismiss({ - expired: this.expired, - value: this.value - }); - } - - /** - * The iframe with the recaptcha was loaded. - * - * @param {HTMLIFrameElement} iframe Iframe element. - */ - loaded(iframe: HTMLIFrameElement): void { - // Search the iframe content. - const contentWindow = iframe && iframe.contentWindow; - - if (contentWindow) { - // Set the callbacks we're interested in. - contentWindow['recaptchacallback'] = (value): void => { - this.expired = false; - this.value = value; - this.closeModal(); - }; - - contentWindow['recaptchaexpiredcallback'] = (): void => { - // Verification expired. Check the checkbox again. - this.expired = true; - this.value = ''; - }; - } - } -} diff --git a/src/components/recaptcha/recaptchamodal.ts b/src/components/recaptcha/recaptchamodal.ts new file mode 100644 index 000000000..9423b211c --- /dev/null +++ b/src/components/recaptcha/recaptchamodal.ts @@ -0,0 +1,68 @@ +// (C) Copyright 2015 Martin Dougiamas +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { Component } from '@angular/core'; +import { ViewController, NavParams } from 'ionic-angular'; + +/** + * Component to display a the recaptcha in a modal. + */ +@Component({ + selector: 'core-recaptcha-modal', + templateUrl: 'recaptchamodal.html' +}) +export class CoreRecaptchaModalComponent { + expired = false; + value = ''; + src: string; + + constructor(protected viewCtrl: ViewController, params: NavParams) { + this.src = params.get('src'); + } + + /** + * Close modal. + */ + closeModal(): void { + this.viewCtrl.dismiss({ + expired: this.expired, + value: this.value + }); + } + + /** + * The iframe with the recaptcha was loaded. + * + * @param {HTMLIFrameElement} iframe Iframe element. + */ + loaded(iframe: HTMLIFrameElement): void { + // Search the iframe content. + const contentWindow = iframe && iframe.contentWindow; + + if (contentWindow) { + // Set the callbacks we're interested in. + contentWindow['recaptchacallback'] = (value): void => { + this.expired = false; + this.value = value; + this.closeModal(); + }; + + contentWindow['recaptchaexpiredcallback'] = (): void => { + // Verification expired. Check the checkbox again. + this.expired = true; + this.value = ''; + }; + } + } +}